Repository navigation
feat(apps): guard startup against newer databases and handed-off domains - #562
Merged
Merged
Conversation
Two safety nets for moving built-in features into official apps. Newer database: - Drizzle applies only migrations newer than the latest recorded one, so an older image used to start silently on a database migrated by a newer image. `migrate.ts` now compares the latest recorded migration with the newest one the image ships, refuses before applying anything and exits with status 78. - The entrypoint treats status 78 as proxy-only mode. The controller, Caddy, PostgreSQL and Valkey keep serving the retained proxy snapshot, while web, background workers and the app manager stay stopped and the database is left unchanged. Other migration failures still stop the appliance. Handed-off domains: - Worker lifecycles accept an `admit` check that runs right before the first start. A false result leaves the loaded worker unstarted in the new `handed_off` state; a failing check retries like a failed load. - Host monitoring, Docker discovery and CrowdSec reconciliation start only while the handoff journal leaves their domain to platform, so a restart or a downgrade to any image with this check never runs a second productive copy. Refs #457 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
|
Warning Review limit reachedYou'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 59 minutes. View limit details
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. |
The backup harness runs the real normal-startup dispatcher with stubbed roles. The dispatcher now calls `migrate_or_hold_proxy` around the migration step, so the harness loads that guard, the proxy-only hold and its status constant from the entrypoint. Co-Authored-By: Claude Opus 5.5 <[email protected]>
RentnerKev
added a commit
that referenced
this pull request
Nov 24, 2026
Since #562, an older image refuses a database that a newer image migrated and serves only the retained proxy snapshot. The image comparison still started the baseline normally after the candidate's upgrade, so every candidate with a new migration failed there. Compare the newest migration both images ship. Without new migrations the baseline must start normally as before; with them it must hold proxy-only mode with web stopped, while the cluster, rows and role grant stay intact. Co-Authored-By: Claude Opus 5.5 <[email protected]>
7 of 13 tasks
RentnerKev
added a commit
that referenced
this pull request
Nov 24, 2026
* feat(apps): serve the legacy feature handoff through App API v1 Wire the four Marketplace contract operations from the native broker to the handoff journal: getLegacyHandoff, beginLegacyHandoff, readLegacyHandoffPart and commitLegacyHandoff. Each call resolves the active generation with a live lease and requires the domain as a declared provider profile with an authorized app.provider.register grant, all in one read committed transaction. Domains without a registered source refuse begin, and app removal returns uncommitted handoffs to platform while committed ownership stays. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(apps): check legacy handoff routes in the native app fixture The production fixture app now reads its declared monitoring domain as platform owned, is refused begin while no feature source is registered, and gets 403 for an undeclared domain and after its provider grant is revoked. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(apps): bind legacy handoff part reads to the export digest RentnerProxy/marketplace#81 now passes the export digest with every part read, so a read of a replaced export fails with 409 instead of returning a part. Pin the Marketplace crates to the updated contract head. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(apps): run app management in read committed transactions The removal check now aborts legacy handoffs, and their domain lock refuses any other isolation level. State the level explicitly instead of relying on the database default. Co-Authored-By: Claude Opus 5.5 <[email protected]> * style: apply automatic formatting * chore(deps): pin the Marketplace crates to the merged handoff contract RentnerProxy/marketplace#81 is merged. Pin all four crates to its merge commit on Marketplace main, which stays reachable after the PR branch is deleted. Its tree matches the final PR head; against the previous pin only rustfmt changes in Rust test code differ. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(apps): bind handoff keys and recheck authority after journal work Address the review of the legacy handoff transport: - Begin and commit bind their Idempotency-Key to the domain (and digest) before the journal changes. Reuse with other input returns 409 idempotencyConflict. Keys expire after 30 days and at most 1,024 stay per installation; the journal still dedupes retries of forgotten keys. Purging an app's data drops its keys. - Every handoff request rechecks the caller's deadline after the journal work, so an expired lease or delegation rolls the work back with 401. - The native fixture checks that begin's 404 is the service's refusal. - A DB test covers a begin between the two removal checks. Co-Authored-By: Claude Opus 5.5 <[email protected]> * style: apply automatic formatting * test(apps): roll back a handoff begin whose broker disconnects A begin forwarded just before the app manager stops the broker can wait on the installation row while the second removal check holds it. The new DB test serves the gateway on a real socket, disconnects the client while the begin waits, and checks that the export it then runs is rolled back. Co-Authored-By: Claude Opus 5.5 <[email protected]> * ci: expect proxy-only rollback after a migrating candidate Since #562, an older image refuses a database that a newer image migrated and serves only the retained proxy snapshot. The image comparison still started the baseline normally after the candidate's upgrade, so every candidate with a new migration failed there. Compare the newest migration both images ship. Without new migrations the baseline must start normally as before; with them it must hold proxy-only mode with web stopped, while the cluster, rows and role grant stay intact. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(apps): synchronize the handoff deadline and in-flight tests Address the review of the handoff DB tests: - The lease-expiry case holds the export until the deadline passed and asserts that the export ran, so a slow authorization cannot pass the 401 check without exercising the post-journal recheck. - The in-flight case fails fast when the removal check's lock setup fails, and waits until the begin's session is blocked by exactly that check's backend, failing if it never is. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(apps): pin the in-flight begin to its own database session The in-flight test now finds the session that waits to share-lock the installation row and requires the removal check's backend among exactly its blockers. The export, which runs in the begin's transaction, records its backend PID, and the test asserts it is that waiting session. The handoff DB tests also get an explicit 20 s timeout: each imports the gateway cold and makes dozens of round trips, which can exceed Bun's 5 s default on slow runners. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: rentnerproxy-pr-automation[bot] <353791173+rentnerproxy-pr-automation[bot]@users.noreply.github.com>
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds two startup safety nets that must be in place before the first built-in feature moves into an official app (#457). As agreed, the upgrade preview follows as its own PR, before the first release that removes a built-in feature. That PR needs a separate release asset, because the strict v1 readiness schema rejects new fields, and it needs provider profiles in the catalog.
Older image on a newer database
created_at. An older image therefore used to start silently on a database migrated by a newer image.web/src/db/migrate.tsnow compares the latest recorded migration with the newest migration the image ships, inside the migration lock and before applying anything. If the database is newer, it throwsDatabaseNewerThanImageErrorand the CLI exits with status 78. The log line names both migrations and the remedy.docker/production/entrypoint.shtreats status 78 as proxy-only mode:Handed-off domains
WorkerLifecycleOptionsgets anadmitcheck that runs right before the first start, after restore admission. If it returnsfalse, the loaded worker is never started and its state becomes the new protectedhanded_off. If the check fails, it retries like a failed load.host_monitoring,docker_discoveryandcrowdsec_reconciliationare admitted only while the handoff journal leavesmonitoring,docker-discoveryandcrowdsecto platform (isLegacyFeaturePlatformOwned). A restart, or a downgrade to any image with this check, therefore never runs a second productive copy beside the app.Domains without their own web worker, and the Rust controller workers, are not gated here:
Each extraction gates its own paths with
withPlatformOwnedLegacyFeaturewhen it registers its source.Related issue
Refs #457. Builds on #560. No overlap with #561 or with the handoff transport work.
Type of change
Testing
web/src/tests/db/database-migrate.db.test.tssimulates a future migration row. BothrunMigrateand the CLI process refuse it, the CLI exits 78, and nothing is applied.web/src/tests/tooling/docker/production/startup-guard.test.tsruns the entrypoint guard functions against fixture children:It also checks that the shell status matches
DATABASE_NEWER_THAN_IMAGE_EXIT_CODE.worker-lifecycle.test.tscovershanded_offwithout a start, and a failed admission read that retries the same unstarted worker.worker-admission.db.test.tscovers the exported, committed and platform-owned cases.start.coverage.test.tschecks that exactly the three feature workers ask the journal, with the right domains.Local runs against PostgreSQL 18:
entrypoint.sh.Checklist
Breaking changes
An appliance started with an image older than its database no longer runs web on that database. It stays in proxy-only mode until the matching or a newer image starts. The support report can show the new worker state
handed_off.Screenshots
None.
🤖 Generated with Claude Code