Repository navigation
fix(cli): a lease renewal the backend never answered no longer stops the run's monitor - #119
Merged
ashot merged 5 commits intoNov 23, 2026
Merged
Conversation
…the run's monitor renewTaskLease turned every exception into false, and the heartbeat read false as "the lease is gone": it cleared the run's timer for good. After a laptop wake the first calls time out, so one failed beat left a live run with no renewals. The 5 minute lease lapsed and reclaimStaleTasks fired the trigger a second time while the first run was still working. renewTaskLease now answers null when it got no answer. Only false, the backend's own "you no longer hold it", stops the monitor; null logs and tries again on the next beat.
…or the lease fix - The heartbeat tests move to taskScheduler.heartbeat.test.ts: adding them to taskScheduler.test.ts took it over 800 lines (850), which the max-lines ratchet refuses for a new oversized file. - index.ts's static graph sat at 4851 KB, the pin, and the lease fix's comment in syncService.ts pushed it to 4852. The explanation now sits on the scheduler's heartbeat, which is off that graph. - Re-stamp the daemon build id: the lease fix changes the daemon closure.
…runner, unrelated)
Contributor
|
Merged as a91b400, thanks. A clear write-up and tests that pin both outcomes. It ships with the next CLI release. |
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.
Bug
A trigger run holds a 5-minute lease that the daemon renews every 60 s.
SyncService.renewTaskLeaseturned every exception intofalse, and the run's heartbeat readfalseas "the lease is gone": it loggedLease renewal failed for task …, stopping monitorand cleared the run's timer for good. A network timeout was treated as a lost lease.This happens most after a laptop wakes: the first calls time out, the one renewal in that window fails, and nothing renews the lease again. Within 5 minutes
reclaimStaleTaskssees a lapsed lease for a run that is still alive and fires the trigger a second time. In one case two runs of a daily trigger started 32 minutes apart, and the second messaged the first about the duplicate. The log line appeared 58 times in 10 days on one machine.Fix
renewTaskLeasereturnstrue(renewed),false(the backend answered that this daemon no longer holds the lease) ornull(no answer: timeout, offline, no token).false. Onnullit logs a warning and tries again on the next beat.heartbeat(taskId)(first commit, no behaviour change) so a test can drive one beat.Trade-off
A run whose backend never comes back keeps beating until its max runtime, which already ends it. A run whose lease really was lost still stops at the next beat that gets an answer.
Alternative (not taken)
Make the reclaim sweep wait longer before re-firing. That delays real recoveries (a daemon that died mid-run) and leaves the dropped monitor in place.
Tests
Four new tests, written first and failing before the fix:
renewTaskLeaseanswersnull, notfalse, when the mutation throws.trueandfalsethrough.null.false.They pass, as do
taskScheduler.test.ts,syncService.timeout.test.tsanddaemon.trigger-run.test.ts;cast check clishows 0 errors.Full CLI suite (
bun test --parallel, 1071 files) on a bare Linux machine with bun 1.4.4:The same 22 fail on both: they need real claude/codex clients or tmux behaviour that machine lacks. The extra failure is
short-message delivery into Claude > hi submits exactly once from a composer that is empty, which is flaky: three reruns on each of main and the branch gave mixed results on both.