feat: tag chat-originating agent logs with chat_id#25019
Open
ethanndickson wants to merge 4 commits intomainfrom
Open
feat: tag chat-originating agent logs with chat_id#25019ethanndickson wants to merge 4 commits intomainfrom
ethanndickson wants to merge 4 commits intomainfrom
Conversation
Adds an agentchat package that propagates Coder-Chat-Id and Coder-Ancestor-Chat-Ids from chatd-originated requests through the agent's HTTP middleware and into structured handler/background logs. - New agent/agentchat package with ExtractContext, FromContext, WithContext, Fields, and Middleware. Middleware enriches the loggermw access log and stores the chat identity on ctx. - agent/api.go installs agentchat.Middleware after loggermw.Logger. - Handler and background logs in agentfiles, agentproc, agentgit, agentdesktop, and agentmcp derive a per-request slog.Logger via api.logger.With(agentchat.Fields(ctx)...) so emitted lines carry chat_id and ancestor_chat_ids. - agentproc.process stores a chat-tagged logger on the process struct so post-cmd.Wait goroutines retain chat identity. - chatd's getWorkspaceConn emits a Debug bridge log when chat headers are attached to the agent connection, easing diagnosis of cases where a chat-driven action lacks chat_id on the agent side. Existing chatheaders parser moved from agentgit to agentchat under the new name (ExtractContext) since the helper is now used by multiple agent subsystems unrelated to git.
Use the chat context populated by agentchat.Middleware in file and process handlers instead of reparsing chat headers in each handler. This lets the header parser become package-private and keeps chat identity parsing centralized in middleware. Also documents that agentchat.Middleware must run after loggermw.Logger for access-log enrichment and avoids allocating an empty ancestor slice when no ancestors are present.
Restore the straightforward make/copy in agentchat.WithContext instead of branching on empty slices. Update test expectations for middleware-normalized empty ancestors accordingly while preserving order-sensitive equality for non-empty ancestor lists.
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
johnstcn
approved these changes
May 7, 2026
Comment on lines
+65
to
+67
| if requestLogger := loggermw.RequestLoggerFromContext(r.Context()); requestLogger != nil { | ||
| requestLogger.WithFields(fields...) | ||
| } |
Member
There was a problem hiding this comment.
I've seen some other middlewares panic if they're missing other middlewares upon which they depend. I'm not sure that logging is something worth panicking over though... dealer's choice here. Just flagging this as a potential future foot-gun if someone forgets the logger middleware before adding this on another route.
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Workspace-agent logs emitted while serving chatd-driven requests were not correlated with the originating chat, making agent logs hard to attribute to the corresponding/originating chat.
This adds agent-side chat context middleware that parses
Coder-Chat-Idonce, enriches agent access logs and structured handler/background logs, and adds a chatd bridge log when chat headers are attached to an agent connection.Closes CODAGT-324