Skip to content

refactor: move chat prompt sanitization into codersdk - #28283

Merged
bpmct merged 1 commit into
mainfrom
bpmct/export-sanitize-prompt-text
Aug 19, 2026
Merged

bpmct merged 1 commit into
mainfrom
bpmct/export-sanitize-prompt-text

Conversation

@bpmct

@bpmct bpmct commented Aug 18, 2026

Copy link
Copy Markdown
Member

Exports SanitizePromptText (and its helpers) from codersdk instead of coderd/x/chatd, so API consumers can sanitize prompt text exactly the way the server stores it.

Why

coder/terraform-provider-coderd#412 adds a coderd_chat_system_prompt resource whose system_prompt attribute compares values by their sanitized forms (otherwise the trailing newline from file("system-prompt.md") is perpetual drift, since the server stores the sanitized value). That currently requires a mirrored copy of the sanitizer in the provider, which can silently rot. Per review there (discussion), the sanitizer should be exported from codersdk and imported instead.

What

  • coderd/x/chatd/sanitize.go → codersdk/promptsanitize.go (pure move; package + doc-comment note about why it lives in codersdk)
  • coderd/x/chatd/sanitize_test.go → codersdk/promptsanitize_test.go
  • Callsites updated (exp_chats.go, chatd.go, subagent.go, context_prompt.go); no wrapper left behind, single source of truth
  • No behavior change

Generated by Coder Agents on behalf of @bpmct

Exports SanitizePromptText (with its helpers) from codersdk instead of
coderd/x/chatd so API consumers can sanitize prompt text exactly the
way the server stores it. terraform-provider-coderd needs this for the
coderd_chat_system_prompt resource, whose semantic equality must match
the server's sanitization to avoid false drift; until now it carried a
mirrored copy that could rot.

Pure move plus callsite updates: no behavior change, tests move along
with it.
@bpmct
bpmct requested a review from ethanndickson August 18, 2026 22:56
bpmct added a commit to coder/terraform-provider-coderd that referenced this pull request Aug 18, 2026
…ystem_prompt

Per review, the create-time overwrite advisory now also fires when the
first apply would change include_default_system_prompt away from the
deployment's live value, not just when it would overwrite a non-empty
prompt. Covered by a direct ModifyPlan table test in the
oauth2_provider_settings style.

Also leaves a TODO on the mirrored sanitizer pointing at
coder/coder#28283, which exports it as codersdk.SanitizePromptText;
once the pinned coder/coder includes that commit the local copy goes
away.
@bpmct
bpmct merged commit 8a7e8d9 into main Aug 19, 2026
90 of 95 checks passed
@bpmct
bpmct deleted the bpmct/export-sanitize-prompt-text branch August 19, 2026 13:51
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 19, 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