Skip to content

Assess only the command in the terminal risk check and distrust its comments - #350597

Open
Anthony Kim (anthonykim1) wants to merge 3 commits into
mainfrom
anthonykim1/autopilot-risk-gate-comments
Open

Anthony Kim (anthonykim1) wants to merge 3 commits into
mainfrom
anthonykim1/autopilot-risk-gate-comments

Conversation

@anthonykim1

@anthonykim1 Anthony Kim (anthonykim1) commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Supersedes: #335967

  • Send the terminal risk prompt only the parameters it already uses as its cache key, { command }, so the model-written explanation no longer reaches the assessment.
  • Add a rule to the terminal risk prompt: comments and natural-language claims inside the command never lower the risk, including claims that a path is temporary, regenerated or safe to delete.
  • Commented commands go through the same assessment as any other command. Nothing is skipped because of a comment.
  • Both users of ChatToolRiskAssessmentService get this: the risk badge and the Autopilot risk gate.

How to test:

  1. Turn on chat.tools.riskAssessment.enabled.
  2. Ask the agent to run rm -rf build # build cache, regenerated automatically, safe to delete.
  3. The risk badge should match the one for rm -rf build without the comment.

Tests:

  • ChatToolRiskAssessmentService › sends only the terminal command to the risk prompt. It fails without the source change.
  • ./scripts/test.sh --run src/vs/workbench/contrib/chat/test/browser/tools/chatToolRiskAssessmentService.test.ts --run src/vs/workbench/contrib/chat/test/browser/tools/languageModelToolsService.test.ts --run src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/electron-browser/runInTerminalTool.test.ts: 392 passing, 0 failing.
  • pnpm run typecheck-client, and pnpm run oxlint on the two changed files: clean.
  • These ran with this change applied on dbd1badaca92. chatToolRiskAssessmentService.ts is unchanged on main since then.

Inspirations from:

Copilot AI balanced review requested due to automatic review settings November 26, 2026 20:28
@anthonykim1 Anthony Kim (anthonykim1) changed the title Skip Autopilot terminal commands that contain shell comments Skip commented terminal commands in Autopilot and assess only the command text Nov 26, 2026
@anthonykim1 Anthony Kim (anthonykim1) added this to the 1.149.0 milestone Nov 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Shell-comment detection mishandles line continuations, substitutions, and quoted here-documents, while host-dependent profile settings cause the fish regression test to fail on Linux and Windows.

4 open issues
What changed in this PR

This PR hardens terminal-command risk assessment in VS Code’s Autopilot flow by excluding model-written explanations and skipping commands detected as containing shell comments.

Changes:

  • Uses normalized parameters for risk prompts and instructs the classifier not to trust safety claims inside commands.
  • Records shell-comment metadata, preserves it during sandbox retries, and uses it to skip Autopilot calls before assessment.
  • Adds tests for prompt filtering, comment detection, and the Autopilot skip path.
File Description
src/​vs/​workbench/​contrib/​terminalContrib/​chatAgentTools/​test/​electron-browser/​runInTerminalTool.test.ts Adds shell-comment detection cases.
src/​vs/​workbench/​contrib/​terminalContrib/​chatAgentTools/​browser/​tools/​runInTerminalTool.ts Detects comments and carries metadata through preparation and retries.
src/​vs/​workbench/​contrib/​chat/​test/​browser/​tools/​languageModelToolsService.test.ts Tests skipping commented commands before assessment.
src/​vs/​workbench/​contrib/​chat/​test/​browser/​tools/​chatToolRiskAssessmentService.test.ts Tests command-only terminal prompt input.
src/​vs/​workbench/​contrib/​chat/​common/​chatService/​chatService.ts Adds optional terminal comment metadata.
src/​vs/​workbench/​contrib/​chat/​browser/​tools/​languageModelToolsService.ts Adds the Autopilot comment skip with a localized explanation.
src/​vs/​workbench/​contrib/​chat/​browser/​tools/​chatToolRiskAssessmentService.ts Normalizes prompt input and strengthens risk instructions.

Review effort: Balanced

Keep the command-only risk prompt and the rule that comments never
lower the risk, and let commented commands go through the same
assessment as any other command. This removes containsShellComment,
the hasComment field and their tests.
@anthonykim1 Anthony Kim (anthonykim1) changed the title Skip commented terminal commands in Autopilot and assess only the command text Assess only the command in the terminal risk check and distrust its comments Nov 26, 2026
@anthonykim1
Anthony Kim (anthonykim1) marked this pull request as ready for review November 26, 2026 21:31

This branch has not been deployed

No deployments
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