fix(studio-server): time history idle limits on one clock so a slow machine cannot flip them - #4924
Conversation
Edit accuracy: accurate 1216 (base branch 1216), smooth 1058 of thoseThe gate passes. Quarantined, measured but not gated (1)
|
terencecho
left a comment
There was a problem hiding this comment.
Approved at 14831b3ceea324b1892ad4cce9d75bfc68eb2a56.
The engine and CLI tests share an injected clock and advance it rather than relying on wall-clock sleeps. The production engine and direct CLI paths still default to Date.now; the preview server is not given the test clock. The idle timer's remaining-time recheck and the tests' fake file mtimes are consistent with that clock. I found no introduced behavior regression. A separate watcher-debounce/timer ordering edge exists identically at base and head; this review does not claim that edge is fixed.
The exact-head Studio and runtime tests, Windows engine/CLI tests, and all 11 required checks passed. I did not rerun the PR body's 1.5-second slowed-command probe locally.
— Review by tai (pr-review)
What
History decides when an agent's turn has gone idle on one clock, and the tests that check that limit advance that clock instead of sleeping. A slow machine no longer changes which writes a turn keeps, in the tests or in a preview whose window timer fires late.
Why
Three tests in
packages/cli/src/commands/history.test.tsusedpause(ms)againsthistoryDeps.turnIdleMswith wall-clock margins (600 ms gaps under a 1000 ms limit, 600 or 700 ms over a 300 or 400 ms limit). When a command takes long enough to eat the margin, the gaps between writes cross the limit and a turn that should stay the agent's is filed as Outside. The test for writes closer together than the idle limit is the one that flips.History had three clocks behind that decision:
nowbut still calledDate.now()for sweep times and window touches (projectHistory.ts, three places);Date.now()(historyOwner.ts);Change
now()everywhere it reads the time.historyDeps.nowis the CLI's clock: it stamps turn starts, is passed into the engine it opens, and dates the "ago" column.pause()is gone; the three tests advance the clock instead. Writes the tests do not make through the helper (the baseline files, the turn marker, undo's own writes, renames and deletes) keep real file times; no test here times one of those against the idle limit.The default clock is
Date.now().Proof
Each history command slowed by 1.5 s (a delay added to the test's command runner for this run only):
Each command finishing 0.8 s late, preview mode, "a turn left open ends after the idle limit": with the engine's old bare timer the window ended before the agent's write was seen and the test failed; with the clock check it passes. Disabling the idle rule itself (
projectHistory.ts, thetakesWritecheck) now fails that test in both direct and preview mode.The engine's own history suites (
packages/studio-server/src/history) pass: 138 passed, 2 skipped. The new one opens a window with a 30-day idle limit and fails if any timer delay exceeds Node's range.Under 100 changed lines: a standalone fix of the history idle clock with nothing in flight to carry it.