Skip to content

agy-cli 0.1.114: a reply cut after its tool round goes on from its prefill, not a 400 (#1319) - #1461

Open
wangbingnan136 wants to merge 1 commit into
magpie-community:mainfrom
wangbingnan136:codex/agy-cli-prefill-after-tool-result
Open

wangbingnan136 wants to merge 1 commit into
magpie-community:mainfrom
wangbingnan136:codex/agy-cli-prefill-after-tool-result

Conversation

@wangbingnan136

Copy link
Copy Markdown

Refs #1319 (its second problem and first suggestion: the "live tool_result + assistant prefill tail" dead end).

Summary

In an agent loop (Codex → magpie → agy-cli), a reply that is cut after a tool round comes back to the bridge ending … user(tool_result), assistant(text | thinking):

  • magpie's continuation of a cut reply sends what the client already has as the last assistant message (continuation.request, yetone/magpie internal/gateway/continuation.go);
  • the client's own retry keeps what it recorded of the cut reply (Codex keeps the reasoning item, or agy's ⚠ The stream was interrupted… text).

validateBody turned that shape away with a 400 whose text doesn't match magpie's prefill-refusal pattern (prefill.go), so magpie neither falls back nor appends a user turn, and the turn dies. Typing "continue" works only because it puts a user message last.

The pieces to serve it already exist (interrupted tool turns, steerInSession, replay, the prefill carrier); this connects them:

 validateBody(body)
-  if prefill tail && tool_result in the tail → 400
 
 tool results matched a live call
-  interrupted = isInterruptedToolTurn(body)
+  prefillTail = prefillRun(body.messages) !== null
+  interrupted = prefillTail || isInterruptedToolTurn(body)
   interrupted && session fits → steerInSession: the call gets its real result,
                                 the next prompt is the prefill carrier
   otherwise                   → drop_live ("prefill_tail") + replay
 no live call (the cut turn already finalized)
   → replay: [tool result …] then the carrier (thinking-only tail: no carrier)

Evidence

Seen in production: 8 of these 400s over 4 Codex sessions on one machine. Each time, a long request (4–16 min) was cut mid-reply, by a turn timeout, Unknown model ID, or an upstream stream error, and the client's retry 0.2–0.7 s later got the same 400.

New test/prefill-tool-result.mjs (fake agy, via testkit.mjs):

  • Before: both cases 400 !== 200, agy bridge: a request combining a live tool_result with an assistant prefill tail is not supported
    After: pass
    • live call + tool_result + prefill → the MCP call gets REAL_RESULT_42, same agy process, next prompt has the carrier and the fragment, not the answered result again
    • finished tool turn, retried with a text tail / a thinking-only tail → 200; the replay carries the tool result, then the carrier (none for thinking-only)
  • test/prefill.mjs: the old "rejects tool_result + prefill" assertion now asserts it validates.
  • bun test ./agy-cli.test.mjs: everything passes except test/usage.mjs, which fails the same way on unmodified main on this machine (3 s timeouts in the region-refusal quota cases, flaky in number).
  • bun scripts/check.mjs and bun scripts/bumped.mjs upstream/main: pass.

Merge Danger

Door: two-way. Nothing is stored, and reverting brings the 400 back. AGY_BRIDGE_PREFILL=0 still restores the stock reject for every prefill.

Blast Radius: narrow. Only requests that used to be a 400 take the new branch: a tool round followed by a text-only or thinking-only assistant tail. Every other request takes the same path as before. On these requests, a live session is steered (it keeps its prompt cache) or the round is replayed into a fresh session, the existing "safe, self-healing" degrade.

Not in this PR: #1319's turn timeout on long silent tool-call generation, and the session lost on timeoutTurn.

Version: 0.1.113 → 0.1.114.

…efill, not a 400 (magpie-community#1319)

magpie's continuation of a cut reply, and a client's retry that keeps what it got of it, end with user(tool_result), assistant(text or thinking). validateBody turned that away with a 400 magpie doesn't read as a prefill refusal, so the turn died. It is now served as an interrupted tool turn: a call the session still waits on gets its result and the prefill carrier is the next prompt (steerInSession), otherwise the round is replayed with its results and the carrier. Drops are logged as prefill_tail.
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