Fixes
[CODAGT-737](https://linear.app/codercom/issue/CODAGT-737/compaction-can-treat-the-last-user-message-as-an-assistant-message)
## Problem
Auto-compaction can trigger on a turn whose last history message is a
fresh, unanswered **user** message. Two things go wrong:
1. The summary instruction is appended as another user message.
Providers that merge consecutive same-role messages (verified against
fantasy's Anthropic conversion) fuse it with the user's message, and the
summarizer misattributes the user's instruction as assistant intent.
2. After compaction the original user row falls outside the prompt
window, so the instruction survives only through summary fidelity.
## Fix
Carry unanswered trailing user messages through compaction verbatim
instead of summarizing them. All logic lives in `chatd`; `chatloop` is
unchanged apart from prompt wording.
- **Prepare** (`generation_preparer.go`): `pendingUserSegmentStart`
locates the trailing user rows on the persisted rows, before
provider-switch sanitization (which can drop the assistant row
separating them from an already-answered message). Head and tail are
converted separately so the summarizer input excludes the tail exactly.
Falls back to summarizing everything when no usable segment exists.
- **Commit** (`buildCompactionMessages`): replays the tail after the
boundary trio as uncompressed, model-only user rows. The existing prompt
window query includes them; no SQL, UI, or turn-guard changes. Replay
rows carry no usage, so compaction cannot immediately re-fire.
- **Prompt** (`chatloop/compaction.go`): the summary prefix no longer
claims the assistant "was actively working", which is false in this
case. The summarizer prompt is unchanged.
- `ARCHITECTURE.md` compaction section updated.
## Testing
`go test ./coderd/x/chatd/...` green. New:
`TestBuildCompactionMessages_ReplaysPendingUserMessages`,
`TestPendingUserSegmentStart`,
`TestPendingUserSegmentConversionEquivalence`,
`TestPendingUserSegmentDerivedBeforeProviderSwitchSanitization`,
`TestDecisionGeneratesAfterCompactionWithReplayedPendingUser`.
<details>
<summary>Root-cause repro</summary>
Replaying the reported scenario through fantasy's Anthropic provider
against a capture server:
```
=== fantasy prompt (roles as chatd builds them) ===
[2] role=user "You'll hit compaction now, we'll need to go through some fin..."
[3] role=user "You are performing a context compaction. Summarize the conve..."
=== wire request to Anthropic ===
[2] role=user, 2 content block(s)
block[0]: "You'll hit compaction now, we'll need to go through some final checks..."
block[1]: "You are performing a context compaction. Summarize the conversation so..."
```
</details>
---
🤖 This PR was generated by Coder Agents on behalf of @f0ssel.