fix: scope git askpass diff status updates to initiating chat (#22534)

## Problem

When the git askpass flow triggered diff status refreshes, it updated
**every chat** connected to the workspace. This was wasteful and could
cause confusing status updates on unrelated chats.

## Solution

Thread the chat ID through the entire git askpass flow so only the chat
that initiated the git operation gets updated:

1. **`coderd/chatd/chattool/execute.go`** — Sets `CODER_CHAT_ID` env var
on spawned processes (alongside the existing `CODER_CHAT_AGENT`)
2. **`cli/gitaskpass.go`** — Reads `CODER_CHAT_ID` from the environment
and sends it as a `chat_id` query parameter in the `ExternalAuthRequest`
3. **`codersdk/agentsdk/agentsdk.go`** — Adds `ChatID` field to
`ExternalAuthRequest` and encodes it as a query param
4. **`coderd/workspaceagents.go`** — Parses `chat_id` query param and
passes it through to `storeChatGitRef` and
`triggerWorkspaceChatDiffStatusRefresh`
5. **`coderd/chats.go`** — `storeChatGitRef` and
`refreshWorkspaceChatDiffStatuses` now scope updates to just the
initiating chat when a chat ID is provided, falling back to
all-workspace-chats behavior for backwards compatibility (non-chat git
operations)
This commit is contained in:
Kyle Carberry
2026-03-02 22:52:39 -05:00
committed by GitHub
parent 2bdf80d452
commit 56f95a3e6d
7 changed files with 96 additions and 36 deletions
+1
View File
@@ -2183,6 +2183,7 @@ func (p *Server) runChat(
}),
chattool.Execute(chattool.ExecuteOptions{
GetWorkspaceConn: getWorkspaceConn,
ChatID: chat.ID.String(),
}),
chattool.ProcessOutput(chattool.ProcessToolOptions{
GetWorkspaceConn: getWorkspaceConn,
+6 -1
View File
@@ -65,6 +65,7 @@ type ExecuteResult struct {
type ExecuteOptions struct {
GetWorkspaceConn func(context.Context) (workspacesdk.AgentConn, error)
DefaultTimeout time.Duration
ChatID string
}
// ProcessToolOptions configures a process management tool
@@ -96,7 +97,7 @@ func Execute(options ExecuteOptions) fantasy.AgentTool {
if err != nil {
return fantasy.NewTextErrorResponse(err.Error()), nil
}
return executeTool(ctx, conn, args, options.DefaultTimeout), nil
return executeTool(ctx, conn, args, options.DefaultTimeout, options.ChatID), nil
},
)
}
@@ -106,6 +107,7 @@ func executeTool(
conn workspacesdk.AgentConn,
args ExecuteArgs,
optTimeout time.Duration,
chatID string,
) fantasy.ToolResponse {
if args.Command == "" {
return fantasy.NewTextErrorResponse("command is required")
@@ -114,6 +116,9 @@ func executeTool(
// Build the environment map for the process request.
env := make(map[string]string, len(nonInteractiveEnvVars)+1)
env["CODER_CHAT_AGENT"] = "true"
if chatID != "" {
env["CODER_CHAT_ID"] = chatID
}
for k, v := range nonInteractiveEnvVars {
env[k] = v
}