Skip to content

feat(execution): process events say how long a patch process took to start - #865

Merged
allisonmahmood merged 3 commits into
mainfrom
mcp/836-process-start-time
Oct 22, 2026
Merged

allisonmahmood merged 3 commits into
mainfrom
mcp/836-process-start-time

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

What changed

An agent's call on a company whose server is released waits for the bind, then the version's process start counts against the query's 3 s deadline. Nothing recorded how long a process start takes, so nobody could check that a cold start on Fargate leaves a query enough of its 3 s.

Each process event now says how long its process took to start (startMs, from spawn until ready for its first call) and whether it was the first process its company task started after being bound (firstOnTask). Both are optional on the private management wire, so hosts and supervisors from neighbouring releases keep decoding each other's reports.

The dev executor behind pnpm dev used to keep its process reports in memory and never emit them. It now emits them too, so the dev loop sees the same events.

Closes #836

Look at

A process event as the host emits it, from the local fleet (a separate supervisor process per task, over the management wire, decoded, stored and emitted by the host: the path production takes, run offline). Trimmed:

{
  "type": "process",
  "tier": 2,
  "processGeneration": 1,
  "cause": "stopped",
  "durationMs": 683,
  "callsServed": 1,
  "startMs": 576,
  "firstOnTask": true
}

The same events in the dev loop. pnpm dev up brightline, New Business opened, then its processes left to idle out. From pnpm dev logs, trimmed:

{ processGeneration: 1, cause: "idle", callsServed: 4, startMs: 88,  firstOnTask: true  }
{ processGeneration: 2, cause: "idle", callsServed: 4, startMs: 123, firstOnTask: false }

What decides the numbers is two lines in packages/execution/src/supervisor.ts: startMs is taken when the load finishes and the process is marked ready, and firstOnTask is generation === 1. A supervisor serves one company for its life and counts generations from one. A process that never became ready, such as a load_failed one, has no startMs.

The test, red then green. Before the supervisor change, reports how long each process took to start, and whether it was its task's first fails on its first assertion:

- Expected: true
+ Received: undefined
 ❯ src/Supervisor.test.ts:569:38
      expect(firstEvent.firstOnTask).toBe(true);

With it: Tests 2 passed (the new test, plus the load_failed one now asserting startMs is absent). Likewise, the new Local.test.ts case, where two versions idle out and both events arrive, timed out with nothing delivered before the dev executor forwarded reports.

How the dev executor emits them (packages/execution/src/local.ts): a scoped fiber reads the supervisor's reports about once a second, emits each event, then acknowledges them, the same way the fleet's collection does. When the executor closes, it stops the supervisor and emits what's left, so processes still running at shutdown are reported too. It needs WideEvents from the environment. The server's dev wiring passes it through, and tests that build the executor directly provide WideEvents.layerNoop. A patch repo's compact patchy dev log skips process events (packages/patchy/src/devLog.ts), so builders don't get a line each time an old version idles out. Its --json log carries them.

How it was verified

  • New supervisor test: the first of two versions on a task is firstOnTask: true, the second false. Both have a startMs that is above zero and fits within the bind and the process's life. A load that expires has none.
  • The local-fleet test that checks a process event is delivered once now also asserts that event carries firstOnTask and startMs.
  • New Local.test.ts case for the no-pool dev executor: a process that idles out is emitted by the loop, and one still running when the executor closes is emitted with cause: "stopped". Hand-checked on pnpm dev up brightline (above). ~/Patchy gained nothing.
  • pnpm verify on d4d2d45: 8 of 9 steps pass. The test step had one 5-second timeout in PgliteCompanyDatabases.test.ts at load average 17, in code this PR doesn't reach. It passes alone and in CI on all three Node versions. On the previous head, b003b14, all 9 steps passed; since then only local.ts's shutdown and its test have changed.
  • Targeted suites pass: Supervisor, Fleet, Management, LocalTaskProvider, packages/analytics and packages/api (12 files, 114 tests), plus every Local.make caller (Local, InvocationLocal, QuerySubscriptionsLocal, HandlerTls, PostHog Runtime, devServer, DevelopmentExecution). pnpm typecheck, lint and format pass.
  • Not checked here: production's numbers. Those belong to Allison's release gate, after this has been deployed for a few days (see below).

Surfaces: the management wire (packages/api/src/management.ts, its prose in markdown.ts rendered into docs/API.md), the wide event schema (packages/analytics), the Analytics glossary (Process start), docs/OPERATIONS.md (what emits them, and a Logs Insights query) and the dev executor. The skills already say patchy dev --json records full wide events. No CLI, migration, dev-runner or page change.

Reading production's numbers (release gate, not done here)

Once this has been live for a few days, this read-only HogQL query gives the p50, p90 and maximum process start on Fargate against the 3 s deadline. firstOnTask IS NOT NULL keeps only reports from supervisors of this release or later:

SELECT
  properties.firstOnTask AS firstOnTask,
  count() AS starts,
  round(quantile(0.5)(toFloat(properties.startMs))) AS p50_ms,
  round(quantile(0.9)(toFloat(properties.startMs))) AS p90_ms,
  max(toFloat(properties.startMs)) AS max_ms,
  countIf(toFloat(properties.startMs) > 3000) AS over_3s
FROM events
WHERE event = 'wide.process'
  AND properties.firstOnTask IS NOT NULL
  AND properties.startMs IS NOT NULL
  AND timestamp > now() - INTERVAL 7 DAY
GROUP BY firstOnTask

Starts that never became ready don't have a startMs. Count them by cause with the same filter and properties.startMs IS NULL, grouped by properties.cause. The firstOnTask = true row is the cold start an agent's first call on a released company pays. Its p90 and max against 3000 ms answer #833's question.

Release impact

  • Breaking — requires action from anyone already running this
  • Not breaking — no action required

Two optional fields added to a private wire's process event and to the wide event. No schema, CLI or config change.

  • What does a revert leave behind? Process events already sent to PostHog and CloudWatch, and process report rows in execution_processes whose stored report JSON has the two extra keys. Nothing reads that JSON back.
  • Does the release before it still work with that? Yes. Hosts decode supervisor stats with Effect's default, which drops unknown keys, so an older host reads a newer supervisor's reports. A newer host reads an older supervisor's reports because both fields are optional.

Built by Claude Opus 5.5 (xhigh) in Claude Code on T3 Code; reviewed and accepted by GPT-6.1-Sol (xhigh).

@github-actions github-actions Bot added area:server Touches the server area area:docs Touches the docs area size:s Under 100 changed lines area:cli Touches the cli area area:integrations Company connections and integration implementations size:m 100-500 changed lines and removed size:s Under 100 changed lines labels Oct 22, 2026
@allisonmahmood
allisonmahmood force-pushed the mcp/836-process-start-time branch from f262de6 to b003b14 Compare October 22, 2026 07:51
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Review: GPT-6.1-Sol (xhigh), three rounds

Round 1 (6c0a573): one blocking finding.

  • The default dev paths never emit process events. Local.make (packages/execution/src/local.ts), the no-pool executor behind pnpm dev and patchy dev, created the supervisor but never collected its reports, so the dev loop couldn't see startMs.
    Fixed in b003b14:
    • The executor takes WideEvents from the environment, and a scoped loop emits and acknowledges reports about once a second.
    • The server's dev wiring passes WideEvents through.
    • A patch repo's compact patchy dev log skips process events, which stay in its --json log.
    • A new Local.test.ts case was red before the change and green after. Hand-checked on pnpm dev up brightline.
  • Confirmed sound: the startMs timing, firstOnTask as generation === 1, both directions of mixed-release decoding, analytics and the rendered docs/API.md.

Round 2 (b003b14): one blocking finding.

  • Closing the executor drops its last reports. The report loop was interrupted before the supervisor's finalizer reaped the processes still running, so their stopped reports were never emitted.
    Fixed in d4d2d45:
    • A finalizer registered before the loop stops the supervisor and emits what's left once the loop has stopped.
    • Each emit-and-acknowledge step is uninterruptible, so a close never sends a report twice.
    • The test now also closes the executor with a process running and expects its stopped event. It was red before the fix and is green after.
  • Confirmed: the compact patchy dev filter is the right call.

Round 3 (d4d2d45): no blocking, should-fix or nit findings. Shutdown ordering against the supervisor's finalizer and watchdog, in-flight batches at close, and error handling all check out.

@allisonmahmood
allisonmahmood force-pushed the mcp/836-process-start-time branch from d4d2d45 to b1f09ed Compare October 22, 2026 08:45
allisonmahmood and others added 3 commits October 22, 2026 10:58
…start

Each process event now carries startMs, from spawn until the process was
ready for its first call, and firstOnTask, true for the first process its
company task started after being bound. Both are optional on the wire so
hosts and supervisors of neighbouring releases keep decoding each other's
reports. The numbers let us check, from production's events, that a cold
start leaves a query enough of its 3 s deadline before Patchy MCP lands.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The no-pool executor behind `pnpm dev` and `patchy dev` kept its process
reports in memory and never emitted them, so the dev loop couldn't see a
process's start time. It now emits each ended process's wide event within a
second and acknowledges it, as the fleet's collection does. A patch repo's
compact dev log stays about calls; its --json log carries the full events.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…sses

Closing the no-pool executor stopped its report loop before the supervisor
reaped the processes still running, so their reports were never emitted.
Its finalizer now stops the supervisor and emits what is left, after the
loop stops; each emit-and-acknowledge step is uninterruptible so a close
never sends a report twice.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood force-pushed the mcp/836-process-start-time branch from b1f09ed to 33938a0 Compare October 22, 2026 08:58
@allisonmahmood

allisonmahmood commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner Author

Acceptance: PASS with notes

Checked 33938a021ff63036c3706a0f29ec1e5ed86426a1 (base d4d6ed77665d5a1fa5d4a761956740f2e9d572cb) on fresh brightline data and disposable offline test instances, by GPT-6.1-Sol (xhigh) in the Codex harness on T3 Code.

This verdict covers the process-reporting implementation. Allison explicitly excludes production's process-start numbers and the later #833 release gate. Production was never contacted.

Rebase verification

All three commits match the previously accepted b1f09ed series (git range-diff reports = for each). The complete PR diff before and after the rebase has the same SHA-256, 3e3b6fb58460895924a49779afa5b9ccd001ebfbb16e8b846fefc1bf78df0c82. The sole intervening main change is #867, with no files shared with this PR. The checks below were rerun on this exact head.

Done means

  • Dev process events: passed. A fresh pnpm dev up brightline instance was healthy and emitted first and later process starts with positive timings. Actual server events, trimmed to scenario-safe fields:
{"type":"process","tier":2,"processGeneration":1,"cause":"idle","callsServed":14,"startMs":115,"firstOnTask":true}
{"type":"process","tier":2,"processGeneration":2,"cause":"idle","callsServed":4,"startMs":138,"firstOnTask":false}
  • Fleet reporting path: passed offline. Real workerd suites cover spawn-to-ready timing for first and subsequent processes, no startMs when loading fails, separate task supervisors over the management wire, persistence, and acknowledgement retry without duplicate delivery. The no-pool executor test covers idle emission and the final running process reported as stopped when its scope closes.
  • Mixed releases and CLI logs: passed. An independent probe used the actual base and head StatsReply schemas: the base accepts new reports and drops the extra fields; the head accepts old reports without them. Both firstOnTask values and startMs survive management and analytics decoding; wrong types are refused. The actual devLog.layer suppresses process events in compact mode, retains request logging, and emits both in JSON with timing fields intact.

Golden journeys

  • Use a tier 2 tool: passed. Jordan and Allison opened New Business with sample deals in separate browser profiles. Jordan moved Verdant Grocers from Lead to Discovery and back; Allison's already-open board followed both changes without reloading. In Spend, Jordan tried to approve Copywriter: packaging & menu board copy, his own request. It remained Waiting and showed “You can't approve your own request.” The checked browser snapshots recorded no console errors.
Spend refuses the requester's approval on this head

Spend refuses Jordan's own request

Validation

Local run: execution, analytics, API, local invocation/subscriptions, both integration callers, CLI dev server, server development wiring and scripts/dev:

Test Files  39 passed (39)
     Tests  272 passed (272)

11 of 14 PR checks have passed; test (24), test (22), browser are still running. No failed checks at posting. The local checks above passed on this head. Head CI run.

Notes

  • CI is not yet complete; this verdict does not claim the remaining jobs have passed.

Rollback answers: match the diff. A revert leaves already-emitted events and additional keys in stored report JSON. The previous release accepts those keys, the new release accepts older reports, and stored report JSON has no consumer requiring the new shape. This PR changes no migration or infrastructure; no one-way label is needed.

Surfaces: management wire and generated API documentation, analytics schema/vocabulary, dev execution wiring, and compact/JSON CLI logs apply. No new public CLI contract, migration, company-resource caller, served page, lifecycle transition or package layout change.

Not run

  • Production/Fargate observation and the production percentile query: explicitly outside this verdict, reserved for Allison's later release gate. Local timings do not establish Fargate latency.

No tracked files, PR code, branch, body or labels were changed. The throwaway environment and checkout are being removed after posting.

@allisonmahmood
allisonmahmood merged commit 5f474a6 into main Oct 22, 2026
14 checks passed
@allisonmahmood
allisonmahmood deleted the mcp/836-process-start-time branch October 22, 2026 09:10
allisonmahmood added a commit that referenced this pull request Oct 22, 2026
allisonmahmood added a commit that referenced this pull request Oct 22, 2026
…874)

## What changed

Release 16's What's new entry, written from `dd3f41f`. It covers
everything merged since release 15's `through` (`9e4b0df`), and sets the
`patchy` release to `0.16.0` (`packages/patchy/package.json` and
`CURRENT_RELEASE`).

| Change | PRs |
| --- | --- |
| Fixed: Revoke all machines stops logins still on their way | #867 |
| Behind the scenes: `mcp` and `oauth` kept off company addresses | #863
|
| Behind the scenes: read-only actions and agent tools understood and
enforced before anything writes them | #868 |
| Behind the scenes: logs record how long a tool's server takes to start
| #865 |

#814 is release 15's own entry, so it's left out. #818 and #831 are docs
(Patchy is live; the Patchy MCP spec) and #864 is dev tooling, so none
of them gets a line.

## Look at

- **The entry**, at the top of `releases` in
`packages/core/src/whatsNew.ts`. #867 is the only change a person could
notice. The page's button is still labelled "Revoke all machines"
(Disconnect everything is the spec's future name), so the entry uses
that label.
- **Rollback safety, from the live commit `d77baaf` to `dd3f41f`.** No
PR in the range is labelled `one-way`, and every PR answers both Release
impact questions with "Yes".
- #867 is the only migration: `0019_credentials_ended` adds two nullable
columns, `users.credentials_ended_at` and `device_logins.confirmed_at`.
At `d77baaf`, every insert into `users` and `device_logins` lists its
columns, and nothing reads either table with `SELECT *`.
- `rollback-rehearsal` passed on #863, #865, #867 and #868. #868's run
covered #867's migration already on main: `Exercised rollback paths
passed: d77baaf → ffe9988 → d77baaf`.
- A rollback would reopen what #867 closes: an approved login that
hasn't finished could again get past Revoke all machines. It would also
let new companies take the `mcp` and `oauth` addresses (#863). No
release that writes read-only actions or agent tools has shipped, so
going back past #868 leaves nothing behind.

## How it was verified

- `vitest run packages/core/src/whatsNew.test.ts
packages/api/src/schemas.test.ts`: 14 passed.
- `pnpm typecheck`: 23 of 23 tasks pass. Prettier and eslint are clean
on the changed files.
- The live commit was pinned from `/healthz/deep` (`d77baaf`, release
15). The Deploy run updated last succeeded, and none is unfinished.

## Release impact

- [ ] **Breaking** — requires action from anyone already running this
- [x] **Not breaking** — no action required

The changelog text plus the `patchy` version bump. A CLI installed
before this deploy is told to upgrade, as with every release.

- **What does a revert leave behind?** Nothing. People whose seen marker
reached 16 would just see no new release.
- **Does the release before it still work with that?** Yes.

If this release misbehaves, roll back to
`d77baafcf10c7cdf28c71bd65ea1a0009aa99ced` (release 15).

Built by Claude Opus 5.5 (xhigh) in Claude Code on T3 Code.

Co-authored-by: Claude Opus 5.5 <[email protected]>
@allisonmahmood allisonmahmood mentioned this pull request Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:cli Touches the cli area area:docs Touches the docs area area:integrations Company connections and integration implementations area:server Touches the server area size:m 100-500 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Process events say how long a patch process took to start

1 participant