Skip to content

A release variant beside a recorded sibling is an upgrade on every scan: "1 package has a newer patch available" and updates[] never clear, and a hosted re-scan reports a rewrite it does not make #2370

Backlog

Description

[agent] Filed by the architecture refactor routine. Found on main at cfc870f by running the built binary; the unit test below fails there.

Problem

A package with release variants gets one selected patch per variant: a wheel and its sdist, a gem and its platform gems. When the project records the patch of one variant and not of another, scan classifies the other as an upgrade of the recorded patch, on every run:

  • Agent mode. The default narrowing keeps the installed variant's patch and drops the rest. Every later scan prints 1 package has a newer patch available., lists the package in updates[] and counts it under rollout.counts.upgrade. Nothing is updated, on that run or any later one.
  • Hosted mode. Both variants are written to the one lock entry and the last one stays. Every later scan then says it switched a package and rewrote a file, and asks for a commit. The files are byte for byte the ones before, with the same inode and mtime.

Who it hurts: anyone who reads the scan's last lines or updates[]. A job that opens a pull request or fails while updates[] holds something never settles, and a developer is told to commit a change that is not there.

Cause

classify (crates/socket-patch-core/src/rollout/stage.rs, line 198) asks RecordedIndex::uuids for the uuid recorded for the selected purl. That lookup falls back from the exact key to any qualifier twin (line 174), so a variant with no record of its own gets its sibling's uuid. classify then looks for that uuid among the offers of the variant's own purl (line 204), does not find it, and takes the arm for a recorded patch that is no longer offered (line 224): Recorded::Superseded. The sibling's patch is still offered, under the sibling's purl.

CLI_CONTRACT.md settles what is right. Line 693: a row is ALREADY when "the selection does not supersede" the recorded uuid. Line 694: it is an UPGRADE when "the recorded uuid is no longer offered". Lines 2945 to 2949: "updates[] lists exactly the UPGRADE rows the run acts on" and "a re-scan never swaps an applied patch for an equal sibling".

The same symptom was fixed once for two patches of one purl: 098ad3d (#162), "stop nagging updates for equal-or-older batch-ranked patches". Release variants are the copy that fix did not reach.

Evidence

The unit test

Added to the tests of rollout/stage.rs, with that module's own helpers:

#[test]
fn a_sibling_release_variant_of_a_recorded_patch_is_not_an_upgrade() {
    const WHEEL: &str = "pkg:pypi/six@1.16.0?artifact_id=py2-py3-none-any-whl";
    const SDIST: &str = "pkg:pypi/six@1.16.0?artifact_id=tar-gz";
    let results = vec[
        offer(WHEEL, "w", "2026-01-01T00:00:00Z", &["high"]),
        offer(SDIST, "s", "2026-01-01T00:00:00Z", &["high"]),
    ];
    let offers = offers_from_results(&results, true);
    // Agent mode: a narrow scan recorded the installed wheel's patch alone.
    let stored = manifest(&[(WHEEL, "w")]);
    let recorded = RecordedIndex::new(Some(&stored), &[]);
    let rows = classify(&offers, &recorded, "");
    for row in &rows {
        println!("agent  {} -> {:?}", row.candidate.purl, row.candidate.recorded);
    }
    // Hosted mode: the lockfile pins the package (no qualifier) at the sdist's patch.
    let pins = vec[("pkg:pypi/six@1.16.0".to_string(), "s".to_string())];
    let hosted = classify(&offers, &RecordedIndex::new(None, &pins), "");
    for row in &hosted {
        println!("hosted {} -> {:?}", row.candidate.purl, row.candidate.recorded);
    }
    for row in rows.iter().chain(&hosted) {
        assert!(
            !matches!(row.candidate.recorded, Recorded::Superseded { .. }),
            "{} is reported as an upgrade of its sibling's patch, which is still offered: {:?}",
            row.candidate.purl,
            row.candidate.recorded
        );
    }
}
$ cargo test -p socket-patch-core --lib rollout::stage::tests::a_sibling_release_variant -- --nocapture
agent  pkg:pypi/six@1.16.0?artifact_id=py2-py3-none-any-whl -> Same
agent  pkg:pypi/six@1.16.0?artifact_id=tar-gz -> Superseded { old_uuid: "w" }
hosted pkg:pypi/six@1.16.0?artifact_id=py2-py3-none-any-whl -> Superseded { old_uuid: "s" }
hosted pkg:pypi/six@1.16.0?artifact_id=tar-gz -> Same
pkg:pypi/six@1.16.0?artifact_id=tar-gz is reported as an upgrade of its sibling's patch, which is still offered: Superseded { old_uuid: "w" }
test result: FAILED. 0 passed; 1 failed

Agent mode, the built binary

six 1.16.0, installed from its wheel by uv, and a stand-in patch API that offers two patches of it: one for the wheel, one for the sdist. The sdist's does not match the installed copy, so the first scan records the wheel's alone, as designed.

$ socket-patch scan --mode agent        # the first scan
Found 1 package (1 python)
Applied 1 patch.

$ socket-patch scan --mode agent        # the second, the third, and every one after
Found 1 package (1 python)
1 package has a newer patch available.
Applied 0 of 1 patch: 1 already patched.

With --json, on each of those:

"updates": [{"purl": "pkg:pypi/six@1.16.0", "oldUuid": "bbbbbbbb-0000-4000-8000-000000000011", "newUuid": "bbbbbbbb-0000-4000-8000-000000000012"}]
"rollout": {"counts": {"new": 0, "deferred": 0, "upgrade": 1, "already": 1}}

The run has no updated event and summary.updated is 0. The manifest holds the wheel's record alone, at uuid …11, before and after each scan.

A release with three variants, two of which match the installed copy, shows it as well: two kept, one dropped, one updates[] row on every scan.

Hosted mode, the built binary

The same release, a requirements.txt of one line, and a stand-in that grants both variants.

scan #1   Switched 2 packages to hosted patches; rewrote 1 file.
scan #2   1 package has a newer patch available.
          Switched 1 package to hosted patches; rewrote 1 file. 1 package was already on hosted patches.
scan #3   the same as #2

One package is counted as two, and the pin that stays is the variant that sorts last. On scans #2 and #3 requirements.txt keeps its sha256, inode and mtime. Under --json both variants are applied events on every run (summary.applied: 2), and updates[] names the wheel's uuid as the new one while the file pins the sdist's. A uv project behaves the same, and its next steps read "Commit pyproject.toml to keep the hosted patches."

When the sdist variant's artifact is a patched sdist, the first scan leaves requirements.txt and uv.lock on the .tar.gz and drops the wheel, so a project that installed a wheel builds from source afterwards.

Not checked

This sandbox has no route to the patch service, so the two variants are a stand-in's. The agent-mode half needs only that the narrowing drops a variant, which is what it is for; the contract names "a wheel and its sdist, a gem platform". The hosted half needs one fact from Socket's backend: whether a release is ever granted for two variants at once, and what the sdist variant's artifact is. The production suite asserts a .whl pin for urllib3 1.26.18.

Planned fix

In classify, judge a uuid that came from a qualifier twin against the twin's offers. A sibling that is still offered is then not "no longer offered", and the row is no upgrade. The writer still gets the selected uuid, so a variant that becomes the installed one is still downloaded. The unit test above goes in with it, beside an agent-mode and a hosted CLI test over two variants. Which variant a hosted scan pins when two are granted is a second change, once the backend fact is known.


Generated by Claude Code

Activity

  1. added
    bug
    arch-audit
    on Nov 29, 2026
  2. added a commit that references this issue on Nov 29, 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:p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions