Skip to content

agentHost: auto-approve reads of Copilot SDK tool-output temp files#313837

Merged
roblourens merged 2 commits into
mainfrom
roblou/agents/auto-approve-agent-temp-file-access
May 2, 2026
Merged

agentHost: auto-approve reads of Copilot SDK tool-output temp files#313837
roblourens merged 2 commits into
mainfrom
roblou/agents/auto-approve-agent-temp-file-access

Conversation

@roblourens
Copy link
Copy Markdown
Member

What

When a tool result is too large to fit inline, the Copilot SDK spills it to a temp file under os.tmpdir() (named like copilot-tool-output-<…>.txt or <ts>-copilot-tool-output-<…>.txt) and then asks the model to read that file back in a follow-up turn. Today the agent host prompts the user for permission on every one of those reads, even though the file was just written by the SDK on our behalf.

This change auto-approves those read permission requests, mirroring the existing session-state auto-approval pattern in CopilotAgentSession.

How

  • New helper isCopilotSdkToolOutputTempFile(filePath, tmpDir) in copilotAgentSession.ts:
    • Requires the file's parent directory to be exactly os.tmpdir() (no nested subdirs)
    • Requires the basename to match one of the two SDK naming layouts:
      • <timestamp>-copilot-tool-output-<6-char-id>.txt
      • copilot-tool-output-<timestamp>-<6-char-id>.txt
  • In handlePermissionRequest, after the existing session-state branch, auto-approve when request.kind === 'read' and the path matches the helper.
  • Intentionally read-only — writes to these paths still confirm.

How to repro the original prompt

Ask the agent something like:

Run find /usr -type f and then tell me how many of the results contain "lib". Don't summarize — actually look at the full output.

The shell tool result spills to os.tmpdir()/…copilot-tool-output-….txt, and the follow-up read of that file is what was prompting before this change.

Tests

Added 4 unit tests in copilotAgentSession.test.ts covering:

  • positive case for both SDK filename layouts
  • tool-output-named files outside tmpDir are not auto-approved
  • unrelated files inside tmpDir are not auto-approved
  • write to a tool-output path is not auto-approved

All 78 tests in the suite pass; compile-check-ts-native is clean.

Notes for reviewers

  • The EH CLI (extensions/copilot/src/extension/chatSessions/copilotcli/node/permissionHelpers.ts) does not currently have parity for this. Out of scope for this PR — happy to follow up.

(Written by Copilot)

The Copilot SDK spills oversized tool results to a file under os.tmpdir()
(named like `copilot-tool-output-*.txt`) and asks the model to read it
back in a follow-up turn. These reads were prompting for permission even
though the file was just written by the SDK on our behalf.

Mirrors the existing session-state auto-approval pattern: only auto-
approves `read` requests whose path lives directly in os.tmpdir() and
whose basename matches the SDK's two known naming layouts.

(Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 2, 2026 01:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces permission prompts in the agent host by auto-approving read permission requests for Copilot SDK “spilled” large tool outputs stored as temp files under os.tmpdir(), aligning with the existing auto-approval behavior for internal session-state files.

Changes:

  • Add temp-file pattern detection (isCopilotSdkToolOutputTempFile) for Copilot SDK tool-output spill files.
  • Auto-approve read permission requests when the requested path matches the Copilot SDK temp-file pattern in tmpDir.
  • Add unit tests covering positive/negative cases and ensuring write is not auto-approved.
Show a summary per file
File Description
src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts Adds temp-file detection + auto-approval path for read permission requests targeting Copilot SDK spill files in the OS temp directory.
src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts Adds tests for the new auto-approval behavior and its expected boundaries.

Copilot's findings

Comments suppressed due to low confidence (1)

src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts:627

  • Auto-approving reads in the global OS temp directory based only on basename pattern can leak unrelated local data: any pre-existing file (or symlink) in tmpDir with a matching name would be read without user confirmation. Consider tightening this by validating the target is an actual regular file (not a symlink) and narrowing the match (e.g., enforce expected timestamp/id lengths), or preferably auto-approve only paths that were observed/recorded as SDK-created spill files for this session.
			// Auto-approve reads of large-tool-output temp files written by the
			// Copilot SDK itself. The SDK spills oversized tool results to
			// `os.tmpdir()/copilot-tool-output-…txt` and then asks the model
			// to read them back in a follow-up turn — no need to confirm.
			if (request.kind === 'read' && typeof request.path === 'string') {
				if (isCopilotSdkToolOutputTempFile(request.path, this._environmentService.tmpDir.fsPath)) {
					this._logService.info(`[Copilot:${this.sessionId}] Auto-approving Copilot SDK tool-output temp file ${request.path}`);
					return { kind: 'approve-once' };
				}
			}
  • Files reviewed: 2/2 changed files
  • Comments generated: 2

Comment thread src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts Outdated
Comment thread src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts
@roblourens roblourens enabled auto-merge (squash) May 2, 2026 01:43
@roblourens roblourens marked this pull request as draft May 2, 2026 01:43
auto-merge was automatically disabled May 2, 2026 01:43

Pull request was converted to draft

@roblourens roblourens marked this pull request as ready for review May 2, 2026 01:50
@roblourens roblourens enabled auto-merge (squash) May 2, 2026 01:50
- Restrict the SDK tool-output regex to \d{10,} for the timestamp and
  exactly 6 lowercase alphanumeric chars for the random id, matching
  what the SDK actually emits and reducing the auto-approval surface.
- Drop the `export` from `isCopilotSdkToolOutputTempFile` since it has
  no callers outside this module.

(Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@roblourens roblourens merged commit 96e4e9e into main May 2, 2026
40 of 41 checks passed
@roblourens roblourens deleted the roblou/agents/auto-approve-agent-temp-file-access branch May 2, 2026 03:09
@vs-code-engineering vs-code-engineering Bot added this to the 1.119.0 milestone May 2, 2026
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.

3 participants