Skip to content

feat: add manual chat compaction via /compact#27081

Merged
ibetitsmike merged 6 commits into
mainfrom
mike/chat-manual-compact
Jul 21, 2026
Merged

feat: add manual chat compaction via /compact#27081
ibetitsmike merged 6 commits into
mainfrom
mike/chat-manual-compact

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Adds a user-triggered /compact action for Coder Agents chats: typing /compact in the composer (or picking it from the / trigger menu) summarizes the conversation so far to free up context window space.

How it works

  • New POST /api/experimental/chats/{chat}/compact endpoint (owner-only, RBAC ActionUpdate, excluded from the public API reference via x-apidocgen skip). It marks the chat with a durable one-shot chats.compaction_requested_at signal and moves it waiting -> running via a new RequestCompaction state transition; no message row is inserted. AI Gateway attribution needs no per-request key: generation preparation resolves the owner's synthetic API key (feat: add synthetic gateway keys #27170) like any other turn.
  • RequestCompaction hands off chat ownership (clears worker_id/runner_id) so a worker acquisition hint is published; since the transition changes no history, the previous runner could otherwise miss the request under reordered pubsub delivery.
  • The background chat worker picks the chat up like any other turn. A pending manual request takes precedence over turn completion in the generation decision, and forces compaction even below the automatic threshold (and when compaction is disabled via threshold=100). The commit step consumes the request marker in the same transaction; any transition that ends the turn clears stale markers.
  • The summary triplet reuses the automatic-compaction path, now tagged with a source (automatic | manual) that is plumbed through streamed progress parts, persisted tool JSON, and the UI label ("Summarized (manual)").
  • Validation order: busy chats reject with 409 (state-machine conflict), empty/already-compacted chats with 409 "nothing to compact", archived chats with 400; the owner usage-limit check runs last so no-op requests surface the specific conflict instead of a limit error.
  • Web UI: the / trigger menu now has a built-in "Commands" group listing /compact; submit intercepts exactly /compact and calls the endpoint instead of sending a message. A personal or workspace skill named compact takes precedence over the built-in command; while skill collisions are still resolving, an exact /compact submission is blocked with a retryable hint instead of leaking as message text. History and queued-message edits are never intercepted. After compaction, the context usage indicator resets to its unknown state until the next assistant response reports fresh usage, instead of showing the stale pre-compaction number.
  • codersdk: ExperimentalClient.CompactChat.

Worker-path execution (rather than compacting synchronously in the handler) reuses the existing lock fencing, live "Summarizing..." streaming, retry accounting, restart resilience, and debug-run observability. Rationale documented in coderd/x/chatd/ARCHITECTURE.md.

Testing

  • State machine: transition-matrix coverage for RequestCompaction, marker lifecycle tests (carried by lease renewals/queue appends, cleared by terminal transitions, consumed by commit), ownership handoff + acquisition hint assertions.
  • Worker: decision-ordering and forced-compaction unit tests; active-server end-to-end test (manual compact below threshold produces a source=manual summary, returns to waiting, no assistant follow-up; busy chat rejected).
  • API: success, archived, non-owner, RBAC-denied, empty-chat, no-daemon cases; usage-limit ordering (at-limit owners still get state/nothing-to-compact conflicts for no-op requests, with marker rollback).
  • Frontend: Storybook play tests for the Commands menu group, submit intercept, skill-name collision, queued-edit passthrough, and manual/automatic tool rendering; unit tests for command availability resolution and the post-compaction context usage reset.

This PR was created by Mux, an AI coding agent, working on Mike's behalf.

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Docs preview

📖 View docs preview for docs/admin/security/audit-logs.md

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

ℹ️ 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/exp_chats.go
Comment thread site/src/pages/AgentsPage/AgentChatPage.tsx Outdated
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: e559be4fe1

ℹ️ 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 force-pushed the mike/chat-manual-compact branch from e559be4 to 2bbc883 Compare July 16, 2026 18:08
@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: 2bbc8835c9

ℹ️ 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 force-pushed the mike/chat-manual-compact branch from 2bbc883 to a90f1df Compare July 18, 2026 21:18
@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: a90f1df9c5

ℹ️ 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 site/src/pages/AgentsPage/AgentChatPage.tsx Outdated
@ibetitsmike
ibetitsmike force-pushed the mike/chat-manual-compact branch from a90f1df to cf31511 Compare July 18, 2026 21:37
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: cf31511e63

ℹ️ 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 force-pushed the mike/chat-manual-compact branch from cf31511 to 0c6cb3e Compare July 18, 2026 21:53
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 0c6cb3ebef

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

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 14fe83a2ec

ℹ️ 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 force-pushed the mike/chat-manual-compact branch from 14fe83a to 7777503 Compare July 20, 2026 16:24
@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: 77775038f1

ℹ️ 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 site/src/pages/AgentsPage/AgentChatPage.tsx Outdated
Comment thread coderd/x/chatd/chatd.go Outdated
@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: 4940f451ec

ℹ️ 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
@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: 64bd129049

ℹ️ 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/exp_chats.go
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@coder-tasks

coder-tasks Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Documentation Check

Updates Needed

  • docs/reference/api/chats.md - Regenerate the API reference. coderd/apidoc/swagger.json now defines POST /api/experimental/chats/{chat}/compact ("Compact chat"), but the generated docs/reference/api/chats.md is missing this endpoint, so the spec and the published reference are out of sync. Earlier revisions of this PR included the generated section; it appears to have been dropped in a rebase/regen. Run the docs generation (make gen) to restore it.

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: 35a5a5d00c

ℹ️ 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 site/src/pages/AgentsPage/AgentChatPage.tsx
@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: a5c9450913

ℹ️ 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 force-pushed the mike/chat-manual-compact branch from a5c9450 to 574065d Compare July 20, 2026 18:26
@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: 574065dd2b

ℹ️ 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 force-pushed the mike/chat-manual-compact branch from 574065d to ef8f7c2 Compare July 21, 2026 08:44
@ibetitsmike
ibetitsmike merged commit 3227cac into main Jul 21, 2026
32 of 33 checks passed
@ibetitsmike
ibetitsmike deleted the mike/chat-manual-compact branch July 21, 2026 08:58
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 21, 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