Skip to content

fix(execution): local task start no longer hangs when an unrelated process exits - #501

Merged
allisonmahmood merged 2 commits into
mainfrom
t3code/implement-issue-486
Oct 3, 2026
Merged

allisonmahmood merged 2 commits into
mainfrom
t3code/implement-issue-486

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Oct 2, 2026 •

Copy link
Copy Markdown
Owner

When a local task missed readiness, its owner killed it and then scanned /proc to make sure nothing was left. If any process on the machine exited between the scan opening its /proc/<pid>/stat and reading it, the read failed with ESRCH. The store only treated ENOENT as "gone", so the owner crashed before recording stopped, and start waited out its ~10s deadline. That is the CI flake in #486.

The store's process readers (processIdentity, groupMembers) now treat ESRCH like ENOENT, the same way the execution launcher's /proc reader and the CLI's dev state already do. The owner's three SIGKILL sites go through one helper that tolerates a process that exited after it was seen alive. The owner still writes stopped only after it has seen the exit itself.

Verified:

  • New LocalTaskStore.test.ts opens a process's stat file, reaps the process, then reads through the open handle, so the kernel raises a real ESRCH. Both tests failed with ESRCH before the fix.
  • With ~400 short sleep processes churning, the readiness-reap test failed 3 of 40 runs on main (10.3–10.5s timeouts) and passed 40 of 40 with the fix (389–699ms). Its 10s budget is unchanged.
  • Every pnpm verify suite passes locally, run one at a time: format, lint, typecheck, pnpm test (1627 tests), postgres-concurrency, cli-smoke, tier2-smoke and browser.

Closes #486

Made by Claude Opus 5.5 via Claude Code; reviewed by GPT 6.1 Sol via codex.

@github-actions github-actions Bot added the size:s Under 100 changed lines label Oct 2, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Codex review (GPT 6.1 Sol)

No material findings in PR #501: no blockers, should-fix items, or nits.

  • Correctness/spec: Both process readers handle ENOENT and ESRCH, and every owner kill uses the guarded helper. Unexpected errors still propagate. Ignoring ESRCH does not certify a stop by itself: the current owner still awaits child close; recovery still checks group disappearance and retains the slot when descendants remain without a matching live leader. I found no recovery or descendant-reap regression.
  • Test: Both new tests passed. Restoring the old catches in memory made both fail with genuine kernel ESRCH at the handle read. Hoisting and module identity are sound. Cleanup kills the registered sleeps, and non-Linux skips happen before spawning. No material slow-CI flaw identified. The mock is justified for this plain async module with no Effect layer; it controls timing while the kernel supplies the error.
  • Standards: Comments are concise and accurate, TypeScript is idiomatic, and the diff stays within the Agent Brief’s scope.

One existing limitation remains at packages/execution/src/localTaskOwner.ts:152: a descendant can exit and its PID be reused between alive(member) and kill(member.pid), potentially signaling an unrelated process. That race predates this PR; swallowing ESRCH does not introduce or widen it.

allisonmahmood added a commit that referenced this pull request Oct 3, 2026
Gap: the surviving-group recovery case hit the procfs ESRCH race that
open PR #501 fixes, so it cannot land before it; this removes it and
keeps the stale-identity case. That case now registers its own cleanup
before killing anything: recorded processes and the supervisor's group are
SIGKILLed only while their recorded start time still matches, without
relying on the recovery under test. Its procfs observations retry, since a
read can race a process's exit until #501 lands.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
(cherry picked from commit 54582c8ceb0088a05f70df6c28a0039584d5a8b6)
allisonmahmood added a commit that referenced this pull request Oct 3, 2026
Gap: the surviving-group recovery case hit the procfs ESRCH race that
open PR #501 fixes, so it cannot land before it; this removes it and
keeps the stale-identity case. That case now registers its own cleanup
before killing anything: recorded processes and the supervisor's group are
SIGKILLed only while their recorded start time still matches, without
relying on the recovery under test. Its procfs observations retry, since a
read can race a process's exit until #501 lands.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
(cherry picked from commit 54582c8ceb0088a05f70df6c28a0039584d5a8b6)
allisonmahmood added a commit that referenced this pull request Oct 3, 2026
The test audit found behaviour that matters and that no test checked at
any layer. This adds those tests. One of them found a real bug, fixed
here.

**Security and isolation**
- `POST /api/runtime/subscriptions` refuses bearer tokens, cross-site
requests, a wrong wire, a principal mismatch, and another viewer's,
another company's, a stale or a wrong-version document. A second viewer
cannot take over a document by reusing its id. Removing each ownership
guard makes its test fail.
- SDK generation refuses another company's shared table, shared store
and target patch.
- Logout revokes the signed-in Clerk session, not just its cookies. The
portal's `/log` route joins the signed-out and foreign-company 404
checks.
- The ECS task provider refuses unsafe options and a partial previous
revision, which would otherwise silently lose rollout auth during secret
rotation.
- The CLI writes `credentials.json` and the pending device login
owner-only from the first byte (0600 file, 0700 directory), as ADR-0004
promises.

**Data loss and reclamation**
- Purging a tier 2 patch reclaims every server artifact, including after
a failed object delete.
- When file reclamation stops part way, the orphan sweep finishes it
without touching another patch's files.
- Recovery reclaims a local task record whose pid now belongs to an
unrelated live process, without signalling that process. The case where
the detached owner itself dies is parked on
`test/local-owner-recovery-parked` until #501 lands: on CI it hit the
`ESRCH` race #501 fixes.
- The Postgres connector's cancel is admitted (a private DNS answer is
refused before any socket) and verified over TLS. Its backend really
stops.

**Rules now pinned**
- **Quota:** two different creates racing for an owner's last slot get
one 201 and one `live_patch_quota_exceeded`. The quota gates creation
only (decided): restore and reassign may leave an owner above it, and
the glossary now says so.
- **CLI:** SIGTERM exits 130 like SIGINT. The tier 0 starter builds and
publishes under the static-page policy.
- **Patch list:** it leaves out another company's patches.
- **Typed refusal codes:** `Refusal.code` is now the API's refusal-code
union, so a mistyped code in the definitive-refusal list fails typecheck
instead of silently keeping or discarding a saved publish.

**Bug fixed:** `S3ContentStore.list` only refused a continuation token
equal to the one it had just sent. A listing whose tokens cycled kept
paging until the server failed. It now refuses any token already seen in
the listing. Malformed listings (missing key or timestamp, invalid date,
truncated without a token) now fail within one or two requests.

Made by Claude Opus 5.5 via Claude Code

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
allisonmahmood and others added 2 commits October 3, 2026 20:42
…l task start

A process reaped after procfs opens its stat file fails the read with
ESRCH, not ENOENT. The local task store treated that as an error, so the
owner of a task that missed readiness died before recording `stopped`
and `start` waited out its ~10s deadline. The store's process readers
and the owner's kill sites now treat ESRCH as "already gone".

Closes #486

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Narrows the mocked path instead of casting it, and the owner's kill
helper says a negative pid signals a group.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@allisonmahmood
allisonmahmood force-pushed the t3code/implement-issue-486 branch from da0a97a to d408ea0 Compare October 3, 2026 18:42
@allisonmahmood
allisonmahmood merged commit 22cf9d0 into main Oct 3, 2026
11 checks passed
@allisonmahmood
allisonmahmood deleted the t3code/implement-issue-486 branch October 3, 2026 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:s Under 100 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flaky: LocalTaskProvider readiness-reap test times out on CI

1 participant