Skip to content

🤖 feat: queue messages behind special sends instead of erroring (FIFO message queue)#3696

Merged
ammario merged 7 commits into
mainfrom
message-queue-8t3e
Jul 10, 2026
Merged

🤖 feat: queue messages behind special sends instead of erroring (FIFO message queue)#3696
ammario merged 7 commits into
mainfrom
message-queue-8t3e

Conversation

@ammar-agent

@ammar-agent ammar-agent commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

Sending a message while an internal workspace-turn follow-up (or another metadata-bound send) was queued failed with a hard error dialog. This PR restructures MessageQueue from a single merged batch into FIFO dispatchable entries, so special sends own their turn and later messages queue behind them without errors. It also keeps backend-initiated queue work non-disruptive: background monitor wakes are hidden from/restored separately from the user's composer, and live foreground bashes are moved to background before a monitor wake dispatches after the current step.

Background

MessageQueue previously merged every queued message into one combined send (joined text, one metadata object, one callback set). That forced hard rejections for sends that must stay attached to exactly one dispatch, including workspace-turn follow-ups, agent-skill invocations, and compaction requests.

The FIFO change made background and user entries able to coexist, exposing two related UX risks that this PR also addresses:

  • synthetic/background queue entries could appear as editable queued input or be restored over an unsent user draft;
  • a queued background monitor wake used tool-end dispatch, which could soft-stop the stream while a foreground bash was still attached and abort that process instead of preserving its work.

Implementation

  • MessageQueue now holds ordered QueueEntry items and dispatches one entry at a time with dequeueNext().
  • Plain user follow-ups still batch into the newest compatible open entry. Compaction, agent-skill, workspace-turn, callback-carrying, and ownership-changing sends start separate entries so metadata, callbacks, and origin never leak between turns.
  • All previous Cannot queue ... throw paths are removed.
  • User-visible queue projections expose only user-authored entries. Synthetic/background entries remain in the real FIFO for dispatch and completion bookkeeping but do not render an editable queue card or restore into the composer.
  • Queue events retain an all-entry hasQueuedMessages signal so background follow-up bookkeeping remains correct even when the renderer has no user-visible queued message.
  • restore-to-input clears/cancels the complete queue but emits only user-authored text/files/reviews. Restore events are workspace-scoped so a background workspace cannot overwrite the currently mounted composer.
  • Bash monitor wakes still use tool-end (send-after-step) dispatch, but first background any live foreground bash tool calls. The process keeps running under background tracking instead of being killed by the ensuing stream abort.
  • Interrupting a queued workspace turn removes only its matching FIFO entry, preserving unrelated user messages.

Validation

  • Regression coverage for FIFO ordering and metadata/callback isolation.
  • Regression coverage for ownership-separated entries and user-visible queue projections.
  • Regression coverage proving synthetic background entries do not surface in queue UI or restore over user input.
  • Regression coverage proving streaming monitor wakes send foreground bashes to background.
  • Targeted suites: 516 tests passed across messageQueue, agentSession.queueDispatch, workspaceService, and WorkspaceStore.
  • make typecheck passed.
  • make static-check passed.

Risks

Medium: this changes the hot path for mid-stream sends, queue rendering/restoration, and bash-monitor wake dispatch. Existing batching semantics remain for compatible user messages; special sends and ownership boundaries are isolated into FIFO entries. Synthetic entries are hidden only from user-editable projections, while all-entry queue state is preserved for dispatch and response-completion logic. Monitor wake behavior matches the existing user send-after-step UX by migrating foreground bash work before soft-stopping the stream.


Generated with mux • Model: openai:gpt-5.6-sol • Thinking: high • Cost: $41.31

@ammar-agent

Copy link
Copy Markdown
Collaborator 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: 294388fed2

ℹ️ 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
@ammar-agent

Copy link
Copy Markdown
Collaborator Author

@codex review

Addressed the P2: interruptWorkspaceTurn now uses a targeted removeQueuedWorkspaceTurn(workspaceId, handleId, ...) path that removes only the matching workspace-turn entry (and notifies its cancel callback), leaving unrelated queued user messages pending. Covered by a new MessageQueue.removeWorkspaceTurn unit test.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 36f6bc81ea

ℹ️ 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".

1 similar comment
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 36f6bc81ea

ℹ️ 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".

@ammar-agent

Copy link
Copy Markdown
Collaborator Author

@codex review

Updated the queue fix to keep background work non-disruptive:

  • synthetic/background entries no longer appear in or restore over the user's composer;
  • restore events are scoped to the owning workspace;
  • bash monitor wakes background live foreground bashes before tool-end dispatch, matching send-after-step semantics and preserving in-flight work.

Local targeted tests, typecheck, and make static-check are green.

@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: b985a91d59

ℹ️ 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/agentSession.ts
@ammar-agent

Copy link
Copy Markdown
Collaborator Author

@codex review

Addressed the send-now priority issue: the queued-message card now promotes the oldest user-authored entry ahead of hidden synthetic/background entries before dispatch. Hidden work stays queued and resumes through the normal drain lifecycle.

Added a regression test for user/background/user ordering; targeted tests, typecheck, and make static-check pass.

@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: ebeb42fe6b

ℹ️ 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/agentSession.ts
@ammar-agent

Copy link
Copy Markdown
Collaborator Author

@codex review

Addressed the partial-drain send-now guard issue: queued card identity now derives from the visible queue projection, so dispatching one FIFO entry changes the id and resets the in-flight guard for the remaining card.

Added a WorkspaceStore regression test; targeted tests, typecheck, and make static-check pass.

@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: 57a0e064fd

ℹ️ 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/browser/stores/WorkspaceStore.ts Outdated
@ammar-agent

Copy link
Copy Markdown
Collaborator Author

@codex review

Addressed the queue-card id allocation issue: identity now includes only lightweight attachment/review metadata (media type, filename, URL length, file/line), never attachment data URLs or review bodies.

WorkspaceStore tests, typecheck, and make static-check pass.

@ammar-agent

Copy link
Copy Markdown
Collaborator Author

@codex review

Addressed the attachment-id performance concern: queued card identity now includes only lightweight attachment/review metadata (media type, filename, URL length, file path, line range), never serialized data URLs or review payloads.

WorkspaceStore regression test, typecheck, and make static-check pass.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 4b774d4019

ℹ️ 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".

@ammario ammario merged commit 956ac53 into main Jul 10, 2026
22 of 24 checks passed
@ammario ammario deleted the message-queue-8t3e branch July 10, 2026 22:48
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.

2 participants