Skip to content

[agent] 🤖 fix: preserve queue-cut continuations - #4045

Open
coadler wants to merge 24 commits into
mainfrom
fix-monitor-queue-cut-continuation
Open

[agent] 🤖 fix: preserve queue-cut continuations#4045
coadler wants to merge 24 commits into
mainfrom
fix-monitor-queue-cut-continuation

Conversation

@coadler

@coadler coadler commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

Preserve agent execution when a monitored background task settles during task_await.

Background

A monitor wake can queue while task_await reads the same terminal output. The queued wake then stops the model step.

The output read makes the wake redundant. The reconciler cancels it before dispatch, so the workspace becomes idle without a continuation.

Implementation

  • Replace the queue-state query with an atomic tool-end claim.
  • Reject a wake when its cancel signal already fired.
  • Detach cancellation after a wake commits the queue cut.
  • Restore cancellation when a provider stream cut fails.
  • Skip canceled heads when selecting the next live queue entry.
  • Add queue and session regression coverage for the lost-continuation order.
  • Align the legacy forwarding package with the current release version.

Risks

Risk is low. The queue change only affects cancellation after an entry commits a tool-end stream cut.

An obsolete wake can run when newer process state supersedes it. This preserves progress, and the newer wake still follows.


Generated with xum • Model: openai:gpt-5.6-sol • Thinking: xhigh • Cost: $0.00

@coadler

coadler commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review the atomic queue-cut handoff and its cancellation behavior.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-02T22:53:30.826400Z 29da334 Manual request
🔒 Security Review Completed 2026-09-02T22:58:23.630014Z 29da334 Manual request

Security findings

Advisory findings (8)

ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coadler

coadler commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

The latest commit covers the same handoff for provider-executed tools.

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

ℹ️ 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 Outdated
Comment thread src/node/services/messageQueue.ts Outdated
@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: e8d2813b80

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@coadler

coadler commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

Both findings are fixed in 4477c75. Please review the restored cancellation and canceled-head handling.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 4477c75cde

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

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: 4477c75cde

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@coadler

coadler commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

The queue fix is unchanged. Commit 93c4805 also repairs the 0.28.3 compatibility version that blocks main CI.

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: 93c4805c4f

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@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: 93c4805c4f

ℹ️ 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 Outdated
@coadler

coadler commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

The continuation observers now ignore canceled physical heads in 86172e8. Please review the live-entry invariant.

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: 86172e8046

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@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: 86172e8046

ℹ️ 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
Comment thread src/node/services/messageQueue.ts Outdated
@coadler

coadler commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

Both findings are fixed in 15efef1. Please review live-entry emptiness and provider-claim ownership.

@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: 15efef1d9b

ℹ️ 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
Comment thread src/node/services/agentSession.ts Outdated
Comment thread src/node/services/messageQueue.ts
Comment thread src/node/services/messageQueue.ts

@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 Security Review

Here are some automated security review suggestions for this pull request.

Reviewed commit: 15efef1d9b

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment thread src/node/services/agentSession.ts Outdated
@coadler

coadler commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

All four findings are fixed in ed20fe3. Please review unified claim ownership, pinned commit, and canceled-entry draining.

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

ℹ️ 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 Outdated
Comment thread src/node/services/agentSession.ts Outdated
Comment thread src/node/services/agentSession.ts

@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 Security Review

Here are some automated security review suggestions for this pull request.

Reviewed commit: ed20fe3001

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment thread src/node/services/agentSession.ts Outdated
@coadler

coadler commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

The four findings are fixed in 2f73051. Please review admission ownership, hard-interrupt gating, fallback draining, and latch updates.

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: 2f73051305

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@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: 2f73051305

ℹ️ 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 Outdated
Comment thread src/node/services/agentSession.ts Outdated
Comment thread src/node/services/agentSession.ts
Comment thread src/node/services/agentSession.ts
@coadler

coadler commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

The four findings are fixed in 7a3adcb. Please review the acceptance boundary, failed-Stop restoration, and dispatch cleanup.

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

ℹ️ 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 Outdated
Comment thread src/node/services/agentSession.ts
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ 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".

@coadler

coadler commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

Both Send-now findings are fixed in ef8ca92. Please review claim preservation and serialized queue admission.

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

ℹ️ 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 Outdated
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ 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".

@coadler

coadler commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

The Send-now finding is fixed in 5a566ee. Please review the user-claim classification and synthetic admission cancellation.

Mux added 19 commits September 2, 2026 16:53
Skip canceled queue heads when selecting the continuation. Restore cancellation when a provider stream cut fails.

🤖 Generated with [xum](https://xum.sh)

Co-authored-by: Mux <noreply@coder.com>
Use the next live FIFO entry for dispatch, continuation, and cut attribution. This keeps canceled heads from misclassifying the committed cutter.

🤖 Generated with [xum](https://xum.sh)

Co-authored-by: Mux <noreply@coder.com>
Treat canceled-only queues as empty for continuation checks. Restore provider claims when user interruption abandons the queue cut.

🤖 Generated with [xum](https://xum.sh)

Co-authored-by: Mux <noreply@coder.com>
Retain SDK and provider claim ownership until dispatch. Pin committed entries and discard canceled entries without entering preparation.

🤖 Generated with [xum](https://xum.sh)

Co-authored-by: Mux <noreply@coder.com>
Keep queue claims through preparing admission. Reject late claims during hard interrupts. Clear canceled queue latches.

🤖 Generated with [xum](https://xum.sh)

Co-authored-by: Mux <noreply@coder.com>
Restore claims when hard interruption fails. Release claims before irreversible acceptance. Clear canceled dispatch state and emit restored queue state.

🤖 Generated with [xum](https://xum.sh)

Co-authored-by: Mux <noreply@coder.com>
Keep queue admission serialized through stream start. Preserve claimed user entries when Send now follows a hard interrupt.

🤖 Generated with [xum](https://xum.sh)

Co-authored-by: Mux <noreply@coder.com>
Preserve only queued user claims during Send now. Cancel synthetic dispatches before acceptance.

🤖 Generated with [xum](https://xum.sh)

Co-authored-by: Mux <noreply@coder.com>
Keep admitted user input during Send now. Notify failure-only callbacks when cancellation wins before acceptance.

🤖 Generated with [xum](https://xum.sh)

Co-authored-by: Mux <noreply@coder.com>
Delay claimed user admission until descendant cleanup finishes. Requeue reversible input when a later Stop cancels it.

🤖 Generated with [xum](https://xum.sh)

Co-authored-by: Mux <noreply@coder.com>
Finalize durable queue callbacks before a hard Stop blocks provider startup.

🤖 Generated with [xum](https://xum.sh)

Co-authored-by: Mux <noreply@coder.com>
Release irreversible claims after descendant cleanup. Let their exact provider turn consume the durable row.

🤖 Generated with [xum](https://xum.sh)

Co-authored-by: Mux <noreply@coder.com>
Release irreversible synthetic admissions after descendant cleanup. Keep stale probes disabled after the rollback boundary.

🤖 Generated with [xum](https://xum.sh)

Co-authored-by: Mux <noreply@coder.com>
Mark canceled synthetic turns as provider-excluded after their rollback boundary.
Keep queue settlement blocked until hard-stop cleanup finishes.

🤖 Generated with [xum](https://xum.sh)
Co-authored-by: Mux <noreply@coder.com>
Filter stopped synthetic rows from each history-based model transcript.
Keep claimed wakes cancelable until StreamManager owns startup.

🤖 Generated with [xum](https://xum.sh)
Co-authored-by: Mux <noreply@coder.com>
🤖 Generated with [xum](https://xum.sh)

Co-authored-by: Mux <noreply@coder.com>
🤖 Generated with [xum](https://xum.sh)

Co-authored-by: Mux <noreply@coder.com>
🤖 Generated with [xum](https://xum.sh)

Co-authored-by: Mux <noreply@coder.com>
🤖 Generated with [xum](https://xum.sh)

Co-authored-by: Mux <noreply@coder.com>
@coadler
coadler force-pushed the fix-monitor-queue-cut-continuation branch from 09755ec to 5fa3537 Compare September 2, 2026 21:54
@coadler

coadler commented Sep 2, 2026

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: 5fa3537269

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

@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 Security Review

Here are some automated security review suggestions for this pull request.

Reviewed commit: 5fa3537269

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment thread src/node/services/agentSession.ts Outdated
Mux added 2 commits September 2, 2026 17:15
🤖 Generated with [xum](https://xum.sh)

Co-authored-by: Mux <noreply@coder.com>
🤖 Generated with [xum](https://xum.sh)

Co-authored-by: Mux <noreply@coder.com>
@coadler

coadler commented Sep 2, 2026

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 Security Review

Here are some automated security review suggestions for this pull request.

Reviewed commit: a559620eac

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment thread src/node/services/historyService.ts
🤖 Generated with [xum](https://xum.sh)

Co-authored-by: Mux <noreply@coder.com>
@coadler

coadler commented Sep 2, 2026

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 Security Review

Here are some automated security review suggestions for this pull request.

Reviewed commit: 29da334d8f

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment on lines +7482 to +7486
cancelSignal: dispatchClaim.queueClaim.admissionSignal,
admissionStale: () =>
!dispatchClaim.admissionIrreversible &&
(dispatchClaim.queueClaim.admissionSignal.aborted ||
internal?.admissionStale?.() === true),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Security: Cancel claimed wakes when task_stop wins admission

With a bash-monitor wake claimed after task_await returns the same output, if an ancestor runs task_stop while the wake is dequeued in PREPARING, this replacement discards the already-aborted reconciler signal. task_stop only clears queue-resident entries and only stops AIService when a stream is registered, while this path calls AgentSession.sendMessage directly and supplies no admissionStale probe. The interrupted task can therefore start a provider/tool-capable turn from attacker-influenceable process output after task_stop succeeds. Carry the task stop epoch/status into the claimed admission, or let task_stop cancel the active claim before returning.

Useful? React with 👍 / 👎.

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