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

Skip to content

feat(coderd/x/chatd): open a chat_turn span per prompt - #28972

Draft
jscottmiller wants to merge 1 commit into
scott/chatd-stages/4-provider-attemptsfrom
scott/chatd-stages/5-turn-span
Draft

feat(coderd/x/chatd): open a chat_turn span per prompt#28972
jscottmiller wants to merge 1 commit into
scott/chatd-stages/4-provider-attemptsfrom
scott/chatd-stages/5-turn-span

Conversation

@jscottmiller

@jscottmiller jscottmiller commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Each chat prompt runs inside a chat_turn root span owned by the runner (runnerTurnSpan), with the generation step, prepare, MCP connect, commit, thinking, tool call, compaction, retry backoff, and queue wait stages parented under it. The span is anchored at the trigger message's creation time so the reconstructed acquisition stage falls inside the turn.

Turn lifecycle:

  • Ensure opens the span on the first generation task and returns a turnToken. Methods that take a token no-op when the turn has since been replaced, so a task that outlives its turn cannot finish the next one.
  • A turn closes in two steps. Complete marks it finished from inside the last generation step; Settle closes the span after that step's stage has ended, so the finishing step is inside the span.
  • When the finishing transition promotes a queued message, Settle opens the next turn anchored at the moment that message was queued and records its queue_wait against the new turn. FinishTurnResult.PromotedQueuedAt carries that timestamp out of the transition.
  • Detached background work (inflightContext) strips the span context and runs in the background scope, so title, summary, and status label generation start their own trace roots.

chat_turn spans are standalone roots: the turn executes on a worker, often on another replica, and no trace context is persisted. ARCHITECTURE.md gets TODO markers for the human author.


Part of the chatd lifecycle observability stack: 1 extract step · 2 stage tracer · 3 stream stages · 4 provider attempts · 5 turn span · 6 capacity wait · 7 turn accounting · 8 dashboard. Supersedes the experimental branch in #28741.

🤖 This PR was generated by Coder Agents on behalf of @jscottmiller.

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
jscottmiller force-pushed the scott/chatd-stages/4-provider-attempts branch from 8b252aa to 2653138 Compare September 11, 2026 19:17
@jscottmiller
jscottmiller force-pushed the scott/chatd-stages/5-turn-span branch from 3363b52 to 926fabc Compare September 11, 2026 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

experimental Changes that might not necessarily be merged, until its approved to proceed with.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant