Repository navigation
Stop re-reading chat history when ending answered connector turns - #49272
Conversation
…rn's answered messages once
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
Perf scan on 7c04830 (fresh reviewer): PASS, nothing blocking.
|
|
Review status for 7c04830: ready Problem: at each connector turn end and each recovered turn, Orca did work that grew with chat history:
Change: the scan stops once both answers are found, and the answered-message list is built once and shared. Nothing users see changes. Verified:
Deferred: none. Building the answered-message list still searches the items once per steer (submissions × items). That cost was already there and is now paid once instead of twice. |
ELI5
When a chat turn ends, Orca reads that turn's rows to find the reply it should send back. For a turn that only read files, it kept reading every older row in the chat even after it had found the answer. It also built the same list of answered messages twice. Now it stops once the answer is found and builds the list once.
What Changed
structuredAgentSessionTurnReplystops scanning once both answers (plain prose and bot prose) are found. Before, it could stop only after finding a tool call that may have changed something, so a read-only turn always scanned every row in its window back to the start. During recovery, that window can stretch from an old unanswered request to the head of the chat. The "tools ran" flag is still collected whenever the turn has no bot answer, which is the only time anything reads it (no_answeroutcome, empty-answer retry, the outcome sentence).outboxTurnbuilds the turn's answered-message list once. That one list now feeds both the reply stamps and the check for whether the turn answered other messages. Before, it was built twice. The newconnectorReplyStampsOftakes the already-built list, andconnectorReplyTurnStampswraps it for the callers that don't have the list yet. Turn attribution had the same double call and now uses the same path.Why
Both were extra work that grew with history size and ran on every connector turn end and on every recovered turn. The early stop keeps every output the same: once both answers are found, nothing earlier in the scan can change them, and the only value left unset is one that no code reads for an answered turn.
Linked Issue
Internal release-scan findings (no GitHub issue).
Visual Proof
N/A: no UI or behavior change; this only cuts work done while ending and recovering turns.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Added a perf contract,
structured-agent-session-turn-reply.performance.test.ts. It counts the rows the scan reads for an answered read-only turn after 1,000 and 10,000 rows of history: 1 with this fix, 1,002 and 10,002 with the fix reverted (checked on Linux). A control case checks that a turn with no bot answer still reports an earlier edit as a tool run.A throwaway benchmark (not committed) ran the real
endedTurnand counted calls tojournalTurnAnsweredMessagesand the item reads inside them, before and after.pnpm check:changedpasses on Linux.Performance
No new allocations, timers, or I/O.
Risk
Level: Low. The riskiest part is the "tools ran" flag, which an answered turn can now return as false where it used to return true. Every reader of that flag checks it only after confirming the turn had no answer, so nothing users see changes. If it went wrong, a turn with no answer would leave out the "tools ran, check before asking again" note. A plain revert backs this out; nothing is saved differently.
AI Disclosure
Review
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)