Repository navigation
feat(mocactl): list your own config bundles (bundles list) - #678
Conversation
`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]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
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}` }); |
There was a problem hiding this comment.
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:
deleteConfigBundlereturns 403 forbidden to the uploader, becauseowner !== subjectHash(p.sub). Only an admin can free those bundles, which is the feature:mocactl bundles listto enumerate caller's live config bundles #559 situation again.refreshBundle/dropBundleEntryact on a stray keysh: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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
Closes #559.
The problem
mocactl bundlesonly haddelete DIGEST, keyed by a digest the caller must already hold. A crash betweenmocactl promotereturning 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-bundlesandmocactl bundles list [--json], reading the per-owner budget zsetrecordBundlealready maintains — no keyspace scan, no new index.Two design points worth review attention
1.
promotedAtis stored, not derived from the score. The zset score is expiry, andtouchBundlepushes it tonow + TTLevery time a session uses the bundle. Soscore - TTLwould report a three-week-old orphan as promoted today — the opposite of useful for spotting one.promotedAtbecomes a third meta field written only byrecordBundle, so a touch cannot move it;expiresAtcomes from the score, which the score does honestly answer.parseMetastill accepts the 2-field legacy value and reportspromotedAt: 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 overMIN_BUNDLE_CHARGE_BYTES— and the read costs two round trips whatever N is.Behaviour notes
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.BYTESis the charge (compressed, floored at 4 KiB), not the size of the caller's directory; documented as such.promotetool write storage directly, keep no budget entry, and so do not appear — the same population only an admin can delete.| wc -lanswers 0;--jsonprints{"bundles":[]}.Verification
tsc --noEmit, both packagesprettier --checkon all 18 filescheck-doc-links.pyMutations used: dropping the owner
zRemfromdropBundleEntry; havingrefreshBundlerewritepromotedAt; 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 nullpromotedAt; printing the empty-listing message to stdout. The owner-match mutation survived the first pass, which is whydrops a member of my index whose meta names another subjectexists.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.tsandsbx-up-cortex.test.tswithwaitFor/ 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