Skip to content

feat(config): add opt-in revision-aware configuration sync - #35

Merged
ALikesToCode merged 1 commit into
feat/prompt-cache-costfrom
feat/config-revision-sync
Oct 9, 2026
Merged

ALikesToCode merged 1 commit into
feat/prompt-cache-costfrom
feat/config-revision-sync

Conversation

@ALikesToCode

Copy link
Copy Markdown
Owner

Summary

Adds revision-aware live configuration sync behind CONFIG_REVISION_SYNC_ENABLED, which defaults to false. While the flag is off, no poller or freshness guard is registered, existing reads, saves, authentication and catalog refresh timing are unchanged, and nothing reads or writes control_revisions.

  • With the flag on, every write to these domains increments a committed revision counter in the same D1 transaction as the data:
    • model overrides;
    • provider catalog;
    • key controls;
    • model grants.
  • Auto routes reuse the existing config snapshot counter, and a snapshot apply bumps it exactly once.
  • Account and key writes in worker/control-users-d1.mjs bump both security counters atomically, with CAS for concurrent writers.
  • Containers poll revisions through the existing control-state scheduler, with jitter. They reload a domain only when a newer revision is committed.
    • Defaults: CONFIG_SYNC_TTL_SECONDS=30; CONFIG_SECURITY_TTL_SECONDS=5, capped at 5.
  • Ordinary config (auto routes, provider catalog) keeps the last good copy during an outage and reports it as stale.
  • Security config fails closed:
    • API and MCP requests return 503 config_security_stale while key controls, model grants or overrides can't be verified within the security TTL.
    • A key revoked through the account writer is rejected on the next request after the poll, without waiting for the verified-key memo to expire.
  • GET /admin/config/revisions (dashboard admin, 404 when disabled) shows domain revisions, ages and stale flags. It shows no keys, model lists or content.
  • The flag requires Container D1 storage (INTELLIGENCE_STORAGE_BACKEND=d1 and AUTH_STORAGE_BACKEND=d1). In standalone SQLite mode it logs one warning and stays off.
  • services/gateway_extensions.py is the single static Flask registrar that the Wave 3 integration uses to mount the other Flask hooks in a fixed order.

Details are in docs/config-revision-sync.md.

Deployment

Apply migrations 0016 and 0017 before enabling the flag. A push to main does not apply D1 migrations:

npx wrangler d1 migrations apply multillm-intelligence --remote

Stacking and integration

This PR is stacked on #34 (prompt cache buckets) because its migration 0017 follows 0016. Review only the top commit.

The Wave 3 integration PR mounts the revisioned auto-route handler on the private outbound dispatcher, and adds the native Worker freshness guard and polling.

Shared registrations

  • Added tests/test_config_revision_sync_worker.mjs to test:worker and tests/test_config_revision_sync_integration.mjs to test:integration.
  • Added CONFIG_REVISION_SYNC_ENABLED, CONFIG_SYNC_TTL_SECONDS and CONFIG_SECURITY_TTL_SECONDS to the Container env keys.
  • Added control_revisions to the D1 readiness tables.
  • Added worker/config-revision.mjs to the secret firewall inventory.

Tests

  • tests/test_config_revision_sync.py and tests/test_config_revision_sync_worker.mjs: new.
    • They cover two instances observing a newer revision, stale ordinary config, a revocation outage failing closed, and monotonic and concurrent CAS.
    • They also cover the refresh storm bound, a snapshot apply bumping once, and unchanged startup defaults.
  • tests/test_config_revision_sync_integration.mjs (in test:integration, which installs the Python dependencies): a key revoked through the real D1 writer is rejected by the registered Flask auth path before its memo expires. npm run test:integration: 7 passed.
  • Full Python suite: 3,262 passed, 2 skipped. ruff, mypy and bandit are clean.
  • npm run test:worker: 1,249 passed.
  • cf:migrations:check reports 17 contiguous, additive migrations.
  • test:deploy, free routes, client headers and the wrangler deploy --dry-run bundle all pass.
  • tests/test_frontend_build.mjs fails locally because @tailwindcss/cli is not installed. It fails the same way on main.

This is part of Wave 3, and the Wave 3 integration PR adds the README line.

Commit a revision counter with every model override, catalog, key-control and grant write, poll revisions through the control-state scheduler and reload only on newer revisions, behind CONFIG_REVISION_SYNC_ENABLED, default off. Security config fails closed when it cannot be verified within its TTL. Adds the static Flask gateway registrar and migration 0017.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-08T22:32:21.762598Z c4b22a9 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 8, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 641e2287-a204-41be-b627-85629b601833

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · 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

Comment @coderabbitai help to get the list of available commands.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
multillm-proxy c4b22a9 Oct 08 2026, 10:29 PM

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c4b22a93ad

ℹ️ 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".

Comment on lines +79 to +80
export async function handleRevisionedAutoRoutes(request, env, { handleAutoRoutesRequest, boundedBody }) {
if (!revisionSyncSettings(env).enabled) return handleAutoRoutesRequest(request, env);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Route auto-route RPCs through the revision wrapper

When revision sync is enabled but snapshots are not, this wrapper is the only code that converts a normal put into revisionedSave; however, the production dispatcher in worker/intelligence-outbound.mjs still calls handleAutoRoutesRequest directly, while only the test fixture invokes this function. Consequently, dashboard auto-route saves update D1 without advancing config_snapshot_revisions, so running Containers continue serving their cached routes indefinitely. Wire this wrapper into the /v1/auto-routes production dispatch.

Useful? React with 👍 / 👎.

Comment thread worker/d1-schema.mjs
"media_jobs", "media_job_items", "shadow_eval_samples", "shadow_eval_results",
"shadow_eval_config", "shadow_eval_policy_backups", "prompt_templates",
"config_snapshot_revisions", "config_snapshots", "config_snapshot_applications"]);
"config_snapshot_revisions", "config_snapshots", "config_snapshot_applications", "control_revisions"]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep the opt-in table out of unconditional readiness

If this code is deployed before migration 0017 while CONFIG_REVISION_SYNC_ENABLED remains false, /ready now reports control_revisions missing and returns 503 because d1Readiness checks every entry in this unconditional list. That breaks the promised disabled-mode rollout and can prevent otherwise healthy Containers from becoming ready even though no enabled operation needs the table. Make this table required only when revision sync is enabled, or preserve readiness compatibility until the migration is applied.

Useful? React with 👍 / 👎.

Comment on lines +30 to +34
@login_required
def admin_status():
if not (AuthService.get_current_user() or {}).get("is_admin"):
return jsonify({"error": "admin_required"}), 403
return jsonify(app.extensions["config_revision_sync"].status()), 200, {"Cache-Control": "no-store"}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Authenticate status without requiring the failed authority

During a D1 authority outage, even an administrator with an existing dashboard session cannot reach this diagnostic endpoint: login_required calls AuthService.get_current_user(), which re-reads the account from D1 and clears the session when that read fails. Thus the newly added revision status route redirects to login precisely when operators need to inspect stale domains, despite the extension otherwise exempting admin status from the freshness guard. Provide an outage-safe administrator authentication path for this status endpoint.

Useful? React with 👍 / 👎.

@ALikesToCode
ALikesToCode merged commit 3a2a5dc into feat/prompt-cache-cost Oct 9, 2026
5 of 7 checks passed
@ALikesToCode
ALikesToCode deleted the feat/config-revision-sync branch October 26, 2026 20:15
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