Repository navigation
fix(orchestration): wait for opencode's composer marker before worker-start's paste #20451
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 1 commit
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 |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' | ||
| import { createOrchestrationWorkerReleaseHarness } from './worker-release.test-support' | ||
|
|
||
| // tui-idle fires on the generic OSC-title idle edge. opencode (and mimo-code, which shares its | ||
| // config) enable bracketed paste before their composer actually mounts, so tui-idle can resolve | ||
| // on their boot splash: worker-start then pastes the dispatch preamble into a screen with no | ||
| // composer to catch it, and the preamble is silently dropped even though the receipt reports | ||
| // `input_accepted` / `ready`. This asserts worker-start waits for opencode's own composer-mount | ||
| // marker (`waitForAgentComposerReady`, reusing the existing render-cursor-after-bracketed-paste | ||
| // detector) before writing the preamble, and that unrelated agents are unaffected. | ||
| describe('worker-start composer readiness for opencode', () => { | ||
| const harness = createOrchestrationWorkerReleaseHarness() | ||
| beforeEach(() => harness.setup()) | ||
| afterEach(() => harness.cleanup()) | ||
|
|
||
| it('waits for the opencode composer marker before delivering the preamble', async () => { | ||
| const composerWait = vi | ||
| .spyOn(harness.runtime, 'waitForAgentComposerReady') | ||
| .mockResolvedValue(true) | ||
| const sends: string[] = [] | ||
| vi.spyOn(harness.runtime, 'sendTerminalAgentPrompt').mockImplementation(async () => { | ||
| sends.push('sendTerminalAgentPrompt') | ||
| return { handle: 'term_worker', accepted: true, bytesWritten: 1 } | ||
| }) | ||
| composerWait.mockImplementation(async () => { | ||
| sends.push('waitForAgentComposerReady') | ||
| return true | ||
| }) | ||
|
|
||
| const task = harness.db.createTask({ | ||
| spec: 'opencode composer fixture', | ||
| runId: harness.activeRunId | ||
| }) | ||
| const result = (await harness.call('orchestration.workerStart', { | ||
| task: task.id, | ||
| from: 'term_coord', | ||
| agent: 'opencode' | ||
| })) as { state: string } | ||
|
|
||
| expect(result.state).toBe('ready') | ||
| expect(composerWait).toHaveBeenCalledWith('term_worker', 'opencode') | ||
| expect(sends).toEqual(['waitForAgentComposerReady', 'sendTerminalAgentPrompt']) | ||
| }) | ||
|
|
||
| it('proceeds anyway when the opencode composer marker times out', async () => { | ||
| vi.spyOn(harness.runtime, 'waitForAgentComposerReady').mockResolvedValue(false) | ||
|
|
||
| const task = harness.db.createTask({ | ||
| spec: 'opencode timeout fixture', | ||
| runId: harness.activeRunId | ||
| }) | ||
| const result = (await harness.call('orchestration.workerStart', { | ||
| task: task.id, | ||
| from: 'term_coord', | ||
| agent: 'opencode' | ||
| })) as { state: string } | ||
|
|
||
| expect(result.state).toBe('ready') | ||
|
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. This test only pins that a timeout doesn't block the start; it would still pass if the code skipped the preamble after |
||
| }) | ||
|
|
||
| it('does not gate an unrelated agent (codex) on the opencode composer marker', async () => { | ||
| const composerWait = vi | ||
| .spyOn(harness.runtime, 'waitForAgentComposerReady') | ||
| .mockResolvedValue(true) | ||
|
|
||
| const task = harness.db.createTask({ spec: 'codex fixture', runId: harness.activeRunId }) | ||
| const result = (await harness.call('orchestration.workerStart', { | ||
| task: task.id, | ||
| from: 'term_coord', | ||
| agent: 'codex' | ||
| })) as { state: string } | ||
|
|
||
| expect(result.state).toBe('ready') | ||
| expect(composerWait).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('does not gate a reused --terminal (no --agent, e.g. a pre-warmed handle)', async () => { | ||
| const composerWait = vi | ||
| .spyOn(harness.runtime, 'waitForAgentComposerReady') | ||
| .mockResolvedValue(true) | ||
|
|
||
| await harness.startWorker({ terminal: 'term_worker' }) | ||
|
|
||
| expect(composerWait).not.toHaveBeenCalled() | ||
| }) | ||
|
Comment on lines
+19
to
+111
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. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Add
|
||
| }) | ||
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 returned boolean is dropped, so a composer timeout — which is exactly the opencode race this PR fixes — still leaves no trace beyond an ordinary
state=readyreceipt. Consider logging a warning (the draft-paste path does this inpasteWorktreeStartupDraftWhenReady) or folding the value into the receipt, so a timed-out paste is distinguishable from a landed one.