Skip to content

[cherry-pick] Cache terminal risk assessment by command only#315685

Merged
chrmarti merged 1 commit into
release/1.120from
cherry-pick/315663
May 11, 2026
Merged

[cherry-pick] Cache terminal risk assessment by command only#315685
chrmarti merged 1 commit into
release/1.120from
cherry-pick/315663

Conversation

@vs-code-engineering
Copy link
Copy Markdown
Contributor

@vs-code-engineering vs-code-engineering Bot commented May 11, 2026

#315616

Cherry-pick of #315663 from main.

Summary

Fixes the terminal confirmation badge showing Assessing risk… with a spinner every time, instead of using the cached assessment, when re-running the same command outside the sandbox.

The risk assessment cache key was tool.id + stableStringify(parameters). For run_in_terminal the parameter set includes model-generated explanation, goal, and requestUnsandboxedExecutionReason fields, which differ on every invocation even when the underlying command is identical — so the cache never hit on the second run.

This narrows the cache key for run_in_terminal to just `{ command }`. Other tools are unaffected and still key on their full parameter set.

Repro

  1. Set `chat.tools.riskAssessment.enabled: true` and `chat.agent.sandbox.enabled: true`
  2. In agent mode, run a command that requires unsandboxed access (e.g. `curl https://google.com\`)
  3. Trigger the same command again — badge now renders instantly from cache.
Session Context

Key decisions from the development session:

  • Cache key scope: Only narrowed for `run_in_terminal` (via the `TerminalToolId.RunInTerminal` id). The previous full-parameter key is preserved for all other tools, since their parameters are typically the deterministic inputs of the call.
  • Normalized fields: Only `command` is used. Fields like `explanation`, `goal`, `requestUnsandboxedExecutionReason`, `mode`, `timeout`, and `requestUnsandboxedExecution` are excluded because they're either model-generated descriptive text or execution-mode controls that don't change the risk semantics of the command itself.
  • Shared helper: `getCached` and `assess` both go through a single `_cacheKey` helper so the lookup and insertion keys can't drift.

Copilot AI review requested due to automatic review settings May 11, 2026 14:16
@vs-code-engineering vs-code-engineering Bot added the cherry-pick-artifact Auto-generated cherry-pick PR label May 11, 2026
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@chrmarti chrmarti enabled auto-merge (rebase) May 11, 2026 15:05
@chrmarti chrmarti merged commit 44c17a0 into release/1.120 May 11, 2026
39 of 40 checks passed
@chrmarti chrmarti deleted the cherry-pick/315663 branch May 11, 2026 15:09
@vs-code-engineering vs-code-engineering Bot added this to the 1.120.0 milestone May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-pick-artifact Auto-generated cherry-pick PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants