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 <willem.jiang@gmail.com>
This commit is contained in:
Danila Katalshov 2026-11-23 10:07:30 +03:00 committed by GitHub
parent 81288bfcac
commit 76a47652fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 35 additions and 18 deletions

View File

@ -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) |

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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.