Skip to content

feat(mocactl): list your own config bundles (bundles list) - #678

Merged
cwiklik merged 1 commit into
rossoctl:mainfrom
cwiklik:feat/bundles-list-559
Nov 3, 2026
Merged

cwiklik merged 1 commit into
rossoctl:mainfrom
cwiklik:feat/bundles-list-559

Conversation

@cwiklik

@cwiklik cwiklik commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Closes #559.

The problem

mocactl bundles only had delete DIGEST, keyed by a digest the caller must already hold. A crash between mocactl promote returning and whatever stored the digest left an unrecoverable orphan: it holds bytes against the 16 MiB subject budget for 30 days, and the caller cannot find it to delete it.

The reporter's workaround was redis-cli KEYS 'config:bundle:*' on the control plane — a cluster-admin surface, and exactly the keyspace scan the isolation spec §13 (#361) forbids on a caller-facing path.

This is the sibling of #552 / #675 one layer up: same failure, config bundles instead of workloads, control plane instead of harness.

What this adds

GET /v1/config-bundles and mocactl bundles list [--json], reading the per-owner budget zset recordBundle already maintains — no keyspace scan, no new index.

$ mocactl bundles list
DIGEST                                                                  BYTES  PROMOTED (UTC)    EXPIRES (UTC)
sha256:9f2c…                                                             8192  2026-11-02 14:03  2026-12-02 14:03
sha256:1ab7…                                                             4096  2026-10-28 09:41  2026-11-27 11:12

Two design points worth review attention

1. promotedAt is stored, not derived from the score. The zset score is expiry, and touchBundle pushes it to now + TTL every time a session uses the bundle. So score - TTL would report a three-week-old orphan as promoted today — the opposite of useful for spotting one. promotedAt becomes a third meta field written only by recordBundle, so a touch cannot move it; expiresAt comes from the score, which the score does honestly answer. parseMeta still accepts the 2-field legacy value and reports promotedAt: null, so no migration is needed.

2. Unpaged on purpose. A score cursor is unsound here: a concurrent touch moves a member's score mid-walk, so the cursor could skip or repeat a digest. (The sessions index pages safely only because its score is an immutable createdAt.) N is bounded instead — the subject budget over MIN_BUNDLE_CHARGE_BYTES — and the read costs two round trips whatever N is.

Behaviour notes

  • Reports the budget's view, not the keyspace's: entries are not EXISTS-checked, because a charge whose key has already gone still holds bytes until the next admit reaps it, and that charge is precisely what the caller needs the digest of in order to delete.
  • A member whose meta names another subject is dropped, so a crossed write cannot widen into a cross-tenant read.
  • Another subject's bundles are indistinguishable from none (/workloads: authorize caller-named PVCs per subject, and scope workload names #358) — for an admin too. This is not an audit command.
  • BYTES is the charge (compressed, floored at 4 KiB), not the size of the caller's directory; documented as such.
  • Bundles promoted by the harness's own promote tool write storage directly, keep no budget entry, and so do not appear — the same population only an admin can delete.
  • Empty listing writes to stderr only, so | wc -l answers 0; --json prints {"bundles":[]}.

Verification

Check Result
control-plane tests (real Valkey) 1028 passed, 3 skipped
mocactl tests 1648 passed, 4 skipped
tsc --noEmit, both packages clean
Mutation tests 8/8 killed
prettier --check on all 18 files clean
check-doc-links.py 212 files, 0 broken

Mutations used: dropping the owner zRem from dropBundleEntry; having refreshBundle rewrite promotedAt; removing the expiry score filter; returning a shared owner key; dropping the owner-match guard; rejecting legacy 2-field meta; reversing the sort; printing a raw null promotedAt; printing the empty-listing message to stdout. The owner-match mutation survived the first pass, which is why drops a member of my index whose meta names another subject exists.

Pre-existing flakiness, not from this change: the full mocactl suite fails roughly 1 run in 3 on app.test.tsx, overlay-*.test.tsx, sbx-push.test.ts and sbx-up-cortex.test.ts with waitFor / 5 s timeout errors. I confirmed this against a stashed clean tree, which fails the same way at the same rate; the failing test names differ run to run and all pass in isolation. Not introduced here, and not fixed here.

Assisted-By: Claude

`mocactl bundles` only had `delete DIGEST`, keyed by a digest the caller
must already hold. So a crash between `mocactl promote` returning and
whatever stored the digest left an unrecoverable orphan: it holds bytes
against the 16 MiB subject budget for 30 days and the caller cannot find
it to delete it. The workaround was `redis-cli KEYS 'config:bundle:*'`
on the control plane -- a cluster-admin surface, and exactly the
keyspace scan the isolation spec S13 (rossoctl#361) forbids on a caller-facing
path.

Adds `GET /v1/config-bundles` and `mocactl bundles list [--json]`,
reading the per-owner budget zset that `recordBundle` already maintains,
so there is no scan and no new index.

Two design points worth the reader's time:

- The zset score is EXPIRY, and a session using a bundle pushes it to
  now+TTL. Deriving "promoted at" from `score - TTL` would therefore
  report a three-week-old orphan as promoted today -- the opposite of
  useful. So `promotedAt` becomes a third meta field written only by
  `recordBundle`; `expiresAt` comes from the score, which the score does
  honestly answer. `parseMeta` still accepts the 2-field legacy value
  and reports `promotedAt: null` for it.

- Unpaged on purpose. A score cursor is unsound here because a
  concurrent touch moves a member's score mid-walk, so it could skip or
  repeat a digest; the sessions index pages safely only because its
  score is immutable. N is bounded instead by the subject budget over
  MIN_BUNDLE_CHARGE_BYTES, and the read costs two round trips whatever N
  is.

The listing reports the budget's view, not the keyspace's: an entry is
not EXISTS-checked, because a charge whose key has already gone still
holds bytes until the next admit reaps it, and that charge is precisely
what the caller needs the digest of in order to delete it. A member
whose meta names another subject is dropped, so a crossed write cannot
widen into a cross-tenant read. Another subject's bundles are
indistinguishable from none (rossoctl#358), for an admin too: this is not an
audit command.

Closes rossoctl#559

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: cwiklik <[email protected]>
@cwiklik
cwiklik requested a review from pdettori as a code owner November 3, 2026 14:01
@cwiklik cwiklik added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 3, 2026

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

APPROVE. This adds GET /v1/config-bundles and mocactl bundles list. They read the caller's own budget zset (no keyspace scan), filter by the meta owner hash, use an exclusive (now bound matching admitBundle, and fetch the expiry score WITHSCORES (node-redis 6.3.0 ZRANGE_WITHSCORES → {value, score:number}, which matches the new interface). Storing promotedAt separately from the expiry score, and accepting legacy 2-field meta, both check out. The listing leaves budget state untouched, the route is auth: 'api', and cross-subject/admin isolation is tested. The mocactl table runs every cell through sanitizeRemote. The route, openapi, contract test, http-api.md, cli-mocactl.md and README are all updated.

Three non-blocking comments: a rollback-compatibility note on the meta format change (bundle-budget.ts:156), a clearer message when a newer mocactl hits an older control plane (headless.ts:412), and a stale comment (bundle-budget.ts:181).

Author: cwiklik (MEMBER — maintainer)
Areas reviewed: TypeScript (control-plane, mocactl), tests, OpenAPI/docs
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, signed-off: yes
CI status: all 17 checks passing; merges cleanly with current main (851ef35)

Assisted-By: Claude Code

const hash = subjectHash(subject);
const score = expiryMs(nowMs);
await redis.hSet(BUNDLES_META_KEY, { [digest]: `${bytes}:${hash}` });
await redis.hSet(BUNDLES_META_KEY, { [digest]: `${bytes}:${hash}:${nowMs}` });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion — rollback compatibility of the meta format.

Writing promotedAt into the existing meta value changes a format that the current release's parseMeta reads as owner = raw.slice(i + 1). After a rollback (setup.sh with an older --image, or kubectl rollout undo, both described in docs/operations/upgrades.md), every bundle promoted under this version parses with owner = "<hash>:<ms>", so on the old control plane:

  • deleteConfigBundle returns 403 forbidden to the uploader, because owner !== subjectHash(p.sub). Only an admin can free those bundles, which is the feature: mocactl bundles list to enumerate caller's live config bundles #559 situation again.
  • refreshBundle / dropBundleEntry act on a stray key sh:cp:bundles:owner:<hash>:<ms>, while the real owner zset is never refreshed. The subject's budget then undercounts once the original score passes.

Upgrades.md says a rollback across a data-format change is untested, so this doesn't block. Still, a separate hash (e.g. sh:cp:bundles:promoted, HSET in recordBundle, HDEL wherever the meta field is deleted: dropBundleEntry, unrecordBundle, the expired sweep in admitBundle) would keep meta exactly as an older control plane reads it. It costs one more hmGet in the listing (it could go in the same MULTI). If you'd rather keep the 3-field meta, a line in upgrades.md saying that bundles promoted after this version are admin-only to delete after a rollback would be enough.

try {
bundles = (await cancellable(rt.cp.listConfigBundles(), opts.signal)).bundles;
} catch (err) {
return failed(io, err);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion — newer mocactl against an older control plane.

A control plane from before this PR has no GET /v1/config-bundles, so its router answers a bare 404 {"error":"not_found"}. describeError then reaches the show branch and prints just not_found. That's the same pattern isModelSwitchUnsupported / MODEL_SWITCH_UNSUPPORTED already handles for the model routes (core/messages.ts). Mapping status === 404 && code === 'not_found' here to something like "this control plane does not support listing bundles — upgrade it" (exit 1), plus a test, would make the version skew obvious.

*
* Unpaged on purpose. This zset is scored by EXPIRY, which a touch moves, so a score cursor could
* skip or repeat a digest mid-walk; the sessions index pages safely only because its score is an
* immutable promotedAt. N is bounded instead: the subject byte budget over MIN_BUNDLE_CHARGE_BYTES

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit — the sessions index is scored by createdAt (ownership.ts zAdd(ownerKey(rec.owner), { score: rec.createdAt, … })), not promotedAt. The PR body has it right.

@cwiklik
cwiklik merged commit e08aafd into rossoctl:main Nov 3, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature: mocactl bundles list to enumerate caller's live config bundles

2 participants