Repository navigation
feat(coderd/x/chatd): open a chat_turn span per prompt - #28972
Closed
jscottmiller wants to merge 1 commit into
Closed
jscottmiller wants to merge 1 commit into
jscottmiller wants to merge 1 commit into
Conversation
This was referenced Sep 4, 2026
jscottmiller
force-pushed
the
scott/chatd-stages/5-turn-span
branch
from
September 9, 2026 23:19
02c8b6d to
a2ad5b2
Compare
jscottmiller
force-pushed
the
scott/chatd-stages/5-turn-span
branch
from
September 11, 2026 02:26
a2ad5b2 to
3363b52
Compare
jscottmiller
force-pushed
the
scott/chatd-stages/5-turn-span
branch
from
September 11, 2026 19:17
3363b52 to
926fabc
Compare
jscottmiller
force-pushed
the
scott/chatd-stages/5-turn-span
branch
from
September 14, 2026 20:16
926fabc to
8b43bfd
Compare
jscottmiller
force-pushed
the
scott/chatd-stages/5-turn-span
branch
from
September 14, 2026 22:06
8b43bfd to
bf128ab
Compare
jscottmiller
force-pushed
the
scott/chatd-stages/5-turn-span
branch
from
September 15, 2026 21:39
bf128ab to
5f5ba82
Compare
jscottmiller
force-pushed
the
scott/chatd-stages/5-turn-span
branch
from
September 16, 2026 03:12
5f5ba82 to
58caa7a
Compare
jscottmiller
force-pushed
the
scott/chatd-stages/5-turn-span
branch
from
September 17, 2026 16:55
58caa7a to
5660227
Compare
jscottmiller
force-pushed
the
scott/chatd-stages/5-turn-span
branch
2 times, most recently
from
September 17, 2026 21:26
1407ab3 to
fa51203
Compare
jscottmiller
force-pushed
the
scott/chatd-stages/5-turn-span
branch
from
September 21, 2026 00:09
fa51203 to
5586c22
Compare
jscottmiller
force-pushed
the
scott/chatd-stages/5-turn-span
branch
from
September 21, 2026 22:52
5586c22 to
6e676b0
Compare
jscottmiller
force-pushed
the
scott/chatd-stages/5-turn-span
branch
from
September 23, 2026 01:37
6e676b0 to
e1e09ff
Compare
The runner owns a runnerTurnSpan that opens a chat_turn root span on the first generation task of a prompt, anchored at the trigger message, and hands every task a turn token so a task that outlives its turn cannot finish the turn that replaced it. A turn closes in two steps: the finishing transition calls Complete from inside the step, and Settle closes the span after the step's stage has ended, opening the next turn from a promoted queued message when there is one. The generation step, prepare, mcp_connect, commit, compaction, thinking, tool_call, retry_backoff, acquisition, and queue_wait stages hang off the turn, and inflight work is detached from it as background scope.
jscottmiller
force-pushed
the
scott/chatd-stages/5-turn-span
branch
from
September 23, 2026 02:15
e1e09ff to
c39b2af
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Superseded by #29771. Closed in favor of the reduced stack #29773.
Each prompt runs inside a
chat_turnroot span owned by the runner (runnerTurnSpan); the generation step, prepare, MCP connect, commit, thinking, tool call, compaction, retry backoff, and queue wait stages are parented under it, andStages/StageModelare passed toGenerateAssistant, activating the PR 3 stages.chat_turnspans are standalone roots: the turn runs on a worker, often on another replica, and no trace context is persisted.Anchoring: the span starts at the event that triggered the turn, the later of the last user prompt and a pending compaction request, so the reconstructed
acquisitionstage falls inside the turn and a/compactturn does not claim idle time. Anchors are monotonic per runner; an older trigger is clamped to the previous anchor and counted asstage_anomalies_total{reason="stale_anchor"}.Lifecycle:
Ensureopens the span on the first generation task and returns aturnToken; token-taking methods no-op once the turn has been replaced. The nextEnsurecloses an invalidated turn first, so an interrupted turn cannot absorb the prompt promoted after it.Invalidate(token, outcome, err)records how the turn stopped:interrupted(task context done),abandoned(expected exit such as a fence mismatch),errorotherwise. Retryable task errors do not invalidate. The span ends with the error and carriesturn_outcome; a turn still open at runner teardown isabandoned.Completemarks the turn finished from inside the last step;Settlecloses the span after that step's stage ends. When the finishing transition promotes a queued message,Settleopens the next turn anchored at the queue time (FinishTurnResult.PromotedQueuedAt) and records itsqueue_wait.Server.PromoteQueuedrecords a standalonequeue_waitfor API-driven promotions.Ensureresolves the chat's organization name (Server.organizationName, one lookup per organization, cached for the server's life) and puts it on the turn context with the chat kind. It is a span attribute on every stage span, not a metric label.StageModelwhen configured, else the chat model's.generation_stepno longer carriesgeneration_attempt; the attempt is only known oncommitandprovider_attempt.inflightContext) strips the span context and runs inbackgroundscope, so title, summary, and status label generation are their own trace roots. Summary and status label generation carry the chat kind; title generation runs without a chat and carries none.ARCHITECTURE.md gains a "Lifecycle tracing" section.
🤖 This PR was generated by Coder Agents on behalf of @jscottmiller.