Skip to content

fix(cloudflare): Harden constraint cache state handling#1035

Draft
dcramer wants to merge 2 commits into
mainfrom
fix/explicit-constraint-cache
Draft

fix(cloudflare): Harden constraint cache state handling#1035
dcramer wants to merge 2 commits into
mainfrom
fix/explicit-constraint-cache

Conversation

@dcramer
Copy link
Copy Markdown
Member

@dcramer dcramer commented May 30, 2026

Make Cloudflare constraint caching preserve separate states for org cache hits, verified project constraints, and project verification timeouts. Project timeouts now get a short-lived cache entry so repeated MCP startup requests do not pay the same slow capability lookup, while tool filtering still fails open when capabilities are unknown.

Explicit Cache Entries

KV entries now use discriminated shapes instead of overloading projectCapabilities: null, and reads validate those persisted shapes through a Zod schema. The cache key namespace moves from v1 to v2 so deployed v1 entries with the old shape are never mixed with the new entry model.

Canonical Constraint Boundaries

The worker rejects invalid org/project URL slugs before verification or cache key construction. Cache keys now use the already-validated project slug literally instead of trimming inside the key builder, avoiding accidental project-to-org cache namespace collapse.

Background Cache Writes

Constraint cache writes are routed through a helper that requires a waitUntil scheduler. The worker handler passes ctx.waitUntil, keeping request responses from waiting on KV writes without leaving cache writes as unmanaged background promises.

@dcramer dcramer force-pushed the fix/explicit-constraint-cache branch from 8568274 to 014531d Compare May 30, 2026 20:56
Cache project verification timeouts with explicit timeout entries.

Keep fail-open behavior while giving org, verified project, and timeout entries separate shapes.

Co-Authored-By: GPT-5 Codex <codex@openai.com>
@dcramer dcramer force-pushed the fix/explicit-constraint-cache branch from 014531d to 5761626 Compare May 30, 2026 21:16
Validate URL constraint slugs before they reach verification or cache key construction. Replace the hand-rolled KV shape guards with a Zod schema so cached org, verified project, and timeout entries share one runtime contract.

Keep project cache keys literal instead of trimming inside the key builder, which avoids collapsing malformed project scopes into the org cache namespace.

Co-Authored-By: GPT-5 Codex <noreply@openai.com>
@dcramer dcramer changed the title fix(cloudflare): Make constraint cache states explicit fix(cloudflare): Harden constraint cache state handling May 30, 2026
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