Skip to content

fix: count client contact made during a tick slower than tickMs (#6813) - #6823

Merged
janicduplessis merged 4 commits into
mainfrom
fix/6813-stimd-idle-contact
Dec 2, 2026
Merged

janicduplessis merged 4 commits into
mainfrom
fix/6813-stimd-idle-contact

Conversation

@janicduplessis

@janicduplessis janicduplessis commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Description

stimd copied lastContact into contactSince when a tick started and tested that copy when the tick ended. A contact that arrived during the tick was ignored, so a tick longer than tickMs always counted as idle, and two in a row ended stimd with nothing runs in this Stim home while a client was talking to it.

Reading the current lastContact alone is not enough. stimd's own passes call liveShareKeepReason, which dials stimd's CLI socket through connectNet, and that self-contact would keep a quiet home up forever (daemon-cadence.test.ts fails). The tick-start copy was what hid it.

Solution

  • The idle check reads the current lastContact.
  • connectNet marks its first frame net: true, and stimd takes no contact from a connection that carries it.
  • This also covers CLI callers of connectNet (stim share, stop's share cleanup, doctor's server probe): their net.connect handoff no longer counts as contact. Nothing is lost: while the net thread runs, stimd stays up for it anyway ("the net thread serves"), and while it does not, the handoff fails with net-off. Their other ops still count.
  • An older stimd ignores the extra field.
  • The exit gate after the second idle tick awaits an engine check, after the tick sampled what keeps stimd alive. A contact during that wait, or a net thread that started meanwhile (for example stim serve, which registers no active command), now also keeps stimd up: the gate requires no contact within tickMs and no running net thread, like the tick does.

I chose this over the issue's suggestion of asking the net thread for live shares in-process, which needs plumbing into every liveShareKeepReason caller, some of them in worker threads.

Test plan

  • stimd.integration.test.ts gets a row "a client hello during ticks longer than tickMs": measureTick waits 1500 ms with tickMs: 1000 while a hello arrives every 30 ms. It fails on main (expected 'exited' to be 'running') and passes here; the gate's contact clause alone would also pass it. The existing probe and client-hello rows still pass.
  • daemon-cadence.test.ts "a workspace with no activity recorded in its state does not" covers the net: true half: it fails with only the idle-check change and passes with both.
  • daemon-cadence.test.ts gets two rows "... during the engine check before the idle exit does": they hold the gate's engine check open, then send a hello, or start the net thread and let 2 minutes pass, and expect a third tick. Each fails without its gate clause (stimd stops after two ticks).
  • Related stimd and daemon integration suites pass locally on macOS.

Fixes #6813

stimd copied lastContact when a tick started and tested that copy when
the tick ended, so a tick longer than tickMs always counted as idle. The
idle check now reads the current lastContact.

stimd dials its own CLI socket to list web shares, so that dial must not
count as contact. The net.connect handoff now marks its first frame with
net: true, and stimd takes no contact from such a connection. While the
net thread runs stimd stays up for it anyway, and while it does not the
handoff fails.
@janicduplessis janicduplessis added area: cli packages/stim-cli, including its README and guide review: ai-approved A fresh AI review found nothing left to fix labels Dec 2, 2026
…unning (#6813)

The exit gate awaits an engine check after the idle sample. A client that
contacts stimd during that wait, such as stim serve asking for the net
thread, does not register as an active command, so stimd shut down under
it. The gate now also requires no contact within tickMs.
@janicduplessis janicduplessis added review: ai-approved A fresh AI review found nothing left to fix and removed review: ai-approved A fresh AI review found nothing left to fix labels Dec 2, 2026
… stimd running (#6813)

The exit gate now also keeps stimd up while the net thread runs, as the
tick does, so a listener stim serve started after the idle sample is not
closed under it. The gate tests stop their daemon in a finally block, and
the slow-tick row uses 1 s slow ticks so the unfixed exit lands well
inside its window.
@janicduplessis janicduplessis added review: ai-approved A fresh AI review found nothing left to fix and removed review: ai-approved A fresh AI review found nothing left to fix labels Dec 2, 2026
… docs: LLP 0012 names the gate's contact and net thread checks (#6813)
@janicduplessis janicduplessis removed the review: ai-approved A fresh AI review found nothing left to fix label Dec 2, 2026
@janicduplessis janicduplessis added the review: ai-approved A fresh AI review found nothing left to fix label Dec 2, 2026
@janicduplessis
janicduplessis marked this pull request as ready for review December 2, 2026 21:56
@janicduplessis
janicduplessis merged commit 4cc3769 into main Dec 2, 2026
63 of 65 checks passed
@janicduplessis
janicduplessis deleted the fix/6813-stimd-idle-contact branch December 2, 2026 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli packages/stim-cli, including its README and guide review: ai-approved A fresh AI review found nothing left to fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stimd exits as idle when its ticks run longer than tickMs, ignoring contacts made during the tick

1 participant