Skip to content

feat(availability): check many package versions at once, also through a group - #473

Merged
M0Rf30 merged 3 commits into
openartifact:mainfrom
orcamedia:feat/availability-batch
Nov 12, 2026
Merged

M0Rf30 merged 3 commits into
openartifact:mainfrom
orcamedia:feat/availability-batch

Conversation

@orcamedia

Copy link
Copy Markdown
Contributor

First PR of #471: batch availability, without vulnerabilities and without oa check. It follows the design agreed in this comment.

API

POST /api/v1/repositories/{name}/availability with {"packages": [{"package", "version"}, ...]}:

  • Limits: 1 to 1000 entries, at most 1024 bytes per field, body at most 1 MiB. Duplicates are answered once.
  • Results: one per entry, in request order. Each has the GET's fields plus status (available / held / not_found / unknown) and repository, the repository that decided.

The MCP tool check_dependencies(repository, packages) calls the same api.ExplainAvailabilityBatch, the way check_availability shares ExplainAvailability, and marks the result untrusted.

Decisions

One repository

  • Hosted: not_found unless a live version with a live file is stored. Matching works as in PackageVersionHolds (name/name_key, version/version_key). Otherwise the quarantine and license holds apply.
  • Proxy: unknown when the cached metadata can't say, not_found when it doesn't list the version. Otherwise the gate decides, with the publish time from the same metadata.
  • Blocked repository: held (repository_blocked).

Group

  1. A blocked group refuses everything.
  2. Members are taken as in group.Handler.members, minus members the caller can't read (any type, as Dispatcher.authorize does).
  3. Hosted wins: unless merge_proxy_versions is set, a name a remaining hosted member holds is decided by the hosted members only. If none of them has the version, the answer is not_found.
  4. Otherwise the first member that has the version decides, held or not.
  5. A proxy that can't tell makes the answer unknown, and later members aren't consulted.

Cost

  • The group members are listed once.
  • Curation rules are loaded once per proxy member.
  • Two queries cover all hosted data for every entry and member: HostedNamesHeld and HostedVersionsStored, both unnest over the entries.
  • One cached-metadata read per (proxy member, distinct package), through the new proxy.Service.CachedVersions, which wraps Hooks.Versions and never fetches. At most 8 reads run at a time, and only for entries no earlier member decided.

TestAvailabilityBatchCost pins this with 900 entries: one call each for members, rules, held names and stored versions, and one read per (proxy, package) actually reached. TestAvailabilityBatchReadConcurrency checks that reads peak at exactly 8.

RBAC

isRepoAvailabilityBatchRoute gives the POST read, outside the safe-method set, so nothing else widens. The rbac_hardening_test.go case flips to read. New cases pin PUT, DELETE and deeper POST paths of availability to manage. The existing POST cases for held-back-versions and proxy-versions still expect manage.

Tests

  • Engine (availability_batch_test.go, fakes that count calls): hosted, proxy and blocked single repositories, then one case per group rule:

    • skipped members (blocked, nested, other format, unreadable);
    • hosted wins;
    • merge_proxy_versions;
    • a holding member decides;
    • an unlisted version passes to the next member;
    • an uncached proxy gives unknown;
    • a held hosted version;
    • nobody has it.

    Also a blocked group (no member or cache is touched), cost, concurrency, and docker refused. I checked the tests catch mistakes by breaking hosted wins and the blocked-member skip on purpose: both failed.

  • SQL (tests/integration, real Postgres): TestHostedBatchMatchesPackageVersionHolds checks that the batch holds equal PackageVersionHolds for every stored version (vulnerability, license, clean, identity-key match, other repository), that deleted and unknown versions aren't stored, and the names held.

  • HTTP: the endpoint through a group, plus validation (bad JSON, no or empty packages, a missing or oversized field, 1001 entries).

  • MCP: check_dependencies through the authenticated stack. For an admin, a hosted member owns the name; for the read-only token that member is invisible and the proxy decides. Also refusals: bounds, docker, an unreadable repository.

Checked against a real server

A Composer group (php-hosted, then php-proxy, a Packagist proxy with a block rule on guzzlehttp/guzzle 6.*), with Guzzle's metadata fetched once:

entry status via
guzzlehttp/guzzle 7.8.1 available (min_age checked) php-proxy
guzzlehttp/guzzle 6.5.8 held: curation "EOL, use 7.x" php-proxy
guzzlehttp/guzzle 99.0.0 not_found php
monolog/monolog 3.5.0 (never fetched) unknown php-proxy
guzzlehttp/guzzle 7.8.1 (duplicate) available php-proxy

check_dependencies over MCP gave the same answers.

Two questions for review

  1. A curation hold on an uncached package. evil/backdoor 1.0.0 against a proxy with a block rule on evil/* currently answers unknown, because nothing is cached. For the formats whose downloads curationRefusal gates before any fetch (those with Hooks.Coordinates: apk, conan, ivy, pacman, mirrored), the 403 doesn't depend on the cache. Those could answer held without reading it. Worth doing here, or as a follow-up?
  2. Formats that filter metadata. Composer, npm and others gate in their own Serve by leaving held versions out of the metadata. In a group, the merged metadata could then offer that version from a later member. Does "the first member that has the version decides, held or not" hold for those formats as well, or does a version hidden by one member's gate pass to the next member there? I followed your rule as written. If merged formats behave differently, the change is local to advance.

Checks

  • golangci-lint run ./... passes, also with -tags integration for tests/integration and internal/database.
  • go test -short -race passes for internal/{api,mcp,middleware,proxy,database} and cmd/server.
  • The integration test passes against Postgres 18.
  • make docs-check and make deadcode pass, and the -tags noai,nomcp build passes.
  • vue-tsc --noEmit passes with the regenerated client.

Next: oa check with composer.lock and package-lock.json, then vulnerabilities from the OSV mirror.

🤖 Generated with Claude Code

@M0Rf30 M0Rf30 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this follows the design agreed in #471. No blockers. #472 is merged, so this needs a rebase (tools_gate.go, drift_test.go, mcp.md and upgrading.md overlap).

Your questions

  1. Curation hold on an uncached package: do it in a follow-up. unknown is honest and safe for now.

  2. Formats that filter their metadata: I checked the serving path. The merged npm packument and the composer p2 document can offer a version from a later member when an earlier member's gate hid it. The download then goes through firstHit, and probeWriter only skips a member on a 404 or 5xx, so a 403 from the earlier member ends the install.

    • npm: the tarball path is the same for every member, and the npm proxy answers a held tarball with checkGate's 403. The rule "first member that has the version decides, held or not" holds.
    • composer, curation: serveComposerDist runs checkGate from the path, before the reference is compared, so it is a 403 and the rule holds.
    • composer, minimum age: this hold is only checked in locateComposerDist, after dist.ProxyRef() != p.Ref. A dist relinked from a later member whose reference differs gets a 404 from the earlier proxy, and the later member serves it. So under a minimum-age hold, the version passes to the next member when the dist references differ (for example two proxies of different upstreams). It stays held when they match.

    I'd rather fix serving than special-case advance: have serveComposerDist check the minimum age before the reference too (or 403 any gated version of the package regardless of reference). That's the safer behavior anyway, and then your rule holds as written. A separate PR is fine; until then, mention the gap in hosted-proxy-group.md.

Small points

  • Hosted-wins definition: HostedNamesHeld treats a name as held when the member has a live version with a live file. Serving decides it by whether the member answers a package document with 200 (internal/group/hostedwins.go). Please add a comment saying the two are meant to match, so a later change to either side gets noticed.
  • Unchecked read result: readCached throws away the result of g.Wait(). That's correct today, but a read that later returns an error would be silently dropped. A sync.WaitGroup with a semaphore, or checking the error, makes that explicit.
  • check_availability description: after the rebase, its group sentence should also point at check_dependencies, which now answers for a group.

orcamedia and others added 3 commits November 12, 2026 18:37
… a group

POST /api/v1/repositories/{name}/availability answers up to 1000
package versions (duplicates once, results in request order) with the
GET's fields plus status (available, held, not_found, unknown) and the
repository that decided. The MCP tool check_dependencies calls the same
function, api.ExplainAvailabilityBatch.

A hosted repository answers not_found for a version it does not store,
a proxy not_found when its cached metadata does not list the version
and unknown when the metadata is not cached or the format lists no
versions. A group follows the serving path: a blocked group refuses
everything; nested groups, members of another format, blocked members
and members the caller cannot read are skipped; unless
merge_proxy_versions is set a name a remaining hosted member holds is
decided by the hosted members only; otherwise the first member that has
the version decides, held or not; a proxy that cannot tell makes the
answer unknown.

Cost: the members once, the curation rules once per proxy member, the
hosted data in two queries (HostedNamesHeld, HostedVersionsStored, which
match like PackageVersionHolds), and one cached-metadata read per proxy
member and distinct package (proxy.Service.CachedVersions, never
fetching), at most 8 at a time and only for entries no earlier member
decided.

The POST only reads: isRepoAvailabilityBatchRoute gives it read like the
GET, and the rbac_hardening_test case flips from manage to read.

Refs openartifact#471.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The batch answer gives reasons with source not_found and unknown; the
AvailabilityReason enum only listed the GET's five, so api-fuzz flagged
the 200 response of POST /availability as violating the schema. With the
enum widened, the web client's sourceLabel needs labels for both: added
in every locale, and the "labels every source" test covers them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…_dependencies

- HostedNamesHeld and hostedwins.go each say the other must stay equal
  (database predicate vs the package document serving probes).
- readCached runs under a WaitGroup and semaphore: the reads have no
  error to return, so nothing is discarded.
- check_availability's description and its group error point at
  check_dependencies, which answers for a group.
- hosted-proxy-group.md states the composer minimum-age case where
  serving passes a version on and the batch reports it held.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@orcamedia
orcamedia force-pushed the feat/availability-batch branch from e0e8883 to 6e42e8d Compare November 12, 2026 13:47
@orcamedia

Copy link
Copy Markdown
Contributor Author

Rebased on main and addressed the three points:

  • Hosted-wins definition: HostedNamesHeld and hostedwins.go each now say the other must stay equal (the database predicate and the package document that serving probes).
  • Unchecked read result: readCached runs under a sync.WaitGroup with a semaphore. The reads have no error to return, so nothing is discarded.
  • check_availability: its description and its group error now point at check_dependencies, which answers for a group.

The composer minimum-age gap is documented in hosted-proxy-group.md (under "Check many versions at once").

Follow-ups I'll send as separate PRs:

  1. serveComposerDist: check the minimum age before the reference comparison, so the rule holds as written.
  2. A curation hold on an uncached package: answer held instead of unknown where the download is refused before any fetch.

@M0Rf30
M0Rf30 merged commit 587447f into openartifact:main Nov 12, 2026
23 checks passed
@orcamedia
orcamedia deleted the feat/availability-batch branch November 13, 2026 16:51
orcamedia added a commit to openartifact/openartifact-agent-plugin that referenced this pull request Nov 13, 2026
Version 0.2.0: the `check-lockfile` skill, using the
`check_dependencies` tool that landed in openartifact/openartifact#473.

## What the skill tells the agent

1. **Find the repository** the project installs from, the
`/repos/<name>` in its package manager config. A group is fine, since
`check_dependencies` answers for one.
2. **Extract the pinned versions with `jq`**, not by reading the
lockfile into context. The filters apply the rules of `oa check`
(openartifact/openartifact#476): path packages, links, bundled packages,
workspace folders, and git or file dependencies are left out. There are
instructions for when `jq` is missing, and for lockfileVersion 1.
3. **Call `check_dependencies`** with at most 1000 entries per call.
4. **Report by status:**
- `held`, with the reason, rule id or `until` time, and the deciding
repository;
   - `not_found`;
- `unknown`, explained as "the proxy hasn't cached this package yet",
not as a block.
5. **Suggest fixes that respect the registry**, with no public-registry
fallback, handing off to `check-dependency` for an available version.

Servers without the tool (any release before #473) get a check of the
direct dependencies through `check_availability`, and the agent says the
whole lockfile couldn't be checked.

## Checked

- I ran both `jq` commands exactly as written in the skill against the
parser fixtures of #476. They return the same lists as the Go parser (4
and 5 dependencies).
- End to end against a server built from current `main`: the extracted
list from a `composer.lock` went to `check_dependencies` on a Composer
group. Guzzle 6.5.8 came back held ("EOL, use 7.x"), 7.8.1 available,
and two uncached packages unknown.
- `scripts/check-plugin.py` passes and `reuse lint` reports compliance.
CI's Agent Skills job validates the new skill.

Not tested: a full agent session using the skill. The tool is on `main`
but not in a server release yet.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Areef <[email protected]>
Co-authored-by: Claude Fable 5.2 <[email protected]>
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.

2 participants