fix(agent-runtime): three correctness bugs in adapter and legacy-bridge - #263
Merged
Merged
Conversation
1. adapter.ts β sessions capability falsely advertised when only
warmSession is defined. The old condition (resetChat || warmSession)
created a SessionBackend whose resetChat silently returned undefined,
misleading callers that checked capabilities.sessions into believing
they could reset the session. Guard is now resetChat-only; warmSession
is still forwarded when present alongside resetChat.
2. legacy-bridge.ts β non-plain-object tool inputs silently dropped.
pipeEventsToCallbacks converted any tool_call input that was not a
plain object (e.g. an array, which is valid for tool_call.input:
unknown) to {} without any diagnostic. A console.warn now surfaces
the data loss so operators can identify Phase-3 backends emitting
array-shaped tool inputs before the legacy bridge strips them.
3. legacy-bridge.ts β dead-code saw variable in reduceEventsToResult.
The spread ...(saw ? {} : {}) evaluated to an empty object in both
branches, making the saw flag have no effect on the returned value.
Removed the variable and fixed the comment to accurately describe
when the synthesised-result path is taken.
https://claude.ai/code/session_01Ddo8qvtcTtq5NVU4SkwCCP
This was referenced Jun 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Deep code review of the
main...HEADdiff surfaced three correctness bugs in the newagent-runtimeinfrastructure (Phase 1β2). All are in code that has no production callers yet, which means they would have silently shipped as-is into Phase 3+ without being caught by tests. All 2990 tests pass before and after this fix.Bug 1 β
adapter.ts:sessionscapability falsely advertised when onlywarmSessionis definedFile:
src/core/agent-runtime/adapter.tsRoot cause:
If a legacy backend defined only
warmSession(noresetChat), the adapter would:capabilities.sessions = truesessions.resetChat()method that callslegacy.resetChat?.()β which returnsundefinedand does nothingCallers checking
backend.capabilities.sessionswould believe the backend supports session reset, callsessions.resetChat(chatId), and silently get a no-op. No error, no log, no reset.Fix: Guard session object creation on
legacy.resetChatbeing defined.warmSessionis still forwarded when both are present.Bug 2 β
legacy-bridge.ts: non-plain-object tool inputs silently discardedFile:
src/core/agent-runtime/legacy-bridge.tsRoot cause:
The
tool_callevent inevents.tstypesinputasunknownβ valid values include arrays and other non-plain objects. The legacyonToolUsecallback requiresRecord<string, unknown>, so the bridge must convert. The old code silently replaced any non-plain-object input with{}:A Phase 3 backend emitting
{ type: "tool_call", name: "write_file", input: ["a", "b"] }would silently have["a", "b"]replaced with{}before reachingonToolUse. The tool would receive empty arguments.Fix: Add a
console.warnwhen data loss occurs, so operators can identify backends producing array-shaped tool inputs before the bridge strips them.Bug 3 β
legacy-bridge.ts: dead-codesawvariable inreduceEventsToResultFile:
src/core/agent-runtime/legacy-bridge.tsRoot cause:
...(saw ? {} : {})always spreads an empty object. Thesawflag was computed correctly (settruewhen acompletedevent with a falsy result was seen) but had no effect on the returned value. The comment claimed it distinguished a "silent-stream path" β but both paths produced identical output. This is dead code that would mislead any future engineer extendingreduceEventsToResult.Fix: Remove the
sawvariable and its meaningless spread; clarify the comment.Test results
https://claude.ai/code/session_01Ddo8qvtcTtq5NVU4SkwCCP
Generated by Claude Code