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

Skip to content

feat: remove chat chain mode - #26980

Merged
johnstcn merged 8 commits into
mainfrom
cian/codagt-445-remove-chain-mode-entirely
Jul 6, 2026
Merged

feat: remove chat chain mode#26980
johnstcn merged 8 commits into
mainfrom
cian/codagt-445-remove-chain-mode-entirely

Conversation

@johnstcn

@johnstcn johnstcn commented Jul 3, 2026

Copy link
Copy Markdown
Member

Removes OpenAI Responses "chain mode" from chatd. Chain mode sent previous_response_id on follow-up turns instead of replaying full history, saving input tokens on long chats. Referencing stored responses was not observed to work consistently: the provider would periodically report a stored response ID as unknown (most likely pruned after a retention period; zero-data-retention orgs and API key rotation are other suspects), and each new provider error format broke the chain-broken classifier that drove recovery. Every turn now replays full input, accepting larger requests on long chats in exchange for a recovery-free path.

Closes CODAGT-445.

Changes

  • Delete chatopenai/responses.go (chain detection, activation, prompt filtering, response ID extraction) and its tests.
  • Delete the ChainBroken classification in chaterror and the chatloop retry bookkeeping that disabled chain mode mid-generation.
  • Drop the chain_broken label from the coderd_chatd_stream_retries_total metric.
  • Stop reading and writing chat_messages.provider_response_id; delete the dead ClearChatMessageProviderResponseIDsByChatID query. The column stays on disk for rollback safety; dropping it is a follow-up migration.
  • Delete three chatloop hooks no caller sets (ReloadMessages, DisableChainMode, PrepareMessages), the dead AgentChatContextSentinelPath constant, and stale chain-mode comments.

Not touched: the aibridge provider_response_id columns (unrelated feature), the Store provider option, which now only controls provider-side response retention (whether to keep it at all is a follow-up), and the go.mod fantasy fork (carries 13 other changes; only its replay-safety item related to chain mode, and that logic still protects full replay).

Follow-ups

  • Migration to drop chat_messages.provider_response_id after a release cycle: CODAGT-748.
  • Product decision on keeping the Store option now that it has no in-product consumer.
  • Optional: simplify reference-replay logic in coder/fantasy now that no consumer sends previous_response_id.
Implementation plan

Executed in three phases on this branch:

  1. Red (test(coderd/x/chatd): drop chain mode test coverage): deleted chain-mode tests: chatopenai/responses_test.go, six TestActiveServer_ChainBroken* tests, TestClassify_ChainBroken*, TestAdvisorChainMode_SnapshotKeepsFullHistory, TestOpenAIResponsesChainMode*. chatd_chainmode_test.go was renamed to chatd_helpers_test.go because it housed shared helpers used by ~20 other test sites.
  2. Green (feat(coderd/x/chatd): remove chain mode): deleted chatopenai/responses.go entirely; the chain activation block in generation_preparer.go; ChainModeDisabled plumbing and the chain_broken log field in generation.go; ChainBroken and chainBrokenClassification in chaterror; the chain_broken metric label; PersistedStep.ProviderResponseID in chatloop; the PreviousResponseID reset in chatadvisor (Store=false behavior kept); ProviderResponseID from internal step structs, chatstate params, and the CreateChatMessages INSERT; the dead ClearChatMessageProviderResponseIDsByChatID query with its dbauthz wrapper; regenerated DB and metrics artifacts via make gen.
  3. Refactor (chore(coderd/x/chatd): drop dead ReloadMessages hook and stale chain comments): removed the orphaned ReloadMessages chatloop hook and reworded three stale chain-mode comments.

Deliberately skipped: shrinking the RecordStreamRetry signature (the ClassifiedError param enforces that callers classify errors via chaterror.Classify before recording), merging the chatadvisor clone/reset helpers (the clone is required for correctness: the reset mutates the options map in place), and any change to generation_preparer.go's promptRows fetch (verified still multi-purpose).

Verification: make build, make gen (no diff on re-run), make fmt, make lint, and go test ./coderd/x/chatd/... ./coderd/database/dbauthz/... all pass locally with postgres.


🤖 Generated by Coder Agents on behalf of @johnstcn.

@linear-code

linear-code Bot commented Jul 3, 2026

Copy link
Copy Markdown

CODAGT-445

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Docs preview

📖 View docs preview for docs/admin/integrations/prometheus.md

@johnstcn johnstcn changed the title feat(coderd/x/chatd): remove chain mode feat: remove chat chain mode Jul 3, 2026
@johnstcn

johnstcn commented Jul 3, 2026

Copy link
Copy Markdown
Member Author

/coder-agents-review

@coder-agents-review

coder-agents-review Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Chat: Review posted | View chat
Requested: 2026-07-03 16:49 UTC by @johnstcn
Spend: $38.96 / $100.00

Review history
  • R1 (2026-07-03): 15 reviewers, 2 Nit, 3 Note, 2 P3, COMMENT. Review

deep-review v0.9.0 | Round 1 | 121107f..e38f363

Last posted: Round 1, 7 findings (2 P3, 2 Nit, 3 Note), COMMENT. Review

Finding inventory

Findings

# Sev Status Location Summary Round Reviewer Posted
CRF-1 Nit Open chatd_helpers_test.go:161 Stale hardcoded chat title "chain mode test" in general-purpose helper R1 Netero, Chopper Yes
CRF-2 P3 Open chatd_test.go:12495 Doc comment first line truncated during adjacent test deletion R1 Hisoka Yes
CRF-3 P3 Open chatd.go:3787 buildSystemPrompt comment says "initial prompt assembly" but runs every turn R1 Razor Nit, Gon P2 Yes
CRF-4 Nit Open chatd_test.go:5899 require.True(strings.Contains) should be require.Contains for diagnostics R1 Leorio Yes
CRF-5 Note Open PR description Orphaned column has no drop-migration ticket R1 Knuckle Yes
CRF-6 Note Open chatloop/metrics.go:111 chain_broken label removal is metric contract change for operators R1 Chopper Yes
CRF-7 Note Open chatadvisor/runtime.go:64 Comment verbosity pattern: several rewritten comments lead with mechanism the code already shows R1 Gon P2 Yes
CRF-8 Nit Dropped by orchestrator (file comment on test helper is Go convention; filename is self-documenting) chatd_helpers_test.go:3 File comment restates filename R1 Gon No
CRF-9 P2 Dropped by orchestrator (comment is accurate per Leorio; verbosity covered by CRF-7 pattern note) chatadvisor/runtime.go:93 resetProviderOptionsForNestedCall doc opens with mechanism narration R1 Gon No
CRF-10 P2 Dropped by orchestrator (comment explains why, not just what; subsumed by CRF-7) chatadvisor/runner.go:46 Inline comment restates function calls below R1 Gon No
CRF-11 P2 Dropped by orchestrator (comment is accurate per Leorio; verbosity covered by CRF-7) context_prompt.go:20 AgentChatContextSentinelPath doc carries redundant phrasing R1 Gon No
CRF-12 P2 Dropped by orchestrator (comment is accurate per Leorio; verbosity covered by CRF-7) chatloop/chatloop.go:65 PersistedStep doc enumerates content types visible from type constraint R1 Gon No

Contested and acknowledged

(none)

Round log

Round 1

Panel (15 reviewers). 0 P0, 0 P1, 0 P2, 2 P3, 2 Nit, 3 Note posted. 5 dropped (comment verbosity subsumed by pattern note). Reviewed against 121107f..e38f363.

About deep-review

CRF = Coder Review Finding (P0-P4, Nit, Note)

Reviewer Focus
Bisky tests
Chopper ops/errors
Churn-guard change verification
Ging language modernization
Gon naming
Hisoka edge cases
Killua perf
Kite change integrity
Knov contracts
Knuckle SQL
Komugi flake/determinism
Kurapika security
Law decomposition
Leorio docs
Luffy product
Mafu-san process
Mafuuu contracts
Melody dispatch/pairing
Meruem structural
Nami frontend
Netero mechanical checks
Pariston premise testing
Pen-botter product gaps
Razor verification
Robin duplication
Ryosuke Go arch
Takumi concurrency
Zoro shape

🤖 Managed by Coder Agents.

coder-agents-review[bot]

This comment was marked as resolved.

@johnstcn

johnstcn commented Jul 6, 2026

Copy link
Copy Markdown
Member Author

Smoke-tested in workspace.

@johnstcn
johnstcn marked this pull request as ready for review July 6, 2026 09:15
Copilot AI review requested due to automatic review settings July 6, 2026 09:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Removes OpenAI Responses “chain mode” from chatd so every follow-up turn replays full history rather than relying on previous_response_id, simplifying retry and error-classification logic and avoiding provider chain-state loss edge cases.

Changes:

  • Deletes chain-mode activation/detection code and related tests, plus chain-broken classification and retry bookkeeping.
  • Removes chain_broken metric label and stops persisting chat_messages.provider_response_id (column retained for rollback).
  • Cleans up dead chatloop hooks and stale chain-mode comments, regenerating DB/metrics artifacts accordingly.

Reviewed changes

Copilot reviewed 34 out of 37 changed files in this pull request and generated no comments.

Show a summary per file
File Description
scripts/metricsdocgen/generated_metrics Updates generated metric label set for coderd_chatd_stream_retries_total.
docs/admin/integrations/prometheus.md Updates Prometheus docs for removed chain_broken label.
coderd/x/chatd/message_conversion.go Stops mapping step ProviderResponseID into DB message conversion.
coderd/x/chatd/message_conversion_test.go Updates tests to remove ProviderResponseID expectations and rename test.
coderd/x/chatd/integration_responses_test.go Removes chain-mode-specific integration tests and request recorder fields.
coderd/x/chatd/generation.go Removes chain-mode-disabled retry state and chain_broken logging; drops ProviderResponseID propagation.
coderd/x/chatd/generation_preparer.go Removes chain-mode activation and prompt filtering in generation preparation.
coderd/x/chatd/context_prompt.go Updates sentinel-path comment now that chain-mode tests are gone.
coderd/x/chatd/chattest/openai.go Removes previous_response_id decoding from OpenAI test request struct.
coderd/x/chatd/chatstate/messages.go Removes ProviderResponseID from chatstate insert parameter assembly.
coderd/x/chatd/chatopenai/responses.go Deletes chain-mode implementation for OpenAI Responses.
coderd/x/chatd/chatopenai/responses_test.go Deletes chain-mode unit tests for OpenAI Responses.
coderd/x/chatd/chatloop/metrics.go Removes chain_broken label and related formatting in stream retry metric.
coderd/x/chatd/chatloop/metrics_test.go Updates metric tests for new label set and removes chain-broken case.
coderd/x/chatd/chatloop/chatloop.go Removes persisted ProviderResponseID capture and deletes unused RunOptions hooks (PrepareMessages, DisableChainMode, ReloadMessages).
coderd/x/chatd/chaterror/classify.go Removes chain-broken classification and the ChainBroken field from ClassifiedError.
coderd/x/chatd/chaterror/classify_test.go Deletes tests covering chain-broken classification propagation.
coderd/x/chatd/chatdebug/service_test.go Removes ProviderResponseID field seeding in debug service tests.
coderd/x/chatd/chatd.go Stops writing ProviderResponseID on chat message insert params; updates related comments and structs.
coderd/x/chatd/chatd_test.go Removes chain-mode-dependent assertions and switches to full-replay expectations.
coderd/x/chatd/chatd_retry_test.go Updates retry logging/metric assertions to remove chain_broken.
coderd/x/chatd/chatd_helpers_test.go Introduces shared active-server test helpers previously housed in chain-mode test file.
coderd/x/chatd/chatd_chainmode_test.go Deletes chain-mode active-server tests.
coderd/x/chatd/chatadvisor/runtime.go Updates provider-options cloning/reset comments and removes PreviousResponseID reset logic.
coderd/x/chatd/chatadvisor/runner.go Updates advisor runner comment to match new provider-options reset behavior.
coderd/x/chatd/chatadvisor/runner_test.go Updates advisor tests to validate Store isolation instead of PreviousResponseID behavior.
coderd/x/chatd/attempt.go Removes ProviderResponseID from step durable data struct.
coderd/database/queries/chats.sql Removes provider_response_id from CreateChatMessages insert and deletes the clear query.
coderd/database/queries.sql.go Regenerates sqlc output reflecting removed insert arg and deleted clear query.
coderd/database/querier.go Removes the clear query from the querier interface.
coderd/database/querier_test.go Updates tests to use new InsertChatMessages params without ProviderResponseID.
coderd/database/dbmock/dbmock.go Regenerates mocks to remove ClearChatMessageProviderResponseIDsByChatID.
coderd/database/dbmetrics/querymetrics.go Removes query-metrics wrapper for the deleted clear query.
coderd/database/dbgen/dbgen.go Stops passing ProviderResponseID into message inserts when seeding chat messages.
coderd/database/dbgen/dbgen_test.go Updates generator test to remove ProviderResponseID assertions.
coderd/database/dbauthz/dbauthz.go Removes dbauthz wrapper for the deleted clear query.
coderd/database/dbauthz/dbauthz_test.go Removes authz method test coverage for the deleted clear query.
Files not reviewed (3)
  • coderd/database/dbmetrics/querymetrics.go: Generated file
  • coderd/database/dbmock/dbmock.go: Generated file
  • coderd/database/querier.go: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@johnstcn
johnstcn requested review from ibetitsmike and mafredri July 6, 2026 09:56
mafredri

This comment was marked as resolved.

@johnstcn
johnstcn merged commit b21e071 into main Jul 6, 2026
40 of 41 checks passed
@johnstcn
johnstcn deleted the cian/codagt-445-remove-chain-mode-entirely branch July 6, 2026 10:57
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 6, 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.

4 participants