Skip to content

fix(session): drop nameless tool calls before storing or replaying - #293

Open
raymondginger2018-sudo wants to merge 1 commit into
HKUDS:mainfrom
raymondginger2018-sudo:fix/nameless-toolcall-persist-replay
Open

raymondginger2018-sudo wants to merge 1 commit into
HKUDS:mainfrom
raymondginger2018-sudo:fix/nameless-toolcall-persist-replay

Conversation

@raymondginger2018-sudo

Copy link
Copy Markdown
Contributor

Summary

A tool call whose function.name is missing or blank can reach the transcript (a model/provider leaving the name empty, or a parser glitch that keeps the raw payload but drops the name). It used to be persisted as-is and replayed verbatim on resume, so every later request for that session was rejected with missing field name (400/422) and the session never recovered — an unrecoverable poison from a single bad call.

Changes

  • core/sessions/transcript.py
    • New _named_tool_calls() guard: keeps only calls whose function.name is a non-blank string.
    • kernel_message_to_record filters through the guard on save, so a poisoned call never enters the store.
    • session_message_to_kernel filters again on rebuild, so a session poisoned before this fix heals itself on resume.
    • record_fingerprint hashes the same filtered set, so a cleaned replay is not mistaken for an unchanged record (no duplicate re-save on every resume).
    • An assistant turn holding nothing but nameless calls is not written at all; the runner's existing orphan tool-result handling covers results that lose their call.

Tests

tests/test_session_transcript.py +5 cases / 101 lines:

  1. nameless call dropped before store (siblings with a valid bash call survive)
  2. stored nameless call dropped on resume (text stays, undeliverable call goes)
  3. a turn of only nameless calls leaves nothing behind
  4. fingerprint matches the cleaned replay → no duplicate re-save
  5. pre-fix poisoned record round-trips cleanly

Local CI replay (pr-ready, Windows, COMPARE_FROM=aa6ed161): KNOWN-RED | jobs=10 | rc0=29 | new=0 | known=1 — the single known red (windows-lifecycle:group2) is pre-existing and unrelated to this diff.

Dependency note

No new imports; both files already exist on main. core/sessions/transcript.py is the only production file touched.

Scope

Single-intention fix: 1 commit, 2 files, +134/-11.

A tool call whose function has no name can reach the transcript when a
model or provider leaves the name blank. It used to be persisted as-is
and replayed on resume, so every later request for that session was
rejected with "missing field name" and the session never recovered.

kernel_message_to_record now keeps only the calls that name their
function, session_message_to_kernel drops the nameless ones again when
a stored turn is replayed so an already poisoned session heals itself,
and record_fingerprint hashes the same filtered set so a cleaned replay
is not mistaken for an unchanged record. An assistant turn holding
nothing but nameless calls is not written at all; the runner's existing
orphan tool-result handling covers the results that lose their call.

This branch has not been deployed

No deployments
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.

1 participant