Skip to content

fix(tools): derive valid git diff argv in sandboxed decorator - #617

Merged
andreapn merged 1 commit into
use-agent-os:mainfrom
Preciousuche:fix/tools-git-diff-sandbox-argv
Sep 1, 2026
Merged

fix(tools): derive valid git diff argv in sandboxed decorator#617
andreapn merged 1 commit into
use-agent-os:mainfrom
Preciousuche:fix/tools-git-diff-sandbox-argv

Conversation

@Preciousuche

@Preciousuche Preciousuche commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Description

Closes #614

Summary

Fixes the @sandboxed argv_factory derivation for the built-in git_diff tool.

Problem

git_diff's @sandboxed decorator defined its argv_factory as:

argv_factory=lambda a: (
    "git",
    "diff",
    "--cached" if a.get("staged") else "--unstaged",
    str(a.get("path", "")),
)

This produced invalid arguments:

  1. --unstaged is not a valid git flag.
  2. When path is omitted (None), str(a.get("path", "")) stringifies None to "None".

While this tuple is not directly executed by the runner, it feeds sandbox action fingerprinting (sandbox/integration.py) and operator approval surfaces:

  • Approval Safety & Auditability: Operators and audit logs are presented with git diff --unstaged None, misrepresenting the command that will execute.
  • Fingerprint Equivalence: Fingerprints derived from invalid tuples misrepresent action equivalence across calls.

Solution

Replaced the inline lambda with _git_diff_argv(a) that mirrors the actual command construction in git_diff:

  • Returns ("git", "diff")
  • Appends "--cached" only when staged is truthy
  • Appends ["--", str(path)] only when path is provided and non-empty

Tests

Added regression tests in tests/test_tools/test_git_workdir_policy.py verifying:

  • Unstaged diff without path: ("git", "diff")
  • Staged diff without path: ("git", "diff", "--cached")
  • Unstaged diff with path: ("git", "diff", "--", "src/main.py")
  • Staged diff with path: ("git", "diff", "--cached", "--", "src/main.py")

Fixes #614

@Preciousuche
Preciousuche force-pushed the fix/tools-git-diff-sandbox-argv branch from e06a85a to 0f0ae5d Compare August 31, 2026 08:43

@andreapn andreapn 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.

LGTM

@andreapn
andreapn merged commit aa35769 into use-agent-os:main Sep 1, 2026
6 checks passed
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.

[Bug]: sandbox decorator emits invalid --unstaged flag and empty path argument

3 participants