Repository navigation
Conversation
Each context handoff lists the ID of every item it omitted, and its delivery copies the list. A turn start read all of them for the thread, so one turn start on a long thread could take 700 MB of heap. Cut the lists in SQLite unless this turn can deliver the handoff or needs its delivery for coverage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Problem
Starting a turn on a long thread can take about 700 MB of heap, enough to take down a 4 GB server.
Each
full_thread_summaryhandoff stores the ID of every item it omitted inhistory.omittedItemIds, and delivery copies that list intodelivery.omittedItemIds.getTurnStartContextreads every handoff of the thread in full, on every turn start. The lists grow with history length times handoff count: on one install with long-lived threads they are 97% of 950 MB of handoff payloads.I found it investigating a
JavaScript heap out of memoryabort on 0.1.8-nightly.20261109.4399. The last turn to be requested was on a thread whose handoffs alone cost 736 MB to load, with about 3.7 GB of heap already in use, and it never finished starting. That link is inferred from timing and size (there was no core dump). The query is the same on main.Expected: a turn start loads the lists it can use.
Change
getTurnStartContextcuts the two lists in SQLite, before they reach the JS heap, unless this turn can use them:history.omittedItemIdsand persists the handoff again.delivery.omittedItemIds, whichcoveredItemIdsreads. It keeps it for any native thread, so a resume onto an earlier one counts the same.No schema change and no stored data changes. The windowed read already does the same with
json_remove.Scope
A bug fix for a crash, in one query. It is small and the cause is in the query itself, so I didn't open an issue. #35597 is about the same function, and #35723 lists "still reads every ... context handoff of the thread" under "Not in this change", so this doesn't overlap that PR's fix.
Not changed here: how the lists are written.
Verification
loads startup state without obsolete transcript payloadscase inTurnStartReads.test.tswith seven handoff shapes. It fails on main (settled elsewhere: expected [ 'item:omitted' ] to deeply equal undefined) and passes with the fix.deliveryto the run's provider thread was identical, and no other field changed: 0 mismatches. A deliberately broken query produced 151, so the comparison can fail.vp run check:changedpasses.ProviderTurnStartService,ContextHandoffBudget,ContextHandoffService,ProviderSwitch.integrationandOrchestrator.control-readstests pass (245).Written by Claude Opus 5.5 in Claude Code, running in T3 Code.
🤖 Generated with Claude Code