Skip to content

fix: commit spawn-failure tool results and converge the promoted queue - #27498

Closed
ibetitsmike wants to merge 7 commits into
mike/chat-hooks/audiencefrom
mike/chat-hooks/followups
Closed

ibetitsmike wants to merge 7 commits into
mike/chat-hooks/audiencefrom
mike/chat-hooks/followups

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Jul 25, 2026 •

Copy link
Copy Markdown
Collaborator

Second of two follow-up PRs from review of the chat lifecycle hooks stack. Stacked on #27497.

Addresses three findings that were escalated rather than fixed in place, because fixing them inside the reviewed PRs would have restacked the whole stack and invalidated exact-head approvals.

Commit tool results when a spawn hook dispatch fails

When a user_prompt_submit hook refused a subagent spawn, executeLocalTools returned immediately. Sibling tools in the same batch had already run, but their results were discarded, so the model never saw them and the chat errored with no record of the work.

The turn now falls through to the normal commit path and passes the classified dispatch error as PostCommitError. commitGenerationStep already commits the step and finishes with the error atomically, so sibling results persist while the chat still parks in error.

Two details worth reviewing:

  • Spawn admission failure takes precedence when a post_tool_use dispatch also fails. Spawn admission is the causal root and preserves the expected last_error. The concurrent error is logged.
  • PostToolUseResults sweeps every non-provider result, which would have fired post_tool_use for a spawn that never ran. It now skips results carrying a dispatch failure, reusing the same per-result predicate as DispatchFailureFromResults. Siblings still dispatch.

GenerationDispatchError leaves Retryable false, so this does not introduce a retry loop.

Document that post_compact effects can resume generation

Documentation only, no behavior change. Manual compaction normally returns to waiting with no assistant follow-up, but a post_compact hook effect that commits a user-visible message leaves visible history incomplete and resumes generation. A model-only effect such as model_context does not, because it is filtered out of the query that the completeness check reads.

The existing manual compaction test ran with hooks disabled, so this interaction was uncovered. It is renamed to say so, and a new table-driven test pins both cases.

Converge the queue after a promoted send

After a promote, the client suppressed the promoted head locally, but only the server knows the resulting queue when another tab queued or promoted concurrently. The page now issues one uncursored getChatMessages request and applies the result through a single new store action.

Three traps this avoids, all found while designing it:

  • invalidateQueries would refetch every loaded page, because queued_messages rides on page 0 of the infinite query.
  • REST hydration is refused outright once a queue_update has arrived, so a cache-driven fix would be inert.
  • The existing stale-snapshot guard ignores any snapshot listing a promoted ID, which in this exact bug is the snapshot we need.

The store tracks a convergence fence that advances whenever an in-flight request goes stale: an accepted authoritative snapshot, or a change of active chat. The apply is dropped when the fence moved, which covers both a server update landing mid-request and navigation away from the chat, including an A to B to A round trip. The apply is additionally scoped to the originating chat by identity, since the fence is a token the caller captures and a late capture would otherwise carry another chat's queue into the shared store.

The store action returns the queue it actually applied, which the caller mirrors into the react-query cache. Returning the raw server response would have re-cached a row that an overlapping explicit promotion had suppressed.

Validation

  • make lint clean
  • go test ./coderd/x/chatd/... -race -count=1 green
  • Full AgentChatPage.stories.tsx suite (25 stories), AgentsPage unit suites, tsc, biome, knip, and React compiler lint all green
  • New tests for all three fixes were verified red before the fix and green after

Mux opened this PR on Mike's behalf.

…ails

A failed user_prompt_submit dispatch during subagent spawn admission
returned before the commit, discarding the whole step. A sibling tool in
the same batch had already run and mutated the workspace, so its result
was lost and the tool would be re-executed on retry.

The step now commits and the turn fails afterwards through the existing
PostCommitError path, which runs CommitStep and FinishError atomically.
Spawn admission takes precedence over a concurrent post_tool_use failure
because it is the causal root; the other error is logged. post_tool_use
no longer fires for a refused spawn result, since that tool never ran.
…eneration

The manual-compaction contract claimed the chat always returns to
waiting with no assistant follow-up. The generation decision reads
user-visible history, so a post_compact effect that commits a
user-visible message leaves the history incomplete and the turn
continues. A model-only effect reaches the model without resuming.

No behavior change. TestManualCompactionPostCompactEffects pins both
sides of the distinction, and the existing hooks-disabled manual
compaction test is scoped to that case.
A send that promotes the queue head suppresses that ID locally, but a
concurrent queue mutation in another tab can leave the row queued
server-side, so the transcript and the queue both showed it until the
next authoritative snapshot.

The page now issues one uncursored messages request after the promotion
and hands the result to the store, which clears the promotion markers
and applies the snapshot in a single transition. The store counts every
authoritative snapshot, including the stale ones it discards, so a
queue_update arriving during the fetch makes the refetch a no-op.
…ve chat

The queue store is shared across chats, so a promote convergence request
that resolves after the user navigates away applied the previous chat's
queue to the one now displayed. Pass the originating chat ID through to
applyPromoteRefetchQueuedMessages and drop the response when it no longer
matches the active chat.
@github-actions

Copy link
Copy Markdown
Contributor

Docs preview

Check off each page once it's been reviewed. If a page changes in a later push, its checkbox clears automatically so it gets a fresh look. Pages not yet wired into the docs navigation aren't listed here.

@coderagents

coderagents Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Documentation Check

Updates Needed

  • docs/admin/setup/chat-lifecycle-hooks.md - The post_compact resume behavior is documented only in coderd/x/chatd/ARCHITECTURE.md, which is internal. It is user-visible: a post_compact effect that commits a user-visible message (user_message) makes a manual /compact continue into an assistant response instead of returning to waiting, while a model-only model_context effect does not. Add this to the hook effects section (near the existing pre_compact model_context exception at the end of "Return a response"), so consumer authors know a post_compact user_message triggers an extra generation.

The other two changes need no docs:

  • Committing sibling tool results when a spawn user_prompt_submit dispatch fails is already covered by the updated "Plan failure recovery" paragraph in docs/admin/setup/chat-lifecycle-hooks.md.
  • The promoted-send queue convergence fix is an internal frontend bug fix with no user-facing surface change; docs/ai-coder/agents/architecture.md message queuing already describes the intended behavior.

Automated review via Coder Agents

@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: 5b31356291

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

…efetch

applyAuthoritativeQueuedMessages advanced the queue version before deciding
whether to discard a snapshot as stale, so a delayed queue_update naming a
promoted ID both failed to apply and invalidated the in-flight convergence
refetch. Any message another tab queued in that window stayed invisible
until the next update. Advance the version only when a snapshot is accepted.

Route the convergence request through react-query per FE7, using a dedicated
uncursored query so it gains request deduplication, retry, and error
handling without refetching every loaded infinite-scroll page.
@ibetitsmike

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: fda7c2f0c6

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

Return the queue the store actually applied, so the caller mirrors the
filtered result into its cache instead of the raw server snapshot. The
raw snapshot can still list a row suppressed by an overlapping explicit
promotion, which reappeared after navigating away and back.

Advance the convergence fence whenever the active chat changes, so a
request issued before an A to B to A round trip cannot apply to the
later visit.
@ibetitsmike

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: c20b97343b

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

… story

The convergence response matched the optimistic queued message, so the
assertions were already satisfied by the optimistic reconciliation and
stayed green with the settle fetch removed. Have the server also report
a message queued by another tab, which only the convergence fetch can
reveal.
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 607e178483

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

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

Closing: this change is now folded into the base PRs of the stack, so it no longer needs a separate PR.

The spawn-failure tool result commit moved into #27429, and the five frontend queue-convergence commits were squashed into a single commit in #27430.

Closed by Mux, an AI coding agent, on Mike's behalf.

@ibetitsmike
ibetitsmike deleted the mike/chat-hooks/followups branch July 27, 2026 11:12
@linear-code

linear-code Bot commented Jul 27, 2026

Copy link
Copy Markdown

CODAGT-868

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