Skip to content

Fix stale retained worker release reconciliation - #13920

Closed
Jinwoo-H wants to merge 2 commits into
mainfrom
stale-worker-release-reconciliation
Closed

Jinwoo-H wants to merge 2 commits into
mainfrom
stale-worker-release-reconciliation

Conversation

@Jinwoo-H

Copy link
Copy Markdown
Contributor

Fixes #13860
Linear: STA-3932

Problem

Settled supervised workers with external, user-owned, or transferred terminal ownership stayed permanently retained after their runtime terminal handle went stale. Release returned before consulting the provider that authoritatively owns process liveness, so there was no safe path from retained ownership to released accounting.

Root cause and invariant

SQLite is authoritative for orchestration ownership/release state, while the owning local/WSL/SSH provider inventory is authoritative for the immutable PTY process incarnation. Handle staleness is not death: a daemon, SSH, or restored PTY may survive a runtime handle generation.

Invariant: a settled resource may reconcile to released only when one fresh inventory from its exact owning provider positively excludes its exact immutable process incarnation. Live, missing/malformed identity, invalid host scope, unavailable inventory, active transferred owner, or corrupted ownership history all remain retained.

The two-signal oracle requires:

  1. persisted ownership_state and release_state both become released;
  2. closeTerminal remains uncalled and the receipt reports processAction: none.

Design

  • Perform one bounded provider-scoped inventory only on the retained release path.
  • Classify an exact incarnation as live, positive absence as dead, and every unavailable or ambiguous shape as unknown.
  • Re-check requester/current-owner settlement, ownership history, resource identity, and release state inside one BEGIN IMMEDIATE transaction before committing release.
  • Extend dead reconciliation to all domain-settled states, including stopped and abandoned, without enabling their normal process-close path.
  • Register the invariant and executable evidence in the settled-worker reliability gate.

Alternatives rejected:

  • Treating terminal_handle_stale as death could discard a surviving daemon/SSH/paired PTY.
  • Widening the retained-reason allowlist could release a live user-owned terminal.
  • A force flag would move unsafe liveness classification to callers instead of fixing authoritative truth.

Deterministic red / red / green evidence

Byte-identical command:

pnpm exec vitest run --config config/vitest.config.ts \
  src/main/runtime/rpc/methods/orchestration-worker-release.test.ts \
  -t 'reconciles a dead external|reconciles a dead user|reconciles dead transferred' \
  --reporter=verbose
  • Actual latest origin/main 444638d96b: 3/3 red; all three resources remained retained.
  • Candidate d44d46178b: 3/3 green.
  • Candidate with production restored exactly to 444638d96b: 3/3 red.
  • Restored candidate: 3/3 green.

The same test bytes asserted durable state and zero terminal-close calls in every run.

Validation

pnpm exec vitest run --config config/vitest.config.ts \
  src/main/runtime/orca-runtime-process-incarnation-liveness.test.ts \
  src/main/runtime/rpc/methods/orchestration-worker-release.test.ts \
  src/main/runtime/rpc/methods/orchestration-worker-release-recovery.test.ts \
  src/main/runtime/rpc/orchestration-mutation-ledger.test.ts \
  src/main/runtime/orchestration/worker-transcript-read.test.ts \
  src/renderer/src/lib/worker-terminal-takeover-report.test.ts --reporter=dot
# 6 files, 67 tests passed

pnpm exec vitest run --config config/vitest.config.ts \
  tests/e2e/completed-worker-retirement-resume.unit.test.ts \
  src/cli/handlers/orchestration-worker-cli.test.ts --reporter=dot
# 2 files, 9 tests passed

pnpm typecheck:node
pnpm check:reliability-gates
pnpm check:max-lines-ratchet
pnpm exec oxlint <six touched TypeScript files>
git diff --check origin/main...HEAD

Two internal-review-until-clean rounds completed. Round 1 fixed malformed provider-incarnation metadata being usable as evidence; round 2 was clean across adversarial, architecture, performance/resource, platform, security, UX, mobile/backcompat, and readiness lenses.

Risks and gaps

  • A retained release adds one explicit, timeout-bounded provider inventory. It adds no polling, retries, timers, subprocesses, renderer work, or per-session follow-up fanout.
  • Output cannot be archived after the terminal surface/process record is already gone; the receipt may correctly keep archive: null.
  • Live Windows/WSL/SSH/paired-runtime journeys remain reliability-gate gaps. Physical Windows was not required for this fix because no ConPTY, OS process termination, filesystem, updater, sleep, firewall, or window lifecycle semantics changed; the causal boundary is provider inventory classification plus SQLite settlement.
  • Federated worker release remains explicitly unsupported and retained; no RPC/wire field or mixed-version contract changed.

@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Already reviewed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 25116cf8-1acd-43db-89ee-9f496a42d0b8

📥 Commits

Reviewing files that changed from the base of the PR and between d44d461 and 5d85b7c.

📒 Files selected for processing (1)
  • config/reliability-gates.jsonc
🚧 Files skipped from review as they are similar to previous changes (1)
  • config/reliability-gates.jsonc

📝 Walkthrough

Walkthrough

The change adds shared host-scope parsing and exact process-incarnation liveness classification for local, WSL, and SSH providers. OrcaRuntime exposes liveness inspection with timeout and unknown-state handling. Database reconciliation validates settled states, ownership history, process incarnation, and release state before releasing retained terminals. Release handling now reconciles dead processes without closing them. Tests and reliability metadata cover routing, ownership transfers, stopped and abandoned workers, invalid inventory, and release outcomes.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: reconciling stale retained worker releases.
Description check ✅ Passed The description explains the problem, design, linked issue, validation, risks, and gaps, but omits several template headings and checklist confirmations.
Linked Issues check ✅ Passed The implementation addresses issue [#13860] by safely reconciling dead settled resources without closing terminals or weakening live-ownership protections.
Out of Scope Changes check ✅ Passed The configuration, implementation, and tests remain focused on stale retained worker release reconciliation and its reliability coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 749b3073-b879-43ab-bf5a-3043fc20e3a0

📥 Commits

Reviewing files that changed from the base of the PR and between 444638d and d44d461.

📒 Files selected for processing (7)
  • config/reliability-gates.jsonc
  • src/main/runtime/orca-runtime-process-incarnation-liveness.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/orchestration/db.ts
  • src/main/runtime/orchestration/worker-terminal-process-liveness.ts
  • src/main/runtime/rpc/methods/orchestration-worker-release.test.ts
  • src/main/runtime/rpc/methods/orchestration-worker-release.ts

Comment thread config/reliability-gates.jsonc Resolved
@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

Superseded by the combined, rebased PR #13927, which includes this cleanup fix plus the authoritative worker-completion fix and validates both together through one real compiled-CLI Electron journey. Closing this duplicate PR without merging.

@Jinwoo-H Jinwoo-H closed this Aug 12, 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.

Worker retention becomes permanently unclearable once the terminal is gone (worker-release refuses as external_terminal)

1 participant