fix: target specific chat in MarkStale instead of broadcasting to all workspace chats#23883
Conversation
… workspace chats When a git operation triggers external auth, the agent sends a chat_id identifying which chat initiated the operation. Two gaps caused every chat on the workspace to receive the git context: 1. CODER_CHAT_ID was never injected into process environments, so gitaskpass always sent an empty chat_id. 2. The server handler ignored the chat_id query param and MarkStale broadcast to all workspace chats via filterChatsByWorkspaceID. This commit: - Injects CODER_CHAT_ID into cmd.Env in agentproc so gitaskpass can read and forward it. - Reads chat_id from query params in workspaceAgentsExternalAuth and threads it through chatGitRef. - Refactors MarkStale to accept a MarkStaleParams struct. When ChatID is provided, targets only that chat; otherwise falls back to the existing workspace-wide broadcast.
|
🤖 Clean fix — the data flow is now complete end-to-end and the P2 Missing test for invalid When Validated: wrote P3 Targeted path skips workspace ownership check ( When Validated: wrote Mitigated by the data flow ( |
| Origin string | ||
| // ChatID, when non-empty, targets a single chat instead | ||
| // of broadcasting to every chat on the workspace. | ||
| ChatID string |
There was a problem hiding this comment.
meat cian says: why not make this a uuid.UUID
|
Thanks for the thorough review! P2 — invalid ChatID fallback: Added P3 — workspace ownership check on targeted path: Agree this is low risk given |
@kylecarbs a comment is probs fine here |
|
Added a comment on the targeted path in 9111576 documenting the workspace ownership skip and why it's safe. |
johnstcn
left a comment
There was a problem hiding this comment.
Approved in advance, pending comment regarding making ChatID in MarkStaleParams a uuid.UUID
Parse chat_id at the handler boundary instead of inside MarkStale. Removes the string-parsing fallback path — invalid values are silently ignored at parse time.
|
Changed |
Problem
Subagent chats were receiving git context (branch, remote origin, PR
status) from their parent or sibling chats' git operations. When a git
operation triggers external auth, the workspace agent sends
chat_ididentifying which chat initiated it — but this was broken at two levels:
Agent side:
CODER_CHAT_IDwas never injected into processenvironments.
chatdsetsCoder-Chat-IdHTTP headers and theagent extracts them for process isolation, but never propagated
CODER_CHAT_IDtocmd.Env. Sogitaskpassalways sent an emptychat_id.Server side:
workspaceAgentsExternalAuthignored thechat_idquery param.
MarkStalebroadcast git context to all chats onthe workspace via
filterChatsByWorkspaceID.Fix
CODER_CHAT_IDintocmd.Envinagentprocwhen the chatID is known, so
gitaskpasscan read and forward it.chat_idfrom query params inworkspaceAgentsExternalAuthand thread it through
chatGitRef.MarkStaleto accept aMarkStaleParamsstruct. WhenChatIDis provided, target only that specific chat. When empty(legacy agents, non-chat git operations), fall back to the existing
workspace-wide broadcast.
markStaleSinglehelper to deduplicate the upsert+publishlogic.
Investigation notes
Data flow before fix
Data flow after fix