Repository navigation
Make worker completion and cleanup authoritative - #13927
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdded federated lifecycle settlement support with protocol version 3 and capability negotiation. Remote worker results now wait for Run-home confirmation. Federation synchronization exchanges settlement records and replays unacknowledged relays. CLI handling validates legacy worker reports and throws structured rejection errors. Worker release now checks exact process-incarnation liveness and reconciles dead resources without closing processes. Tests and reliability-gate metadata cover settlement, replay, rejection, migration, JSON output, release, and compiled-CLI behavior. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
|
@coderabbitai review |
|
|
@coderabbitai review |
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 6
🧹 Nitpick comments (7)
src/cli/handlers/orchestration.ts (1)
605-607: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueThis rejection branch is unreachable.
Line 594 throws
RuntimeClientErrorfor any result whoselifecycle.actionisrejected, including the relay shape.printResulttherefore never runs with a rejected relay lifecycle, so this branch is dead code.Remove it, or restrict the throw at line 594 to the non-relay shapes if the relay case is meant to print instead of fail.
src/main/runtime/rpc/methods/orchestration-federation-relay.ts (2)
89-98: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider logging settlements dropped above the acknowledged watermark.
The filter discards any settlement whose
sequenceexceedsthroughSequencewithout a response signal. The sending peer receivesacknowledgedThroughonly, so it cannot tell that its settlement was ignored. The Run-home waiter then blocks until the 30-second timeout insrc/main/runtime/rpc/methods/orchestration.tsand returnsoperation_unknown. A debug log at the drop point would make that path diagnosable.The publish-after-acknowledge ordering is correct. The durable acknowledgement commits before waiters are released.
22-40: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueDerive
FederatedLifecycleSettlementfrom the shared schema.The inline schema duplicates
FederatedLifecycleSettlement. Export the schema fromsrc/main/runtime/orchestration/federation-lifecycle-settlement.ts, infer the type from it, and remove the cast at Line 95. This keeps the wire contract and TypeScript type aligned.Zod 4 supports multi-value discriminators, so
z.enum(['completed', 'failed'])is valid here.src/cli/handlers/orchestration-lifecycle-json-rejection.test.ts (1)
23-49: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAssert that the handler rejected before you format the error.
If
ORCHESTRATION_HANDLERS['orchestration send']resolves instead of rejecting,rejectionstaysundefined.reportCliErrorthen prints aruntime_errorenvelope and the test fails on the code mismatch. The failure message points at the envelope contents rather than at the missing rejection, which makes the regression harder to diagnose.An explicit guard names the real cause.
♻️ Proposed refactor
} catch (error) { rejection = error } + expect(rejection).toBeDefined() reportCliError(rejection, true, { commandPath: ['orchestration', 'send'] })The fixture is otherwise correct. The
rejectedlifecycle carries norelaykey and noauthority, so the verdict short-circuits the compatibility reads and the singlecallmock is sufficient.src/cli/handlers/orchestration-lifecycle-rejection.test.ts (2)
183-262: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider asserting the call count in the two acceptance tests.
expect(process.exitCode).not.toBe(1)passes forundefined,0, and any value other than1. The real signal in these tests is that the awaited handler did not reject. Neither test asserts that the two compatibility reads actually ran, so a regression that skips verification and accepts the report unconditionally would still pass.The test on Line 105 already uses
toHaveBeenCalledOnce()for the opposite case. The same style applies here.♻️ Proposed refactor
- expect(process.exitCode).not.toBe(1) + expect(callMock).toHaveBeenCalledTimes(3) })Apply the same change to the retry test on Line 261.
13-14: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDrain
callMock’s one-time queue inafterEach.Add
callMock.mockReset()aftervi.clearAllMocks(). Do not replacevi.clearAllMocks(), because it also clears call history forprintResultand other module mocks.src/cli/handlers/orchestration-migration.test.ts (1)
15-52: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert that settled results require only the send call.
Add
expect(call).toHaveBeenCalledOnce()to ensure both settlement variants bypass compatibility reads.Source: Learnings
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d49e322c-8578-473f-bf1b-5192961ea19c
📒 Files selected for processing (18)
config/reliability-gates.jsoncsrc/cli/handlers/orchestration-lifecycle-json-rejection.test.tssrc/cli/handlers/orchestration-lifecycle-rejection.test.tssrc/cli/handlers/orchestration-migration.test.tssrc/cli/handlers/orchestration-worker-settlement.tssrc/cli/handlers/orchestration.test.tssrc/cli/handlers/orchestration.tssrc/main/runtime/orchestration/db.tssrc/main/runtime/orchestration/federation-lifecycle-settlement.tssrc/main/runtime/orchestration/federation-sync.tssrc/main/runtime/rpc/methods/orchestration-federated-worker-start.tssrc/main/runtime/rpc/methods/orchestration-federation-lifecycle-settlement.test.tssrc/main/runtime/rpc/methods/orchestration-federation-relay.tssrc/main/runtime/rpc/methods/orchestration-federation-start-schema.tssrc/main/runtime/rpc/methods/orchestration-federation.test.tssrc/main/runtime/rpc/methods/orchestration.test.tssrc/main/runtime/rpc/methods/orchestration.tssrc/shared/protocol-version.ts
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/runtime/orchestration/db.ts (1)
5359-5360: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winAdd an intermediate-state assertion for
worker_donesettlement.The production path omits
settleRemoteOutcomeand settles the attachment through the Run-home acknowledgment. Extend the existing lifecycle test to assertstate: 'ready'before acknowledgment and the terminal state afterward.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: a0bfef34-ac33-48dc-92cd-7af5deae8bba
📒 Files selected for processing (10)
config/reliability-gates.jsoncsrc/cli/handlers/orchestration-lifecycle-json-rejection.test.tssrc/cli/handlers/orchestration-lifecycle-rejection.test.tssrc/cli/handlers/orchestration-migration.test.tssrc/cli/handlers/orchestration-worker-settlement.tssrc/cli/handlers/orchestration.tssrc/main/runtime/orchestration/db.tssrc/main/runtime/orchestration/federation-lifecycle-settlement.tssrc/main/runtime/rpc/methods/orchestration-federation-lifecycle-settlement.test.tssrc/main/runtime/rpc/methods/orchestration-federation-relay.ts
💤 Files with no reviewable changes (1)
- src/cli/handlers/orchestration.ts
🚧 Files skipped from review as they are similar to previous changes (6)
- src/cli/handlers/orchestration-lifecycle-rejection.test.ts
- src/cli/handlers/orchestration-worker-settlement.ts
- config/reliability-gates.jsonc
- src/main/runtime/orchestration/federation-lifecycle-settlement.ts
- src/main/runtime/rpc/methods/orchestration-federation-relay.ts
- src/cli/handlers/orchestration-migration.test.ts
fbdaebc to
6e4f891
Compare
|
Addressed the remaining CodeRabbit test nit in d4cf101: the federation lifecycle oracle now asserts that the remote attachment is still |
|
|
There was a problem hiding this comment.
🧹 Nitpick comments (2)
tests/e2e/orchestration-worker-settlement-release-cli.spec.ts (1)
243-253: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winSet
busy_timeouton the test SQLite handles.The test opens
orchestration.dbwhile the Electron application holds the same file open. The application setsbusy_timeout = 5000(seesrc/main/runtime/orchestration/db.tslines 325-327), but this handle does not. In WAL mode only one writer proceeds at a time, so a concurrent application write makes theUPDATEon line 250 fail immediately withSQLITE_BUSYinstead of waiting.The window is small because the worker already settled and its terminal is closed. Adding the pragma removes the residual flake risk on a reliability-gate spec.
Apply the same pragma to the verification handle opened on line 267.
♻️ Proposed change
const db = new Database(path.join(userDataDir, 'orchestration.db')) try { + db.pragma('busy_timeout = 5000') db.prepare( `UPDATE worker_terminal_resources SET ownership_state = 'external', release_state = 'retained', retained_reason = 'external_terminal' WHERE owner_dispatch_id = ?` ).run(dispatch.result.dispatch!.id) } finally { db.close() }Apply the same addition to the verification handle:
const verified = new Database(path.join(userDataDir, 'orchestration.db')) try { + verified.pragma('busy_timeout = 5000') expect .soft(src/main/runtime/rpc/methods/orchestration-worker-release.test.ts (1)
725-744: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAssert that transferred ownership remains unreleased. After the old dispatch release, assert that the second worker’s resource retains
ownership_state: 'owned'andrelease_state: 'not_requested'.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 1eba2d0e-afba-4dab-b2d0-a488ee40808c
📒 Files selected for processing (9)
config/reliability-gates.jsoncsrc/main/runtime/orca-runtime-process-incarnation-liveness.test.tssrc/main/runtime/orca-runtime.tssrc/main/runtime/orchestration/db.tssrc/main/runtime/orchestration/worker-terminal-process-liveness.tssrc/main/runtime/rpc/methods/orchestration-federation-lifecycle-settlement.test.tssrc/main/runtime/rpc/methods/orchestration-worker-release.test.tssrc/main/runtime/rpc/methods/orchestration-worker-release.tstests/e2e/orchestration-worker-settlement-release-cli.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/runtime/rpc/methods/orchestration-federation-lifecycle-settlement.test.ts
d4cf101 to
1416f0f
Compare
|
Rebased onto current origin/main 4b9fb46. On exact head 1416f0f: pnpm run build:cli plus the real compiled-CLI Electron E2E passed; 89 focused completion, federation, and cleanup tests passed; typecheck, lint, reliability gates, and diff checks passed. @coderabbitai review the latest head. |
|
🧠 Learnings used
|
* fix: require authoritative worker completion verdicts * Harden federated settlement replay * fix(orchestration): reconcile dead retained workers * docs: record SSH worker release coverage * test(e2e): exercise worker settlement and release CLI * docs: register combined orchestration CLI oracle * test(orchestration): pin pre-ack attachment state
ELI5
Orca previously trusted two "probably done" signals. A worker could send
worker_donewith the wrong identity and the CLI could printok:trueeven though the task was still running. Separately, a worker terminal that had already disappeared could remain permanently marked "retained." This PR makes both decisions use authoritative state: only the Task/Dispatch owner can confirm completion, and only the owning terminal provider can prove an exact process incarnation is gone before cleanup releases it.What Changed
worker_donecalls.releasedonly when the authoritative local/WSL or exact SSH provider positively excludes their immutable process incarnation. Unknown inventory remains retained, and this path never closes a process.out/cli/index.jsprocesses for wrong-identity completion, valid completion, and dead-worker release.Why
Fixes #13858
Fixes #13860
The invariant is: a CLI may report completion only after the authoritative Task/Dispatch owner proves the exact report settled, and cleanup may release retained ownership only after the authoritative terminal provider proves the exact immutable process incarnation is absent.
The structural ownership fix is the best long-term implementation. A CLI-only patch cannot prove Run-home settlement, and treating a missing process listing as death could close or release remote work incorrectly. The chosen design fails closed across version skew and unknown provider state while keeping normal current-version calls constant-time.
Downsides and risks:
Linked Issue
Fixes #13858
Fixes #13860
Supersedes #13920.
Visual Proof
N/A — this changes CLI/runtime orchestration state and has no renderer or UI diff.
Testing
Deterministic byte-identical oracle:
5ea7df1a5b: red. A real compiled CLI process using the wrong worker identity exited 0 withok:truewhile the Dispatch stayeddispatched; the valid caller received no explicit lifecycle verdict;worker-releaseleft SQLite atexternal/retained.ok:false/dispatch_capability_invalid; Task and Dispatch remain dispatched; the exact worker receives{action:"completed"}; an independent RPC read observescompleted; compiledworker-releasereturnsreleasedwithprocessAction:"none"; an independent SQLite read observesreleased/released; the coordinator terminal remains live.64aec94cb2: red with the same false-success and retained-state failures.1416f0f126on latestorigin/main4b9fb46646: green in 19.3 seconds.Additional validation:
242/242 combined focused CLI/runtime/DB/federation/release tests.
4/4 combined Electron cases: compiled CLI, legacy/current restart recovery, and worker visibility.
Fresh combined reviews: architecture/adversarial 89 tests; performance/resource 149 tests; platform/security/compatibility 520 tests; all clean.
pnpm typecheckpnpm lint(only existingWorktreeJumpPalette.tsxhook warnings)reliability manifest, max-lines ratchet, changed-code quality, localization checks, and
git diff --checkI manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Implemented and reviewed with Codex agent assistance under maintainer supervision.
Review
Fresh adversarial architecture/readiness, performance/resource, and security/platform/wire-compatibility reviews found no actionable issues. Optional wire fields are capability-negotiated; missing or malformed identities remain unknown; no new polling, retries, unbounded collections, subprocess fanout, or process-close path was added. SSH uses the exact target inventory, while local/WSL use the provider's combined inventory and match only exact immutable PTY incarnation.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck, and proportional focused/E2E builds and tests pass; full CI is required before mergeAuthor