Skip to content

A crate below a workspace member that carries package.workspace is taken for a standalone project: a hosted scan from it with a stray lock says applied, and cargo no longer loads the workspace #2510

Backlog

Description

[agent] Found by the architecture refactor routine while running the Cargo workspace-root check against cargo locate-project --workspace (lead L203). Checked on main at d987721.

Problem

cargo finds a crate's workspace root by walking up from the crate. The walk ends at the first ancestor manifest that either has a [workspace] table that does not exclude the crate, or is a package with package.workspace = "<path>": that pointer names the root for everything below it too.

workspace_root_refusal in vendor/cargo.rs reads the pointer only in the project's own manifest. In an ancestor it looks for a [workspace] table alone, so a package that carries a pointer is passed over, and the crate below it is taken for a standalone project. The layout is the one package.workspace exists for, a member that lives outside the root's directory, with a path dependency of its own beneath it:

repo/ws/Cargo.toml           [workspace] members = ["app", "../outer"]   (and the Cargo.lock)
repo/ws/app/Cargo.toml       [package]
repo/outer/Cargo.toml        [package] workspace = "../ws"; [dependencies] inner = { path = "inner" }
repo/outer/inner/Cargo.toml  [package]                                (no pointer of its own)
$ cd repo/outer/inner && cargo locate-project --workspace --message-format plain   # cargo 1.93.1 and 1.97.0
repo/ws/Cargo.toml
$ cargo metadata --no-deps | jq '[.packages[].name]'
["app", "outer", "inner"]

workspace_root_refusal on main, for each directory (a probe that prints its answer):

Directory cargo's workspace root The check
repo/ws itself root
repo/ws/app (a member inside the root, control) repo/ws refuses: "is a member of the cargo workspace rooted at repo/ws/Cargo.toml"
repo/outer repo/ws refuses: "sets package.workspace = "../ws""
repo/outer/inner repo/ws root

Through the binary, the bench's hosted Cargo project placed at outer/inner of that layout (control: the same project at ws/inner under members = ["inner"]), scan --mode hosted --yes --json:

Run from A stray Cargo.lock in the crate Result
ws/inner (control) yes or no exit 1, cargo_manifest_not_workspace_root, nothing written
outer no exit 1, cargo_manifest_not_workspace_root
outer/inner no exit 0, skipped, redirect_cargo_lockless_dependents: "This project has no Cargo.lock … commit a lockfile (cargo generate-lockfile) and re-run"
outer/inner yes exit 0, applied: registry = "socket-patch-<uuid>" on the declaration in outer/inner/Cargo.toml, a new outer/inner/.cargo/config.toml, the stray lock rewritten

After the last row cargo no longer loads the workspace from its root or from the member, where it loaded from all three directories before:

$ cd repo/ws && cargo metadata --no-deps        # the same from repo/outer; cargo 1.93.1 and 1.97.0
error: failed to load manifest for workspace member `repo/ws/../outer`
Caused by:
  failed to load manifest for dependency `bench-app`
Caused by:
  failed to parse manifest at `repo/outer/inner/Cargo.toml`
Caused by:
  registry index was not found in any configuration: `socket-patch-60723d93-343e-4a9e-8990-da44931c175b`

cargo reads .cargo/config.toml from the directory it runs in upward, so the registry the pin names is known only inside outer/inner, and the lock cargo reads (ws/Cargo.lock) was never touched.

The lockless row is safe, but its remedy leads nowhere: cargo generate-lockfile in a member writes the workspace's lock at ws/, so the re-run prints the same warning.

Who it hurts: narrow. It needs a member outside the root's directory that carries package.workspace, a path crate below that member, a run from that crate, and for the wrong outcome a lock left in the crate from when it was standalone (the state #1094 and #1101 closed for npm and Bun members). When it is hit, the run says applied and the workspace stops building from its root.

How far the check agrees with cargo

400 generated trees of 14 directories ([workspace] roots with members and exclude sets, nested roots, packages with and without a pointer, path dependencies, a crate under target/package), 4,248 manifests. cargo 1.97.0 loads 2,312 of them, 2,092 as their own root and 220 as members: the check gives cargo's answer for all 2,312. Of the 1,936 cargo refuses, the check says "root" for 39, and each of those sits below a package with a pointer (the generated pointers aim at directories that are not roots, so cargo fails there). The hand-built layout above is the loadable form of those 39.

Where

  • workspace_root_refusal: the pointer is read from doc (the project's manifest) only; for an ancestor, a manifest with no [workspace] table is skipped.
  • Hosted mode, vendored mode and vex discovery share the check.

It is the same class as two earlier fixes of this check: abb5787 (#417, #590: a hosted scan from a workspace member "rewrites only the member, and breaks every build") and e3aa39a (#2077: exclude read the way cargo reads it). Both taught it one more branch of cargo's root lookup; the pointer on an ancestor is the branch still missing.

Planned fix

In the ancestor loop of workspace_root_refusal, a parsed ancestor manifest with package.workspace ends the walk as cargo's does: the project is a member of the workspace that pointer names, so the run refuses with cargo_manifest_not_workspace_root and names that root (the pointer resolved against the ancestor's directory). About 15 production lines, and a unit test beside workspace_root_refusal_reads_exclude_as_the_member_walk_does with the layout above.

Behavior change: a refusal (exit 1, nothing written) for a crate below a package that carries package.workspace, where the run today skips (no lock) or applies (stray lock). That is what the control gets, and what the crate's parent gets today.

Not run

  • Vendored mode in this layout (the bench serves no vendored artifact). It calls the same check before it writes [patch.crates-io], which cargo ignores outside the root manifest.
  • vex after the applied row, and the in-memory hosted engine.
  • A root run in this layout patches nothing either: from ws the scan skips with redirect_cargo_toml_dep_not_found, "a transitive-only dependency … no [dependencies] entry in Cargo.toml declares it", while outer/inner/Cargo.toml declares it. The member is outside the directory the run may write, so the skip stands; only its reason is off. Not part of this issue's fix.
  • Windows and macOS.

Generated by Claude Code

Activity

  1. added
    bug
    arch-audit
    on Dec 4, 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:p2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions