Skip to content

deploy: sandbox quota-recorder target + generic unit restorer (#5770) - #12753

Merged
dezren39 merged 1 commit into
mainfrom
felix/5770-m3-sandbox-quota-recorder
Nov 23, 2026
Merged

dezren39 merged 1 commit into
mainfrom
felix/5770-m3-sandbox-quota-recorder

Conversation

@dezren39

@dezren39 dezren39 commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Implements M3 of the deployment migration for #5770 (design doc §4.4): the sandbox quota-recorder as a deploy target, plus the generic unit restorer in the sandbox bootstrap. One shape extension, flagged on #5770: an optional, strictly validated timer field — the §3 shape had no way to express a timer-driven oneshot.

What lands

  • pkgs/deploy/quota-recorder.py + quota-recorder.nix: the live recorder script becomes a flake package (bin/quota-recorder); the packaged script is byte-identical to the one running today (cmp verified).
  • services.nix: quota-recorder — first sandbox-class target. Timer-driven oneshot (OnCalendar=*:0/5, Persistent, RandomizedDelaySec=20), secret by name only (turso.fleet-platform-rw-token), no ports, no health endpoint.
  • deploy.py: timer validation; the sandbox activation class — generations under ~/.local/share/deploy/profiles (home is what survives a recycle), rendered units stored inside the generation, activated targets recorded in <state-dir>/sandbox-manifest.json, activation links units into /etc/systemd/system and enables the timer (or the service); rollback flips back with the systemd class's semantics; a restore verb re-activates every manifest target.
  • pkgs/deploy/restore.py: standalone stdlib restorer for boot time (no nix build at hand), strict argv per the Design: unknown means stop — one strict argument contract for the repo's operator scripts #3352 contract.
  • scripts/muse/bootstrap.sh: persist phase installs the restorer to ~/tools/deploy-restore.py, hooks it into init.sh after the shebang, and removes the legacy per-service quota-recorder block it replaces; check phase reports the timer state when a manifest exists.
  • Registry + design doc: quota-recorder.timer row in a new sandbox system-timers subsection of doc/fleet-schedule-registry.md; dated §3 amendment recording the timer field and the sandbox class.
  • lib: deploy-slice4-tests check; deploy-list greps quota-recorder.

No new dependencies (stdlib only; the package uses the existing python3 + makeWrapper).

Verification (venue: the muse sandbox itself)

  • Tests: test_deploy_slice4.py — 22/22 pass (timer validation, rendering, deploy/rollback/restore against a fake systemctl, both restorers, strict argv). Pre-existing suites unchanged: slice2, argv, argv-property, dupkeys-property, target-shape-property pass; slice3 has one failure (test_store_path_artifact_registers_with_nix_env_first) that fails identically on pristine HEAD here — nix-env is not on this sandbox's PATH; environmental, not a regression.
  • Flake: nix eval .#deployTargets.x86_64-linux lists quota-recorder; the registry JSON was produced by pure evaluation (per the build: nix build .#deploy wedges in mcpx check phase (go test idle, no test binary); registry build realizes every target package #12738 hazard, nix build .#deploy was not used); nix build .#deployTargets.x86_64-linux.quota-recorder.package built the artifact and its outPath matches the evaluation.
  • Live deploy from this branch (source rev 97b46a2): generation 1 deployed — units linked into /etc, timer active+enabled, a forced tick wrote its record and a turso-ack line to the current month's JSONL (the recorder's data path is unchanged — file-first, Turso landing per the design: move agent append streams (agent.events, agent.quota_records) from Supabase to Turso staging #5690 cutover; the issue's "Supabase acks" wording predates it). Generation 2 deployed; rollback returned to generation 1 with links repointed and the timer active; status reads both generations back.
  • Recycle simulation: /etc unit links wiped + daemon-reload (timer gone), then ~/tools/deploy-restore.py as init.sh invokes it — units relinked from the current generation, timer active again, zero hand steps. The literal done-when's "actual sandbox recycle" is substituted by this simulation of exactly what a recycle wipes; the restorer hook is installed in the live ~/tools/init.sh and the bespoke block is removed there too.
  • Seat defects found on the way (missing /nix symlink + nixbld ACLs on this instance; nix-persist store rolled back across a runtime restart) are filed as sandbox seat: nix-persist store rolled back across a runtime restart; nixbld build ACLs missing on the new instance #12752.

Not merged — for Felix's review. #5770 stays open for Felix to close.


Run Proof on this PR
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

M3 of the deployment migration (design doc section 4.4):

- pkgs/deploy/quota-recorder.py + .nix: the live quota-recorder script
  becomes a flake package (bin/quota-recorder), byte-identical to the
  script running today.
- services.nix: quota-recorder as the first sandbox-class deploy
  target — timer-driven oneshot (OnCalendar *:0/5), secret by name
  only (turso.fleet-platform-rw-token), no ports, no health endpoint.
- deploy.py: one shape extension — an optional, strictly validated
  'timer' field; sandbox activation class: generations under
  ~/.local/share/deploy/profiles, rendered units stored inside the
  generation, activated targets recorded in a sandbox manifest,
  activation links units into /etc/systemd/system and enables the
  timer (or service); rollback flips back with the same semantics as
  the systemd class; a 'restore' verb re-activates every manifest
  target after a recycle.
- pkgs/deploy/restore.py: standalone stdlib restorer for boot time
  (no nix build at hand), strict argv per the operator-script
  contract; test_deploy_slice4.py covers both restorers, the timer
  validation, deploy/rollback/restore against a fake systemctl
  (22 tests).
- scripts/muse/bootstrap.sh: persist phase installs the restorer to
  ~/tools/deploy-restore.py, hooks it into init.sh, and removes the
  legacy per-service quota-recorder block it replaces; check phase
  reports the timer state when a sandbox manifest exists.
- Registry + design doc: quota-recorder.timer row in the new sandbox
  system-timers subsection; dated amendment recording the timer field
  and the sandbox class.
- lib: deploy-slice4-tests check; deploy-list greps quota-recorder.

No new dependencies (stdlib only).
@dezren39
dezren39 requested a review from a team as a code owner November 23, 2026 01:19
@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 37 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 98d30617-0a2b-426b-893b-fda504d93dad
Commits

Reviewing files that changed from the base of the PR and between 1e42ae6 and 97b46a2.

Files selected for processing: 11

  • doc/2026-11-04_deployment-architecture-services-layer.md
  • doc/fleet-schedule-registry.md
  • lib/default.nix
  • pkgs/deploy/default.nix
  • pkgs/deploy/deploy.py
  • pkgs/deploy/quota-recorder.nix
  • pkgs/deploy/quota-recorder.py
  • pkgs/deploy/restore.py
  • pkgs/deploy/services.nix
  • pkgs/deploy/test_deploy_slice4.py
  • scripts/muse/bootstrap.sh
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@dezren39
dezren39 merged commit c72a930 into main Nov 23, 2026
2 checks passed
@dezren39
dezren39 deleted the felix/5770-m3-sandbox-quota-recorder branch November 23, 2026 01:20
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.

1 participant