Repository navigation
feat: a Redis schema-version key, and the config bundle's format version carried and checked - #868
Conversation
…eck it
BUNDLE_FORMAT_VERSION was written only into lockfile.json, which the
store drops (ADR-0038), so no reader ever saw it. buildBundle now adds
a content entry, format.json ({"formatVersion":1}). It is content like
any other: the digest covers it and the store keeps it, and it records
the format, never the digest, so the digest does not depend on itself.
It sits at the bundle root, outside every prefix a reader acts on, so a
harness from before this change ignores it.
assertBundleFormat runs on verified content in prepareBundle (the
control plane's upload, answered with 400 invalid_request and the
reason) and in getBundle (the harness's read and attach), and refuses a
newer or malformed format. A bundle without the entry, built before it
existed, reads as version 1, so stored bundles and older clients keep
working.
Change policy and upgrades page updated.
Closes rossoctl#510
Assisted-By: Claude Code
Signed-off-by: Rong Chang <[email protected]>
Redis had no version marker, so a release rolled back past a stored-data change, or pointed at a Redis restored from a newer one, would misread keys it does not know. The key exists now, before the first change that needs one (change policy decision 6). sh:schema-version holds SCHEMA_VERSION (1). checkSchemaVersion writes it with SET NX when absent, accepts the same or an older version, and refuses a newer one or a value that is not a version. An older version is left as it is: the policy requires a release to read what the previous one wrote, and whether a bump should raise the stamp (locking the previous release out) is for the change that first bumps it. guardSchemaVersion runs the check on a short-lived client of its own once Redis answers, retrying while it does not, and exits the process on a refusal. The control plane, each worker and the relay arm it at start. It does not block boot, because every one of them already starts before Redis and waits for it. It never logs the URL. Change policy and upgrades page updated. Closes rossoctl#509 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
…uses writes checkSchemaVersion sent SET NX first, so a Redis that refuses writes (full under noeviction, a read-only replica, an ACL without SET) failed the check outright. guardSchemaVersion treated that error as an unreachable Redis and reconnected every 2 s forever, without ever checking the stamp. The check now GETs first and sends SET NX only when the key is absent. guardSchemaVersion now tells an error reply apart from a lost connection. A refusal leaves the version unknown, not newer, so the guard logs it once, naming the reply, keeps the process running, and retries with a back-off that doubles up to 60 s. A newer stamp is still refused when writes are. Docs: an absent key, with any sh: data, means version 1. The key has no TTL, so Redis needs a noeviction or volatile-* eviction policy, or the key must be re-stamped after a FLUSHALL or restore. A re-promoted workflow gets a new bundle digest once. Tests pin each entry point's guard call. Refs rossoctl#509 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Review at bb21603
This adds the Redis schema-version key (sh:schema-version, checked by the control plane, the P6 worker and the relay) and a format.json marker in config bundles, which upload and the harness read both check. I verified:
- The GET-then-SETNX logic and the race branch, and the strict version parsing.
- The guard's error-reply / unreachable split and its back-off.
- That the URL is never logged.
- That every entry point reads the same
REDIS_URLas its stores. - That
format.jsonsits outside every prefix the unpack and the overlay act on. - That the upload maps
BundleFormatErrorto 400 before theredis_unavailablefallback.
No defects in the code. Two non-blocking items: the harness-side refusal surfaces as a generic 500, and two lines in upgrades.md overstate what the guard does today.
Author: webchang (MEMBER, maintainer)
Areas reviewed: TypeScript (config-bundle, control-plane, server, sandbox-relay, harness tests), Docs
Agent/IDE config (.claude/.vscode): none
Commits: 3, all signed off: yes
CI status: all checks passing at submit time
- nit: the commit subjects carry no conventional prefix, and two are longer than 72 characters. The PR title is fine.
Drafted by an AI reviewer and approved by a human before posting.
| if (actual !== digest) throw new BundleDigestMismatchError(digest, actual); | ||
| // A format newer than this reader knows throws rather than unpacking a layout it would misread: | ||
| // the same "never degrade" rule as above (#510). No marker reads as version 1. | ||
| assertBundleFormat(entries); |
There was a problem hiding this comment.
suggestion: When the harness reads a bundle in a newer format, this throws BundleFormatError. But turnErrorStatus (packages/server/src/server.ts:518) maps only BundleNotFoundError to 410. Everything else becomes a 500 internal_error, logged as [turn] unclassified error. So "fails loudly" reaches the caller as a generic 500, and the upgrade hint is only in the server log. Consider a stable status and code (for example 409 or 422 config_bundle_unsupported), plus a server-side test.
There was a problem hiding this comment.
Fixed in 7edb826: on /v1/turn (and its /turn alias), a bundle in a newer or unreadable format now answers 422 config_bundle_unsupported, with the reason and what to upgrade in message, on the sync path and before the first SSE frame; tests cover both. 422 rather than 409, because the 409s here are states a retry can outlive, and on this route a 409 is TurnConflict, whose turnId clients attach to. The harness contract goes to 1.5.0, shipped with control plane 1.28.0.
| - **No schema version.** There is no schema-version key or migration tool for Redis. New fields are handled by | ||
| tolerant reads. The only versioned artefact at rest is the credential envelope (`v1.`). | ||
| - **Redis schema version.** Redis holds `sh:schema-version`, written by the first control plane, worker or relay to | ||
| start. A process that finds a version newer than it knows exits with the reason in its log, so a release rolled back |
There was a problem hiding this comment.
suggestion: "a release rolled back past a schema change fails at start" overstates two things.
(a) The guard runs in the background after the listener is up. The process serves until Redis answers and then exits, and it keeps running indefinitely if the write on an absent key is refused.
(b) checkSchemaVersion leaves an older stamp as it is, so on an existing deployment a future bump does not raise the stamp. A rollback is then refused only if that bump PR chooses to raise it.
change-policy.md words this correctly ("not supported"). Suggest matching it here and saying "exits once Redis answers" rather than "at start".
There was a problem hiding this comment.
Fixed in 04de0fd: it now says the check runs in the background once the process is serving and exits once Redis answers, and that a rollback past a schema change is not supported, refused only if the newer release raised the stored version, matching change-policy.md.
| and plain `kubectl rollout undo` also works. Redis data is not versioned, so a rollback across a data-format change | ||
| is untested. | ||
| and plain `kubectl rollout undo` also works. Redis data carries a schema version (above): a rollback | ||
| between releases that share it needs no step, and one past a schema change is refused at start. Rollback is otherwise |
There was a problem hiding this comment.
nit: Same point as above: "one past a schema change is refused at start" holds only if the bumping release raises the stored version, and this PR leaves that open. Suggest "is not supported (and is refused once a release raises the stamp)".
There was a problem hiding this comment.
Fixed in 04de0fd: it now reads "is not supported (and is refused once a release raises the stamp)".
A session whose promoted bundle is stored and intact but in a format this harness does not read made getBundle throw BundleFormatError, which turnErrorStatus did not classify: the caller got 500 internal_error and the upgrade hint was only in the server log. turnErrorStatus now maps it to 422 config_bundle_unsupported, with the error's own sentence (versions found and known, what to upgrade) as the body's message, on the sync path and before the first SSE frame. 422, not 409: the 409s here are state a retry can outlive (turn_in_progress, template_not_active), and on /v1/turn a 409 is TurnConflict, whose turnId a client attaches to; 422 is what policy_refused and workload_refused use for a refusal no retry fixes. harness-openapi.yaml goes to 1.5.0 with the new 422, shipped with control plane 1.29.0 (main is at 1.27.0 and 1.28.0 is claimed by an open PR), whose section also records the upload's existing 400 invalid_request for a newer format. Refs rossoctl#509 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
The guard runs in the background once a process serves: it retries until Redis answers and then exits on a newer version, and it runs on if Redis refuses the write on an absent key. checkSchemaVersion leaves an older stamp as it is, so a rollback is refused only if the bumping release raises the stamp. Say so, matching change-policy.md, instead of "fails at start" and "is refused at start". Refs rossoctl#509 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
Main took 1.27.0 (rossoctl#864, the base URL's page), so this PR's contract version is 1.28.0, the next free one (it was 1.29.0 while rossoctl#874 held 1.28.0; whichever merges second renumbers). Its section goes above 1.27.0, and the change-policy list keeps both entries. rossoctl#863 made /turn a documented alias of POST /v1/turn, response by response, so the alias gets the new 422 too (the alias contract test caught it). Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
rossoctl#868 took 1.28.0 (the config bundle's format version, harness 1.5.0), so this PR's per-source bound on login starts is 1.29.0: its CHANGELOG section goes above 1.28.0, openapi.yaml and change-policy say 1.29.0, and the change-policy list keeps both entries in order. Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
Brings 25 upstream merges since 1aa8dd6, among them the sbx OIDC identity provider (rossoctl#851), the Redis schema-version key and config bundle format marker (rossoctl#868), the provisioner Redis ACL user (rossoctl#869), the relay keepalive env (rossoctl#866), the per-source OIDC pending bound with the forwarded-headers Route pin (rossoctl#874), the egress refusal hints and control-plane index (rossoctl#864), the empty-workspace sweep (rossoctl#872) and the orphan-sweep log split (rossoctl#849). No conflicts. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
Closes #509
Closes #510
Both follow-ups come out of the change policy (
docs/reference/change-policy.md, decisions 6 and 7). There are three commits: one per issue, then review fixes to the schema-version check and its docs.What changed and why
#510: the config bundle's format version survives upload and is checked on read
BUNDLE_FORMAT_VERSIONused to live only inlockfile.json. The store drops that file (ADR-0038), so no reader ever saw the version.buildBundlenow adds a content entry,format.json({"formatVersion":1}), inpackages/config-bundle/src/format.ts. It is content like any other: the digest covers it and the store keeps it. It records the format and never the digest, so the digest still does not depend on itself (the concern in the comment oncontentDigest).skills/,prompts/,context/,prompt/,memory/). A harness from before this change ignores it, so the previous release can still read bundles built by this one.assertBundleFormatruns on digest-verified content in two places. InprepareBundleit guards the control plane's upload:POST /v1/config-bundlesanswers400 invalid_requestwith the reason, the earliest point the client that built the bundle can be told. IngetBundleit guards the harness's read, which is the attach path throughresolvePromotedConfig/attachPromotedConfig. A newer format, or a marker that is not a positive integer, throwsBundleFormatErrorand nothing is unpacked.format.jsonreads as version 1. That covers bundles already stored and bundles built by older clients.upgrades.mdsays so.#509: a schema-version key in Redis
packages/control-plane/src/schema-version.tsaddssh:schema-version(prefixsh:, likesh:sandbox:records) withSCHEMA_VERSION = 1.checkSchemaVersionreads the key first and writes it withSET NXonly when it is absent, so concurrent first starts agree. It accepts the same version or an older one, and throwsSchemaVersionErroron a newer version or on a value that is not a version. A key that is absent, even with othersh:data present, means version 1: every release before this key wrote version-1 data.noeviction(OOM command not allowed), a read-only replica (READONLY), and an ACL user withoutSET(NOPERM).guardSchemaVersionruns that check on a short-lived client of its own once Redis answers. It keeps two kinds of failure apart:SET NXon an absent key in a Redis that refuses writes): the version is unknown, not newer. The guard logs this once, naming the reply, keeps the process running, and retries with a back-off that doubles up to 60 s. The check lands once the refusal clears.exit(1). It never logs the URL, which carries the password. The control plane (main.ts), each P6 worker (packages/server/src/worker.ts) and the relay (packages/sandbox-relay/src/main.ts) arm it at start. It does not block boot: each of these already starts before Redis and waits for it (P6 on Kubernetes, slice 1: supervisor, relay, Redis, control plane and container sandboxes as K8s workloads #423), and refusing to start while Redis is merely absent would be a new failure mode. The workers check too, not only the control plane, because a deployment without the control plane (the compose trial without its profile) still has workers writing sessions.docs/reference/configuration.mdis unchanged.REDIS_URLis the only input, read as each component already reads it.change-policy.md, the "contract today" bullets now describe both markers, a short "Version markers" section says when each is bumped and what readers do, and decisions 6 and 7 are marked done. Indocs/operations/upgrades.md, the version-skew and rollback notes are updated.sh:data, means version 1.noevictionorvolatile-*eviction policy. Underallkeys-*the key can be evicted.FLUSHALL, or a restore that lost the key, re-stamp it with the data's version. Otherwise the next process to start stamps its own version, which after a future bump could put an old version over newer data.Choices the policy leaves open, made here and easy to change
SCHEMA_VERSIONshould raise the stored value, and so lock the previous release out, depends on whether that change is still readable by the previous release. Only that change knows, so it is left to it. The decision is theolderbranch ofcheckSchemaVersion.0,1.0," 1",2x, an empty string) are refused like a newer version, rather than overwritten.400 invalid_requestwith a message naming the version. I did not add a new error code, so the OpenAPI document and its version are unchanged.Tests
New and extended tests:
packages/config-bundle/test/format.test.ts(17 tests).buildBundlewritesformat.json, and it survivesprepareBundle(the lockfile does not). The digest covers the marker. For a bundle without the marker, with an older version, with the current version, with a newer version, or with a malformed marker: accepted, accepted, accepted, refused, refused.prepareBundleandgetBundleboth refuse a newer format and read a bundle without the marker.packages/control-plane/test/handlers-config-bundles.test.ts: an upload in a newer format getsinvalid_request, the message names the version, and nothing is stored.harness/test/config-resolver.test.ts:resolvePromotedConfigrejects a stored bundle in a newer format and unpacks nothing. It applies a bundle without the marker and one in the current format, and the marker turns up in neither the context nor the prompt fragments.packages/control-plane/test/schema-version.test.ts(28 tests).SET NXhas its version classified.OOM,READONLY,NOPERMonSET), the current version is still checked by GET alone, a newer version is still refused, and a refused write on an absent key comes through as an error reply rather than a version error.guardSchemaVersion: it retries until Redis answers and closes its client, reports the outage only once, exits 1 on a newer version (also when writes are refused), and runs on against an older one. On a refused write to an absent key it logs once, does not exit, and writes the key once the refusal clears. Its back-off doubles up to the cap (fake timers). It never logs the password.main.ts, the server'sworker.ts, the relay'smain.ts) callsguardSchemaVersioninside its main-module block and names its component.Before the fix (source reverted, new tests kept, on
0eee39b0):format.test.ts: 10 failed, 7 passed. For example:expected undefined to be '{"formatVersion":1}\n'. The built bundle had no marker.expected { status: 201, … } to match object { code: 'invalid_request' }, because a newer-format bundle was stored. Every schema-version test failed, because there is no key or check on main.SET NXbeforeGET: 8 of 28 failed. The "exits on a newer version even when Redis refuses writes" test hit the 5 s timeout, because that version retried forever without ever checking.config-resolver.test.ts: 1 failed (promise resolved "{ …(7) }" instead of rejecting). A newer-format bundle was unpacked and applied. The two acceptance tests passed, as they should.After the fix, all of these pass. Full suites (clean environment, pnpm 9):
@moca/config-bundle@moca/control-plane@moca/harness@moca/server(includes the env-name guard)@moca/sandbox-relaytsc --noEmitis clean for config-bundle, control-plane, harness, server, sandbox-relay and mocactl.python3 scripts/check-doc-links.pyreports 0 broken links, and Prettier passes on all changed files.The real Redis client was also checked against a disposable Valkey 9 container. Each line below is one run of the guard:
That last run exited 1. I then ran it against an ACL user allowed
GETbut notSET:The
ro-newerrun exited 1, and thero-absentrun was still running 2.5 s later. Against a closed port the guard loggedredis schema version not checked yet (connect ECONNREFUSED …); retryingonce and the process kept running.Out of scope
guardSchemaVersioncall.configRef) still checks only that the bundle exists. The format is enforced at upload and at the harness's read, so the control plane does not need to fetch the whole bundle at create time.format.jsonmust be on its list.Every commit is signed off (DCO).
Assisted-By: Claude Code