Skip to content

fix(core): terminalize orphaned child claims through events - #46943

Open
kitlangton wants to merge 2 commits into
v2from
child-claim-events
Open

fix(core): terminalize orphaned child claims through events#46943
kitlangton wants to merge 2 commits into
v2from
child-claim-events

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

Why

Restart recovery clears unrecoverable child execution claims with a direct SQL update, without publishing a terminal event. The claim disappears, but the child's projected idle outcome and stale retry state do not reflect that its execution ended, and event consumers never receive that transition.

What Changes

Restart state Result
Claimed child without a running recoverable subagent job Publish session.execution.interrupted with reason superseded; release its claim and reset resume accounting in the event commit.
Child owned by a running recoverable background subagent job Preserve its original claim and resume accounting; continue through existing job recovery.
Claimed top-level Session Continue through existing top-level recovery and attempt limits.
Child without a claim, or a second sweep after cleanup No new interruption event.

The existing terminal projector records the interrupted idle outcome and clears stale retry state without changing Session recency. Existing event consumers can now observe the child as interrupted/cancelled. Claim cleanup does not resume foreground orphans; existing background-notification wake-ups remain unchanged.

Session Recovery

Replace the mutating SessionStore.releaseChildClaims operation with a read-only listChildClaims query using the same eligibility filter. Recovery publishes one existing terminal event per selected child, with store.release in the commit hook so event projection and local claim release are atomic. Event replay still does not manage process-local execution claims.

Scope

This PR owns only child-claim terminalization and focused recovery tests. It does not rename time_suspended, add a migration, change public event schemas, or extract the background-job recovery flow.

Verification

Using Bun 1.4.0:

# From packages/core
bun typecheck
bun run test test/session-execution.test.ts test/session-projector.test.ts test/session-view.test.ts
bun run test test/bus.test.ts test/job.test.ts test/session-run-coordinator.test.ts

# From the repository root
bunx prettier --check packages/core/src/session/execution/restart.ts packages/core/src/session/store.ts packages/core/test/session-execution.test.ts
bunx oxlint packages/core/src/session/execution/restart.ts packages/core/src/session/store.ts packages/core/test/session-execution.test.ts
git diff --check
git push -u origin child-claim-events
  • Core typecheck passes.
  • Focused execution/projector/view tests: 54 passed. New assertions cover persisted terminal events, projection and retry cleanup, unchanged recency, repeat-sweep idempotence, preservation of recoverable child claims/accounting, and top-level recovery.
  • Bus/job/coordinator tests: 91 passed, including event commit transaction and replay behavior.
  • Formatting and whitespace checks pass. Oxlint reports no errors and two existing consistent-return warnings in unchanged test bodies.
  • The unmodified pre-push hook passed its workspace typecheck: 33 successful tasks, 27 cached. No hooks were skipped.
  • Tests use the real Bus, database, projectors, execution coordinator, and job recovery with a controlled runner; no live server/provider or TUI end-to-end run was performed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant