Repository navigation
Fix: persist Redis so a setup-vm.sh re-run keeps every session - #607
Conversation
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Summary
The persistence half is right: a named volume plus AOF, a non-destructive re-run when the container already matches, and a Compose path that matches the k8s and VM paths. The adoption design (SAVE, then an appendonly-off conversion, then CONFIG SET appendonly yes) is also well reasoned. One blocking problem: the migration path the PR advertises can't be reached the way the warning and the docs tell operators to use it. The default run already replaces the pre-#410 container with one on moca-redis, so a follow-up SH_REDIS_ADOPT_VOLUME=1 run finds a matching container and does nothing. The adoption sequence also has two failure-path gaps (details inline).
Author: cwiklik (MEMBER — maintainer)
Areas reviewed: Shell (setup-vm.sh, its test, compose test, smoke.sh), YAML (docker-compose.yml), Docs (vm README, P4-ON-P6.md, demo, maturity table)
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: passing (all 14 checks green, including shellcheck and deploy-scripts)
Must-fix
-
adopt_redis_volumeis unreachable after the default run (setup-vm.sh:291, P4-ON-P6.md:630, README.md:672). On a pre-#410 host, the first re-run without the flag warns and thenstart_redisrunspodman run --replace … -v moca-redis:/data. From then on,redis_container_diffreturnsmatches, sosudo env SH_REDIS_ADOPT_VOLUME=1 ./deploy/vm/setup-vm.sh(exactly what the warning prints) keeps the running container and never migrates. The old sessions are left on an orphaned anonymous volume, and the only remaining route is the by-hand recipe. Even if adoption could run at that point, it would copy over amoca-redisthat already holds sessions created since the first run. Possible fixes:- (a) On the default path, leave the anonymous-volume container running and stop with the warning until the operator picks
SH_REDIS_ADOPT_VOLUME=1, or an explicit opt-out such as=0that starts fresh. - (b) Let the flag name an orphaned volume to adopt from (
SH_REDIS_ADOPT_VOLUME=<volume>), and refuse it whenmoca-redisis non-empty.
Either way, add a test case for the warn-then-re-run-with-flag sequence: that's the path operators will actually take, and today's tests only cover the flag on the first run.
- (a) On the default path, leave the anonymous-volume container running and stop with the warning until the operator picks
Non-blocking: the adoption path has no failure handling (stopped sh-redis, a leftover sh-redis-adopt, and a re-run that then dies at SAVE). The AOF-rewrite wait goes on to SHUTDOWN NOSAVE even after it times out. And the *appendonly* glob also matches --appendonly no.
| "host installed before #410 does). This run starts Redis on the named volume" \ | ||
| "'$MOCA_REDIS_VOLUME' instead, so those sessions become unreachable -- they are NOT" \ | ||
| "deleted, and podman keeps the old volume until you remove it. To migrate them into the" \ | ||
| "named volume, re-run with: sudo env SH_REDIS_ADOPT_VOLUME=1 $0" >&2 |
There was a problem hiding this comment.
must-fix: this advice can't work after this run. When adopt_redis_volume returns, start_redis replaces sh-redis with the moca-redis container (L378). The next run's redis_container_diff then reports matches (image, port, volume and --appendonly all line up), so start_redis returns at L374 before adopt_redis_volume is ever called, and the SH_REDIS_ADOPT_VOLUME=1 re-run printed here is a no-op. The anonymous volume stays orphaned. Also, by then moca-redis already holds the sessions created since this run, so adopting into it afterwards would overwrite them anyway. Suggest either not replacing the container on this path (keep the old one running and exit non-zero with this warning until the operator chooses =1 or an explicit =0/fresh start), or letting the flag name an orphaned volume and refusing a non-empty moca-redis. Please also add a test for the warn → re-run-with-flag sequence.
| leaves that volume in place and starts the named one empty, so the control plane's session and | ||
| ownership index reads as gone (the workspaces stay under `/srv/workspaces` until idle reclaim, | ||
| orphaned). Nothing is deleted — re-run once with | ||
| `sudo env SH_REDIS_ADOPT_VOLUME=1 ./deploy/vm/setup-vm.sh` to migrate it. Do that before a demo, |
There was a problem hiding this comment.
must-fix (same root cause as setup-vm.sh:291): after "the first re-run warns … starts the named one empty", sh-redis is already on moca-redis and matches, so re-running "once with SH_REDIS_ADOPT_VOLUME=1" doesn't migrate anything. Whatever the fix in setup-vm.sh turns out to be, this sentence (and README.md:672) should describe the order that actually works, which today is: pass the flag on the first post-#410 run.
| previous one: those sessions were unreachable but never deleted, and a long-lived rig can hold a | ||
| stack of them (`podman volume ls`). | ||
|
|
||
| On such a host the first re-run warns that it is leaving that volume behind and starts the named one |
There was a problem hiding this comment.
must-fix (same as setup-vm.sh:291): "the first re-run warns … To migrate the sessions in it instead, re-run once with" reads as "run it plainly, then run it again with the flag", and that second run is a no-op once the first has replaced sh-redis. If the flag has to be on the first run, say so explicitly, and say what to do if that run has already happened (the by-hand recipe below, aimed at the right orphan).
| # SAVE first, synchronously: the dump.rdb on disk is otherwise as old as the last save point, so | ||
| # copying without this silently drops the most recent sessions -- the ones most likely to matter. | ||
| podman exec sh-redis redis-cli SAVE | ||
| podman stop sh-redis |
There was a problem hiding this comment.
suggestion: from this point on, nothing undoes a failure. If anything later fails under set -e, say the cp (no dump.rdb, e.g. a host whose Redis never hit a save point), the PING loop running out, or CONFIG SET, the script exits with sh-redis stopped, and possibly with sh-redis-adopt still running on moca-redis. The re-run that the error invites then fails at L297, because podman exec on a stopped container errors, and the flag wedges the installer. Consider a trap or explicit error path that removes sh-redis-adopt and podman starts sh-redis again, and/or podman start sh-redis before the SAVE when it isn't running.
| for ((i = 0; i < 60; i++)); do | ||
| [[ "$(podman exec sh-redis-adopt redis-cli INFO persistence 2>/dev/null | | ||
| sed -n 's/^aof_rewrite_in_progress:\([0-9]*\).*/\1/p')" == 0 ]] && break | ||
| sleep 1 |
There was a problem hiding this comment.
suggestion: if this loop runs out its 60 s with the rewrite still in progress (a large dataset, or slow disk), execution falls through to SHUTDOWN NOSAVE. That's exactly the partial-AOF/silently-empty outcome the comment above warns about, and the next log line says "adopted". Please check aof_rewrite_in_progress:0 and aof_last_bgrewrite_status:ok after the loop, and fail (leaving the old volume untouched) when either doesn't hold.
| out+=("/data volume is '$volume', expected $MOCA_REDIS_VOLUME") | ||
| fi | ||
| fi | ||
| [[ "$appendonly" == *appendonly* ]] || out+=("it runs without --appendonly yes") |
There was a problem hiding this comment.
nit: *appendonly* also matches a container created with redis-server --appendonly no, which would then read as matching and never be fixed. *'--appendonly yes'* matches only what L380 actually creates.
|
Thanks — the must-fix was real, and worse than a doc problem: the warning made its own advice unreachable, so there was no sequence of runs that ever migrated anything. Fixed in fb723a2. Per item
EvidenceEach of the four fixes was mutation-tested — reverting any one of them fails the suite (restoring warn+continue fails with the exact "advice unreachable" case; dropping the timeout check, the rollback, or the glob each fail too). The mocks only pin shape and order, so I also probed real podman with a seeded pre-#410
One note: the rewrite-timeout case spun the real 60s loop and took the suite from 17.5s to 78s, so the two retry caps are env knobs (
Assisted-By: Claude |
|
Heads-up on the red The cause is the Evidence it is time, not this diff: Split the fix out as #608, since it is Assisted-By: Claude |
start_redis ran `podman run --replace` unconditionally, with no named volume. Redis holds the control plane's session and ownership index, the harness session state, the lease store and sh:sandbox:records -- so every re-run silently forgot every user's sessions. A re-run is also the documented way to apply a changed control-plane.env, which made the installer's own procedure destructive. Seen twice in one run during the P6.3 acceptance (rossoctl#425). Redis now runs on a named volume (MOCA_REDIS_VOLUME, default moca-redis) with `--appendonly yes`, matching what the Kubernetes path already did (PVC in deploy/k8s/base/redis.yaml plus appendonly in deploy/k8s/setup.sh). And a re-run no longer replaces a container that already matches: redis_container_diff inspects the image, published port, /data volume and appendonly setting, leaves an identical container alone, and names the differing field when it does replace one -- otherwise an operator sees their Redis recreated with no way to tell why. Two corrections to the issue's own premises, both from live podman probes: 1. redis:7-alpine declares VOLUME /data, so the old form orphaned data on a fresh anonymous volume rather than destroying it -- the rig accumulated 11. Those sessions are recoverable, so SH_REDIS_ADOPT_VOLUME=1 migrates them. Off by default: the installer warns about the old volume rather than rewriting live data unasked. 2. The recovery recipe on rossoctl#410 ("copy dump.rdb in, start Redis") yields an EMPTY Redis once AOF is on, because Redis 7 loads the AOF and ignores an existing dump.rdb -- probed to DBSIZE=0. The order that works, and the order the adoption path implements and the tests pin: start with appendonly OFF so the RDB loads, CONFIG SET appendonly yes, then `--appendonly yes` thereafter. This had to land in the README too, or the next operator follows a documented procedure into an empty Redis. The anonymous volume is detected via `volume inspect --format {{.Anonymous}}`, not from the mount: podman reports an anonymous volume's .Name as a 64-hex id, indistinguishable from a name an operator chose. Reverting that read makes the adoption path unreachable on every real host, which the new tests catch. Compose gets the same volume and appendonly, since its "no volume, same as the VM path" justification no longer holds. Closes rossoctl#410 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: cwiklik <[email protected]>
The first cut warned and carried on. That made its own advice unreachable: the warning run replaced sh-redis with the moca-redis container, so every later run's redis_container_diff said `matches`, start_redis returned early, and the SH_REDIS_ADOPT_VOLUME=1 re-run the warning printed migrated nothing. With no flag the installer now STOPS and changes nothing, naming both routes (=1 migrate, =0 start fresh). start_redis propagates the refusal, so the run aborts under set -e rather than replacing the container out from under it. Also from review: - refuse to adopt into a non-empty MOCA_REDIS_VOLUME, which would otherwise overwrite sessions created since the first post-rossoctl#410 run; - roll back a failed migration (remove sh-redis-adopt, drop the half-written volume, restart sh-redis), so the re-run the error invites can succeed -- and `podman start sh-redis` before SAVE, since `podman exec` on a stopped container was what wedged it; - treat an AOF-rewrite timeout as a FAILURE instead of falling through to SHUTDOWN NOSAVE and logging "adopted" over a partial AOF; check both aof_rewrite_in_progress and aof_last_bgrewrite_status; - match `--appendonly yes` exactly, not a bare *appendonly* glob that also matched `--appendonly no` and would have kept persistence off forever. Verified against real podman on a seeded pre-rossoctl#410 container: the refusal leaves it running on its anonymous volume with the key readable and no moca-redis created; a forced mid-migration failure restores that same state; adoption migrates the key with aof_enabled=1; the next run is a no-op; and the key survives a restart. Each of the four fixes was mutation-tested -- reverting any one of them fails the suite. The rewrite-timeout case spun the real 60s loop, so the two retry caps are env knobs (defaults unchanged); the suite is back to 17.5s from 78s. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: cwiklik <[email protected]>
fb723a2 to
619c591
Compare
|
@ingpaolodettori-dev ready for re-review when you have a moment. All 6 review comments are addressed in CI is now 14/14 green. The earlier
|
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Follow-up on 619c591 (rebase of 51fb054+fb723a2 onto main d8bc58b).
git range-diff shows both commits =, and the PR's own files are byte-identical to fb723a2. The only blocker from the last round was the red deploy-scripts, and that was the Ubuntu 26 systemd-analyze breakage fixed by #608, as you said. It is green on this head.
All 6 items from the 51fb054 review were verified fixed at fb723a2: refuse-without-flag with the =1 re-run that actually migrates (docs aligned), =0 opt-out, checked steps with rollback that restarts sh-redis, AOF-rewrite timeout/aof_last_bgrewrite_status failing the adoption, and the exact --appendonly yes glob.
Approving, which clears our earlier CHANGES_REQUESTED. One non-blocking suggestion inline (the non-empty-target probe fails open, and the rollback's volume rm --force makes that dangerous), fine as a follow-up.
| # differs between rootful and rootless podman. | ||
| redis_adopt_target_nonempty() { | ||
| podman volume exists "$MOCA_REDIS_VOLUME" 2>/dev/null || return 1 | ||
| [[ -n "$(podman run --rm -v "$MOCA_REDIS_VOLUME:/data" --entrypoint sh \ |
There was a problem hiding this comment.
suggestion (carried over from the fb723a2 round, still open): this probe fails open. If the podman run itself fails (a pull or storage error, a volume that can't be mounted, a podman hiccup), stdout is empty, the target reads as "empty", and adoption goes ahead. The probe exists to protect the case where moca-redis already holds data, and that's exactly where it does harm: if redis_adopt_migrate then fails at any step, redis_adopt_rollback runs podman volume rm --force "$MOCA_REDIS_VOLUME" (L435) and deletes the sessions that were already there. Suggest treating a failed probe as "not empty" (or as an error), e.g. capture the output and the exit status separately and return 0 when the run fails. Also consider having the rollback remove the volume only if this run created it (volume exists before volume create), so a failed adoption can never destroy data it didn't write. Not blocking; fine as a follow-up.
Summary
start_redisranpodman run --replaceunconditionally, with no named volume. Redis holds the control plane's session and ownership index, the harness session state (@moca/session-backend), the lease store andsh:sandbox:records— so every re-run silently forgot every user's sessions. A re-run is also the documented way to apply a changedcontrol-plane.env(deploy/vm/README.md,deploy/microvm/P4-ON-P6.md), which made the installer's own procedure destructive. Seen twice in one run during the P6.3 acceptance (#425).Two changes, both of which the issue asks for:
Persistence. Redis now runs on a named volume (
MOCA_REDIS_VOLUME, defaultmoca-redis) with--appendonly yes— matching what the Kubernetes path already did (PVC indeploy/k8s/base/redis.yaml,appendonly yesindeploy/k8s/setup.sh). The volume alone would not be enough: without AOF, Redis snapshots only on itssavepoints, so a reboot still drops the last window's writes out of a volume that was kept.A re-run is non-destructive.
redis_container_diffinspects the image, published port,/datavolume and appendonly setting; an identical container is left alone, and when one does get replaced the log names the field that differed — otherwise an operator sees their Redis recreated with no way to tell why. This matches the contract the rest of the installer already keeps (install_env_filenever clobbers an operator-edited env file).This closes the gap
docs/reference/maturity-and-lifecycle.mdnames as a Single-VM promotion blocker.Two corrections to the issue's own premises, both verified by live podman probe (6.1.1, arm64)
1. The data was orphaned, not destroyed. As @pdettori noted,
redis:7-alpinedeclaresVOLUME /data, so each--replacegot a new anonymous volume and orphaned the last — the rig accumulated 11. Those sessions are recoverable, which is what makes an opt-in adoption path worth building:SH_REDIS_ADOPT_VOLUME=1migrates them. It is off by default — the installer warns about the old volume, naming it and the flag, rather than rewriting live data unasked.2.⚠️ The recovery recipe in that comment becomes wrong the moment AOF is on. With
--appendonly yes, Redis 7 ignores an existingdump.rdband loads the empty AOF instead. I probed both paths:dump.rdbinto a fresh volume, start with--appendonly yesDBSIZE=0,GET=[]— silently emptyCONFIG SET appendonly yesDBSIZE=1,GET=[old-session],aof_enabled=1So "copy
dump.rdbin, start Redis" yields an empty Redis after this change, and a naive--appendonly yesover the rig's live volume would discard the very sessions we are saving. The second order is whatadopt_redis_volumeimplements, what the tests pin, and what the README now documents — with an explicit "do not just copy adump.rdbin" warning, or the next operator follows a documented procedure into an empty Redis.A detection detail worth recording: the anonymous volume is identified via
podman volume inspect --format '{{.Anonymous}}', not from the mount. podman reports an anonymous volume's.Nameas a 64-hex id — indistinguishable from a name an operator chose. My first cut assumed an empty.Name, which would have made the adoption path unreachable on every real host. The new tests catch that: reverting the.Anonymousread reproduces exactly that bug and the suite fails.Compose
deploy/compose/docker-compose.ymljustified having no volume as "No volume, same as the VM path" — a premise this change removes, so it gets the same named volume and appendonly. Separable: say the word and I'll drop this half if you'd rather compose stay throwaway.Tests
Six new cases in
deploy/vm/tests/setup-vm.test.sh, in the file's existing style (mock argv asserted out of$MOCK_LOG):sh-redisissues norun/rm/stop— the issue's own acceptance item;/datamount, missing appendonly) replaces it and says which field differed;-v moca-redis:/dataand--appendonly yes;SH_REDIS_ADOPT_VOLUME=1, the recorded order isSAVE→ stop → copy → appendonly-off conversion →CONFIG SET appendonly yes→ final run. The order is the part that was wrong in the issue's recipe, so it is what the test pins;Honest limitation: the suite mocks podman entirely, so it pins the shape and order of the adoption, not Redis's own loading behaviour. That is established by the live probes above — including the full end-to-end adoption against a seeded pre-#410 container (no
-v, no appendonly), which read backGET=[old-session]withaof_enabled=1. Both probes cleaned up fully.Verification
bash deploy/vm/tests/setup-vm.test.shbash deploy/compose/tests/compose.test.shshellcheck -S warning(the 4 touched scripts)prettier --check(the 6 touched docs/YAML)make test-deploymake test-deployfails 2 assertions indeploy/microvm/tests/build-snapshot.test.sh(the snapshot-publish scenarios). Both are pre-existing and unrelated: identical failures on a stashed clean tree, in a file this PR does not touch, and CI is green on691c866d— my exact base. They look like a macOS-host artifact of that harness's non-rootinstall/permission shimming.No
.go,.protoor TypeScript touched, so thebuf/gofmt/pnpmgates are unaffected. No rig needed — the single-VM path's tests are cluster-free and root-free by design.Out of scope
Backup and upgrade guides — the other half of the Single-VM promotion gap in
maturity-and-lifecycle.md. Worth its own issue.Closes #410
Assisted-By: Claude Code