fix(daemon): run the long lanes off the tick path #7

Merged
vhaudiquet merged 1 commits from kosmos/rhema-claw:fix/forge-pass-off-tick into main 2026-11-22 01:44:39 +00:00
Collaborator

What it means: the resident loop does one thing at a time, and a turn is one of the things. tick awaits forge_driver.run_once(), and Driver::run_once awaits every run it admits — so for as long as a turn is under way, the loop is not detecting. No forge poll, no watch health row, no due task fired, no calendar reminder, no phone delivery.

That is what last_ok_at: 00:35:02 was. The turn started at 00:35:03 and ran to its ten-minute lease; the loop never came round to poll again, so the health row froze 11 minutes back and looked like a network failure. It wasn't one.

Arithmetic: a 60s poll interval and a ten-minute turn is one poll per turn, i.e. a 10× under-poll of every watch during any turn. With the lease raised to an hour (PR #5) the same shape freezes detection for an hour — so this has to land with or before that one.

The change

  • Daemon::resident_tick — detect, then hand the forge and jobs passes to their own tasks; the interactive drain stays inline, since its runs are the chat itself. run() uses it.
  • spawn_pass — one pass per lane at a time. A tick that fires mid-pass leaves its events in the dispatcher's inbox, which is already the queue; a second concurrent pass would only lose lease acquisitions to the first and log the loss. The in-flight flag is released by a drop guard, so a panicking pass cannot strand its lane.
  • Daemon::tick keeps its shape and semantics exactly: --once and the tests still mean "the work happened" when a pass returns, and the [claw] pass: N detected, H handled, F failed line is unchanged there. The detached passes log without a detected count, which they do not own.

The jobs lane is in here too, not just the forge one: same defect, same fix, and a coding job is the longest run the daemon has. Two lines apart, so splitting them would just be two reviews of one idea.

What this does not fix

A tick that fires while a pass runs does no admission of its own, so a key released mid-pass waits for the next tick to pick it up (≤ one poll interval, 60s). That is the debounce the dispatcher already applies to a re-acquire; it is not new latency, and removing it means an admission path separate from the pass, which is a bigger change.

Test

a_spawned_pass_holds_its_lane_instead_of_stacking — a gated stub handler: the pass starts on its own task (the caller has already returned), the lane reads as held while it runs, a second spawn_pass mid-pass is skipped rather than stacking, and the flag clears when the pass ends. Deterministic (semaphores, not sleeps) with a timeout on the start, so a regression fails instead of hanging.

bin/gate.sh is green locally (fmt, clippy -D warnings, check — all targets). No test binaries can run on this box; CI runs them.

**What it means:** the resident loop does one thing at a time, and a turn is one of the things. `tick` awaits `forge_driver.run_once()`, and `Driver::run_once` awaits every run it admits — so for as long as a turn is under way, the loop is not detecting. No forge poll, no watch health row, no due task fired, no calendar reminder, no phone delivery. That is what `last_ok_at: 00:35:02` was. The turn started at 00:35:03 and ran to its ten-minute lease; the loop never came round to poll again, so the health row froze 11 minutes back and looked like a network failure. It wasn't one. Arithmetic: a 60s poll interval and a ten-minute turn is one poll per turn, i.e. a 10× under-poll of every watch during any turn. With the lease raised to an hour (PR #5) the same shape freezes detection for an hour — so this has to land with or before that one. ## The change - `Daemon::resident_tick` — detect, then hand the forge and jobs passes to their own tasks; the interactive drain stays inline, since its runs are the chat itself. `run()` uses it. - `spawn_pass` — one pass per lane at a time. A tick that fires mid-pass leaves its events in the dispatcher's inbox, which is already the queue; a second concurrent pass would only lose lease acquisitions to the first and log the loss. The in-flight flag is released by a drop guard, so a panicking pass cannot strand its lane. - `Daemon::tick` keeps its shape and semantics exactly: `--once` and the tests still mean "the work happened" when a pass returns, and the `[claw] pass: N detected, H handled, F failed` line is unchanged there. The detached passes log without a detected count, which they do not own. The jobs lane is in here too, not just the forge one: same defect, same fix, and a coding job is the longest run the daemon has. Two lines apart, so splitting them would just be two reviews of one idea. ## What this does not fix A tick that fires while a pass runs does no admission of its own, so a key released mid-pass waits for the next tick to pick it up (≤ one poll interval, 60s). That is the debounce the dispatcher already applies to a re-acquire; it is not new latency, and removing it means an admission path separate from the pass, which is a bigger change. ## Test `a_spawned_pass_holds_its_lane_instead_of_stacking` — a gated stub handler: the pass starts on its own task (the caller has already returned), the lane reads as held while it runs, a second `spawn_pass` mid-pass is skipped rather than stacking, and the flag clears when the pass ends. Deterministic (semaphores, not sleeps) with a timeout on the start, so a regression fails instead of hanging. `bin/gate.sh` is green locally (fmt, clippy `-D warnings`, check — all targets). No test binaries can run on this box; CI runs them.
kosmos force-pushed fix/forge-pass-off-tick from 04ff7290c7 to c89c18db0c 2026-11-22 01:14:56 +00:00 Compare
vhaudiquet added 1 commit 2026-11-22 01:44:24 +00:00
fix(daemon): run the long lanes off the tick path
android / release (pull_request) Skipped
android / debug (push) Successful in 2m20s
android / release (push) Successful in 2m0s
ci / checks (push) Successful in 1m16s
ci / test (push) Successful in 47s
ci / chart (push) Successful in 6s
ci / docker (push) Successful in 1m33s
ci / web (push) Successful in 13s
android / debug (pull_request) Successful in 2m15s
ci / checks (pull_request) Successful in 1m4s
ci / test (pull_request) Successful in 40s
ci / chart (pull_request) Successful in 5s
ci / docker (pull_request) Successful in 1m29s
ci / web (pull_request) Successful in 12s
ci / publish-edge-images (deploy/docker/claw.Dockerfile, rhema-claw) (pull_request) Skipped
ci / publish-edge-images (deploy/docker/ui.Dockerfile, rhema-claw-ui) (pull_request) Skipped
ci / publish-edge-chart (pull_request) Skipped
ci / publish-edge-images (deploy/docker/claw.Dockerfile, rhema-claw) (push) Successful in 1m36s
ci / publish-edge-images (deploy/docker/ui.Dockerfile, rhema-claw-ui) (push) Successful in 14s
ci / publish-edge-chart (push) Successful in 3s
ae198c6f26
`tick` awaited `forge_driver.run_once()` (and the jobs one before it), and
`Driver::run_once` awaits every run it admits. So while a turn was under
way the loop stopped doing everything else: no forge poll, no watch
health, no due task, no calendar reminder, no phone delivery. With a 60s
poll interval and a ten-minute turn, the daemon polled once per turn —
which is why `last_ok_at` sat frozen at 00:35:02 while the turn that
started at 00:35:03 ran. Not a network problem, and not the watch.

Worse in combination with a longer lease: an hour-long turn would freeze
detection for an hour.

Split the pass. The resident loop (`run`) now uses `resident_tick`, which
detects and then hands the forge and jobs passes to their own tasks; the
interactive drain stays inline, since its runs are the chat itself. One
pass per lane at a time — a tick that fires mid-pass leaves its events in
the dispatcher's inbox for the next one, which is the queue the
dispatcher already is; a second concurrent pass would only lose lease
acquisitions to the first. The in-flight flag is cleared by a drop guard,
so a panicking pass cannot strand its lane permanently.

`tick` keeps its exact shape and semantics: `--once` and the tests still
mean "the work happened" when a pass returns, and the forge-line log
(`[claw] pass: N detected, H handled, F failed`) is unchanged there. The
detached passes log without the detected count, which they do not own.
vhaudiquet force-pushed fix/forge-pass-off-tick from c89c18db0c to ae198c6f26 2026-11-22 01:44:24 +00:00 Compare
vhaudiquet merged commit ae198c6f26 into main 2026-11-22 01:44:39 +00:00
Sign in to join this conversation.
No Reviewers
No labels
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vhaudiquet/rhema-claw#7