Repository navigation
Conversation
The sandbox control plane fenced the workspace snapshot on every wrapper heartbeat that reported a busy workspace. A busy workspace stays busy for as long as a terminal PTY runs, so an open terminal fenced the snapshot, wrote the allocation row and logged one diagnostic every heartbeat. A capture is only possible while the previous idle heartbeat left the disk's idle candidate in place. Fence the first busy heartbeat that sees that candidate, which clears it once. Later heartbeats of the same busy episode change nothing, and no capture can start until an idle heartbeat makes the disk eligible again. The active and terminal fences are unchanged.
…ends The busy fence records the mutation time that starts the snapshot idle wait. After a busy episode longer than the wait, an idle heartbeat kept that old timestamp, so scheduling and capture eligibility both saw an expired wait and a capture could run as soon as the terminal closed. The idle heartbeat that restores the disk's idle candidate now restarts the wait with its own timestamp. Repeated idle heartbeats keep it, so the wait does not restart while the workspace stays idle. Active heartbeats, the terminal fence and the sandbox shutdown deadline are unchanged. Add a regression test for a busy episode longer than the idle wait: no capture during it or immediately after it, and a capture after one idle minute.
This comment has been minimized.
This comment has been minimized.
chrarnoldus
left a comment
There was a problem hiding this comment.
bot: services/cloud-agent-next/src/control-plane/sandbox/sandbox-do.ts:8399 — The first idle heartbeat after a wrapper reconnect resets the snapshot timer even if the workspace stayed idle. This can delay a pending snapshot or schedule a redundant one. Refresh idleConnectionId on reconnect, but reset lastMutationAt only when there was no previous idle candidate.
The idle heartbeat restarted the snapshot idle wait whenever the disk's idle candidate did not name the current connection. A reconnect changes the connection id while the workspace stays idle, so the next idle heartbeat pushed a pending capture a full wait away. Every fence clears the idle candidate, so a missing candidate is the only sign that the wait must restart. Refresh the candidate to the current connection on every idle heartbeat, and reset the wait only when the candidate was absent. A reconnect now keeps the wait. Add a regression test: an idle candidate, a replacement wrapper with a new connection id, and an idle heartbeat that keeps lastMutationAt and does not delay the pending capture.
|
bot: Fixed in 026bf04. The idle heartbeat now always refreshes |
Manual QA — T-122Untestable · tested
Test details and evidenceScenarios
Problems foundNone attributable to this change. The blocker is a local environment gap and happens before any heartbeat fence can be evaluated. It is recorded under "Not tested". Not tested
Post-deploy checks
Verdict: untestable |

Why
The service that runs agent sessions fenced the workspace snapshot on every heartbeat while the workspace was busy. A workspace counts as busy for as long as any attached terminal has a running PTY, so a single open terminal kept the workspace busy for many minutes. Each heartbeat then wrote the workspace snapshot allocation row, increased its invalidation generation, and logged a fence diagnostic. One sandbox produced about 1 fence every 5 seconds for 28 minutes, which is a pointless Durable Object write and log noise on every sandbox with an open terminal.
A snapshot capture can only start while the disk's idle candidate is in place. This change fences the first busy heartbeat that sees that candidate and then does nothing for the rest of the same busy episode. That single fence clears the candidate, so no capture can start until an idle heartbeat restores it. When the idle heartbeat restores the candidate, it also restarts the snapshot idle wait, so a long busy period does not count toward the wait and a capture does not run the moment a terminal closes. Workspace snapshots stay unpublished for the whole busy period. The
activeandterminalfence reasons are unchanged.Summary
services/cloud-agent-next/src/control-plane/sandbox/sandbox-do.ts: the heartbeat handler fencesworkspace_busyonly when the allocation's workspace disk still carries an idle candidate (idleConnectionId). The fence clears the candidate, so later busy heartbeats in the episode are no-ops and the diagnostic is emitted once per busy episode.lastMutationAt) when an idle heartbeat restores the candidate. Scheduling (the alarm) and capture eligibility both readworkspaceSnapshotIdleAt, so they now use the same idle clock. Repeated idle heartbeats keep the timestamp, and a wrapper reconnect refreshes the connection id without restarting the wait, so a pending capture is not delayed.services/cloud-agent-next/test/integration/control-plane-workspace-snapshots.test.ts: one test drives three busy heartbeats and asserts one fence diagnostic, one generation increment, no capture during the episode, and a second fence after an idle heartbeat starts a new episode. Another test covers a busy episode longer than the idle wait: no capture during it or immediately after it, and a capture after one idle minute. A third test reconnects a wrapper while the workspace is idle and asserts the idle wait is kept and the pending capture is not delayed.services/cloud-agent-next/test/integration/helpers/fake-wrapper.ts: the fake wrapper can request heartbeat acknowledgements, so the tests can order heartbeat processing deterministically.Verification
No manual test ran. The change affects Worker heartbeat handling and snapshot scheduling in the Durable Object, with no user-facing UI or API surface, and the repository runs a separate manual QA phase after review. Automated checks are listed in Reviewer Notes.
Visual Changes
N/A
Reviewer Notes
Automated checks:
pnpm exec vitest run --config vitest.workers.config.ts test/integration/control-plane-workspace-snapshots.test.ts test/integration/workspace-snapshot-diagnostics.test.ts— 112 passed.pnpm exec vitest run --config vitest.workers.config.ts test/integration/control-plane-session-v2.test.ts— 123 passed.pnpm exec vitest run src/control-plane/sandbox/workspace-snapshot.test.ts src/control-plane/sandbox/allocation.test.ts— 46 passed.expected 4 to be 2for the generation after three busy heartbeats) and passes with the change.lastMutationAtstays about 90 seconds behind the idle heartbeat) and passes with the change.lastMutationAtchanges across the reconnect) and passes with the change.pnpm run typecheck,pnpm run lint, andoxfmt --checkon the changed files pass.pnpm exec vitest run(unit suite): 9717 passed, 1 failed inscripts/sentry-source-maps.test.ts. That test also fails on a clean checkout of the base commit in this environment, so it is pre-existing and unrelated.Design choices and limitations:
idleConnectionIdprecondition already answers "could a capture have started since the last fence", and the busy fence clears it, so it is the dedupe marker. The idle heartbeat restores the candidate and restarts the idle wait only when no candidate was present; a reconnect keeps the candidate and does not restart it.workspace_busyfence. No capture was possible in that state, so no fence is needed; every fence that is emitted remains countable.