fix(task): align background delegate-task output with OpenCode TUI session metadata contract#2309
Merged
code-yeongyu merged 3 commits intodevfrom Mar 5, 2026
Merged
Conversation
There was a problem hiding this comment.
1 issue found across 2 files
Confidence score: 4/5
- This PR is likely safe to merge, with minimal runtime risk since the reported issue is confined to a test file rather than production logic.
- The main concern is in
src/tools/delegate-task/background-task.test.ts: using an exact millisecond timeout withsetTimeoutcan cause intermittent CI failures when execution runs slightly slower than expected. - Given the issue severity (7/10) and high confidence, increasing the test timeout should reduce flaky failures without changing feature behavior.
- Pay close attention to
src/tools/delegate-task/background-task.test.ts- timeout sensitivity may cause non-deterministic test outcomes.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/tools/delegate-task/background-task.test.ts">
<violation number="1" location="src/tools/delegate-task/background-task.test.ts:16">
P1: Increase the timeout value to prevent flaky test failures caused by `setTimeout` taking longer than the exact millisecond duration specified.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| //#given - reduce waiting to keep tests fast | ||
| __setTimingConfig({ | ||
| WAIT_FOR_SESSION_INTERVAL_MS: 1, | ||
| WAIT_FOR_SESSION_TIMEOUT_MS: 2, |
There was a problem hiding this comment.
P1: Increase the timeout value to prevent flaky test failures caused by setTimeout taking longer than the exact millisecond duration specified.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/tools/delegate-task/background-task.test.ts, line 16:
<comment>Increase the timeout value to prevent flaky test failures caused by `setTimeout` taking longer than the exact millisecond duration specified.</comment>
<file context>
@@ -0,0 +1,158 @@
+ //#given - reduce waiting to keep tests fast
+ __setTimingConfig({
+ WAIT_FOR_SESSION_INTERVAL_MS: 1,
+ WAIT_FOR_SESSION_TIMEOUT_MS: 2,
+ })
+ })
</file context>
72722f7 to
39d94a4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix 3 contract mismatches between
delegate-taskbackground output metadata and OpenCode TUI'sTaskcomponent expectations, preventing broken session syncing and ambiguous task ID semantics.Problem
When
delegate-tasklaunches a background task, the output metadata sent to OpenCode's TUI had several issues:sessionId: "pending"— When the background manager hasn't resolved the subagent session yet, we emittedmetadata.sessionId = "pending", causing TUI to callsync.session.sync("pending")on a non-existent session.task_idfield — OpenCode's built-intasktool emitstask_id: <sessionId>in its output, but our background path omitted it entirely.task_idsemantics — Our background flow has two distinct IDs (background manager task ID vs session ID), but the output conflated them.Root Cause Analysis (with OpenCode source references)
TUI Contract:
metadata.sessionIdOpenCode's TUI
Taskcomponent usesprops.metadata.sessionIdto sync the child session and count toolcalls:Sync trigger (
index.tsx:1952-1955):Toolcall counting (
index.tsx:1957-1965):TUI Contract:
task_idoutputOpenCode's built-in
tasktool emitstask_id: <sessionId>as a session resumption key (task.ts:147-153):TUI Permission rendering
TUI permission dialog reads
data.subagent_typefor task display (permission.tsx:300-313).Changes
Commit 1:
fix(task): avoid pending sessionId metadata in background delegate outputmetadata.sessionIdwas set to"pending"when session wasn't yet created, causing TUI sync failures.sessionIdin metadata when a real session ID is available. Conditionally emit<task_metadata>block.src/tools/delegate-task/background-task.ts,src/tools/delegate-task/background-task.test.ts(new)Commit 2:
fix(task): align background output task_id with opencode contracttask_idfield that OpenCode's TUI and agents expect for session resumption.task_id: <sessionId>to<task_metadata>block (matching upstream contract). Rename human-readable label toBackground Task IDto distinguish from session-basedtask_id.Commit 3:
fix(task): disambiguate background task_id metadatatask_id(session ID) vs background manager task ID were ambiguous in output.background_task_id: <bg_task_id>to<task_metadata>block alongsidetask_id: <sessionId>, making both IDs explicit.Test Coverage
New test file
src/tools/delegate-task/background-task.test.tswith 3 test cases:does not emit synthetic pending session metadata when session id is unresolvedsessionId, no<task_metadata>block when session unavailableemits task metadata session_id when real session id is availablesession_id,task_id,background_task_idall present with correct valuescaptures late-resolved session id and emits synced metadataVerification
bun test src/tools/delegate-task/background-task.test.ts src/tools/delegate-task/tools.test.ts— 112 pass, 0 failbun run typecheck— cleanbun run build— cleanSummary by cubic
Aligns delegate-task background output with OpenCode TUI’s Task contract to fix session syncing and clarify task ID semantics. Background output now emits session metadata only when a real or late-resolved session is available and distinguishes between session and background task IDs.
Written for commit 39d94a4. Summary will update on new commits.