fix(server): supervise background service updates - #5171
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
There was a problem hiding this comment.
One convention issue found in the new apps/server/src/cloud/systemdSelfUpdate.ts error model. Everything else (namespace imports, Migrations.ts / client-runtime error classes, CLI-boundary layer provision) matches the conventions.
Posted via Macroscope — Effect Service Conventions
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 70c2420. Configure here.
ApprovabilityVerdict: Needs human review This PR introduces a new supervised systemd self-update mechanism with automatic rollback capability, database migration validation, and a new readiness endpoint. The scope and complexity of these infrastructure changes—new CLI commands, systemd orchestration logic, and cross-package modifications—warrant human review. You can customize Macroscope's approvability policy. Learn more. |
[gpt-5.6-sol] RESPONDING ON BEHALF OF THEOFollow-up audit feedback identified two rollback gaps, both addressed in cd25a3d:
The systemd lifecycle is now covered by an opt-in acceptance test using uniquely named disposable host/helper units. It passed both a real successful handoff and a real rollback where the candidate bound HTTP but withheld runtime readiness ( Focused unit tests, server/contracts typechecks, formatting, and targeted lint also pass. |

A boot-service self-update currently edits and restarts
t3code.servicefrom inside that service's own cgroup. systemd can terminate the restart child during teardown, which makes the request process restore the old unit and leaves remote clients waiting for a server that never reached the requested version.This moves activation into a fixed-name transient systemd user service with its own cgroup. The helper stages the candidate, performs a blocking restart, verifies the exact version through the public readiness endpoint, and restores and verifies the previous unit on failure. Targets validate their migration identities against the database before the known-good server stops, and clients now distinguish a verified rollback from a restart timeout.
Focused verification:
vp test run apps/server/src/cloud/selfUpdate.test.ts apps/server/src/cloud/systemdSelfUpdate.test.ts apps/server/src/persistence/Migrations.test.ts packages/client-runtime/src/state/server.test.ts apps/server/src/bin.test.ts apps/server/src/cli/service.test.tsvp test run apps/server/src/persistence/Migrations apps/server/src/persistence/Migrations.test.tsvp run --filter t3 typecheckvp run --filter @t3tools/client-runtime typecheckvp run --filter t3 build:bundleBuilt by gpt-5.6-sol with the Codex harness in T3 Code.
Note
High Risk
Changes critical server self-update, systemd unit lifecycle, and database migration gating for remote activation; failures are mitigated by staged plans, helper rollback, and readiness probes, but mis-handoff or lock-release edge cases could still leave operators debugging receipt files under
self-update.Overview
Boot-service self-updates no longer rewrite and restart
t3code.servicefrom inside that service’s cgroup. The running server stages a plan and hands activation to a transientt3code-self-update.serviceviasystemd-run, which applies the candidate unit, verifies readiness, and rolls back on failure.Preflight and readiness: Before stop, the target build runs a read-only database migration frontier check (
service _validate-update). A new/.well-known/t3/readyendpoint blocks until the runtime has published lifecycleready(not merely HTTP up). Hidden CLI commands_apply-updateand_validate-updatesupport the helper and preflight.Client: The update flow waits for disconnect/backoff before accepting a
readyevent, then validates the resumed version (ServerUpdateWrongVersionErroron verified rollback).Migrations:
validateMigrationIdentitiesandvalidateAutomaticUpdateMigrationFrontierreject unsafe automatic activation when schema frontiers disagree.Reviewed by Cursor Bugbot for commit da8ebd3. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Delegate server self-update activation to a supervised systemd transient unit with rollback
selfUpdate.tswith a staged plan file handed off to a transientsystemd-runhelper unit (systemdSelfUpdate.ts) that handles install, restart, readiness polling, and rollback with receipt files.service _validate-update) that runs against the target build before any restart, preventing unsafe schema migrations from being applied automatically.GET /.well-known/t3/readyto the server HTTP API, backed by a newawaitReadysignal onServerRuntimeStartup; the systemd helper polls this endpoint to verify the resumed server version matches the expected target.ServerUpdateWrongVersionErrorif the resumed server version differs from the requested target, and surfaceServerUpdateRestartTimeoutErrorif no backoff signal is observed within 30 seconds.Macroscope summarized da8ebd3.