Skip to content

Ask CortexDB for every scope instead of its first fifty - #142

Merged
CodeGhost21 merged 1 commit into
tinyhumansai:mainfrom
CodeGhost21:fix/cortex-scope-listing-truncation
Sep 7, 2026
Merged

Ask CortexDB for every scope instead of its first fifty#142
CodeGhost21 merged 1 commit into
tinyhumansai:mainfrom
CodeGhost21:fix/cortex-scope-listing-truncation

Conversation

@CodeGhost21

@CodeGhost21 CodeGhost21 commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

What changed

CortexDialect::scopes asked v1/scopes/list for nothing and took whatever came
back. The endpoint caps that listing at fifty and documents neither the cap
nor the limit parameter that lifts it — its OpenAPI entry lists no parameters
at all, and the response carries no cursor, no has_more, and no total. Nothing
in a capped response distinguishes it from a complete one.

That listing feeds entriesnamespace_summariesexport_page. A
deployment holding more namespaces than the cap exported a subset of itself and
reported success
. A live instance was measured holding 93 scopes and listing
50. Per-namespace reads address a namespace directly, so they never notice; the
truncation only shows up in the paths that enumerate, which is why it went
unseen.

The fix:

  • send limit=10_000, far above any plausible namespace count;
  • refuse a response that fills that limit rather than returning it. With no
    cursor there is no way to ask for the rest and no way to tell a full page from
    a truncated one, so the same reasoning as MAX_PAGES applies: a loud error
    beats a short answer the caller cannot detect.

The conformance double now reproduces the cap (defaults to 50, honours limit),
so every Cortex test runs against the engine's real shape instead of a stub that
always returns everything. A double that returns the whole set cannot catch an
adapter that forgot to ask.

Public API / behavior changes

No API change. One behavior change: scopes — and therefore
namespace_summaries and export_page — now returns an error instead of a
silently short listing when a deployment exceeds SCOPE_LIST_LIMIT.

Tests

Two new tests in crates/tinymemory-remote/src/conformance_test.rs:

  • every_namespace_is_listed_past_the_engines_undocumented_default — writes 64
    namespaces and asserts all 64 come back. Verified to reproduce the bug:
    reverted to the old call it fails with left: 50, right: 64.
  • a_scope_listing_that_fills_the_limit_is_refused_rather_than_trusted — a
    listing of exactly SCOPE_LIST_LIMIT entries must error, not be returned.

Validation

Run from the repository root, all green:

Command Outcome
cargo fmt --all -- --check pass
cargo clippy --all-targets --all-features -- -D warnings pass
cargo build --all-targets --all-features pass
cargo test --all-features pass — full workspace, 0 failures

Deliberately untested

The exact value of the engine's undocumented default. The double pins 50 because
that is what a live v0.9.9 instance returns; if the vendor changes it, the guard
still holds — the adapter names its own limit and refuses a full page either way.

Summary by CodeRabbit

  • Bug Fixes

    • Scope discovery now requests a larger result set, reducing the chance of incomplete namespace and scope listings.
    • The adapter now reports an error when a scope response reaches the maximum requested limit, preventing potentially truncated results from being treated as complete.
  • Tests

    • Added coverage for large namespace collections and detection of responses that may be truncated.

`CortexDialect::scopes` called `v1/scopes/list` with no parameters. The
endpoint caps the listing at fifty and documents neither the cap nor the
`limit` that lifts it: its OpenAPI entry lists no parameters at all, and
the response carries no cursor, no `has_more` and no total, so there is
nothing in it that tells a caller it was cut short.

That listing is what `entries` and `namespace_summaries` enumerate, and
so what `export_page` walks. A deployment holding more namespaces than
the cap exported a subset of itself and reported success — a live
instance measured 93. Per-namespace reads address a namespace directly
and never notice, which is why this stayed invisible.

Ask for a limit far above any namespace count, and refuse a response
that fills it rather than returning it: with no cursor, a full page and
a truncated one are the same response, and the same reasoning as
MAX_PAGES applies — a loud error beats a short answer the caller cannot
detect.

The test double now models the cap, so every Cortex conformance test
exercises the real shape rather than a listing that always returns
everything.
@tinysweeper

tinysweeper Bot commented Sep 7, 2026

Copy link
Copy Markdown

How this change flows

4 changed behaviours across 9 relationships. 5 surrounding behaviours are shown (60 graph nodes walked). 45 further behaviours left out to keep the diagram readable.

flowchart LR
  n0["...lay_returns_the_event_its_own_key_created<br/>changed"]:::changed
  n1["cortex_recall<br/>changed"]:::changed
  n2["cortex_scopes<br/>changed"]:::changed
  n3["CortexDialect<br/>changed"]:::changed
  n4["route"]:::impacted
  n5["Result"]:::impacted
  n6["cortex_backend"]:::impacted
  n7["iter"]:::impacted
  n8["new"]:::impacted
  n0 -->|calls| n6
  n1 -->|calls| n7
  n1 -->|tests| n7
  n2 -->|calls| n7
  n2 -->|tests| n7
  n6 -->|calls| n4
  n6 -->|tests| n4
  n8 -->|uses| n3
  n8 -->|uses| n5
  classDef changed fill:#0d4429,stroke:#238636,color:#e6edf3
  classDef impacted fill:#161b22,stroke:#6e7681,color:#c9d1d9
  classDef flagged fill:#5a1e02,stroke:#d93f0b,color:#ffffff
  classDef blocking fill:#67060c,stroke:#f85149,color:#ffffff
Loading

Green: changed behaviour. Grey: surrounding behaviour. Arrows name the call, use, implementation, or test relationship. Orange: has findings. Red: has a finding that blocks the merge.

tinysweeper 0.1.0

@tinysweeper tinysweeper 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.

tinysweeper found nothing blocking. Approving.

             $0.0121 · 67,996 in / 1,713 out · 16,402 cached (24%) · openrouter/openai/text-embedding-3-small, z-ai/glm-5.2, deepseek/deepseek-v4-flash · 443 embedded
critique:    $0.0047 · 25,419 in / 868 out   · 8,505 cached (33%)  · z-ai/glm-5.2, deepseek/deepseek-v4-flash
security:    $0.0056 · 23,462 in / 712 out   · 7,897 cached (34%)  · deepseek/deepseek-v4-flash, z-ai/glm-5.2
tests:       $0.0012 · 13,251 in / 59 out    · 0 cached (0%)       · deepseek/deepseek-v4-flash
description: $0.0005 · 5,864 in  / 74 out    · 0 cached (0%)       · deepseek/deepseek-v4-flash

@tinysweeper tinysweeper Bot added the priority: p3 Whenever. Cosmetic, a nicety, or a cleanup with no user visible effect. label Sep 7, 2026
@coderabbitai

coderabbitai Bot commented Sep 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 6442a39c-92ed-4403-9295-a0746871edac

📥 Commits

Reviewing files that changed from the base of the PR and between be6524c and 6113749.

📒 Files selected for processing (2)
  • crates/tinymemory-remote/src/conformance_test.rs
  • crates/tinymemory-remote/src/cortex.rs

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The Cortex adapter now requests up to 10,000 scopes and rejects full responses as potentially truncated. The Cortex test double applies the endpoint limit. Tests cover listings beyond the default cap and responses that fill the requested limit.

Changes

Cortex scope listing

Layer / File(s) Summary
Adapter scope request and truncation guard
crates/tinymemory-remote/src/cortex.rs
scopes() requests limit=10_000 and returns an error when the response contains 10,000 items.
Conformance double and scope listing tests
crates/tinymemory-remote/src/conformance_test.rs
The test double parses and applies the limit query parameter. Tests verify that 64 namespaces are listed and that a full 10,000-item response is rejected as truncated.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 61137

Cortex scope listings now request up to 10,000 entries and fail safely when completeness cannot be established, preventing silent omission of namespaces. The change is ready to merge.

Suggested reviewers: senamakel, yellowsnnowmann

Poem

A rabbit checks each scope with care
Ten thousand hop through Cortex air
Full pages raise a warning bright
Sixty-four arrive in sight
No namespace hides from view
The listing guard now follows through

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: the adapter requests all available scopes instead of relying on CortexDB's default first fifty scopes.
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Warning

Your free Security trial is over. An organization admin can upgrade to Advanced for continuous pull request security review or dismiss this notice.


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

@CodeGhost21
CodeGhost21 merged commit 5ea7bce into tinyhumansai:main Sep 7, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: p3 Whenever. Cosmetic, a nicety, or a cleanup with no user visible effect.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant