Repository navigation
agentHost: log why a Claude session rebuilds before a turn - #346442
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the change adding diagnostic logging to pre-turn rebuilds.
No open issues 🎉
What changed in this PR
Adds diagnostic logging to Claude session pre-turn rebuilds, making it easier to identify which synced-state changes triggered an SDK subprocess restart.
Changes:
- Evaluates all existing rebuild conditions to collect every applicable reason.
- Logs the session ID, turn ID, and reasons before invoking the existing rebuild path.
| File | Description |
|---|---|
src/vs/platform/agentHost/node/claude/claudeAgentSession.ts |
Collects and logs pre-turn rebuild reasons while retaining the existing rebuild conditions. |
Review effort: Balanced
|
Shouldn't it be 'rebindReason' as it is rebinding the claude session? also the way you changed it to have a array of each condition check, that will leads to evaluation of every condition unlike previously it may skip the rest of condition checks when one of them is true.
|
|
Both fixed in
|
ClaudeAgentSession.send relaunches the SDK subprocess when synced state changed since launch, but did not say which state. Log the changed state, so a rebuild seen in E2E logs, such as the one that drops the /model echo in 'model changes between turns retain provider context', can be attributed. Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
ca9339c to
b07201a
Compare
Logs which synced state made
ClaudeAgentSession.sendrebuild the SDK subprocess before a turn. Today it rebuilds silently. The log is the only change. The conditions move into_getRebindReason(), which checks them in the same order and returns at the first one that differs, so evaluation still stops early like the original||chain.TylerLeonhardt FYI, since this is your area. I'm happy to close this if you'd rather handle it another way.
Why:
Agent Host E2E — Claude › model changes between turns retain provider contexthas failed twice on main recently, both on a busy agent right after a 6–7 s cold Copilot client start:after eachreplay check failed:model request #2 does not match the recorded request. The recorded request gulp-symdest does not preserve links on electron #2 contains the/model<local-command-caveat>echo between the turns, and the live request doesn't.In 493539, turn 2's
sendloggedrebuild isResume=trueat 07.707, right after turn 1's result. That's the pre-flight rebuild insend(synced-state drift), not the model switch. The rebuild launches the SDK withOptions.modelalready set to the new model, so_replayCurrentConfighas nothing to switch and the SDK never writes the/modelecho. Without a rebuild (the recorded path), turn 2 hot-swaps throughQuery.setModel, which does write it. Both paths keep the provider context. Only the replayed request differs, so the test fails whenever some synced state lands between turn 1's launch and turn 2, which a slow cold start makes likely.We couldn't tell which state changed, because the rebind doesn't log its reason. With this change, the next hit will log, for example:
Overlap: #345986 rewrites this same hunk with
_pendingRebuildReasons()and logsrebuilding before turn <id>: <reasons>, which covers this PR. If #345986 lands first, I'll close this one. This PR only matters if the rebuild reason is needed before #345986 lands.Open question for you: once we know the trigger, should the fixture tolerate a rebuild before turn 2, or should the test wait until synced state settles before turn 1?
Validation:
claudeAgent.test.tsandclaudeSdkPipeline.test.tspass (352) on the current head. Earlier,claudeSessionClientToolsModel.test.ts(14) andclaudeSessionClientCustomizationsModel.test.ts(11) passed too. eslint is clean, andtsc --noEmitreports no errors in the Claude agent host files.