-
-
Notifications
You must be signed in to change notification settings - Fork 40.6k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Bug Description
When a browser operation times out, the session is saved with an orphaned tool_use block (no matching tool_result). On next API call, this causes:
unexpected tool_use_id in tool_result blocks
Root Cause
repairToolUseResultPairing() in session-transcript-repair.ts exists but is only called during context sanitization before API calls, not when sessions are loaded from disk.
Steps to Reproduce
- Start a session
- Trigger a browser operation that times out (e.g., screenshot with slow page)
- Session saves with orphaned
tool_useblock - Next API call fails with "unexpected tool_use_id" error
Suggested Fix
Call repairToolUseResultPairing() when loading sessions from disk in session-utils.fs.js:
// In readSessionMessages(), before return:
import { repairToolUseResultPairing } from "../agents/session-transcript-repair.js";
// ... existing code ...
const repaired = repairToolUseResultPairing(messages);
return repaired.messages;Affected Files
src/gateway/session-utils.fs.ts- session loading (needs fix)src/agents/session-transcript-repair.ts- repair function (already exists)src/agents/pi-extensions/transcript-sanitize.ts- only called on context build
Workaround
Manually patch dist/gateway/session-utils.fs.js to call repair on load (verified working).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working