Skip to content

fix: finish cleanup for proven-dead workers with unavailable output - #24515

Open
giloh728 wants to merge 3 commits into
stablyai:mainfrom
giloh728:fix/worker-release-missing-archive-20261002
Open

giloh728 wants to merge 3 commits into
stablyai:mainfrom
giloh728:fix/worker-release-missing-archive-20261002

Conversation

@giloh728

@giloh728 giloh728 commented Oct 2, 2026 •

Copy link
Copy Markdown

ELI5

A finished worker whose terminal disappeared can stay stuck in cleanup when its output was never archived. This change records output as unavailable after the owning provider proves the original process is gone. If cleanup loses a race with another action, its response now reports the resource's current state.

What Changed

Missing-terminal cleanup requires a bounded owning-provider proof for the original UUID incarnation, then rechecks discovery, terminal, host, owner, process identity and release decision after the awaited probe. A matching resource can complete a requested release with archive.status: unavailable; existing archives remain intact.

When settlement is refused, the response is built from the fresh row: an owned pending release stays pending, an unknown release keeps its diagnostic and recovery guidance, a takeover is retained, and an already released row reports that state. The receipt projection is reused in a separate module, keeping the existing file below its configured line limit.

Why

Requesting release changes the row before the old no-archive guard evaluates it. Truthful output unavailability removes that dead end without inventing an archive. Fresh-row responses also prevent a pending or unknown release from being mislabeled as retained. Concurrent retention, takeover, changed identity, or a reappearing process still blocks settlement.

Linked Issue

Fixes #23712

Visual Proof

N/A — worker cleanup accounting and provider evidence only; no renderer changes.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated

macOS ARM64 headless tests: 94 passing tests across all 9 worker-release suites. Coverage includes missing archives, retries, authentic archives, owning-provider proof, reminted identities, concurrent retention/ownership changes, and refused-settlement responses. Node typecheck, default changed-file oxlint, formatting, changed-code quality and ordinary commit hooks passed. No lint suppression or hook bypass was used.

The initial candidate passed an Electron/Vite build. The follow-up was independently checked with the 94 tests, node typecheck and default lint; the build was not repeated. Actual daemon/SSH/WSL/Windows recovery, full repository CI and signed-runtime acceptance remain unverified. Installed production is unchanged.

AI Disclosure

Codex assisted implementation and tests. An independent agent reviewed the frozen source and the four-file follow-up. The account owner requested this recovery work.

Review

The initial 11-file candidate passed an independent 90-test review. The latest four-file follow-up passed independent review, 94 tests, node typecheck and default lint. The committed files match the reviewed byte images. Review receipt SHA-256: 855db14c625e1c047e00dffa0a5d8845064bcc9b5e3ae826457d868560c4c58d.

Source baseline: 9dea72f. Current candidate: 134ae2f.

A subsequent two-line test-comment correction describes the verified settlement accurately. Independent review confirmed that it changes no assertions or behavior; the four verified implementation files are unchanged, and ordinary commit hooks passed. Tests were not repeated for this comment-only commit.

The refused-settlement response correction addresses the Greptile finding. Bot check success is not a maintainer approval or full repository CI result.

Agent skill upstream boundary

  • Not applicable; no upstream skill source, tests or documentation copied.

Notes

No schema/RPC changes, production database edits, fabricated output, retention toggles or broad terminal closes. Unknown evidence cannot authorize release.

The SSH provider capability finding remains a separate limitation: SSH relay UUID cases without an owning-relay liveness probe stay unverifiable. Supporting them requires an incarnation-aware, read-only relay capability and mixed-version coverage. Attaching a terminal or using incomplete inventory as a death probe is not substituted here.

Official signed release and deployment remain with the maintainer release process; publishing this source does not release any production resource.

Checklist

  • This PR is small and focused
  • I explained the before/after, mechanism and reason
  • N/A with reason for visual proof
  • Self-reviewed for correctness, security and performance
  • Cross-platform and SSH/remote impact considered; real platform checks remain outstanding
  • Full repository lint, typecheck, tests and build pass (scoped checks above; CI required)

@giloh728
giloh728 marked this pull request as ready for review October 2, 2026 06:15
@greptile-apps

greptile-apps Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[High risk] Changes worker process cleanup and terminal resource release logic.

The PR should not merge until refused settlements return a receipt that reflects whether release remains pending or unknown.

Findings

  1. P1 Unfinished Release Reported Retained ▶

Summary

The PR adds bounded owning-provider death proof and a fresh inventory check before releasing a missing worker terminal without an archive. It then records unavailable output for a proven-dead original process while preserving existing archives and guarding concurrent resource changes.

  • The new refused-settlement receipt path needs to reflect the resource’s current release state.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Missing worker terminal] --> B[Inventory and owning-provider probe]
  B -->|Death unproven| C[Pending or unknown]
  B -->|Death proved| D[Re-observe terminal]
  D -->|Reappeared| C
  D -->|Still missing| E[Transactional identity and release checks]
  E -->|Checks pass| F[Released; output unavailable if unarchived]
  E -->|Checks fail| G[Return receipt matching current resource state]
Loading

Reviews (1) · Last reviewed commit: "fix(orchestration): settle proven-dead w..."

Comment on lines +49 to +58
const decision = decideWorkerTerminalRelease(reconciled.resource)
return {
dispatchId,
state: decision.action === 'already_released' ? 'already_released' : 'retained',
reason:
decision.action === 'retained'
? decision.reason
: reconciled.resource.retained_reason === 'user_requested'
? 'user_requested'
: 'identity_unproven',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Unfinished release reported retained

If the resource’s host scope or terminal handle changes during the death probe, settleDeadWorkerTerminalRelease correctly refuses to release it. This branch then reports retained even when the current row is still requested or unknown. The caller receives a misleading receipt for an unfinished release, without the pending or unknown recovery guidance. Return a receipt based on the current row’s release state.

@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

🧰 Additional context used
📚 Code guidelines (1)
AGENTS.md — auto-discovered

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 70a55a41-408f-4fc6-a441-d1f001930e44

📥 Commits

Reviewing files that changed from the base of the PR and between d61f266 and 134ae2f.

📒 Files selected for processing (5)
  • src/main/runtime/rpc/methods/orchestration-worker-release-incarnation-fallback.test.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-release-completion.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-release-missing-archive.test.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-release-missing-terminal.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-release-receipt.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/runtime/rpc/methods/orchestration-worker-release-incarnation-fallback.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The runtime now requires a negative PTY probe and a refreshed process inventory before classifying an incarnation as exited. Missing-terminal worker releases use a helper that checks liveness and terminal state, then settles against an expected resource snapshot. Tests cover unavailable archives after confirmed process exit, inconclusive liveness, retention requests, and concurrent resource changes.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 134ae

The change finishes cleanup for workers proven dead and no longer leaves them stuck. It rechecks state before releasing. No concrete merge-blocking issue was found in the supplied evidence.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 134ae

The change strengthens checks before cleanup and preserves concurrent ownership decisions. No introduced security issue was established in the reviewed flow, but behavior across all production environments has not been confirmed.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed local settlement operation is bounded to one identified worker-resource row per invocation, not a broad terminal-close action. Effective authority remains constrained by settled-worker preconditions, durable ownership, host scope, and exact process identity. The existing federated release branch remains separate.

Trust Boundaries and Controls

  • observed — Missing inventory is insufficient evidence of death. The reviewed runtime returns unverifiable for missing probe support, timeout, error, or any result other than false. Probe identity requires a UUID incarnation and compatible host scope; SSH identities must match the recorded connection. Structured sessions continue to use their dedicated session observation rather than PTY absence.

Resilience and Maintainability Implications

  • observed — The post-probe terminal recheck and transactional expected-state comparison prevent observations made before an await from authorizing settlement after a takeover, identity change, or release-state change. Database exceptions roll back, while refused settlement returns the current resource for receipt projection.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 12 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: completing cleanup for workers proven dead when output is unavailable.
Description check ✅ Passed The description covers the required sections, explains the user-facing behavior and mechanism, links issue #23712, documents testing and known verification limits, and addresses cross-platform and SSH…
Linked Issues check ✅ Passed PR #24515 meets the active coding requirements in #23712. inspectTerminalProcessIncarnationLiveness requires a bounded negative PTY probe and two post-probe inventories before it returns exited. I…
Out of Scope Changes check ✅ Passed The changes stay within #23712. The liveness probe, PTY identity filtering, post-probe discovery checks, dead-worker settlement, receipt projection, and related tests implement missing-archive release…
  • Fix all pre-merge checks with AI
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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: Advanced

Run ID: 2bb4d911-f5b6-49c0-aac1-f319512b99f5

📥 Commits

Reviewing files that changed from the base of the PR and between 444f195 and d61f266.

📒 Files selected for processing (11)
  • src/main/runtime/orca-runtime-process-death-probe.test.ts
  • src/main/runtime/orca-runtime-process-incarnation-liveness.test.ts
  • src/main/runtime/orca-runtime-subscribe-to-terminal-resize.ts
  • src/main/runtime/orchestration/db/worker-terminal/worker-terminal-release.ts
  • src/main/runtime/orchestration/worker-terminal-process-liveness.ts
  • src/main/runtime/rpc/methods/orchestration-worker-release-incarnation-fallback.test.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-release-completion.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-release-missing-archive.test.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-release-missing-terminal.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-release-recovery.test.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-release.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Comment on lines +193 to +203
const ptyId = workerTerminalPtyIdForDeathProbe(processIncarnation, hostScope)
const probe = this.ptyController.probePtyLiveness?.bind(this.ptyController)
if (!ptyId || !probe) {
return 'unverifiable'
}
const probed = await withTimeoutResult(
Promise.resolve().then(() => probe(ptyId)),
PTY_CONTROLLER_LIST_TIMEOUT_MS
)
if (!probed.ok || probed.value !== false) {
return 'unverifiable'

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.

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Add an authoritative SSH PTY liveness probe.

For a UUID-suffixed SSH relay worker whose terminal is already missing, SshPtyProvider has no probePtyLiveness implementation. The optional probe is therefore unavailable, so inspectTerminalProcessIncarnationLiveness returns unverifiable instead of exited, even when the process is dead. This can leave the supported interactive SSH release workflow in its unknown or recovery-pending state.

Implement the probe through the owning relay. Return false only after a bounded, successful relay response proves that the PTY is absent. Return null for transport errors, timeouts, incomplete inventories, or other uncertainty. Do not use cached hasPty or livePtyIds as death proof.

@pullfrog pullfrog 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.

ℹ️ No critical issues — one stale comment inline, plus a test-coverage nit below.

Reviewed changes

  • Negative owning-provider death probe — inspectTerminalProcessIncarnationLiveness now requires probePtyLiveness(ptyId) === false for a v4-UUID incarnation, then re-lists and re-classifies; null/probe-less/legacy stays unverifiable (workerTerminalPtyIdForDeathProbe).
  • Post-probe race fences — new worker-release-missing-terminal.ts re-inspects the terminal and re-checks the incarnation lookup after the awaited probe before settling, called from both the completion and retained paths.
  • CAS token + widened archive rule — settleDeadWorkerTerminalRelease takes an optional expectedResource and lets requested/unknown archive-less rows settle as archive_status: 'unavailable' only when that token is supplied; existing archives stay checksum-fenced.
  • Tests updated to the new outcomes, plus a new probe unit suite and race-guard suite.

#26912's case 1 (release_unavailable instead of a permanent release_unknown) and cases 2a–2c/2e are addressed by the three conditions above. The CAS checks, archive-preservation clause, and BEGIN IMMEDIATE ordering all look sound; I found no way for a concurrent retain/takeover/remint to be settled released.

ℹ️ Release-flow tests never exercise the real UUID-only probe

worker-release-missing-archive.test.ts and the updated incarnation-fallback tests mock inspectTerminalProcessIncarnationLiveness, and the shared harness records a legacy runtime_test:term_worker:1 incarnation. The new gate only certifies v4-UUID incarnations, so the path from a genuine probePtyLiveness === false through settleDeadWorkerTerminalRelease to archive_status: 'unavailable' is only covered in isolation in orca-runtime-process-death-probe.test.ts. A single harness-based case setting a UUID incarnation and driving the real runtime method would pin the integration the PR is really about.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

Incremental delta since the prior pullfrog review (d61f2669..134ae2f8, two commits):

  • Extracted a receipt projector — new worker-release-receipt.ts owns WorkerReleaseReceipt, releaseUnknownRecovery, releasePendingRecovery, retainedReason, and a pure workerReleaseReceiptFromResource that turns a fresh row into a receipt; worker-release-completion.ts re-exports the moved symbols so structured-worker-release-stop.ts keeps its import site.
  • Refused settlement reports current state — releaseProvenDeadMissingWorkerTerminal now builds the refused-settlement response from the fresh row instead of hardcoding retained: decideWorkerTerminalRelease first for already_released/retained, then release_unknown (with lastError + recovery) for an unknown row, release_pending for requested/releasing, and retained otherwise.
  • Tests — the "protects … replaced during the death probe" expectation moves to release_pending; new cases pin release_unknown when a column changes while the row is already unknown, and already_released when settlement races an already-released row.
  • Comment correction — 134ae2f8 fixes the stale settlement comment, addressing the prior review's inline thread.

The refused-settlement projection is correct across the branches I traced: the CAS token deliberately omits ownership_state, and a concurrent takeover is still refused by the decideWorkerTerminalRelease(...) !== 'proceed' guard, yielding a retained/user_takeover receipt. Prior review feedback is addressed and its thread was resolved.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

This branch has not been deployed

No deployments
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.

[Bug]: worker-release after #23583: #19166 still reproduces, and interactive release settles on an incomplete host listing

1 participant