Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: allow manual chat compaction from the error state - #28022

Merged
ibetitsmike merged 7 commits into
mainfrom
mike/chatd-compact-from-error
Aug 12, 2026
Merged

fix: allow manual chat compaction from the error state#28022
ibetitsmike merged 7 commits into
mainfrom
mike/chatd-compact-from-error

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

A chat that fails generation with a context overflow (for example Input length 262625 exceeds the maximum allowed input length of 262112 tokens) is stuck in a catch-22: POST /chats/{id}/compact returns 409 because the RequestCompaction transition is only allowed from the waiting state, and the only other way out of the error state is sending or editing a message, which re-runs generation with the same oversized prompt and fails again. Compaction is exactly the recovery a context-overflowed chat needs, and it is unreachable exactly when it is needed.

Three semantic changes:

  • Allow RequestCompaction from the error states: E0 -> R0 and E1 -> R1 (queued messages are preserved and processed after the compaction turn).
  • Clear last_error in Tx.RequestCompaction, matching the architecture rule that transitions leaving E0/E1 clear the stored error. Without this a successful compaction would land in waiting with a stale persisted error.
  • Grant the compaction turn a fresh history epoch: a grant_history_epoch flag on UpdateChatExecutionState sets history_version = snapshot_version, resets generation_attempt, and clears retry_state in the same atomic update that clears last_error (mirroring the chat_messages trigger postcondition). The transition inserts no history, so without this the turn inherits the failed turn's spent retry budget, and resetting the counter alone could collide with message part episode keys still retained on the erroring replica.

No frontend change is required: the chat input is already enabled in the error state and /compact submission already handles both the success and 409 paths. Also updates ARCHITECTURE.md (transition matrix, endpoint, and manual compaction sections), the endpoint's swagger description, and SDK comments.

Mux created this PR on Mike's behalf.

A chat that errors on context overflow is stuck: compaction is
rejected outside the waiting state, and sending a new message re-runs
the same oversized prompt. Allow RequestCompaction from E0/E1 and
clear last_error on the request so /compact becomes the recovery
path.
@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.

@ibetitsmike
ibetitsmike marked this pull request as ready for review August 11, 2026 13:48

@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: 0d340c6361

ℹ️ 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 coderd/x/chatd/chatstate/transition.go
@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: 0d340c6361

ℹ️ 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 coderd/x/chatd/chatstate/transitions.go
A chat that errored after exhausting retryable provider failures keeps
generation_attempt at the cap; RequestCompaction inserts no history,
so the history-change trigger never resets it and the recovery
compaction would inherit the spent retry budget.
@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: fc7d9cb7ef

ℹ️ 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 coderd/x/chatd/chatstate/transitions.go Outdated
Rewinding generation_attempt while sub-cap can reuse message part
buffer episode keys (chat, history_version, attempt) still inside the
15s closed-episode retention window on the erroring replica. Sub-cap
counters continue forward instead; at exhaustion the rewind is
collision-free because backoff spacing expires the earliest episodes
long before the budget runs out.
@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: 705213cf25

ℹ️ 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 coderd/x/chatd/chatstate/transitions.go Outdated
RequestCompaction inserts no history, so the chat_messages triggers
never granted the compaction turn a fresh retry budget. Conditionally
resetting generation_attempt left a boundary at MaxAttempts-1 where
the recovery turn inherited a spent budget, and rewinding the counter
alone could collide with message part episode keys retained on the
erroring replica. Advancing history_version to the transaction's new
snapshot_version, exactly what a history change does, gives the turn
a full budget and collision-free episode keys unconditionally.
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: bf67afa93e

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

…utionState

A standalone AdvanceChatHistoryVersion query exposed a general store
method that can move history_version without any history change. Make
the epoch grant an option on the execution-state update instead, so it
rides the same atomic UPDATE that clears last_error and sets the
compaction marker, and only RequestCompaction can reach it.
At attempt 0 the sync_chat_retry_state trigger cannot clear a stale
retry payload because generation_attempt does not change, so only the
explicit clear in the epoch grant covers it.
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: c8ecce9ead

ℹ️ 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
ibetitsmike merged commit 1458d27 into main Aug 12, 2026
55 of 57 checks passed
@ibetitsmike
ibetitsmike deleted the mike/chatd-compact-from-error branch August 12, 2026 18:39
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants