Skip to content

Fix Seeker indexing and bounded startup recovery - #472

Draft
kentbull wants to merge 1 commit into
WebOfTrust:mainfrom
kentbull:seeker-indexing-fix
Draft

kentbull wants to merge 1 commit into
WebOfTrust:mainfrom
kentbull:seeker-indexing-fix

Conversation

@kentbull

@kentbull kentbull commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

Addresses #470.

Problem

Seeker can accept a credential into Reger and then fail to make it fully searchable:

  • Seeker.index()/unindex() build keys with "".join(values). Numeric attribute values raise TypeError, and compound keys lose field boundaries (("ab", "c") and ("a", "bc") collide).
  • generateIndexes() creates issuee-bearing compound definitions for issuee-less schemas, and absent optional attributes cause path-resolution failures.
  • Entries are written incrementally, so a failure part-way leaves partial index entries behind. Fixing future writes doesn't repair stores that already contain them.
  • SeekerDoer catches every exception and requeues the same cue forever, repeating deterministic failures on every scheduler turn.

Resulting behavior

Typed equality keys. Index, unindex, compound, and equality lookups use one codec, tupleKey. It frames each scalar with a type tag and length, then hashes the tuple with SHA-256, giving a fixed 64-character key that stays under LMDB's key limit even for long compound strings. Strings, integers, and finite floats are separate domains, so 1, 1.0, and "1" are different keys. Signed zero is normalized. Booleans, containers, and non-finite floats are rejected before any entry is written.

Canonical definitions. Index definitions are derived completely from the schema before installation, and each indexing attempt re-derives them. A nonempty schIdx is not treated as a completion marker. Issuer/schema and issuee/schema compound paths are corrected. Issuee-less schemas get no issuee-bearing definitions, and absent optional attributes get no entries.

Startup reconciliation. On Agent startup, Seeker.startRepair() walks accepted credentials from Reger.schms. For each SAID it removes entries from the union of the old and corrected definitions, then rebuilds them. The pass is idempotent and yields in bounded batches: SeekerDoer runs up to 128 repair steps per turn. It rechecks acceptance after each yield, so deletions during repair are handled. Unused definition metadata is removed, but physical LMDB named databases are never dropped. If reconciliation is interrupted, it runs again on the next start.

Recovery state owned by Seeker. Only MissingSchemaError enters pending recovery. Seeker checks one pending schema per turn and re-indexes only when that schema is available. Deterministic and unexpected failures are logged once and are not requeued. The credentials stay accepted in Reger.

Query behavior.

  • Credential queries return HTTP 503 (IndexNotReadyError) while reconciliation is running or recorded failures mean results may be incomplete. The description lists a bounded sample of the affected SAIDs and error types.
  • Numeric sorting and range operators, plus other unsupported operators, return HTTP 400 (UnsupportedQueryError).
  • String prefix matching and string sorting are preserved by resolving stored values.
  • A small CredentialCursor specialization holds credential-specific behavior. ExnSeeker and exchange queries keep their existing key representation and behavior.

Shared exceptions live in the new src/keria/keriaing.py. They subclass ValueError/RuntimeError so existing except clauses keep working.

Validation

  • New tests/app/test_seeker_repair.py: 29 real-LMDB cases. They cover typed numeric/string/float equality, compound collisions, long (153–1024-byte) strings, issuee-less and optional-attribute schemas, legacy poisoned-index repair and idempotence, interrupted repair at four checkpoints, deletion during repair, missing-schema recovery, permanent-failure retention, bounded scheduler batches, and the HTTP 400/503 responses.
  • Fork CI at this head (d35ef3e) passed lint, format, the full make test suite on ubuntu-latest and macos-15, coverage, and Docker: Fix Seeker indexing and bounded startup recovery kentbull/keria#6.
  • Local run on 2026-11-05: ruff lint and format checks passed; git diff --check was clean. Across the seeker-repair, basing, agenting, credentialing, and ipexing test modules, 71 passed. Four TCP-based tests failed with getpeername EINVAL; unmodified main fails them the same way in the same sandboxed environment. The fifth failure is test_agency, which hits a pre-existing persistent local test-store collision. I didn't delete local stores to work around it.

Compatibility and limits

  • The search-key format changes. Existing stores are repaired by startup reconciliation; no KERI database migration is added. Credential and protocol data are unchanged. Don't run old and new Seeker writers against the same index.
  • Equality only. Keys depend on SHA-256 collision resistance and carry no ordering. Numeric ordering and ranges are explicitly unsupported (HTTP 400).
  • Scan performance. Prefix queries, string sorting, and deletion cleanup for failed indexes scan stored values. Reconciliation runs in bounded batches, but its total work grows with the stored corpus and it holds LMDB read snapshots during scans. None of this has been benchmarked at production scale.
  • Narrow schema support. Supported forms are scalar type declarations and the attribute-object oneOf shape. Attributes with no type, or with a type union, fail visibly; general JSON Schema indexing isn't implemented. A missing schema can stay pending indefinitely, but Seeker doesn't keep re-indexing it.
  • Failures are in memory. They're logged and re-evaluated at startup. This PR adds no durable failure store and no admin API.
  • Not a cause analysis. This PR doesn't establish that these defects cause the resource-usage reports in High CPU usage while idling after running for a while  #232 or [Bug]: CPU and RAM usage continuously increase and reach 100% during vLEI issuance/revocation long-run test #450.

🤖 Generated with Claude Code

Encode typed scalar tuples as fixed-size equality keys and derive complete canonical index definitions before use. Repair existing accepted-credential indexes on startup, including partial entries and incorrect compound definitions, without dropping named databases.

Keep recovery state in Seeker, retry only missing schemas, and make permanent failures visible. Bound scheduler work, tolerate deletion during repair, and isolate credential query semantics from exchange queries. Add real LMDB regressions for key boundaries, interrupted recovery, optional attributes, and query error behavior.

Validation: 38 focused tests pass in the pre-publication run; 77 distinct affected cases passed across earlier runs. Ruff and diff checks pass. The existing persistent-state test_agency, full-suite execution, and remote CI remain unqualified.
@codecov

codecov Bot commented Nov 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.48387% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.77%. Comparing base (2703b32) to head (d35ef3e).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/keria/db/basing.py 96.69% 9 Missing ⚠️
src/keria/app/agenting.py 80.76% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #472      +/-   ##
==========================================
+ Coverage   88.73%   88.77%   +0.03%     
==========================================
  Files          27       28       +1     
  Lines        6056     6253     +197     
==========================================
+ Hits         5374     5551     +177     
- Misses        682      702      +20     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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