Close audit-engine gaps: KB writeback, billing enforcement, LLM retry, tests#12
Merged
Merged
Conversation
…, tests Address five gaps found reviewing the codebase against its own claims: 1. REMEMBER now writes durably to the hybrid KB. Add HybridKnowledgeWriter (persistence/knowledge-writer.ts) persisting remembered fragments to Supabase + Neo4j with the same doc_id/chunk_id scheme as the seed ingester, so runtime-learned knowledge survives restarts. Wired through GraphDeps and index.ts; degrades to Crystalline-only when unconfigured. 2. Billing enforces payment before delivering value. The report is now released only after settlement succeeds; InsufficientCreditsError withholds it and exits non-zero. Add canAffordAudit() pre-flight warning, an AccountStore seam (in-memory + file-backed) so balances/on-demand spend persist across runs, and make createMppClient fail loudly when MPP_ENDPOINT is set but the HTTP-402 client is unwired (opt in via MPP_ALLOW_LOCAL_FALLBACK). 3. Add bounded exponential-backoff retry (llm/retry.ts) around chat.invoke so a transient 429/5xx/dropped connection no longer aborts a multi-call audit; deterministic 4xx errors propagate immediately. 4. Wire the previously-dead Neo4jRetriever.retrieve() into the hybrid pipeline as a standalone graph source alongside the Supabase-seed expansion. 5. Add unit tests for the new code and previously-untested logic (retry, account store, MPP, createBilling, knowledge writer, hybrid retriever, REMEMBER writeback, semgrep, solana). Suite grows 85 -> 138 tests. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01C8ZMZAu5Uq1N3NXNQikh3z
daemon-blockint-tech
marked this pull request as ready for review
July 22, 2026 03:18
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
Reviewed the codebase against its own documented claims and found five gaps where behavior diverged from what the README/comments promise. This PR closes all five. Everything stays opt-in and degrades gracefully — a default hermetic run behaves exactly as before.
npm run typecheck,lint,build, andtestall pass. Test suite grows 85 → 138.The gaps and fixes
1. REMEMBER didn't write back to the knowledge base it claimed to
The README and
persistence/store.tsboth stated durable cross-audit knowledge is "persisted to the hybrid knowledge base during the REMEMBER phase." It wasn't — REMEMBER only wrote to the session-scoped in-process Crystalline store. The only writer to Supabase/Neo4j was the offline seed script.persistence/knowledge-writer.ts(HybridKnowledgeWriter) persists each remembered fragment to Supabase (documents/chunks) and/or Neo4j (Document/Chunk/Entity) using the samedoc_id/chunk_idscheme asscripts/ingest-solsec.ts, so runtime-learned knowledge joins the seeded corpus and survives restarts.GraphDeps.knowledge(optional) andindex.ts. Never throws; unconfigured backends are skipped → Crystalline-only, as before.2. Billing delivered the report before enforcing payment
index.tsprinted the full report, then settled — so a failed charge gave the work away for free.createBilling()also minted a fresh full-allotment account every run, so on-demand overflow could never trigger and spend never accumulated. AndcreateMppClientsilently fell back to local settlement even withMPP_ENDPOINTset.InsufficientCreditsErrorwithholds it and exits non-zero.canAffordAudit()pre-flight warns when an account structurally can't pay.billing/account-store.ts(InMemoryAccountStore+FileAccountStore) — a real persistence seam wired as the ledger sink; balances/on-demand spend persist across runs viaBILLING_ACCOUNT_STORE_PATH.createMppClientnow fails loudly whenMPP_ENDPOINTis set but the HTTP-402 client is unwired; opt into hermetic settlement withMPP_ALLOW_LOCAL_FALLBACK=true.3. No retry/backoff — a single transient LLM blip aborted the whole audit
The pipeline makes 6+ LLM calls; none were retried.
llm/retry.ts(withRetry+isTransientError) wrapschat.invokewith bounded exponential backoff + jitter. Retries 429/5xx/connection errors; propagates deterministic 4xx immediately. Sleep is injectable for tests.4. Dead code:
Neo4jRetriever.retrieve()was never calledThe hybrid retriever only ever used
.expand().HybridRetrieveras its own graph source, alongside the Supabase-seed expansion (both share the Neo4j weight bucket).5. Untested core logic
retry,account-store,mpp,create-billing,knowledge-writer,hybrid-retriever, REMEMBER writeback,semgrep,solana.New/changed config (all optional, documented in
.env.example)BILLING_ACCOUNT_STORE_PATH— durable account persistenceMPP_ALLOW_LOCAL_FALLBACK— explicit opt-in to local settlement when an endpoint is configured🤖 Generated with Claude Code
Generated by Claude Code