Skip to content

refactor(cli): one RunLifecycle for the audit and the MCP server; a second interrupt still lets the terminal status land - #1710

Closed
nc9 wants to merge 1 commit into
mainfrom
refactor/run-lifecycle-1663
Closed

nc9 wants to merge 1 commit into
mainfrom
refactor/run-lifecycle-1663

Conversation

@nc9

@nc9 nc9 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1663.

The CLI audit (createRunFinalizer in run-tracker.ts) and the MCP server (RunLifecycle, closeRun, a lifecycles map in mcp/billed-audit.ts) each drove a tracked run from register to terminal PATCH themselves and each reimplemented at-most-once terminal. There is one now.

What

  • createRunLifecycle(registered, options) in lib/run-tracker.ts, returning { registered, markRunning, close, isClosed }:
    • close sends the terminal state at most once, whichever exit path calls it first; every later call (and a concurrent one) waits for that one PATCH. It waits for the register and for the in-flight markRunning, and stops the progress heartbeat first (the CLI's overlay-style: namespaced type selectors keep a cover rule silent (star-pipe iframe, pipe iframe, attribute namespace) #1583 behaviour; the MCP server passes stopHeartbeat: false, it has none).
    • markRunning is sent once and is a no-op after close has been called, including when the close arrived while the register was still in flight: the API applies whichever status lands last, so a late running would flip a finished run back and have it reaped as stalled.
  • createRunFinalizer stays (existing callers and tests) as the close of a lifecycle.
  • CLI audit: builds a lifecycle from its register promise and uses lifecycle.close as finalizeTracked; the MCP server builds one per billed run. The server keeps its shutdown snapshot and map, but no terminal-state logic of its own.
  • Second interrupt: the signal handlers were process.once, so the first signal removed the handler and a second Ctrl-C during the "cancelled" PATCH took the runtime default and killed the process under it. createInterruptHandler stays installed (process.on): the first signal finalizes then re-raises, a later one waits for the PATCH already in flight, never starts a second, for at most SECOND_INTERRUPT_WAIT_MS (3 s) and then exits. The first-signal messages and the crawl bookkeeping run once.

Acceptance criteria

  • CLI audit and the MCP server use the same lifecycle module: createRunLifecycle, pinned by a source test on both files
  • close() called twice sends one terminal update: run-lifecycle-1663.test.ts (sequential, concurrent, register still in flight, no run)
  • A second SIGINT during finalize still sends the terminal status, or exits after the documented cap: createInterruptHandler tests (waits for the PATCH, one finalize; a PATCH that never lands is cut by the cap)
  • markRunning after close is a no-op (test), and a markRunning waiting on the register does not follow a close

Checks

New file 17 tests; run-tracker (65 with the MCP billed-audit tests), audit-website-billing, server, audit-website-max-duration-1271 pass. tsgo, root lint, cli format:check. Temp HOME. CHANGELOG bullet.

Agent skill and docs

  • squirrelscan agent skill (squirrelscan/skills): No change. The skill does not describe interrupt handling or the run lifecycle; a second Ctrl-C now lands the cancelled status, which an agent could not act on differently.
  • Docs: No docs page describes the interrupt handler; the behaviour is in the CHANGELOG bullet. Nothing to update.

…econd interrupt still lets the terminal status land #1663

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9

nc9 commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

Landed on main as 381dbb1 (later commits there carry the review fixes). Closing this draft as superseded.

nik

@nc9 nc9 closed this Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI and MCP each reimplement the tracked-run lifecycle; one RunLifecycle, second Ctrl-C still finalizes

1 participant