Repository navigation
test: retire a dormant worker through host-owned status #23686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,14 +20,34 @@ import { buildFakeAgentCommandOverride } from './fake-agent-command-override' | |
| import { FAKE_AGENT_PASTE_END_SCANNER_SOURCE } from './fake-agent-paste-end-scanner' | ||
|
|
||
| const fakeCliDir = mkdtempSync(path.join(os.tmpdir(), 'orca-e2e-retired-worker-')) | ||
| const recoveryConfigPath = path.join(fakeCliDir, 'recovery-config.json') | ||
| const lifecycleLedgerPath = path.join(fakeCliDir, 'codex-lifecycle.jsonl') | ||
| export const completedWorkerFakeCodexCommand = buildFakeAgentCommandOverride( | ||
| path.join(fakeCliDir, process.platform === 'win32' ? 'codex.cmd' : 'codex') | ||
| ) | ||
| const fakeCodexSource = ` | ||
| const { appendFileSync } = require('node:fs') | ||
| const { appendFileSync, readFileSync } = require('node:fs') | ||
| const ledger = process.env.ORCA_E2E_CODEX_LIFECYCLE_LEDGER | ||
| const append = (event) => appendFileSync(ledger, JSON.stringify({ pid: process.pid, ...event }) + '\\n') | ||
| async function publishRecovery() { | ||
| const config = JSON.parse(readFileSync(${JSON.stringify(recoveryConfigPath)}, 'utf8')) | ||
| for (const hook_event_name of ['UserPromptSubmit', 'Stop']) { | ||
| const response = await fetch('http://127.0.0.1:' + process.env.ORCA_AGENT_HOOK_PORT + '/hook/codex', { | ||
| method: 'POST', | ||
| headers: { 'Content-Type': 'application/json', 'X-Orca-Agent-Hook-Token': process.env.ORCA_AGENT_HOOK_TOKEN }, | ||
| body: JSON.stringify({ | ||
| paneKey: process.env.ORCA_PANE_KEY, | ||
| tabId: process.env.ORCA_TAB_ID, | ||
| worktreeId: process.env.ORCA_WORKTREE_ID, | ||
| launchToken: process.env.ORCA_AGENT_LAUNCH_TOKEN, | ||
| env: process.env.ORCA_AGENT_HOOK_ENV, | ||
| version: process.env.ORCA_AGENT_HOOK_VERSION, | ||
| payload: { hook_event_name, prompt: 'Report completion, then exit normally', ...config } | ||
| }) | ||
| }) | ||
| if (response.status !== 204) throw new Error('Recovery hook rejected: ' + response.status) | ||
| } | ||
| } | ||
| const args = process.argv.slice(2) | ||
| if (args.includes('app-server')) { | ||
| process.stderr.write("error: unrecognized subcommand 'app-server'\\n") | ||
|
|
@@ -44,6 +64,10 @@ process.stdin.on('data', (chunk) => { | |
| process.stdout.write('\\x1b[?25h') | ||
| } | ||
| append({ event: 'input', input }) | ||
| if (input.includes('ORCA_E2E_PUBLISH_DONE')) { | ||
| void publishRecovery().catch((error) => process.stderr.write(String(error))) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.tsRepository: 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.tsRepository: 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.tsRepository: 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 240Repository: stablyai/orca Length of output: 20533 Await recovery publication before normal exit.
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) |
||
| return | ||
| } | ||
| if (input.includes('ORCA_E2E_EXIT_AFTER_DONE')) { | ||
| append({ event: 'normal-exit' }) | ||
| process.exit(0) | ||
|
|
@@ -179,6 +203,10 @@ export function seedCurrentCodexTranscript( | |
| payload: { id: providerSessionId, cwd } | ||
| })}\n` | ||
| ) | ||
| writeFileSync( | ||
| recoveryConfigPath, | ||
| JSON.stringify({ session_id: providerSessionId, transcript_path: transcriptPath }) | ||
| ) | ||
| return transcriptPath | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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!