Repository navigation
fix(harness): a deadline timer aborts a turn when its lease would lapse, not the next renew tick - #835
Conversation
The turn registry judged the lease deadline (leaseMs - renewMs after the last renew that landed) only on renew ticks. With the default timings the deadline is a whole number of ticks, so a tick lands on it exactly; a clock read there even 1 ms short let it pass, and the next check came one full tick later, when the lease had already lapsed in Redis. That is the intermittent "expected 600 to be less than 600" in the "renew never settles" test, and a window in which a lapsed lease's owner still runs. ActiveTurn now arms a deadline timer from the clock read before BEGIN, and every renew that lands rearms it from the clock read before that renew. It fires lease_lost whether a renew is in flight, failing, or hung. It is cleared on end, stop and any abort; a renew that lands after it fired finds the turn aborted and neither aborts again nor rearms. New fake-timer tests under 'lease deadline' pin the abort instant: on main a hung renew aborts at the lapse (40 s, not 30 s) when the clock reads 1 ms short, and at the next tick when the deadline falls between ticks. Closes rossoctl#801 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Summary
Replaces the tick-time checkLeaseDeadline in ActiveTurn with a dedicated setTimeout deadline armed from the pre-BEGIN clock and rearmed by every renew that lands, so a turn aborts lease_lost exactly leaseMs - renewMs after its last good renew instead of up to one tick late (#801). Verified the timer is cleared on end(), stop() and every abort path, that a late-landing renew cannot re-abort or rearm (both abort() and armDeadline() guard on signal.aborted), and that the failed-renew and hung-renew cases are both still covered by the timer. The new fake-timer tests pin the abort instant and the no-leak behaviour; no blocking issues found.
Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript (harness/src/turn-registry.ts), Tests (harness/test/turn-registry.test.ts), Docs (design spec §5.1 still accurate)
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: passing (all checks green)
Takes upstream main at 1a7f41e (19 merges since 032c8f6): the sandbox idle lifetime across docs, control plane, clients and deploy (rossoctl#820, rossoctl#837, rossoctl#842, rossoctl#843), grant redemption (rossoctl#822), the lease-check log line (rossoctl#824), egress fixes (rossoctl#829, rossoctl#834), the mock wait (rossoctl#828), the deadline timer (rossoctl#835), the create rollback (rossoctl#832), multi refusals and the rossoctl#363 leftovers (rossoctl#833, rossoctl#838), the identity near-miss check (rossoctl#827), mocactl login errors (rossoctl#836), the ghostunnel probes (rossoctl#830), refusal-burst deferral (rossoctl#831), a sandbox-worker change (rossoctl#841) and the v0.11 doc truth (rossoctl#821). Conflicts (one): - deploy/sbx/README.md, the "Optional inputs" table. Upstream (rossoctl#843) rewrote the SBX_LIFETIME_DAYS row (the default idle lifetime, at most SBX_MAX_LIFETIME_DAYS) and added the SBX_MAX_LIFETIME_DAYS and SBX_LOWER_WORKSPACE_IDLE rows, which widened the table; the fork had added an SBX_GATE_RECORD_SCHEMA row at its end. Resolved by taking upstream's table whole and appending the fork's SBX_GATE_RECORD_SCHEMA row after SBX_PROFILE, then re-padding the table with prettier. The fork's env-file example line for SBX_GATE_RECORD_SCHEMA merged cleanly. Merged without markers, checked: setup.sh keeps the fork's SBX_GATE_RECORD_SCHEMA validation and its sbx-settings write (so it stays in the settings hash) beside upstream's SH_SANDBOX_MAX_LIFETIME_SECONDS; both ocp-sbx and ocp-combined patch-control-plane.yaml keep the optional SH_GATE_RECORD_SCHEMA from sbx-settings beside the new optional SH_SANDBOX_MAX_LIFETIME_SECONDS; setup.test.sh keeps the fork's cases beside upstream's. The fork's RUNBOOK, README and template-onboarding docs say nothing about sandbox lifetime, refusal bursts, login errors or the create rollback, so none needed a correction; GUIDE.md is unchanged and GUIDE.pdf is not regenerated. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
Closes #801
What changed and why
harness/src/turn-registry.ts:ActiveTurnjudged the lease deadline (leaseMs - renewMsafter the last renew that landed) only on renew ticks. With the default timings (30 s lease, 10 s renew), and the test's (600 ms / 200 ms), the deadline is a whole number of ticks, so a tick lands exactly on it. If the clock reads even 1 ms short on that tick, the check passes, and the next check comes a full tick later, when the lease has already lapsed in Redis. That matches the CI failures (expected 600 to be less than 600,601). It is also a real window where the owner of a lapsed lease keeps running the turn, which §5.1 rules out.lease_lostwhether a renew is in flight, failing or hung, so the margin before the lapse is a fullrenewMsby construction instead of depending on where a tick lands.end(),stop()(registry close) and any abort, so it can't leak or fire late. If a renew lands after the timer fired, it finds the turn already aborted: it doesn't abort again, the first reason (lease_lost) stays, and it doesn't rearm. The tick-timecheckLeaseDeadlineis gone: the timer covers both cases it handled (a skipped tick while a renew hangs, and a failed renew).nullrenew still abortslease_lostat once, andcancelRequestedand the unwatched check work as before.Tests
describe('lease deadline')inharness/test/turn-registry.test.ts: anActiveTurnover a stub registry with fake timers, so the abort instant is exact and doesn't depend on Redis or the scheduler:lease_lostand leaves no rearmed timer;end()orstop(), and none fires after an abort for another reason.expected [ 40000 ] to deeply equal [ 30000 ]: the abort landed when the lease lapsed;expected [ 30000 ] to deeply equal [ 25000 ]: the abort landed at the next tick.turn-registry.test.tspass.harness, in a clean env:pnpm testpassed 70 files (2 skipped), 878 tests (5 skipped), andpnpm typecheckis clean.renewMsheadroom (200 ms) the design intends, and their comment now says so.Every commit is signed off (DCO).
Assisted-By: Claude Code