Skip to content

refactor(coderd): contain the live chat stream in a Session module - #28755

Open
ibetitsmike wants to merge 2 commits into
mainfrom
mike/chatd-stream-session
Open

refactor(coderd): contain the live chat stream in a Session module#28755
ibetitsmike wants to merge 2 commits into
mainfrom
mike/chatd-stream-session

Conversation

@ibetitsmike

Copy link
Copy Markdown
Collaborator

Contains the live chat stream's orchestration in a self-contained Session module. The pubsub subscription, select loop, sync retry/backoff, sync poller registration, parts relay dialing and forwarding, and episode re-selection previously spanned eight stream_*.go files (about 1,680 lines) as unexported Server methods with no direct tests; races and reconnect bugs were only reachable through full WebSocket e2e tests.

Changes

  • coderd/x/chatd/stream_session.go: NewSession(cfg) plus InitialSnapshot(), Events(), and Close(). Orchestration becomes hidden implementation behind that seam.
  • The chat watch WebSocket handler in coderd/exp_chats.go constructs a Session from Server.StreamSessionConfig and forwards events.
  • Direct unit tests drive the Session with in-memory pubsub and a dbmock store: subscribe/notify, reconnect and resubscribe, retry backoff, sync poller kicks, relay forwarding and episode re-selection, and Close teardown. Concurrency paths run with -race -count=3.
  • Fixes a latent sync poller race where unregistering during an in-flight poll could send on a closed channel.
  • Deletes the replaced stream_loop.go, stream_relay.go, stream_subscribe.go, stream_sync_poller.go, and their now-redundant internal tests; remaining repetitive cases are table-driven.
  • ARCHITECTURE.md gains TODO(human) markers only where documented structure moved.

Net diff: 13 files, +1,494 / -1,601 (net -107 across production and tests). Behavior preserving: event ordering, retry/backoff semantics, and error classification are unchanged.

Validation

make gen, make fmt, make lint, pre-commit hooks, go test ./coderd/x/chatd/..., go test -race -count=3 on the session tests, and the TestStreamChat e2e smoke all pass. Remote dogfood UAT passed: incremental convergence after mid-stream refresh, interrupt, two-tab consistency, subagent child streams, and idle snapshot reopening, with zero duplicated or missing parts at the protocol level. A silent-then-burst delivery pattern observed during UAT was A/B tested against the parent commit and reproduces identically on main, so it is pre-existing environmental behavior, not owned by this change.

Disclosure: Xum (an AI coding agent) authored this PR on behalf of @ibetitsmike.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 29, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-08-29T11:32:25.230336Z 922858e Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 922858e7ce

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant