feat(control-plane): add indexed cursor-paginated request history - #1004
Draft
Wibias wants to merge 3 commits into
Draft
feat(control-plane): add indexed cursor-paginated request history#1004Wibias wants to merge 3 commits into
Wibias wants to merge 3 commits into
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
This was referenced Aug 4, 2026
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
RI-02 of the Router Intelligence / Routing Control Plane programme
(
devlog/_plan/260804_router_intelligence/000_master_plan.md). Adds arebuildable SQLite projection of the canonical
usage.jsonlledger plus acursor-paginated request-history API.
usage.jsonlremains the canonical, append-only request evidence. The index(
routing-history.sqlitein the config dir, Bun's built-inbun:sqlite) is aderived query index that can be deleted, corrupted, or stale at any time and
is automatically rebuilt from the ledger without losing history (ADR-1/ADR-8).
Scope
src/routing/history/schema.ts- versioned schema (schema_meta+requestswith filter indexes),HISTORY_SCHEMA_VERSION = 1.src/routing/history/cursor.ts- opaque base64url keyset cursor(
timestamp DESC, request_id DESC),InvalidCursorError.src/routing/history/indexer.ts- open/append/rebuild/repair:PRAGMA quick_check, source file identity(size/mtime), byte-offset incremental append;
JSONL line (skipped until it completes), file replacement/truncation
(identity change -> rebuild), duplicate replay (
INSERT OR IGNORE),crash during indexing (transactional 500-row batches, WAL);
queryRequestHistory,requestHistoryRowById,rebuildRequestHistoryIndex.src/server/management/request-history-routes.ts-GET /api/request-history- filters:provider,model,requestedModel,status,conversationId,surface,inboundProtocol,apiKeyId,profileId,fallback,from,to;limit(1..100),cursor; response carriesentries,nextCursor,hasMore, and anindexstatus block (schemaVersion, indexedRows,sourceSize, sourceMtimeMs, builtAtMs, lastError).
GET /api/request-history/:requestId- one canonical row (404 unknown).ocx logs rebuild-index,ocx logs index-status(run directlyagainst the ledger; no running server needed).
Compatibility
usage.jsonluntouched;/api/logscontract unchanged.ocx logs rebuild-indexforces one explicitly.
Privacy / security
secret surface (same config dir,
0o600semantics, local file).by RI-01 and the usage-log normalizer); no prompts or credentials.
400with stable error codes.bun run privacy:scanpasses.Dependency
feat/ri-01-route-decision-traceshead
b5a8e7c4c. The PR target isdev; while feat(routing): record durable route decision traces #1003 is open the diff alsocontains RI-01's commits, which shrink automatically after feat(routing): record durable route decision traces #1003 merges.
Non-goals
/api/logsor the in-memory ring buffer.Local verification (exact)
bun x tsc --noEmit-> PASSED (0 errors)bun run test tests/request-history-index.test.ts-> 16/16 pass(1574 assertions) covering: empty/missing/corrupt/old-schema/partial-line/
replacement/truncation/duplicate-replay/cursor-stability/invalid-cursor/
page-bounds/rebuild-equivalence/filters/row-by-id
combo-management-api, codex-routing, codex-account-namespaces) -> 269/269
bun run privacy:scan-> passedupstream/devruns out-of-band; resultrecorded in the stack ledger.
Notes for reviewers
LIMIT/INSERT silently mis-bind (positional parameters used everywhere);unfinalized prepared statements keep the DB locked on Windows after close.