Repository navigation
perf(server): drop duplicate provider session status events - #214
Merged
Merged
Conversation
Claude reports a status ping on every model request inside a turn, and ingestion turned each one into a thread.session.set whose only change was updatedAt (2,040 of 2,666 session-set events in a 3.6 h prod sample). A fork helper now skips the dispatch for session.state.changed when status, activeTurnId, lastError, providerThreadId, runtimeMode, providerName and providerInstanceId all equal the projected session. Lifecycle events always dispatch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Thread transfer impact✅ Thread transfer remains within every enforced ceiling.
Baseline: unavailable · PR result: Scenario and decoded snapshot size10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
Claude reports
system/status: requestingon every model request inside a turn. The Claude adapter maps each one tosession.state.changed, andProviderRuntimeIngestionturned every one into athread.session.setwhose only new value wasupdatedAt.In the last 20k prod events, 2,040 of 2,666
thread.session-set(77%) were exact repeats of the previous one apart fromupdatedAt. One thread had 213 in 3.6 h. Each one costs:ThreadPullRequestReactorsync.Fix
orchestration/sessionSetDedupe.expbkt3.ts. It skips the dispatch when the next session equals the projectedthread.sessioninstatus,activeTurnId,lastError,providerThreadId,runtimeMode,providerNameandproviderInstanceId.ProviderRuntimeIngestion.ts: the upstreamorchestrationEngine.dispatch({call becomesdispatchSessionSetUnlessNoOp(...)({. The command literal is untouched.session.state.changedis filtered.session.started,thread.started,turn.*,session.exitedandruntime.erroralways dispatch.Why this is safe:
Projection writes run inside the dispatch transaction (
OrchestrationEngine.tswithTransaction→projectEventDeferred), so the projected session is current when ingestion compares.The readers of
session.updatedAtall key off a real transition, which is never dropped:ProviderSessionReaper.ts:340);ThreadSettlementPolicy.ts:129).Recorded edge case: the fork branch of
ProviderSessionReaperkeeps a session alive when the adapter still holds a turn but the projection'sactiveTurnIdis null. It does this throughlatestThreadEventAtwithin the 30 min threshold. Before this PR, status pings produced session-set events that kept that timestamp fresh; now only real events do. This only matters if the projection has already lostactiveTurnIdand the agent emits nothing else for 30 min, so it is accepted.Evidence
Fork test
ProviderRuntimeIngestion.expbkt3.test.ts, 10 identicalrunningpings in one burst:thread.session-setevents persistedReal transitions (
running → ready → running) and a changed error message still land.Tests run:
NODE_ENV=test vp test runonsessionSetDedupe.expbkt3.test.ts,ProviderRuntimeIngestion.expbkt3.test.ts, and the existingProviderRuntimeIngestion.test.ts+.approval.test.ts: 89 + 77 pass.vp run typecheckinapps/serveris clean.After the expbkt3 deploy I will re-count duplicate session-sets on the expbkt3 DB.
Candidate to upstream: the same no-op comparison would help every T3 Code user.
Model/harness: Claude Opus 5.5 via Claude Code in T3 Code.
🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.