Repository navigation
feat: record how long a refused report child outlives its cancel - #5771
Merged
Merged
Conversation
janicduplessis
commented
Nov 15, 2026
janicduplessis
left a comment
Collaborator
Author
There was a problem hiding this comment.
AI review: head 04a5f66
Verdict: clear
I ran report-runtime.integration.test.ts in the worktree: 21 passed, 2 skipped. I did not run a real stimd.
1. Behaviour identity (exec.ts): no difference from main found
cancel(reason?):cancelledAtandcancelReasonare assigned synchronously at the top of the memoised async body, before the first await.cancelled ??=still runs the body once. A second call with a different reason returns the same promise and leaves the first reason in place. Neither assignment can throw:signal.reasonis a plain property read and theinstanceof/inchecks are guarded.refuse(message, refusal): the thrown error, the destroys,unref()andrejectClosedare unchanged.recordRefusedruns afterunref()and beforerejectClosed, and returns early whenpidis undefined. It only registers a listener or logs. Everything inwrite()is arithmetic and field reads, andlogReportChildswallows sink errors, so nothing can reach the refuse or cancel path.- New
exitlistener: it only assigns two locals. It is attached insidereportChild, so it registers before thecleanupOnExitlistener thatdefaultExecutorattaches afterwards. Theclosehandler is untouched except that it passes'close'. The deferredonce('exit', write)is registered after the recorder, soexitedAtis set whenwriteruns. - Exit before cancel:
exitedAtis already set,writeruns immediately, andcancelToExitMsis negative. This is thedescendantscase undercleanupOnExit.
3. Process lifetime
- An
exitlistener holds no handle, and no timer is added. A CLI process has no sink. In stimd the loop is alive anyway. A child that never exits writes no record, as the PR says. - Low, note (
stimd/main.ts:778): the sink is never cleared. The early-return paths and the final shutdown callwriter.close(), and a later record then goes to a closed writer.writereturns false and incrementsdropped, so nothing throws and nothing is written to a closed fd. Inthreads.tsthe thread'spostMessageis inside thetry. Neither is worth a change.
4. Output
- No stdout or stderr writes. The record is one
infoline with exactly the guide's fields.commandisdescribeReportCommand(basename plusredactArgv, capped at 120 characters), the same text as #5769. Nothing else from argv or env is included. - Note: a forwarded CLI command that runs inside stimd logs through the daemon sink without its invocation id. The record cannot be tied to the command that started the child except through
command.
5. Data
spawnToCancelMs,cancelToExitMsand thetimeoutMsthatbudgetMsreturns (omitted when unbounded) answer how long the child lived after the cancel, why it was cancelled, and what its timeout was.- Note (
exec.tsrecordRefused): fordescendants,cancelToExitMsis the leader's exit. It says nothing about how long the descendants lived. The guide says "that child's own exit", so it is accurate. - Note:
spawnedAtis taken whenreportChildis called, after the spawn. The skew is negligible.
6. Module global sink
- It matches
debug-log.ts, which is also a module-level instance. Each worker thread has its own module instance andthreads.tsinstalls its own sink, which posts to the main thread. The test resets the sink infinally.
7. Test and guide
- The test names a real failure: an uncaptured child that is refused and exits later. Its expectation is independent of the implementation (real child, real exit code,
cancelToExitMs >= 1500against a 3 s child). It sits at the lowest stable seam, with an installed sink standing in for the daemon. - Note: it does not cover the
timeout,report_budgetorexitreasons or the negativecancelToExitMs. That is acceptable for diagnostics. - It uses
process.execPath, so it works on Linux and Windows, and CI passed on both. - The
guide/logs.tsaddition is prose and documents a code-defined event name and fields. No regex test on it is needed.
8. PR body
- Accurate. It says it exercised no real stimd write and no thread record, and both are unexercised.
janicduplessis
marked this pull request as ready for review
November 15, 2026 16:58
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.
Description
A report child whose cleanup is refused (
STIM_CLAIM_UNAVAILABLE) is left running, and the daemon log shows only when stimd next found it stopped, once per tick. How long such a child outlives its cancel is not known, and that number decides whether a longer wait, a caller timeout or signalling is the right fix for #5766.Solution
reportChildinexec.tsrecords, for a child it refuses, when it was spawned, when its cancel started, why, and when the handle deliveredexit. When the exit is seen (immediately if it already was) it writes onedaemon_report_child_exitedinfo record throughreport-child-log.ts. stimd's logger and each stimd thread's logger are installed as the sink, so the record reachesdaemon.ndjson. A CLI process installs none and writes nothing. No timer is added: a listener on the child'sexitevent does not keep the process alive, and a child that never exits writes no record.Fields:
pid,command(the bounded, redacted text of the refusal),cancelReason(timeout,overflowandexitandclosefrom the exec call sites,report_budgetwhen the abort reason is the report's ownSTIM_REPORT_TIMEOUT,abortfor any other abort,unknown),timeoutMswhen the call had one,spawnToCancelMs,cancelToExitMs(negative when the exit came first),exitCode,exitSignal,refusal(unverified,did_not_close,descendants),captured,captureReason.When a refusal happens, what is signalled, retained or waited for, and every error are unchanged.
stim guide logslists the event.Test plan
report-runtime.integration.test.ts: an uncaptured child that is refused and exits 3 s after it started produces one record withcancelReason: abort,refusal: unverified,captured: false,timeoutMs, exit code 0, andcancelToExitMsof at least 1500.test (node 22),test (node 24),test (macos)andtest (windows)passed: https://github.com/appandflow/stim/actions/runs/43736826863daemon.ndjson, and a record produced from a stimd thread. The test uses an installed sink and a real spawned child.Part of #5766