Skip to content

fix(session): drop nameless tool calls on the request path too - #293

Merged
Zongwei9888 merged 1 commit into
HKUDS:mainfrom
raymondginger2018-sudo:fix/nameless-toolcall-persist-replay
Nov 16, 2026
Merged

Zongwei9888 merged 1 commit into
HKUDS:mainfrom
raymondginger2018-sudo:fix/nameless-toolcall-persist-replay

Conversation

@raymondginger2018-sudo

@raymondginger2018-sudo raymondginger2018-sudo commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A tool call whose function.name is blank names nothing, and the provider rejects the whole request that carries one. This drops such calls at both boundaries that matter.

Storage (already reviewed and confirmed on this PR). core.sessions.transcript drops them on save and on rebuild, so a saved session resumes cleanly and the fingerprint change avoids re-saving it.

Request path (this revision). AgentSession._history is kept in memory between turns, so dropping them on storage alone leaves a live run poisoned: the follow-up request in the same turn, and every later turn, were rejected until the process restarted. Every model request goes through AgentRunner._request_view, so the filter now runs there.

  • It runs before _drop_orphan_tool_results on purpose. Dropping a call orphans its tool result, and the orphan pass that follows removes it, so calls and results still pair up.
  • It also drops an assistant message left with no text and no calls.
  • The predicate moved to core.agent_runtime.helpers.named_tool_calls, and transcript.py imports it instead of keeping its own copy, so the storage path and the request path agree on what "named" means.

Changes

4 files, +261 / -13.

  • core/agent_runtime/helpers.py — new named_tool_calls(), the one shared predicate.
  • core/agent_runtime/runner.py — _drop_nameless_tool_calls(), wired into _request_view (both the main path and the minimal-repair fallback).
  • core/sessions/transcript.py — drop the local copy, import the shared helper.
  • tests/test_session_transcript.py — the new AgentSession test.

Tests

tests/test_session_transcript.py — 13 passed. The new test drives AgentSession with a provider whose first response is a call with name="", then asserts:

  • the follow-up request of the same turn carries no nameless call,
  • the next turn's request carries none either,
  • the poisoned turn and the turn after it both reach task_complete.

Mutation check: with the two _request_view call sites disabled, that test fails with request 1 carried a nameless tool call; restoring them turns it green. So it fails for the reason it exists.

Also green: tests/test_agent_session.py (41 with the transcript file), and test_context_window_overflow / test_session_compaction / test_context_isolation / test_context_note_sink (19).

ruff 0.15.21 check and format --check clean. Rebased onto 3dcb0fb4.

Dependency note

None. One new helper plus its two call sites; no new runtime path beyond _request_view.

@Zongwei9888

Copy link
Copy Markdown
Contributor

Thanks, this is a clean fix for the stored side, and we confirmed it:

  • A session saved with a nameless call now resumes, and the next request is valid.
  • The orphaned tool result is dropped by _drop_orphan_tool_results, so calls and results still pair up.
  • The fingerprint change avoids re-saving.

One part is still open: the live session. The service keeps the session in memory between turns; SessionRuntimeRegistry only reloads from the file when another process wrote to it. AgentSession._history still holds the nameless call. We used a fake provider that rejects such calls. On this branch, both the follow-up request in the same turn and the next turn are still rejected; only a restart heals it.

What we'd like added:

  • Drop nameless calls on the request path too. Every model request goes through AgentRunner._request_view (core/agent_runtime/runner.py), right beside _drop_orphan_tool_results. Drop them there, plus any assistant message left with no text and no calls. That covers the live turn, later turns and resumed sessions.
  • Share one helper between the runner and transcript.py.
  • Add a test that drives AgentSession: the provider returns a call with name=""; assert that the next request carries no nameless call and the following turn succeeds.

For context, name="" comes from openai_compat.py (the non-streaming and streaming parsers) and the Responses parser fallbacks; Anthropic always names its calls. Happy to merge once the live path is covered.

A call whose function.name is blank names nothing, and the provider rejects the
whole request that carries one. The record boundary already dropped them on save
and on rebuild, but AgentSession._history lives in memory between turns, so a
live run kept sending the same poisoned list: the follow-up request in the same
turn and every later turn were rejected until the process restarted.

Every model request goes through AgentRunner._request_view, so the filter now
runs there, right beside _drop_orphan_tool_results. It drops the nameless calls
and drops an assistant message left with no text and no calls. It runs before the
orphan pass on purpose: dropping a call orphans its tool result, and the pass
that follows removes it, so calls and results still pair up.

The predicate itself moves to core.agent_runtime.helpers.named_tool_calls, and
core.sessions.transcript imports it instead of keeping its own copy, so the
storage path and the request path agree on what "named" means.

Tests: tests/test_session_transcript.py, 13 passed. The new one drives
AgentSession with a provider that returns name="": it asserts the follow-up
request of the same turn and every later request carry no nameless call, and
that the poisoned turn and the turn after it both complete. Mutation check: with
the two _request_view call sites disabled, the new test fails with "request 1
carried a nameless tool call"; restoring them turns it green.

Also green: tests/test_agent_session.py (41 with the transcript file),
test_context_window_overflow / test_session_compaction / test_context_isolation /
test_context_note_sink (19). ruff 0.15.21 check and format --check clean.
@raymondginger2018-sudo
raymondginger2018-sudo force-pushed the fix/nameless-toolcall-persist-replay branch from 8df55fb to 71e0251 Compare November 16, 2026 11:16
@raymondginger2018-sudo raymondginger2018-sudo changed the title fix(session): drop nameless tool calls before storing or replaying fix(session): drop nameless tool calls on the request path too Nov 16, 2026
@raymondginger2018-sudo

Copy link
Copy Markdown
Contributor Author

Thanks for the precise read of the live path — you were right, and your reproduction is exactly what I see.

The live session is covered now. The filter runs in AgentRunner._request_view, right beside _drop_orphan_tool_results, and on the minimal-repair fallback path as well. It drops the nameless calls and drops an assistant message left with no text and no calls, so the follow-up request in the same turn, later turns, and resumed sessions are all covered without a restart.

One ordering detail worth flagging: it runs before _drop_orphan_tool_results, not after. Dropping a call orphans its tool result, and the orphan pass then removes it, so calls and results still pair up instead of leaving a stray result behind. If you would rather have the order the other way, the orphan result would need explicit removal instead.

One shared helper. The predicate is now core.agent_runtime.helpers.named_tool_calls. transcript.py imports it instead of keeping its own copy, so both boundaries agree on what "named" means.

The test you asked for. test_a_live_session_never_sends_a_nameless_tool_call drives AgentSession with a provider whose first response is a call with name="". It asserts the follow-up request of the same turn carries no nameless call, the next turn's request carries none, and both turns reach task_complete.

I checked the test actually bites: with the two _request_view call sites disabled, it fails with AssertionError: request 1 carried a nameless tool call; restored, it passes. Before the change the recorded requests carried (index=1, id='c1', name='') on the second request and on both later turns — the same shape you reported.

Green: tests/test_session_transcript.py (13), tests/test_agent_session.py plus it (41), and the four context tests (19). ruff 0.15.21 check and format clean. Rebased onto 3dcb0fb4.

One open item I did not guess at: whether you also want the storage path to drop an assistant message that keeps its text but loses its only call. Right now it keeps the text and drops the call, which read as the safer half; say the word if you want it mirrored.

@Zongwei9888
Zongwei9888 merged commit 534e94e into HKUDS:main Nov 16, 2026
12 checks passed
@Zongwei9888

Copy link
Copy Markdown
Contributor

Merged in 534e94e. Thank you. A session that could never recover once a nameless call got in is a real bug, and the live-path test is exactly what we asked for.

On your open question: keeping the text and dropping only the call is right, so nothing needs mirroring.

A closer review turned up two more things, fixed on top in 2e719c7 and 1b31b8d:

  • The model never learned its call failed. The loop still ran the nameless call and saved its "unknown tool" error, and then the request view hid both. The model resent the same reply until the repeat guard stopped the Turn. Such calls are now dropped before they run, and the model is told. Two nameless-only replies in a row end the Turn.
  • Results could be paired with the wrong call. The request view relied on the orphan pass, which matches results by id alone. Some providers reuse ids across turns, and a split stream can give a named and a nameless call the same id. The view now drops exactly the results that followed the removed call. Tool events stay paired with the calls that actually run.

Zongwei9888 added a commit that referenced this pull request Nov 17, 2026
Add the news entry and changelog for the 2026-11-16 community batch
(#289, #293, #303, #307) and fold the 2026-10-31 entry into the
earlier updates. The three points under "What Deep means" now match the
numbered parts of the framework figure, self-evolution is named as
planned, and "Why DeepCode" no longer repeats them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants