perf(hub): seal run digest on crash/failure + session-less terminate (#118 §4)#296
Merged
Merged
Conversation
…118 §4) Only the operator stop path (stopSessionInternal) finalized the run digest at terminal time. A crash/failure (PATCH status=crashed|failed) and a session-less terminate fell through without folding, so the FIRST Insight open on those runs paid the full O(n) backfill (#118 bottleneck #3/#4) on the user's read path. Converge both missing terminal transitions through finalizeDigestOutcome (fold current if stale, then O(1) outcome stamp) — same hook the stop path already uses. Chose finalizeDigestOutcome's idempotent recompute over the background worker's incremental foldDirtyAgent to avoid a double-fold race with that worker. - handlePatchAgent crashed/failed branch -> finalizeDigestOutcome - applyAgentTerminationEffects session-less branch -> finalizeDigestOutcome - test: a crashed agent's digest is sealed (watermark==max, outcome stamped) right after the PATCH, so no read-time backfill is owed Co-Authored-By: Claude Opus 4.8 <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.
Second of the Tier-A perf PRs for #118. Defensive fold-on-close so the first Insight open on an ended run is an O(1) read, not a full O(n) backfill.
Problem (#118 bottleneck #3/#4)
Only the operator stop path (
stopSessionInternal) finalized the run digest at terminal time (stop_session.go:179). Two other terminal transitions fell through without folding:PATCH status=crashed|failed(handlers_agents.go), the path the host-runner reconcile uses.applyAgentTerminationEffectswhere no live session points at the agent.For those runs, the digest stayed behind the event log, so the first Insight open paid the full backfill (10k events → ~10s for the reported session) on the user's read path.
Fix
Converge both missing terminal transitions through the existing
finalizeDigestOutcomehook (folds the digest current if stale, then stamps the terminal outcome — O(1)), the same hook the stop path already uses.Chose
finalizeDigestOutcome's idempotent full recompute over the background worker's incrementalfoldDirtyAgent: callingfoldDirtyAgentsynchronously here would double-fold against the concurrent fold worker (both read the same watermark and fold the same tail). The recompute is race-safe and already battle-tested on the stop path.Changes
handlePatchAgentcrashed/failed branch →finalizeDigestOutcomeapplyAgentTerminationEffectssession-less branch →finalizeDigestOutcomeTestDigestSealedOnCrash: a crashed agent's digest is sealed (watermark == max seq, outcome stamped) right after the PATCH, so no read-time backfill is owedVerification
go build,go vet, gofmt clean. Digest/stop/terminate/patch suites pass, including-race(107s, clean).Part of #118 (Tier A). Sibling: #295 (sessionAgentIDs denorm).
🤖 Generated with Claude Code