Skip to content

An agent-mode scan scoped to an absolute path, or to ".", selects nothing and exits 0 with no patch applied; rollback fails on the same paths #2336

Backlog

Description

[agent] Found by the architecture refactor routine while running the path arguments of agent-mode scan and of rollback over a real npm workspace. Run on main at cfc870f with the binary built from it, npm 10.9 and pnpm 10.28.0.

Problem

Agent-mode scan [PATHS] and rollback <path> decide which installed copies a path names with one matcher (CLI src/path_scope.rs). Two spellings of a directory that holds installed packages select nothing:

  • An absolute path, unless --cwd is also spelled absolute. With the default --cwd . (or any relative --cwd), scan --mode agent "$PWD/packages/b" prints No installed packages found under the given path and exits 0 with no patch applied. rollback "$PWD/packages/b" fails with Path pattern matched no patched packages. The same commands with --cwd "$PWD" select the package.
  • ., the directory itself. scan --mode agent . exits 0 with no patch applied, under a relative and an absolute --cwd. rollback . is read as a name, fails, and suggests ./., which then fails too.

CLI_CONTRACT.md (line 451) says "relative patterns match against the copy path relativized to --cwd, absolute patterns against the absolute path", and "a pattern matching any ancestor directory of the copy path also matches". Both are broken here: the absolute path is an ancestor of the copy, and so is --cwd.

Who it hurts: a developer or a CI job that scopes an agent-mode scan to a directory the way scripts usually spell one ("$PWD/apps/web", "$GITHUB_WORKSPACE/apps/web", .). The run exits 0, so nothing fails, and no patch is applied. Hosted and vendored mode take the same [PATHS] argument and accept every one of these spellings.

Evidence

The project: an npm workspace with two members, installed by real npm install, and a stand-in patch API that offers one patch for each of the four installed packages. The shell is in the project directory (shown as /work/ws).

$ find . -name package.json -path "*node_modules*" -not -path "./node_modules/[ab]/*" | sort
./node_modules/kleur/package.json
./node_modules/left-pad/package.json
./node_modules/ms/package.json
./packages/b/node_modules/left-pad/package.json

$ socket-patch scan --mode agent --yes "$PWD/packages/b"; echo "exit $?"
No installed packages found under the given path: /work/ws/packages/b.
exit 0                                                  # files patched: 0 of 4

$ socket-patch scan --mode agent --yes .; echo "exit $?"
No installed packages found under the given path: ..
exit 0                                                  # files patched: 0 of 4

$ socket-patch scan --mode agent --yes packages/b | head -3          # control: the relative spelling
Found 1 package (1 npm)
Applied 1 patch.
  HIGH  left-pad@1.2.0  CVE-2026-0002

$ socket-patch scan --mode agent --yes --cwd "$PWD" "$PWD/node_modules/ms" | head -3     # control: --cwd spelled absolute
Found 1 package (1 npm)
Applied 1 of 2 patches: 1 already patched.
  HIGH  ms@2.1.2  CVE-2026-0003

$ socket-patch rollback --yes "$PWD/packages/b"; echo "exit $?"
Error: Path pattern matched no patched packages: /work/ws/packages/b (path targets select installed copies; patches for uninstalled packages are reachable by identifier or an unscoped rollback)
exit 1

$ socket-patch rollback --yes .; echo "exit $?"
Error: No patch found matching identifier: . (to target a directory instead, use ./. or ./**)
exit 1
$ socket-patch rollback --yes ./.; echo "exit $?"                    # the first suggestion
Error: Path pattern matched no patched packages: ./. (path targets select installed copies; patches for uninstalled packages are reachable by identifier or an unscoped rollback)
exit 1

$ socket-patch rollback --yes --cwd "$PWD" "$PWD/packages/b"; echo "exit $?"             # control
Rolled back 1 package:
  pkg:npm/left-pad@1.2.0
…
exit 0

The notice about the missing API token, which every scan prints on stderr, is left out.

scan --json over the absolute path exits 0 with "status": "success", "scannedPackages": 0, no event and no warning.

Each spelling of a directory, as the PATH of a dry-run scan in the two kinds of mode. The cell is the run's Found N packages count: a bare scan finds 6, and packages/b holds 1.

PATH --cwd scan --mode agent scan --mode hosted
packages/b, ./packages/b, packages/b/ default, or absolute 1 1
"$PWD/packages/b" absolute 1 1
"$PWD/packages/b" default, ., ../ws, or ws from the parent 0, exit 0 1
"$PWD" absolute 6 6
"$PWD" default 0, exit 0 6
. default, or absolute 0, exit 0 6
./ default, or absolute exit 2, empty pattern 6
*, ** default 6 (a glob of directories)

The same holds for a pnpm workspace member, whose copy is a link into the root store (packages/a selects left-pad, "$PWD/packages/a" selects nothing), and for a Python virtualenv (.venv finds six, "$PWD/.venv" finds nothing).

Cause

BoundScope::matches (CLI src/path_scope.rs, lines 141 to 165) matches an absolute pattern against the candidate path as the crawler gave it (line 147), under the comment "crawler paths are already absolute". The struct's own comment, fifteen lines up, says the opposite and is the true one: "crawler paths are NOT absolutized (the default --cwd . yields candidates like ./node_modules/foo)" (lines 130 to 133). The relative-pattern branch handles that case, with a second prefix strip against the cwd as given (line 151), and has since the matcher landed (#231). The absolute-pattern branch never got it, so it compares /work/ws/packages/b with ./packages/b/node_modules/left-pad.

For .: normalize_pattern (lines 48 to 57) strips a leading ./ and trailing slashes, and leaves a lone .. matches_path_or_ancestor (lines 171 to 184) then tries the copy's relative path and each prefix of it down to its first component, and never the directory they are relative to. So * and ** select everything under --cwd and . selects nothing. rollback builds its hint as ./{id} (CLI commands/rollback.rs, line 2293), which for . is the pattern that cannot match.

No test runs either spelling. The unit tests bind an absolute /proj, except relative_cwd_strips_relative_candidates, which covers the relative pattern only. tests/scan/scan_paths_e2e.rs passes relative patterns. This is the class #1902 fixed in the npm crawler: a path handled as text under the default --cwd ..

Two unit tests beside the others fail on main:

/// An absolute pattern under the default
/// relative `--cwd .`, whose candidates are `./node_modules/foo`.
#[test]
fn absolute_pattern_matches_under_a_relative_cwd() {
    let here = std::env::current_dir().unwrap();
    let member = here.join("packages/b").to_string_lossy().into_owned();
    let s = scope(&[member.as_str()]);
    // Control: the same pattern with `--cwd` spelled absolute.
    let abs = s.bind(&here);
    assert!(abs.matches(&here.join("packages/b/node_modules/left-pad")));
    // The default `--cwd .`.
    let rel = s.bind(Path::new("."));
    assert!(
        rel.matches(Path::new("./packages/b/node_modules/left-pad")),
        "absolute pattern {member} selects nothing under --cwd ."
    );
}

/// `.` names `--cwd`, an ancestor of every copy.
#[test]
fn dot_scopes_everything_under_cwd() {
    // Control: the patterns that already mean "everything under cwd".
    for all in ["*", "**"] {
        assert!(scope(&[all]).matches(&cwd(), Path::new("/proj/node_modules/foo")));
    }
    for dot in [".", "./."] {
        assert!(
            scope(&[dot]).matches(&cwd(), Path::new("/proj/node_modules/foo")),
            "pattern {dot:?} selects nothing under an absolute --cwd"
        );
    }
}
$ cargo test -p socket-patch-cli --lib -- path_scope
test path_scope::tests::relative_cwd_strips_relative_candidates ... ok
test path_scope::tests::absolute_pattern_matches_under_a_relative_cwd ... FAILED
test path_scope::tests::dot_scopes_everything_under_cwd ... FAILED

absolute pattern <repo>/crates/socket-patch-cli/packages/b selects nothing under --cwd .
pattern "." selects nothing under an absolute --cwd

test result: FAILED. 12 passed; 2 failed; 0 ignored; 0 measured; 1064 filtered out

In both tests the control assertions pass.

Planned fix

  1. BoundScope::matches gives an absolute pattern the copy's absolute path: a relative candidate is joined to the absolutized --cwd that the scope already holds. No file is read.
  2. A pattern that normalizes to . names --cwd and matches every copy under it, by the ancestor rule. rollback's hint for . then names a pattern that works.
  3. The two unit tests above, and a CLI test for each command that runs the child from the project directory with no --cwd and an absolute pattern. The suites pin an absolute --cwd, which is why they never met this.

The contract settles both (line 451), and hosted and vendored mode already read the argument this way, so this is not a decision issue. One thing is left as it is: ./ stays the usage error the contract names ("an unparseable or empty pattern is a usage error"). A maintainer who wants it to mean the directory, as it does in hosted mode, can say so here.

The routine has three PRs open and awaiting review, so no PR is opened for this yet.

Not checked: Windows (drive letters and \\?\ paths), and a --global scan, whose copies are outside the project. Seen beside it and not part of this issue: a shell inside a symlinked directory has a $PWD the kernel's working directory does not spell, so "$PWD/packages/b" would still select nothing there after the fix unless the matcher also compares against the --cwd it was given; and packages//b and packages/../packages/b select nothing in agent mode (the contract calls the match "purely textual") where hosted mode takes both.


Generated by Claude Code

Activity

  1. added
    bug
    arch-audit
    on Nov 28, 2026
  2. added a commit that references this issue on Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent:triagedarch-auditbugpriority:p3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions