Skip to content

SCA-261: tighten knowledge graph read budget - #10902

Merged
Git-on-my-level merged 3 commits into
mainfrom
agent/m1-studio-nik-codex-sol-high/3ed644a7
Jul 30, 2026
Merged

Git-on-my-level merged 3 commits into
mainfrom
agent/m1-studio-nik-codex-sol-high/3ed644a7

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Jul 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Tighten GET /v1/knowledge-graph to a deterministic snapshot of at most 500 nodes, 1,000 edges, and 500 canonical assertions, and expose additive returned-count metadata.

Multica: SCA-261

Root cause

TimeoutMiddleware applies HTTP_GET_TIMEOUT and returns a bare 504 when the request exceeds the production 30-second GET budget. The deployed commit already contains #10750's original 2,000-node / 5,000-edge caps, but production heavy-tail requests still pin that ceiling. Including the canonical assertion and privacy-fence reads, that path could consume roughly 11,500 Firestore documents before serialization.

The prior cap was therefore bounded in name but still too large for the request budget. Raising HTTP_GET_TIMEOUT would retain the excessive read and worker cost, so this PR does not change any timeout.

Fix

  • Reduce the server-enforced snapshot to 500 nodes, 1,000 edges, and 500 assertions (roughly 3,000 maximum Firestore documents including active-item and citation-fence reads).
  • Explicitly order each capped Firestore page by document ID so repeated reads select a deterministic subset without requiring a new composite index.
  • Preserve the required nodes and edges arrays and existing truncation/limit fields.
  • Add optional-compatible node_count and edge_count fields describing the records returned in the bounded snapshot.
  • Keep edges referentially closed over the returned node page.

Product invariants affected

  • INV-MEM-4 (proposed): the canonical assertion privacy fence and derived-view ownership remain intact.

Failure-Class

Failure-Class: new

Guard artifact: the 20,000-node / 20,000-edge behavioral fixture fails if the production loader omits its Firestore cap or deterministic ordering, while the HTTP-level regression verifies the additive response and unchanged Firebase dependency.

Verification

  • backend/.venv/bin/python -m pytest -q backend/tests/unit/test_bounded_firestore_list_reads.py backend/tests/unit/test_memory_graph_assertion_read.py backend/tests/unit/test_knowledge_graph_canonical_mutation_routes.py backend/tests/unit/test_timeout_middleware.py backend/tests/unit/test_http_timeout_defaults.py — 47 passed.
  • backend/.venv/bin/pyright --pythonpath backend/.venv/bin/python backend/database/knowledge_graph.py backend/routers/knowledge_graph.py — 0 errors.
  • App-client OpenAPI, Dart DTO, and TypeScript client generation checks — current.
  • OMI_PR_BODY_FILE=pr-body.md make preflight — 27 checks passed.

The repository backend/test.sh wrapper executed all focused assertions successfully, but its Mac CPU-time ratchet rejected an unchanged 5,000-item action-items fixture at 0.17–0.19s (limit 0.12s). The same files pass under focused pytest; this PR does not alter action-items policy.

Operational notes

  • No production deployment, traffic change, rollback, Firestore mutation, or timeout increase.
  • A rollback is not recommended for this chronic heavy-tail class; the serving revision is healthy and the mechanism predates the current chat-stream revision.
  • Action-items, memories, and other GET heavy tails remain outside this PR and require separate production validation even where fix(backend): bound Firestore list reads to stop 30s GET 504s #10750 added initial caps.

Review in cubic

Git-on-my-level and others added 2 commits July 30, 2026 11:35
Reduce the deterministic knowledge-graph snapshot to 500 nodes, 1000 edges, and 500 canonical assertions after the previous higher caps continued to hit the 30-second GET ceiling. Expose returned counts and lock the behavior with empty, small, and 20k-document route fixtures.

Failure-Class: new
Co-authored-by: multica-agent <[email protected]>
Record the aggregate request-budget contract and its large-fixture prevention artifact for the recurring Firestore list-read timeout class.

Co-authored-by: multica-agent <[email protected]>

@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: 92222dc2b3

ℹ️ 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 thread backend/database/knowledge_graph.py Resolved
@mintlify

mintlify Bot commented Jul 30, 2026

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
omi 🟢 Ready View Preview Jul 30, 2026, 4:14 PM

💡 Tip: Enable Workflows to automatically generate PRs for you.

Use the ID returned by node upserts when wiring extraction edges so a legacy node outside the bounded snapshot cannot leave a dangling provisional reference. Add a regression for the capped lookup path.

Failure-Class: none
Co-authored-by: multica-agent <[email protected]>
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