Repository navigation
feat(routing): add opt-in reviewed configuration snapshots - #24
Conversation
CONFIG_SNAPSHOTS_ENABLED (default off) adds admin snapshots of auto-route candidate orders with a paginated diff and a confirmed apply. Apply runs as one D1 batch that checks the revision and stored route state, writes the routes, bumps the revision and appends an audit record, so a stale review returns 409. Rollback is a new snapshot. Snapshots use migration 0015 and fail closed with JSON 503 when its tables are missing.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
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 |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
multillm-proxy | 287f929 | Oct 08 2026, 08:58 PM |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 287f929820
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| response = client.get("/admin/config/snapshots") | ||
| checks.assertEqual(response.status_code, 302) | ||
| with client.application.test_request_context(): | ||
| checks.assertEqual(response.headers["Location"], url_for("login", next="/admin/config/snapshots")) |
There was a problem hiding this comment.
Match the redirect emitted by
login_required
In this unauthenticated scenario, login_required in route_helpers.py redirects with url_for("login") and does not supply a next argument, so the response location is /login, not /login?next=/admin/config/snapshots. This new assertion will therefore fail on every full Python test run; either assert the bare login URL or update the decorator to preserve the destination.
Useful? React with 👍 / 👎.
| result = call("snapshot_apply", id=identifier, current_revision=body["current_revision"], | ||
| confirm=True, actor=actor_identity(user)) |
There was a problem hiding this comment.
Revalidate stored candidate orders before applying
When a snapshot survives a deployment that adds its candidate order to LEGACY_DEFAULT_AUTO_ROUTES, the creation-time check no longer protects this apply path: the stored configuration is applied without validation against the current legacy list, while AutoRouteService._durable_routes subsequently replaces that exact persisted order with DEFAULT_AUTO_ROUTES. The endpoint can consequently return applied: true and append an audit revision even though the reviewed order never becomes effective; revalidate the snapshot against the current defaults during apply or invalidate snapshots that have become retired.
Useful? React with 👍 / 👎.
| user = require_admin_dashboard_user() | ||
| if request.method == "GET": | ||
| return jsonify(config_snapshots.call("snapshot_list")) | ||
| return jsonify(config_snapshots.create(request.get_json(silent=True), user, app.config["API_BASE_URLS"])), 201 |
There was a problem hiding this comment.
Enforce the snapshot byte limit before JSON parsing
The create handler reads and parses the entire request before installing any snapshot-specific body limit, so it inherits the application's 32 MiB default rather than the advertised 256 KiB bound. An authenticated request near that limit is materialized by get_json, then serialized and encoded again by validate_configuration before it can return 413, which can consume several times the request size per worker; set request.max_content_length in the early snapshot gate, as the prompt-template routes do, so oversized snapshots are rejected before parsing.
Useful? React with 👍 / 👎.
| db.prepare(`INSERT INTO auto_routes (route_id, candidates, updated_at) | ||
| SELECT ?, ?, ? WHERE changes()=1 | ||
| ON CONFLICT(route_id) DO UPDATE SET candidates=excluded.candidates, updated_at=excluded.updated_at`) | ||
| .bind(body.route_id, JSON.stringify(body.candidates), body.updated_at)]; |
There was a problem hiding this comment.
Preserve the 200-route bound in ordinary saves
When snapshots are enabled and auto_routes already contains 200 rows, saving a new route through this newly selected path unconditionally inserts a 201st row and still returns stored: true. Ordinary reads are capped at 200 rows, so one persisted route is then omitted based on sort order, and applySnapshot rejects every later snapshot because its count predicate starts above MAX_ROUTES, even when the patch only updates existing routes. Add the same count-and-existence guard used by snapshot apply to revisionedSave.
Useful? React with 👍 / 👎.
Summary
Adds reviewed configuration snapshots for auto-routes behind
CONFIG_SNAPSHOTS_ENABLED, which defaults to false. While the flag is off, every snapshot path returns 404, and auto-route saves keep their current payload, storage and response.POST /admin/config/snapshotsstores an immutable patch of route IDs and candidate model IDs against abase_revision. It does not activate anything.GET /admin/config/snapshotslists the current revision, snapshot metadata and the latest 100 apply records.GET /admin/config/snapshots/<id>/diffshows before and after model lists, 20 routes per page.POST /admin/config/snapshots/<id>/applyneedsconfirm: trueand the current revision. A single D1 batch checks the revision and the exact stored route state, writes the routes, bumps the revision and appends an audit record. A stale review returns 409. A failed route write rolls the whole batch back.no-store.Details are in
docs/config-snapshots.md.Stacked on #23
This branch is based on
feat/prompt-templates(#23) so that migration0015_config_snapshots.sqlfollows0014_prompt_templates.sql. Merge #23 first; GitHub then retargets this PR to main.Before merging to main
Apply the D1 migrations first. A push to main does not apply them, and
/readyreportsd1_schema_missinguntil the three new tables exist:With the flag on, ordinary auto-route saves also advance the revision. If the tables are missing, they fail closed with JSON 503, as do the snapshot routes.
Shared registrations
tests/test_config_snapshots_worker.mjstotest:worker.CONFIG_SNAPSHOTS_ENABLEDto the Container env keys.config_snapshot_revisions,config_snapshotsandconfig_snapshot_applicationstoREQUIRED_D1_TABLES.Tests
npm run test:worker: 1,194 passed. The Worker tests run the migrations in Miniflare D1, including the missing-migration case.cf:migrations:check,test:deploy, free routes, client headers and thewrangler deploy --dry-runbundle all pass.tests/test_frontend_build.mjsfails locally because@tailwindcss/cliis not installed. It fails the same way on main.The README line for this feature is added by the Wave 2 integration PR.