Skip to content

fix(runtime): skip stale pid registration#279

Open
fengjikui wants to merge 1 commit into
marcusrbrown:mainfrom
fengjikui:codex/skip-terminal-pid-append
Open

fix(runtime): skip stale pid registration#279
fengjikui wants to merge 1 commit into
marcusrbrown:mainfrom
fengjikui:codex/skip-terminal-pid-append

Conversation

@fengjikui

Copy link
Copy Markdown

Summary

  • skip delayed orphan PID registration once a task has already reached a terminal state
  • add a regression test for the race where setStatus(..., 'complete') wins before the async getPidIdentity(...).then(...) append runs
  • add a patch changeset

Why

createTask() records orphan-reaper PID entries after an async process identity lookup. A very fast Copilot subprocess can become terminal before that lookup resolves. In that ordering, setStatus(...terminal...) has already removed the PID entry, but the delayed append can write the completed task back into the orphan PID file.

That leaves stale orphan-reaper state for a task that is no longer running. Checking the current task status immediately before append keeps the existing running/cancelling behavior while avoiding terminal-task resurrection in the pid file.

Validation

  • bun test tests/task-registry.test.ts tests/pid-file.test.ts
  • bun run test:unit
  • bun run typecheck
  • bun run lint
  • bun run build
  • npm pack --dry-run --json

Note: local bun test / bun run test:tui on my macOS+Bun 1.3.14 environment hits a Bun SIGTRAP after visible TUI tests start; the touched runtime/unit suites above pass and cover this change.

@fro-bot fro-bot mentioned this pull request Jul 8, 2026
22 tasks
@fro-bot

fro-bot commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Autohealing Verification — schedule-e217cf83-29108401222

This PR is from a first-time contributor, so GitHub Actions CI has not yet been authorized to run on the codex/skip-terminal-pid-append branch. As part of today's autohealing pass I checked out the branch and ran the full local CI matrix against main's toolchain.

Local CI results

Check Result
bun install ✅ clean (no peer warnings)
bun run typecheck ✅ clean
bun run lint ✅ clean (63 files)
bun run build ✅ clean
bun test tests/\*.test.ts ✅ 322 pass / 0 fail (1 new regression test added by this PR)
bun test tests/task-registry.test.ts ✅ 10 pass / 0 fail
bun test tests/pid-file.test.ts ✅ 25 pass / 0 fail

Change assessment

The diff adds a terminal-status guard before the deferred PID-file append in createTask() (src/runtime/task-registry.ts). When getPidIdentity(...) resolves after setStatus(..., 'complete' | 'failed' | 'cancelled', ...) has already removed the PID entry, the append is now skipped, preventing resurrection of an orphan-reaper entry for a task that's no longer running. The new test does not append to the PID file after a terminal transition wins the spawn race reproduces the race and asserts no stale entry appears. The changeset (.changeset/quiet-plants-train.md) is present and correct.

Note

This comment is a CI verification pass, not an approval — a maintainer still needs to approve workflow runs to trigger the hosted CI on this branch. No code changes were made here by the autohealing agent.

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.

2 participants