Skip to content

fix: a queued message being edited waits until you save or cancel - #10

Open
jagrat7 wants to merge 7 commits into
mainfrom
fix/stash-during-queued-edit
Open

jagrat7 wants to merge 7 commits into
mainfrom
fix/stash-during-queued-edit

Conversation

@jagrat7

@jagrat7 jagrat7 commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

Problem

If you're editing a queued message when the running turn ends, the server sends the message with its old text. The client can't save the edit to a message that already started, so it moves the edit into the composer (or drops it) and shows "Queued message is no longer queued". The agent gets the wrong text, and your edit is left to send as a second message.

Repro: start a long turn, queue a follow-up, click ✏️ on it, change the text, and let the turn finish before you save.

Change

The server now knows when a queued message is being edited, and waits for you.

  • Clients hold the message while you edit it (web, desktop and mobile, through the shared edit store). Opening the editor sends queued-run.hold, renews it every 30 seconds, and releases it on Cancel or when you open another message.
  • The queue waits only when the held message is next. Messages ahead of it still run. New messages queue behind it. Subagent results still go out, even ones that queued after the held message.
  • The edit ends one of these ways:
    • Save: the edited text runs.
    • Cancel: the original text runs.
    • Removing the message, from any device or an agent: the next message starts.
    • Send now on a later message: that message starts.
    • No renewal for 2 minutes (a closed tab, say): the hold lapses through a delayed outbox effect, and the original text runs.
  • A turn that fails during the edit still holds the queue, so saving doesn't send the message into a failed provider or the project checkout.
  • A deferred steer waits for the edit too, then steers the edited text. Saved as a slash command, it stays queued in place.
  • An older server rejects the hold, and editing works as it does today.
sequenceDiagram
  participant C as Client
  participant S as Server
  participant A as Agent
  C->>S: queued-run.hold (open editor, renew every 30s)
  A->>S: turn ends
  Note over S: Q is next and held: nothing starts
  alt Save
    C->>S: queued-run.edit (new text)
    S->>A: start Q with the new text
  else Cancel
    C->>S: queued-run.hold { held: false }
    S->>A: start Q with the original text
  else no renewal for 2 min
    S->>S: hold expires
    S->>A: start Q with the original text
  end
Loading

Scope

Fixes pingdotgg#15611 (pingdotgg/t3code). It builds on the approach in pingdotgg#35475 and pingdotgg#18631. It also covers the gap that closed pingdotgg#35475: removing the edited message used to leave the queue stuck.

Verification

  • Server, ThreadStop.test.ts:
    • the queue waits at a held message only once it is next;
    • Resume keeps the hold;
    • saving starts the edited text;
    • a hold renewed halfway is still held at its first deadline;
    • saving an edit after a provider failure leaves the queue held (fails without the fix);
    • the hold ends both by expiry and by release.
  • Server, SteeringCompletion.integration.test.ts: a deferred steer waits for its edit, then steers the edited text. Saved as /context all, it stays queued and steers nothing; that case fails without the fix.
  • Server, QueuedRunOrder.test.ts: a user message waits behind an edited message, and a subagent result passes it.
  • Server, FoundationPersistence.test.ts: the expiry timer runs in its own outbox lane, so a pending timer doesn't block the thread's other effects.
  • Client, queuedRunEdit.test.ts:
    • opening an edit holds and renews;
    • switching or cancelling releases;
    • renewals pause while a save is in flight;
    • a save or a started run sends no release.
  • Web useQueuedRunEdit browser tests and mobile queued-run-edit tests pass, and so does vp run check:changed.
  • Checked by hand in a dev build (web), with the Replay provider:
    • A turn was waiting on an approval. I queued a follow-up, opened it for editing and changed the text without saving, then approved.
    • The turn completed and the follow-up stayed queued and held. There was no "no longer queued" toast, and the edit stayed open.
    • The client's renewal moved the deadline from 20:52:57 to 20:53:57.
    • On save, the hold cleared and the follow-up started with the edited text.
  • Not done: native mobile on a device, and before/after captures.

Claude Opus 5.5 via Claude Code in T3 Code.

@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:S labels Nov 8, 2026
@github-actions

Copy link
Copy Markdown

Thread transfer impact

⚠️ The latest CI run did not produce a thread transfer result for 555e351.

This comment will update automatically after the next completed run.

A queued message that a client is editing gets a short hold. Once it is
next, the queue waits there until the edit is saved, cancelled, or the
hold lapses after two minutes without a renewal. A turn that fails during
the edit still holds the queue, and a steer waiting for its turn waits for
the edit too.
…ave or cancel

Opening a queued message for editing asks the server to hold it, renews
the hold every 30 seconds, and releases it on cancel or when another
message is opened. A server without the hold rejects it and editing works
as before.
@jagrat7
jagrat7 force-pushed the fix/stash-during-queued-edit branch from 555e351 to 6cd61c6 Compare November 23, 2026 08:29
@jagrat7 jagrat7 changed the title fix(web): stashing during a queued-message edit no longer loses the edit fix: a queued message being edited waits until you save or cancel Nov 23, 2026
@github-actions github-actions Bot added size:L and removed size:S labels Nov 23, 2026

@devin-ai-integration devin-ai-integration 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.

Devin Review found 8 potential issues.

Devin Review

runId: queuedRun.id,
providerInstanceId: queuedRun.providerInstanceId,
occurredAt: now,
payload: withoutEditHold(queuedRun),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔴 Saving a queued edit interrupts work

Saving a held deferred steer as /goal <objective> restores steerWhenReadyRunId after the edit clears it. deliverSteerAfterEdit then promotes the command and stops the running turn on a goal-capable provider instead of leaving it queued.

Learn more

Editing a deferred steer into a slash command removes its target so it stays in its original queue position (dispatchQueuedRunEdit). The subsequent hold-release event starts from the original run, restoring the target. When the target turn is running, deliverSteerAfterEdit promotes the edited message. dispatchQueuedMessagePromoteToSteer moves a slash command to the front and can interrupt the target for a goal command.

Example: Ask to steer while a goal-capable provider is starting, open the deferred steer for editing, and save /goal finish the migration once the provider is running. The save interrupts the turn rather than leaving the command in its original queue position.

Recommended fix: Emit one run update that applies both field removals when they apply. Extend the deferred-steer integration case to verify that saving a slash command preserves queue position and writes no interrupt request.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Note

🤖 Claude Opus 5.5 responding on behalf of jagrat7

Fixed in 1172481. The save now sends one run update that drops the edit hold and, for a slash command, the steer target. Before, the second update put the target back. The deferred-steer case in SteeringCompletion.integration.test.ts now also saves as /context all and checks that nothing is steered and the run stays queued with no target. That case fails without the fix.

if (
command.type === "queue.resume" ||
command.type === "queued-run.start" ||
startsQueueAfterCommit(command) ||

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔴 Edit release bypasses failure holds

If an edit ends before the run-end handler processes a committed failure, startNextQueuedRun gets no failure context. It can start queued work on the failed provider or in the project checkout after failed worktree setup.

Learn more

The terminal run and the queue's failure pause are separate writes. dispatchPreparedRunFail records the failed run; handleRunUpdate later handles the terminal event and passes the ended and failed run IDs to queue promotion. A save or hold release can take the thread lock in between. The new automatic start path passes neither ID, so startNextQueuedRunOnce misses both checks even though it reads the failed run. Without a worktree, the runtime policy resolves the project checkout instead.

Example: Queue and edit a follow-up while a new thread prepares its worktree. If worktree setup fails and the save gets the thread lock before the failure reaction writes the queue pause, the follow-up starts in the project checkout.

Recommended fix: Give the new automatic start paths the latest-run safety checks already used by message intake, including receipt replay. Preserve the explicit resume and Send now behavior. Test a save after the terminal projection is committed but before its reaction processes it.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Note

🤖 Claude Opus 5.5 responding on behalf of jagrat7

Fixed in 1172481. Starts that an edit triggers (save, release, expiry, remove, reorder) now pass latestRunEnded: true, as message intake does. They check the latest turn for a failure or a missing worktree even when the run-end handler has not run yet. Resume and Send now still go on as a person asked. New test in ThreadStop.test.ts: the failure is in the projection, its reaction has not run, and the save leaves the queue held. It fails without the change.

Comment on lines +12491 to +12501
if (!command.held) {
// The message may have started or been cancelled while the edit was open.
const run = projection.runs.find((candidate) => candidate.id === command.runId);
if (run?.status !== "queued" || run.editHeldUntil === undefined) return;
yield* emitEvent({
type: "run.updated",
threadId: command.threadId,
runId: run.id,
providerInstanceId: run.providerInstanceId,
occurredAt: now,
payload: withoutEditHold(run),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔴 One device cancels another’s edit hold

When two devices edit the same message, dispatchQueuedRunHold clears their shared hold as soon as either device cancels. The queue can send the original text while the other edit is open, leaving that edit unsavable.

Learn more

Each client starts and renews a hold independently through makeQueuedRunEditStore, but the server stores one deadline per run. A cancellation clears that deadline regardless of which client renewed it. If the queue starts the message, the other client closes the edit; resolveQueuedEditExit discards changed content when the thread already has a draft.

Example: Edit the same queued follow-up on a phone and browser while the previous turn runs. Change the browser text, wait for the turn to finish, then cancel on the phone. The original follow-up runs, and the browser cannot save its changes to that message.

Recommended fix: Associate each hold with an edit-session identifier. Renew and release only that session’s hold, and keep the message paused while any live hold remains. If concurrent edits are not supported, reject the second acquisition and prevent the second editor from releasing the first hold.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Note

🤖 Claude Opus 5.5 responding on behalf of jagrat7

Not changing this. One hold per message is deliberate. If one device cancels while another is editing, the message goes out with its original text and the other device's edit goes through the existing recovery: back into the composer, or dropped if the composer has a draft. That is the same outcome as on main today, so nothing gets worse. Tracking each device's hold would add per-session state to the run for a rare case: two devices editing the same queued message at once.

Comment on lines +2684 to +2686
if (options?.queuedRunId === undefined && storedQueuedRun.editHeldUntil !== undefined) {
return;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Queued subagent results wait behind edits

When a subagent result queues behind an edited message, startNextQueuedRunOnce stops at the edit once the parent turn ends. The parent agent gets no result until the edit hold ends.

Learn more

dispatchContinuation sends completed subagent results with queue_after_active. If the active turn cannot take the result as a steer, the result enters the queue. queuedRunsInDeliveryOrder typically puts the earlier user message first. The idle-thread exception for new results in dispatchMessage does not apply to a result already in the queue.

Example: While a parent turn that cannot accept a steer is running, queue a follow-up and open it for editing. Let a subagent result queue behind that message, then let the parent turn finish. The result waits for the unrelated edit instead of reaching the parent.

Recommended fix: When the next user message is paused for editing, consider eligible delegated completions already in the queue. Preserve the general queue pause and failure checks, and test a completion that queues before the parent becomes idle.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Note

🤖 Claude Opus 5.5 responding on behalf of jagrat7

Fixed in 1172481. nextQueuedRun moved to QueuedRunOrder.ts. When the head is being edited, it now starts the first subagent result in the queue that no Stop or failure holds, so results queued after the edited message still reach the parent. Failure checks still apply to whatever starts. A unit test in QueuedRunOrder.test.ts covers both a user message, which waits, and a subagent result, which passes.

)
-- Titles and edit-hold timers wait only on their own kind: a timer due in
-- minutes would otherwise hold back the thread's turns until it fires.
AND ${effectLane("candidate")} = ${effectLane("active")}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔍 Earlier edit expiry can wait

editHoldExpiryEffect can append a renewed timer due before an existing timer for another message on the same thread. The lane orders pending timers by insertion, so the earlier deadline waits for the later one.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Note

🤖 Claude Opus 5.5 responding on behalf of jagrat7

Not changing this. It needs two different messages on one thread to be held at the same time (two devices, two messages), and the cost is only a late expiry, bounded by the other hold's deadline. Giving each run its own lane would put a JSON read into every outbox claim, which is a hot path.

Comment on lines +132 to +133
renew: setInterval(() => hold(true), QUEUED_RUN_EDIT_HOLD_RENEW_MS),
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔍 Pending renewal can rehold saved edits

startHold can queue a renewal behind an in-flight save on the shared thread command scheduler. Clearing the interval cannot cancel that renewal, which can reapply the hold while the saved message is still queued.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Note

🤖 Claude Opus 5.5 responding on behalf of jagrat7

Fixed in 3579040. Renewals pause while a save is in flight and resume, with an immediate hold, if the save fails. So no renewal can run after a successful save. The store test now checks that no renewals go out during a save and that one goes out after a failed save.

Comment on lines +918 to +921
yield* TestClock.adjust("3 minutes");
yield* holdForEdit(threadId, 1, `${threadId}:renew`, true);
yield* TestClock.adjust("2 minutes");
yield* fireDueHoldTimer;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔍 Renewal test misses the live deadline

fireDueHoldTimer first runs when both deadlines are due, and the test renews only after the original deadline. Draining one effect cannot show that a renewal made before expiry keeps the queue paused at that deadline.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Note

🤖 Claude Opus 5.5 responding on behalf of jagrat7

Fixed in 1172481. When the hold went from 5 minutes to 2, the test's 3-minute renewal ended up after the first deadline. The test now steps in halves of QUEUED_RUN_EDIT_HOLD_MS: it renews halfway, fires the first timer at the original deadline (the message is still held), then lets the renewed hold expire or releases it.

Comment on lines +200 to +202
(held) => {
void holdQueuedRun({ ...target, input: { threadId: target.threadId, runId, held } });
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔍 Real-client edit lifecycle remains unverified

The ThreadQueueSheet closes immediately after opening an edit. The PR lists no real-client pass or base/head scenario proof, both required by verification guidance.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Note

🤖 Claude Opus 5.5 responding on behalf of jagrat7

Agreed that a real-client pass is still owed; the PR description says so. The maintainer is checking it by hand in a dev build. The sheet closing after Edit is existing behavior: navigation.goBack() after beginQueuedRunEdit was already there, and the edit continues in the thread composer.

…aved command's place

Starts that an edit triggers check the latest turn for a failure, as the
run-end handler would, so a save that beats that handler cannot start
queued work after a failed turn. Subagent results pass a message that is
being edited. Saving a deferred steer as a slash command no longer
restores its steer target in a second run update.
A renewal sent while a save is in flight runs after it and would hold the
saved message again.
…ady make

Starts that an edit triggers check the latest turn for a failure, so the
queue no longer needs to read past an edit hold at turn end to apply it.
Also drops comments that restated the code.
…very

A renewal writes only once less than half the hold remains, so clients get
one run update a minute instead of two. Taking a hold no longer tries to
start the queue, and a timer that finds its hold renewed skips the
post-commit work. Hold commands read only their run. Steers that waited
for an edit go through the same promotion as other deferred steers, and a
replayed command now delivers them too.
The hold, its renewal, and the watch always started and stopped together,
so they now live in one record.
@github-actions github-actions Bot added size:XL and removed size:L labels Nov 23, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Queued message sends its original text while being edited

1 participant