From 76a47652fac584d05d2955bdd84e1cf87d5fa207 Mon Sep 17 00:00:00 2001 From: Danila Katalshov <56929384+ADanMan@users.noreply.github.com> Date: Mon, 23 Nov 2026 10:07:30 +0300 Subject: [PATCH] fix(tools): count todos without a status as pending (#8276) * fix(tools): count todos without a status as pending * fix(tools): count null todo statuses as pending * test: stabilize PII redaction scaling check --------- Co-authored-by: Willem Jiang --- README.md | 2 +- .../packages/harness/deerflow/tools/AGENTS.md | 5 ++++ .../tools/builtins/inspect_run_status_tool.py | 2 +- backend/tests/test_inspect_run_status.py | 12 ++++++-- .../tests/test_pii_redaction_middleware.py | 29 ++++++++++--------- docs/guide/context.md | 3 ++ 6 files changed, 35 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index b780af68e9..b55d547d32 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,7 @@ Each guide is the full reference for its topic. Open the one you need. | Sub-agents, task delegation and optional SQLite checkpoint history | [Sub-Agents](docs/guide/subagents.md), [Tool restrictions](docs/guide/subagents.md#tool-restrictions) | | Agent teams, SQLite/PostgreSQL persistence and shutdown behavior | [Agent teams extension](examples/deerflow-extension-agent-teams/README.md) | | Long-term memory | [Long-Term Memory](docs/guide/memory.md) | -| Session goals, context compaction, task notes, evidence-based decisions | [Context, Goals and Agent Decisions](docs/guide/context.md) | +| Session goals, context compaction, todo counters, task notes, evidence-based decisions | [Context, Goals and Agent Decisions](docs/guide/context.md) | | Private knowledge retrieval (RAGFlow) | [Private Knowledge Retrieval](docs/guide/knowledge-retrieval.md) | | Agentic browser control | [Agentic Browser Control](docs/guide/browser-control.md) | | Projects, instructions, document shelf | [Projects](docs/guide/projects.md) | diff --git a/backend/packages/harness/deerflow/tools/AGENTS.md b/backend/packages/harness/deerflow/tools/AGENTS.md index d97e2fb694..81a1aa7d28 100644 --- a/backend/packages/harness/deerflow/tools/AGENTS.md +++ b/backend/packages/harness/deerflow/tools/AGENTS.md @@ -93,6 +93,11 @@ make test-blocking-io `PATHEXT` lookup on Windows, so a bare npm launcher is not found. - **Results contain message chunks only.** Thought chunks stay internal. +## Run inspection + +`inspect_run_status` counts todo mappings with missing or null status as +pending. Keep the snapshot free of message and todo text. + ## Web search recency `time_range` maps to a different parameter for each provider, and omitting it diff --git a/backend/packages/harness/deerflow/tools/builtins/inspect_run_status_tool.py b/backend/packages/harness/deerflow/tools/builtins/inspect_run_status_tool.py index b002ba2a3f..93fbb2c23e 100644 --- a/backend/packages/harness/deerflow/tools/builtins/inspect_run_status_tool.py +++ b/backend/packages/harness/deerflow/tools/builtins/inspect_run_status_tool.py @@ -80,7 +80,7 @@ def snapshot_run_status(state: Mapping[str, Any], context: Mapping[str, Any], *, for item in todos: if not isinstance(item, Mapping): continue - if item.get("status") == "pending": + if item.get("status") in (None, "pending"): pending += 1 elif item.get("status") == "in_progress": in_progress += 1 diff --git a/backend/tests/test_inspect_run_status.py b/backend/tests/test_inspect_run_status.py index 98ac9c509c..7e6d7ee668 100644 --- a/backend/tests/test_inspect_run_status.py +++ b/backend/tests/test_inspect_run_status.py @@ -3,6 +3,7 @@ import asyncio import json +import pytest from langchain_core.messages import AIMessage, HumanMessage, ToolMessage from deerflow.runtime.context_keys import CURRENT_RUN_PRE_EXISTING_MESSAGE_IDS_KEY @@ -101,7 +102,12 @@ def test_bound_tool_has_no_model_supplied_arguments(): assert tool.args == {} -def test_tool_reads_live_graph_state_without_exposing_message_content(): +@pytest.mark.parametrize( + "todo", + [{"content": "private task"}, {"content": "private task", "status": None}, {"content": "private task", "status": "pending"}], + ids=["missing-status", "null-status", "pending-status"], +) +def test_tool_reads_live_graph_state_without_exposing_message_content(todo): from langchain.agents import create_agent from langchain_core.language_models.fake_chat_models import GenericFakeChatModel @@ -122,7 +128,7 @@ def test_tool_reads_live_graph_state_without_exposing_message_content(): graph = create_agent(model=model, tools=[build_inspect_run_status_tool(context_window=100)], state_schema=ThreadState) result = asyncio.run( graph.ainvoke( - {"messages": [HumanMessage(content="secret request")]}, + {"messages": [HumanMessage(content="secret request")], "todos": [todo]}, {"configurable": {"thread_id": "status-test"}}, context={CURRENT_RUN_PRE_EXISTING_MESSAGE_IDS_KEY: frozenset()}, ) @@ -133,6 +139,8 @@ def test_tool_reads_live_graph_state_without_exposing_message_content(): assert snapshot["tool_calls_this_run"] == 1 assert snapshot["scope"] == "current_run_visible" assert snapshot["token_usage"] == {"input": 25, "output": 5, "total": 30} + assert snapshot["todos"]["pending"] == 1 + assert "private task" not in tool_output assert "secret request" not in tool_output diff --git a/backend/tests/test_pii_redaction_middleware.py b/backend/tests/test_pii_redaction_middleware.py index 8c9b22610c..a654ea32d5 100644 --- a/backend/tests/test_pii_redaction_middleware.py +++ b/backend/tests/test_pii_redaction_middleware.py @@ -8,7 +8,9 @@ messages, the tool-boundary allowlist, and the pinned detector registry. import random import re -import time +from statistics import median +from time import process_time +from timeit import Timer from types import SimpleNamespace from unittest.mock import AsyncMock, MagicMock, Mock @@ -160,20 +162,19 @@ class TestDetectors: ], ) def test_redaction_stays_linear_on_whitespace_free_text(self, make_payload): - # The email scan was quadratic in the longest local-part run: 100 KB - # of hex took ~6 s on the event loop, on every model call. Assert the - # shape, not an absolute budget (see test_skill_review_core.py): the - # quadratic path takes ~4x per doubling, the linear one ~2x. - def timed(payload): - def once(): - started = time.perf_counter() - redact_text(payload, _PII_CFG) - return time.perf_counter() - started + # The quadratic email scan took ~6 s for 100 KB of hex. Doubling the + # input takes ~4x as much work for that scan and ~2x for a linear scan. + def redaction_timer(size): + payload = make_payload(size) + return Timer(lambda: redact_text(payload, _PII_CFG), timer=process_time) - return min(once() for _ in range(5)) - - small_elapsed = timed(make_payload(32768)) - large_elapsed = timed(make_payload(65536)) + small_timer = redaction_timer(32768) + large_timer = redaction_timer(65536) + # CPU time excludes runner pauses. Calibrate the batch size above the + # clock's resolution and sample both sizes together to limit drift. + repeats, _ = small_timer.autorange() + samples = [(small_timer.timeit(repeats), large_timer.timeit(repeats)) for _ in range(3)] + small_elapsed, large_elapsed = (median(times) / repeats for times in zip(*samples)) assert small_elapsed < 1.0, f"redaction took {small_elapsed:.2f}s" assert large_elapsed / small_elapsed < 3, f"redaction looks superlinear: 32K took {small_elapsed:.4f}s, 64K took {large_elapsed:.4f}s" diff --git a/docs/guide/context.md b/docs/guide/context.md index 69cd1ba154..2c635cdbe8 100644 --- a/docs/guide/context.md +++ b/docs/guide/context.md @@ -76,6 +76,9 @@ string `content` and a `pending` / `in_progress` / `completed` status (a missing status defaults to `pending`); another shape is rejected with HTTP 400, and an already-stored entry of an unusable shape is ignored instead of failing the model call. +The read-only `inspect_run_status` tool reports todo counts from the visible +state. For embedded integrations and restored checkpoints, it counts missing +and null statuses as pending. In planning mode, if the original `write_todos` call is no longer visible, DeerFlow adds a reminder using the latest task statuses before the next model call. Skipped or failed compaction leaves the existing messages unchanged.