Skip to content

test: retire a dormant worker through host-owned status - #23686

Merged
nwparker merged 3 commits into
mainfrom
nwparker/ci-worker-exit-recovery
Sep 28, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/ci-worker-exit-recovery

Conversation

@nwparker

@nwparker nwparker commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​57 $\color{#cf222e}{\Huge{\mathbf{−}}}$​89 $\color{#cf222e}{\Huge{\mathbf{−}}}$​32
Prod 0 0 0 0

ELI5

The worker-retirement test now checks a completed worker that has never been opened, matching the case it is meant to protect.

What Changed

The fake Codex worker publishes authenticated working/done hooks with its session identity. The test asserts its pane remains unmounted before the first activation. Both CLI close and worker release must remove the tab and recovery authority together, and later activation must not restart the worker.

Why

The old fixture wrote status directly to the renderer and then mounted the worker in the background. On Linux, normal foreground-shell cleanup removed the recovery record before the retirement action ran. Using host-owned status and keeping the worker dormant gives the test a valid recovery record to retire without bypassing production cleanup.

Linked Issue

CI failure: https://github.com/stablyai/orca/actions/runs/36479125813/job/109123429043

Visual Proof

N/A — fixture setup only; application behavior is unchanged.

Testing

  • Both retirement cases pass locally on macOS in hidden Electron with ORCA_BACKGROUND_LAUNCH=1.
  • Changed-code quality gate passes.
  • Recovery positive control, atomic retirement, and no-respawn assertions retained.
  • PR CI validates Linux and typechecking.

Review

No product, protocol, execution-host, path, or platform changes.

Agent skill upstream boundary

  • Not applicable.

Checklist

  • Small, focused, and self-reviewed.
  • Explained the failure and approach.
  • Cross-platform and remote impact considered.

@coderabbitai

coderabbitai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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

📝 Walkthrough

Walkthrough

The end-to-end test verifies that the worker has no pane manager before completion. It seeds the Codex transcript and sends a completion marker through the runtime terminal API. The fake Codex process publishes recovery hook events. After normal exit, the test polls renderer state until it finds both the worker tab and recovery record.

Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to e68fa

The worker-recovery test has a narrow timing race that could make it unreliable. Awaiting hook publication before exit would make the test safer to merge.

Security Architecture Review

Security architecture risk: 🔵 Low · up to e68fa

The change exercises the existing recovery path rather than changing application behavior. No new production exposure was identified, but the test does not establish how recovery behaves under every failure or repeated-event scenario.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed sender runs as a test-selected fake worker. Although it reaches the real local hook endpoint, the inspected change does not add a production caller or network entrypoint.

Trust Boundaries and Controls

  • observed — The fake worker supplies the hook token and launch token. The existing handler authenticates the request, while its disposition gate can suppress events that fail an applicable launch-token fence.

Resilience and Maintainability Implications

  • observed — The fake publishes two hooks in sequence and reports publication errors to stderr; this scenario does not exercise a repeated marker or failure between the requests.

Hardening Proposals

  • proposed — Consider asserting that no mixed tab-and-recovery state is observed during retirement and exercising repeated or interrupted hook publication, to strengthen coverage against stale recovery state.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: testing retirement of a dormant worker through host-owned status.
Description check ✅ Passed The description covers the user-facing behavior, mechanism, motivation, testing, scope, and checklist items. The linked issue section references the reported CI failure, and the visual proof section e…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

@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

  • Poll for settled renderer state after worker exit — the spec now wraps its pre-close { tabPresent, recoveryPresent } read in expect.poll(...).toEqual({ tabPresent: true, recoveryPresent: true }) instead of a one-shot expect(await …), so it waits out the asynchronous renderer recovery update that follows the fixture's normal-exit marker.
  • Precondition for the transition recorder — this read is what the immediately following store.subscribe transition capture assumes; waiting for {true, true} before subscribing keeps the later arrayContaining([{true,true},{false,false}]) assertion attributable to the close path rather than to a still-in-flight update.

Test-only change; no product, protocol, or execution-host surface. The assertions themselves are unchanged in value — only the read is retried (default poll budget resolves to tests/playwright.config.ts's expect: { timeout: 10_000 }). The added poll does not weaken the close-behavior checks, which still run after the close command is issued.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker nwparker changed the title test(e2e): await renderer recovery after worker exit test(e2e): publish worker recovery through its host authority Sep 28, 2026

@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

  • Publish worker recovery through authenticated hooks — the fake Codex worker now POSTs UserPromptSubmit then Stop to /hook/codex with its live launch authority (paneKey/tabId/worktreeId/launchToken/env/version plus session_id/transcript_path) instead of the spec writing renderer status directly, so the test exercises the real host-owned recovery flow the PR body describes.
  • Per-run recovery config for the fake worker — seedCurrentCodexTranscript now writes recovery-config.json (session id + transcript path), which the worker reads when it receives ORCA_E2E_PUBLISH_DONE; the handler returns before the paste-ack path, while ORCA_E2E_EXIT_AFTER_DONE still emits normal-exit and exits.
  • Retained async-recovery poll — the pre-close { tabPresent: true, recoveryPresent: true } expect.poll now waits on host-published state; the removed setAgentStatus seed and the now-unused transcriptPath local leave no dangling references.

The publish payload matches the established shape in tests/e2e/orchestration-worker-transcript-providers.spec.ts, and codex-events.ts confirms UserPromptSubmit → working / Stop → done, so the asserted { origin: 'live', state: 'done', providerSessionId } is what the real pipeline produces. Assertions are unchanged in value; the poll precondition is exactly what the following transition recorder assumes, and close is still issued after the subscription, so the true→false transition remains attributable to close. Test-only change with no product, protocol, or execution-host surface.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@greptile-apps

greptile-apps Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Low risk] Updates end-to-end test fixtures and scenarios.

The PR does not appear safe to merge while the exit-ordering race remains.

Findings

  1. P1 Poll misses the exit ▶

Summary

The test now publishes worker completion and recovery through authenticated host hooks and leaves the worker pane unmounted until first activation.

  • Both retirement modes continue to check recovery removal and absence of a resumed worker.
  • The existing post-exit ordering concern remains unresolved.
Diagram
sequenceDiagram
  participant Test
  participant Worker
  participant Host
  participant Renderer
  Test->>Worker: Send publish marker
  Worker->>Host: Authenticated working and done hooks
  Host-->>Renderer: Publish status and recovery
  Test->>Worker: Send exit marker
  Test->>Renderer: Poll for tab and recovery
  Test->>Host: Close terminal or release worker
Loading

Reviews (2) · Last reviewed commit: "test: keep retired background worker dor..."

Comment on lines +295 to +310
await expect
.poll(() =>
orcaPage.evaluate(
({ paneKey, tabId, worktreeId }) => {
const state = window.__store?.getState()
return {
tabPresent: Boolean(
state?.tabsByWorktree[worktreeId]?.some((tab) => tab.id === tabId)
),
recoveryPresent: Boolean(state?.sleepingAgentSessionsByPaneKey[paneKey])
}
},
{ paneKey: workerPaneKey, tabId: workerBefore.tabId, worktreeId: targetWorktreeId }
)
)
).toEqual({ tabPresent: true, recoveryPresent: true })
.toEqual({ tabPresent: true, recoveryPresent: true })

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 Poll misses the exit
The test already confirms that the tab and recovery record are present before sending the exit command. After the worker writes normal-exit, this poll can therefore pass on that same pre-exit state, before the renderer receives the exit notification. Close can still begin too early, leaving the ordering race this test is meant to fix.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@nwparker nwparker changed the title test(e2e): publish worker recovery through its host authority test: retire a dormant worker through host-owned status Sep 28, 2026

@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: c6183d28-be55-4641-8feb-907eea37c72c

📥 Commits

Reviewing files that changed from the base of the PR and between 80f6d90 and e68fa4a.

📒 Files selected for processing (2)
  • tests/e2e/completed-worker-retirement-resume.spec.ts
  • tests/e2e/helpers/completed-worker-retirement-fixture.ts

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

}
append({ event: 'input', input })
if (input.includes('ORCA_E2E_PUBLISH_DONE')) {
void publishRecovery().catch((error) => process.stderr.write(String(error)))

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 | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
# Inspect the test sequence between the completion marker and normal exit.
ast-grep outline tests/e2e/completed-worker-retirement-resume.spec.ts --view expanded
sed -n '190,310p' tests/e2e/completed-worker-retirement-resume.spec.ts

Repository: stablyai/orca

Length of output: 4475


🏁 Script executed:

#!/bin/bash
sed -n '1,110p' tests/e2e/helpers/completed-worker-retirement-fixture.ts
printf '\n--- remaining relevant helper definitions ---\n'
sed -n '110,240p' tests/e2e/helpers/completed-worker-retirement-fixture.ts

Repository: stablyai/orca

Length of output: 8417


🏁 Script executed:

sed -n '1,110p' tests/e2e/helpers/completed-worker-retirement-fixture.ts
printf '\n--- remaining relevant helper definitions ---\n'
sed -n '110,240p' tests/e2e/helpers/completed-worker-retirement-fixture.ts

Repository: stablyai/orca

Length of output: 8417


🏁 Script executed:

rg -n -C 8 'ORCA_E2E_(PUBLISH_DONE|EXIT_AFTER_DONE)|publishRecovery|UserPromptSubmit|Stop' tests/e2e/helpers tests/e2e tests src | head -n 240

Repository: stablyai/orca

Length of output: 20533


Await recovery publication before normal exit.

publishRecovery() sends the UserPromptSubmit and Stop requests sequentially, but the input handler does not retain its promise. The exit branch calls process.exit(0) independently. If the exit marker arrives while either request is pending, publication can be interrupted.

Suggested fix
+let recoveryPublication = Promise.resolve()
+
-process.stdin.on('data', (chunk) => {
+process.stdin.on('data', async (chunk) => {
...
-    void publishRecovery().catch((error) => process.stderr.write(String(error)))
+    recoveryPublication = publishRecovery().catch((error) => {
+      process.stderr.write(String(error))
+    })
     return
   }
   if (input.includes('ORCA_E2E_EXIT_AFTER_DONE')) {
+    await recoveryPublication
     append({ event: 'normal-exit' })
     process.exit(0)

@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

  • Kept the completed worker dormant instead of background-mounting it — the spec no longer dispatches orca-background-mount-terminal-worktree nor polls __paneManagers for the worker tab; it now asserts the pane manager is never mounted (toBe(false)) and the target worktree stays unactivated, so the close/release path runs against a genuinely never-opened background worker whose recovery record was published through the real host hooks (tests/e2e/completed-worker-retirement-resume.spec.ts:163).

The delta is test-only. The tab still exists in tabsByWorktree because terminal-tab creation is store-level (terminal-tab-creation.ts), independent of TerminalPane mount (use-terminal-pane-mount-lifecycle.ts), so the later tabPresent: true and the true→false transition assertions remain meaningful with no mounted pane. The one-shot negative read is safe at that point: no done/Stop hook has been published yet, so nothing has triggered a background wake of the tab.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit e87772b into main Sep 28, 2026
42 checks passed
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.

1 participant