Skip to content

🤖 fix: queue busy workspace turn follow-ups#3617

Merged
ThomasK33 merged 3 commits into
mainfrom
fix/workspace-turn-queue-followups
Jun 23, 2026
Merged

🤖 fix: queue busy workspace turn follow-ups#3617
ThomasK33 merged 3 commits into
mainfrom
fix/workspace-turn-queue-followups

Conversation

@ThomasK33

@ThomasK33 ThomasK33 commented Jun 23, 2026

Copy link
Copy Markdown
Member

Summary

Queue follow-up messages for busy existing workspace turns instead of failing when the target workspace is already running.

Background

Parent/orchestrator workspaces can target an already-created workspace with task(kind="workspace", workspace.mode="existing"). That previously failed with existing workspace is busy; wait until it is idle, even though the chat layer already supports queued follow-up messages.

Implementation

  • Adds workspace.queueDispatchMode for existing workspace turns so orchestrators can choose tool-end or turn-end queue dispatch.
  • Records busy existing workspace turns as queued task handles and transitions them to running once the queued message is accepted.
  • Uses WorkspaceService's message-busy predicate before deciding whether an existing workspace turn is queued vs immediately running, so COMPLETING-phase turns are not marked active early.
  • Reserves/counts queued workspace-turn handles as active unless they are simply queued behind an already-counted workspace turn for the same target workspace.
  • Ignores stale uncorrelated stream-end events that occurred before the queued workspace-turn prompt in history, avoiding activation races during queue flush at prior turn completion.
  • Carries workspace-turn acceptance/failure/cancel callbacks through the message queue so pre-stream failures and queue clears settle the durable handle.
  • Rejects queued-turn acceptance if the handle is interrupted while the queued message is dispatching but before stream startup.
  • Keeps workspace-turn queued messages isolated from batching with other queued content, preserving one task handle per stream-end metadata marker.
  • Clears queued workspace-turn payloads when interrupted before dispatch, so a terminated queued handle cannot send later.
  • Updates synced tool docs/generated skill content for the new input parameter.

Validation

  • env MUX_ESLINT_CONCURRENCY=1 make static-check
  • bun test src/node/services/messageQueue.test.ts src/node/services/tools/task.test.ts src/common/utils/tools/toolDefinitions.test.ts src/node/services/taskService.test.ts --test-name-pattern 'MessageQueue|workspace turn queue dispatch mode|accepts workspace turn queue dispatch mode|createWorkspaceTurn (creates a normal workspace|reprompts only owner-created|queues busy owner-created|reserves a slot before queueing|counts active workspace turns)|uncorrelated stream-end before queued workspace turn prompt'
  • bun test tests/ui/chat/unreadIndicator.test.ts -t "hides Mark unread for already-unread rows" (local check for unrelated Integration CI flake)

Risks

Moderate risk in workspace-turn orchestration and queued-message handling. The queue now carries internal callbacks, so the implementation keeps workspace-turn messages single-entry to avoid orphaning task handles or applying metadata to the wrong turn.


Generated with mux • Model: openai:gpt-5.5 • Thinking: xhigh • Cost: $24.67

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b71deba993

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/node/services/taskService.ts Outdated
Comment thread src/node/services/taskService.ts
@mintlify

mintlify Bot commented Jun 23, 2026

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
Mux 🟢 Ready View Preview Jun 23, 2026, 4:41 PM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

Please take another look.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 88454baa34

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/node/services/messageQueue.ts
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

Please take another look.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a7f766e0ca

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/node/services/taskService.ts Outdated
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

Please take another look.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 16df052fae

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/node/services/taskService.ts Outdated
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

Please take another look.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c81cd60a8d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/node/services/taskService.ts Outdated
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

Please take another look.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7d312b326a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/node/services/taskService.ts
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

Please take another look.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2921e7fe31

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/node/services/taskService.ts Outdated
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

Please take another look.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 08b110ef7f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/node/services/taskService.ts
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

Please take another look.

@ThomasK33

Copy link
Copy Markdown
Member Author

Codex thread response:

  • PRRT_kwDOPxxmWM6LrWSZ / "Keep the idle precheck authoritative for existing turns": addressed in 09c95bd. Existing turns now pass requireIdle: true whenever the handle was not precomputed as queued, so an idle-to-busy race fails instead of queueing behind a running-marked handle. The busy path still uses requireIdle: false only for handles persisted as queued.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 09c95bd0ce

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/node/services/taskService.ts
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

Please take another look.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dfdbf7bb2e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/node/services/taskService.ts Outdated
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

Please take another look.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 59e38fcbfd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ThomasK33
ThomasK33 force-pushed the fix/workspace-turn-queue-followups branch from 59e38fc to 800e96e Compare June 23, 2026 18:44
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

Rebased on latest main and squashed the final diff; please take another look.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 800e96e168

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/node/services/workspaceService.ts Outdated
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

Please take another look.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d58d894f5b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/node/services/taskService.ts Outdated
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

Please take another look.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 2a6599f6c8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ThomasK33
ThomasK33 added this pull request to the merge queue Jun 23, 2026
Merged via the queue into main with commit 25d1d25 Jun 23, 2026
24 checks passed
@ThomasK33
ThomasK33 deleted the fix/workspace-turn-queue-followups branch June 23, 2026 19:58
@mux-bot mux-bot Bot mentioned this pull request Jun 23, 2026
LeonidasZhak pushed a commit to LeonidasZhak/mux that referenced this pull request Jun 30, 2026
## Summary

Long-lived auto-cleanup PR maintained by the **Auto-Cleanup Agent**.
Each pass lands at most one extremely low-risk, behavior-preserving
cleanup drawn from recently merged `main` activity, then advances the
checkpoint below.

Auto-cleanup checkpoint: 620c2a6

This PR currently contains six accumulated cleanups against `main`:

1. `src/node/services/taskService.ts` — dedupe queued-message foreground
backgrounding into a private helper.
2. `src/node/services/workflows/workflowScriptResolver.ts` — reuse the
`SKILL_SCRIPT_PATH_PREFIX` constant for canonical-path construction.
3. `src/node/services/workflows/WorkflowTaskServiceAdapter.ts` — extract
the duplicated agent-task creation arg shape into a shared
`WorkflowTaskCreateArgs` type.
4. `src/constants/workspaceTags.ts` (new) — centralize the
workspace-turn task tag keys, removing the cross-layer
`"mux.taskHandleId"` string duplication.
5. `src/node/services/tools/workflowProgress.ts` — extract the
duplicated "latest phase" lookup into a shared `getLatestPhaseEvent`
helper.
6. `src/browser/features/RightSidebar/Workflows/WorkflowBadges.tsx` —
map workflow run-status glyphs through an exhaustive
`Record<WorkflowRunStatus, LucideIcon>` instead of a repeated
`if`-chain.

## This pass

Rebased the branch onto the latest `origin/main` (clean) and considered
the three new commits since the prior checkpoint:

- coder#3624 (`feat: add Workflows right-sidebar tab with live run
streaming`)
- coder#3626 (`tests: add UI primitive stories and fix design-sync previews`)
- coder#3627 (`feat: return workflow plan agent results`)

coder#3624 added `WorkflowBadges.tsx`, whose `WorkflowStatusIcon` selected a
glyph through a four-branch `if`-chain that re-spelled the identical
`className="h-3 w-3 shrink-0"` + `style={{ color }}` props in every
branch and fell back to a default `<Circle>` for unmatched statuses.
Replaced that with a module-level `WORKFLOW_STATUS_ICON:
Record<WorkflowRunStatus, LucideIcon>` map (mirroring the existing
`WORKFLOW_STATUS_META` / `WORKFLOW_TONE_VAR` records in the same
feature) and render the looked-up icon once. Behavior-preserving: the
map reproduces the prior mapping exactly (`pending`/`running` →
`Circle`, `backgrounded`/`interrupted` → `Pause`, `completed` → `Check`,
`failed` → `X`), and using a `Record` makes the mapping exhaustive so a
newly added run status is a compile error here rather than a silent
fall-through. coder#3626 (Storybook/design-sync, test-only) and coder#3627
(already extracts its own `__muxAgentReturnValue` runtime helper)
offered no additional low-risk dedup.

<details>
<summary>Prior pass — workflowProgress getLatestPhaseEvent
helper</summary>

coder#3623 added `src/node/services/tools/workflowProgress.ts`, in which both
`buildWorkflowProgressSummary` and `formatWorkflowProgressNote`
independently re-spelled the same `run.events.findLast((event) =>
event.type === "phase")` expression to find the latest phase event.
Extracted that into a single private `getLatestPhaseEvent(run)` helper
and referenced it from both functions, giving the "latest phase"
definition one source of truth so the summary builder and the note
formatter can't drift. Behavior-preserving: the helper's body and
inferred return type are identical to the inline expression, so both
call sites compute exactly the same value.

</details>

<details>
<summary>Prior pass — checkpoint-only advance for coder#3621 (Claude Design
integration)</summary>

coder#3621 is purely additive and lives entirely under `.design-sync/` (plus
one `.gitignore` entry); it contains zero production (`src/`) code.
`.design-sync/**` is outside both the ESLint scope (`src/**`) and the
TypeScript `include`, so `make static-check` cannot validate the
behavior-preservation of any refactor there. That pass advanced the
checkpoint without a code change.

</details>

<details>
<summary>Prior pass — workspace-turn task tag keys
centralization</summary>

The workspace-turn task tag key `"mux.taskHandleId"` is **written** by
`TaskService.createWorkspaceTurn` (node, coder#3617/coder#3619) and **read** by
`findWorkspaceForTaskTarget` in `TaskToolCall.tsx` (browser, coder#3613) —
the same magic string duplicated across the node/browser boundary.
Extracted the three workspace-turn task tag keys (`handle`,
`ownerWorkspaceId`, `turn`) into a new `@/constants/workspaceTags`
module and referenced `WORKSPACE_TURN_TASK_TAGS` from both the node
write site and the browser read site. Behavior-preserving: the extracted
values are byte-identical to the previous literals, so the persisted tag
keys and all lookups are unchanged.

</details>

<details>
<summary>Prior pass — WorkflowTaskServiceAdapter WorkflowTaskCreateArgs
type</summary>

`WorkflowTaskServiceLike` (in `WorkflowTaskServiceAdapter.ts`) declared
the agent-task creation argument object **twice** — once inline in
`create(args: { ... })` and again inside `createMany?(args: Array<{ ...
}>)` — as byte-identical 10-field shapes. Extracted a named
`WorkflowTaskCreateArgs` interface and referenced it from both `create`
and `createMany`. Behavior-preserving: structurally identical interface,
signatures unchanged.

</details>

<details>
<summary>Prior pass — workflowScriptResolver SKILL_SCRIPT_PATH_PREFIX
reuse</summary>

In `workflowScriptResolver.ts`, the `skill://` prefix is named by the
module-level constant `SKILL_SCRIPT_PATH_PREFIX`, but the two
canonical-path builders re-spelled the literal `` `skill://${...}` ``
instead of reusing the constant. Both builders now interpolate
`${SKILL_SCRIPT_PATH_PREFIX}`. Behavior-preserving:
`SKILL_SCRIPT_PATH_PREFIX` is exactly `"skill://"`, so the interpolation
is byte-identical.

</details>

<details>
<summary>Prior pass — taskService queued-message dedup</summary>

Considered coder#3605 (`fix: background foreground waits for prequeued
messages`), which open-coded the same queued-message guard at two
`TaskService` wait-registration sites. Both sites now delegate to a
single private helper
`backgroundForegroundWaitIfQueued(shouldBackgroundOnQueuedMessage,
requestingWorkspaceId)`. Behavior-preserving: the helper folds in the
`requestingWorkspaceId` truthiness guard and the pushed call is
unchanged.

</details>

## Validation

- `make static-check` is green for the touched code (ESLint, `tsconfig`
+ `tsconfig.main.json`, Prettier). (`fmt-shell-check` is the only
non-passing step, solely because the `shfmt` binary is absent in this
environment; no shell files are touched.)
- Targeted tests pass: `bun test
src/browser/features/RightSidebar/Workflows/workflowDisplay.test.ts
src/browser/features/RightSidebar/Workflows/projectWorkflowRun.test.ts`
(32 tests) cover the same Workflows feature module the change lives in.

## Risks

Minimal. All accumulated changes are pure local extractions / constant
reuse; no logic, types, or call semantics change.

---

_Generated with `mux` • Model: `anthropic:claude-opus-4-8` • Thinking:
`xhigh`_

<!-- mux-attribution: model=anthropic:claude-opus-4-8 thinking=xhigh -->

---------

Co-authored-by: mux-bot[bot] <264182336+mux-bot[bot]@users.noreply.github.com>
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