Skip to content

feat(context): add opt-in reversible context paging - #50

Merged
ALikesToCode merged 2 commits into
integrate/gateway-waves-1-4from
feat/context-pages
Oct 9, 2026
Merged

ALikesToCode merged 2 commits into
integrate/gateway-waves-1-4from
feat/context-pages

Conversation

@ALikesToCode

Copy link
Copy Markdown
Owner

Summary

Adds opt-in reversible context paging. With CONTEXT_PAGING_ENABLED unset (the default), history, storage and responses are unchanged.

  • Who it applies to: a managed client that declares the multillm_context_retrieve capability. When its history doesn't fit the candidate's input window, complete older exchanges are replaced by signed retrieval handles. Nothing is summarized or truncated.
  • What is kept whole:
    • A page holds the exact stored JSON of an exchange.
    • A tool call is never split from its results.
    • System and developer messages, incomplete exchanges and the latest user exchange always stay in full.
  • Retrieval:
    • Through the multillm_context_retrieve tool or an authenticated GET /v1/context/pages/<page_id>.
    • Each retrieval checks ownership, session, current policy revision, expiry, the HMAC, byte length and SHA-256.
    • A handle alone grants nothing.
    • Retrieval never dispatches a provider call.
  • Storage:
    • Bodies go in the existing R2 bucket under context-pages/. Metadata goes in D1 context_pages (migration 0024).
    • Limits: 64 KiB per page and 1 MiB of active pages per session, with a one-hour TTL.
    • The session limit check and the inserts run in one statement, so competing writers can't exceed it.
  • Errors:
    • Zero-content retention disables paging before any storage call.
    • 413 context_window_exceeded when the protected content still doesn't fit.
    • 404 for missing, expired, foreign or stale handles.
    • 403 for missing grants.
    • 503 when storage is unavailable; generation stops and nothing is truncated.

Details are in docs/context-pages.md.

Shared registrations

  • Migration intelligence-migrations/0024_context_pages.sql and the context_pages entry in worker/d1-schema.mjs.
  • tests/test_context_pages_worker.mjs in test:worker, and CONTEXT_PAGING_ENABLED in the Container env keys.
  • app.route('/v1/context/pages/<page_id>', methods=['GET']) in the Flask route inventory. It is authenticated, returns Cache-Control: private, no-store and dispatches to no provider. worker/context-pages-d1.mjs is in the edge module inventory.

Left for the Wave 5 integration

  • Register register_context_page_routes in app.py.
  • Run PagingRequest in the unified path before lossy optimization.
  • Add the private /v1/managed-state/context-pages operation and Worker handleContextPageRequest.
  • Page roleplay handleTurn.
  • Expose multillm_context_retrieve through the gateway MCP server.
  • Strip the capabilities field when paging is on.

Tests

  • tests/test_context_pages.py and tests/test_context_pages_worker.mjs cover:
    • exact round-trips including Unicode and tool calls;
    • group integrity;
    • protected messages;
    • window fitting and 413;
    • the HMAC and hash checks;
    • expiry;
    • foreign and stale handles;
    • zero retention;
    • the atomic session limit;
    • flag-off behavior.
  • Full Python suite: 3,926 passed, 2 skipped. ruff, mypy and bandit are clean.
  • npm run test:worker: 1,475 passed. npm run test:integration: 7 passed.
  • migrations:check (24 contiguous, additive migrations), test:deploy, free routes, client headers and the wrangler deploy --dry-run bundle all pass.

Apply the migration before enabling the flag: npx wrangler d1 migrations apply multillm-intelligence --remote.

CI notes

  • GitHub python/node jobs: the dependency-audit steps fail on every branch, including main. fix(deps): clear the CI dependency audit advisories #42 fixes that.
  • Workers Builds: fails on this stack because the Wave 3 base adds the AdmissionCoordinator Durable Object migration, which wrangler versions upload cannot apply. This is expected until wrangler deploy runs on main.

This is part of Wave 5. It is based on integrate/gateway-waves-1-4, the Wave 4 integration branch. The README line comes with the Wave 5 integration PR.

Behind CONTEXT_PAGING_ENABLED (default off), a managed client that declares the multillm_context_retrieve capability can have complete older exchanges replaced by signed retrieval handles instead of being summarized or truncated. Pages keep the exact stored JSON, never split a tool call from its results, and are scoped to the principal, session and policy revision. Bodies go in the existing R2 bucket and metadata in D1 (migration 0024), with 64 KiB per page, 1 MiB per session and a one-hour TTL. Zero-content retention disables paging, and a request whose protected content still does not fit returns 413.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Oct 9, 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: 7575e966-16e6-4b01-afa1-15df4aff2220

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 9, 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 failed
View logs
multillm-proxy 5940bdc Oct 09 2026, 02:33 AM

@ALikesToCode

Copy link
Copy Markdown
Owner Author

Merged the Wave 4 integration glue (integrate/gateway-waves-1-4 at cd4ac5f) into this branch, so the Wave 5 stack builds on the wired base. CI after the merge: 3,974 Python passed, 2 skipped; 1,501 Worker; 7 integration; 24 contiguous migrations; deploy, free routes, client headers and the wrangler dry run pass.

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