Repository navigation
design: ranked search nominates from the index and confirms in one snapshot (D142, #504) - #505
Merged
Merged
Conversation
…one snapshot (#504) Analysis of why ranked P1 search scans every chunk, the nominate-confirm-refill design in the P1 search design (§6, §8, §9, §12, §14) with wording reconciled in the open query space, retrieval, document search and D140 designs; D142 with refinement notes in D94 and D98; the unchosen distinct-text search index proposal with its pilot-based adoption trigger; and the delivery plan. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
Ranked-read context with snapshot export/import for the SQL sandbox and pinned instants; one nomination cursor per channel (one BM25 scoring generation), disjoint fetches, scores carried; positive-match-only lexical semantics; channel-specific termination and a structured search result through RRF, fact merge, envelopes, semantic_invocations and scope_pending.complete; enforced and EXPLAIN-attested nomination plans; coverage-first facts merged by (coverage, distance, kind, id); cost-model limits; executable quality gates; distinct-text proposal fans out to member chunks with an isolated-prototype prerequisite; contrary contracts reconciled (D94/D98/D140 notes, graph, open query space, retrieval). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
One canonical BM25 score (fieldnorm-quantized length, one shared routine, bitwise ties) across index, exact tiers, SRFs, probe and oracle, with a reviewed memtable scorer-identity patch and a per-build scorer-identity gate; fetched-candidate vs index-internal work separated; predeclared paired non-inferiority LoCoMo gate; remaining same-statement clauses reconciled; open query space sequencing moved to plan/plans; immutable source links. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
Pin float8 accumulation order in the canonical BM25 score and qualify equivalence with today's ordering as measured (the upgrade comparison includes the scorer patch); fix the three residual statement-snapshot wordings; record review round 3. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
Pins upstream v1.5.1 (fa142d04), which supports PostgreSQL 19 and fills post-filtered BM25 top-k scans; removes docker/pg_textsearch-pg19.patch; updates the graph catalog version map, the D98 audit test, image provenance and the self-hosting requirements page. License and notice checksums are unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…ions Adds a CI regression test: v2 of a three-section document with one edited paragraph re-extracts and re-embeds only the changed chunk and its immediate same-section neighbours, while every other chunk reattaches its v1 claims and carries its v1 vector. Records the owner's approval (2026-10-21) of the distinct-text investigation/adoption rule and the incremental-ingestion invariant in D142 and the proposal. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
Adds adapters/p1_ranked.py: one nomination cursor per search (join-free index statement, planner controls scoped to DECLARE, EXPLAIN-attested index plan), disjoint doubling fetches confirmed by primary key with the unchanged eligibility predicates, positive-match-only BM25, the canonical-score stop margin (index score <= canonical <= index/(1-1/9)), channel-specific termination and HNSW exhaustion by exact count. Claim/chunk semantic and BM25 searches run on it in one read-only REPEATABLE READ ranked-read connection; explicit candidate sets stay exact; entity-scoped searches rank coverage tiers (exact up to 5,000 items, loop inside larger tiers, entity work budget). Results are P1SearchResult (tuple + account). Writers reject zero-norm and non-finite vectors. Unit tests pin the stop margin to the fieldnorm table and the reviewer's 48/50/67 counterexample. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
Implementation decision: keep the standalone <@> operator as the canonical BM25 score, evaluated in the nomination cursor's executor, and stop only past a proven margin (quantization rounds lengths down by < 1/9, so index <= canonical <= index/(1-1/9)). No extension patch; a scorer-bound gate re-verifies the bound per image build. Design §6/§8.3/§9, D142, D98 note, graph design, analysis and plan updated; flagged for the next review round. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…ult propagation Deployment-wide fact search and fact nomination run one D142 loop per fact table merged by (distance, kind, id); entity profile search runs on the loop; entity-scoped and explicit-key fact searches stay exact scans and report their account; entity-scoped testimony nomination enforces positive-match BM25 and the entity work budget. Accounts propagate: P1SearchIds keeps the account for unscored ids, nomination envelopes disclose early stops as truncation (reason p1_<termination>) and report a boundary instead of known_empty when a search stopped on a bound, and claims_and_sources_context marks its testimony lists truncated when any channel stopped early. SQL-shape tests updated to the join-free nomination plus confirmation. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…register unit test Connection.execution_options() mutates the connection in SQLAlchemy 2.0, which turned later statements into server-side cursors; stream_results is now passed per statement. Nomination statements carry LIMIT = work budget because both extensions use their index only for ORDER BY ... LIMIT. Registers test_p1_ranked.py in the unit test inventory. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
The previous commit's inventory edit dropped unrelated entries; this restores the file byte-for-byte and inserts the one new path. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
The SQL sandbox exports its READ ONLY, REPEATABLE READ request snapshot and the P1 adapter imports it (BoundedPostgresReadPool.snapshot(import_snapshot=...)), so nomination, continuation and the executor's D48 confirmation read one state; a failed export is p1_unavailable. Invocation records carry the D142 termination (completed or p1_<reason>). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…ontracts Freshness.scope_pending gains complete (false when a probe nomination stopped on a bound; count is then a lower bound), threaded from every probe's account. claims_and_sources_context runs its P1 reads in one pool snapshot (nested operations reuse the enclosing one). Regenerates openapi.json, the TypeScript client contracts and the memory_v1 surface manifest; re-pins the LoCoMo surface manifest hash and protocol fingerprint that embed it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
Real pg_textsearch/pgvector proofs: BM25 loop equals the canonical (standalone) oracle under a restrictive document filter, scores included; absent/stop-word queries return no lexical rows and end exhausted, with no zero-score tail; the reviewer's 48/50/67 counterexample returns the 67-token canonical winner at k=1; a 40/41-token canonical tie orders by stable id; a rejecting confirmation ends work_budget; HNSW nomination with confirmation proves exhaustion by count; an imported snapshot hides rows committed after export. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
benchmarks/p1_ranked: explain_real.py (WP-RS.0, for a copy of a real deployment), sweep.py (size sweep with current, 1% filter and history strata over superseded duplicate editions), recall.py (HNSW recall gate with the design's starting thresholds) and locomo_gate.py (predeclared paired non-inferiority test; unit-tested). Docs: positive-match BM25, early-stop truncation reasons (p1_*), invocation termination reasons and scope_pending.complete; llms-full.txt regenerated. Plan records per-WP status, including what is pending. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…traction identity The ranked Postgres proofs now publish the deployment's P1 channels, as the adapter requires. The owner-invariant reuse test counted claim rows on v2 chunks as re-extraction, but a D56 Selection replay also materializes claims on the new chunk; it now compares extraction input identities and pins the model-call count to them. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…hange; revision-pinned scorer-bound gate The approved design bound the scorers with a local pg_textsearch patch; the implementation replaced it with the §8.3 margin. D142, the design, the analysis and the plan now say so as a design change for the dual review. The scorer-bound gate text now matches what exists: a unit gate that fails when the image pins a revision other than the one the margin was verified on, and Postgres proofs on the built image; the randomized spill-mixed corpus is named as not built. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…e eligible rows Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
`= ANY(:batch_ids)` let the planner drive confirmation from the eligibility joins: every eligible chunk, each re-probing the whole id array. The scaling sweep caught it at 17 s for one 4,000-id batch at 30k chunks. Confirmation and the exact tier now unnest the batch and probe each candidate through a LATERAL existence/score subquery (131 ms for the same batch). Testimony, fact and entity confirmation share the shape. Verified on an isolated Postgres (built engine image): test_p1_ranked_pg, test_postgres_p1, test_postgres_p1_document_filters, test_d140_scoped_retrieval — 61 passed. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…per-candidate confirmation The D140 seed's words come from hashint8 (a 32-bit hash) divided by 2**63, so every word is w0 and every chunk has 24 words: every BM25 score ties and the sweep measured only tie runs. The sweep now rewrites search text with Zipf-skewed words of 20-300 words per chunk before measuring. Design §8.3 step 3 records the LATERAL per-candidate confirmation and that per-rule-class rejection counts are not implemented yet. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
With a 1% document filter the loop fetched up to the work budget and still stopped short (sweep: 5% of queries at 30k chunks, 30% at 300k). A document-filtered search now reads its eligible rows up to the exact-tier threshold + 1 and scores them exactly when they fit, as entity tiers do. The oracle proof runs both through the loop and through the tier. Design §8.4 records it as a post-approval addition. Verified on an isolated Postgres (built engine image): 62 passed across test_p1_ranked_pg, test_postgres_p1, test_postgres_p1_document_filters, test_d140_scoped_retrieval. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…eeds D134 metadata The tier's eligibility probe let the planner start from every chunk: 6 s at 3M chunks for a 60-document filter. It now starts from the matching versions (live_matching_versions, the set form of live_version_matches) and reads each version's chunks through a LATERAL subquery: 511 ms for 60 documents, 107 ms for 6. The sweep now gives every seeded version D134 metadata; without it the document stratum matched nothing. Verified on an isolated Postgres (built engine image): 62 passed. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…d the open 1% stratum Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
… test (review r1 P1-2) A fixed 1e-4 slack is not a bound: float4 accumulation error grows with the number of terms, and 40,000 single-occurrence terms in one long document reach canonical/index = 1.12533 against the fixed margin 1.12523 (the reviewer's counterexample, emulated in a unit test). The margin is now (1+ε)^4/(1-1/9) with ε = 2(n+16)u, n an upper bound on analyzed query terms ((len+1)//2) and u the float4 unit roundoff. A new Postgres test spills half a randomized corpus and checks both inequalities and the index order for every streamed row against bm25_get_current_score(). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…ero vectors (review r1 P2-6) require_p1_vector (port contract) now guards every P1 vector writer, including both profile-refresh paths on the provider response, before any write transaction. HNSW exhaustion counts exclude zero-norm legacy rows, which cosine HNSW does not index. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…nput rows; shared tiers; pinned operation (review r1 P1-5, P1-6, part of P1-4/P1-7) - P1-5: fact nomination (loop and scoped branches) joins facts_visible_history before a row counts toward the candidate cut. - P1-6: the entity budget counts mention rows (and, for scoped fact scans, endpoint fact rows) at most budget+1 before anything is scored; nominate_testimony_scored runs the same coverage-tier execution as ordinary search (exact small tiers, the index loop in large ones). - The bounded read pool's snapshot pins a ReadOperation (deadline and the transaction's now() or an explicit instant); nested reads clamp statement_timeout to the time left, and the P1 adapter takes its default instant and deadline from it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…napshot, deadline and instant (review r1 P1-1, P1-3, P1-4, P1-6 mapping) - Port methods return P1SearchResult/P1SearchIds explicitly; test doubles follow. merge_accounts moves to the port and keeps limits. - search_claims/search_chunks, claims_and_sources_context and standalone facts_context own a ranked-read operation: nomination (always with an explicit scope at the pinned instant), confirmation, hydration, entity checks and pending/freshness reads use its snapshot connection. - Early stops are disclosed (p1_<reason>) and never become known_empty: public searches, the testimony hybrid (per-channel reason through RRF and combine_evidence), fact fusion and the profile channel (even with no profile ids). Statement-timeout expiry answers with a typed p1_deadline boundary; entity_scope_too_broad is a typed boundary in every caller. - New failing-first tests (test_d142_accounts.py: 4 of 5 fail on the old code). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…ans hydration (review r1 P1-1, P1-3, P1-4, P1-7) - The SQL bridge exports pg_export_snapshot() with the request's now(); the P1 adapter imports both, so every default scope and fact time inside the SRF uses the request's authority instant. pg_confirmed_at reports that pinned instant (now()) instead of statement_timestamp(). - The imported snapshot stays open through confirmation and chunk-body hydration. - BridgeSettings carries the request's absolute statement deadline; every SRF spends that one budget instead of a fresh 30 s each. - SemanticInvocation publishes fetched and rejected from the search account (nominated is only the returned prefix); OpenAPI and the TypeScript contracts are regenerated. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…ocument-filtered searches (review r1 P1-9, post-approval design change) A document-filtered chunk search enumerates its eligible rows from the matching versions (at most FILTER_PUSHDOWN_LIMIT = 100,000). Up to the exact-tier threshold they are scored exactly; above it the set is pushed into the BM25/HNSW index scan as a hashed membership filter, so the cursor streams eligible rows only, in index order, under the same stop rules; the HNSW exhaustion count is filtered alike. Confirmation still applies every predicate. The oracle proofs now cover the plain loop, the pushdown and the exact tier; the semantic exhaustion proof covers loop and pushdown. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…nd more strata (review r1 P2-4) Queries come from the generator's own Zipf distribution, identical at every size; strata add 0.1%/10% document filters and both sides of the 5,000-row tier; each query runs through QueryEngine.search_chunks and reports the public outcome (k returned, boundary reason) with the adapter's account (fetched, rounds, termination); eligible-row counts, corpus and query hashes are recorded; the nomination-work proxy explains the production statement read to the measured depth. --measure-only measures an existing corpus. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…e measures production paths (review r1 P2-2, P1-9) On a clustered 100k-vector corpus the gate failed at pgvector's default ef_search 40 (mean recall@10 0.887, single queries at 0.0); 200 measured 0.999 unfiltered and 0.996 with a 1,000-document filter. The recall harness no longer disables the exact tier: the filtered stratum is sized above it (pushdown + HNSW) and any stratum answered exactly makes the gate inconclusive. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…egression suite (review r1 P2-3) The builder stage starts a throwaway cluster of the exact PG19 server build and runs make installcheck; a failure prints regression.diffs and fails the build. On the pinned image all 82 upstream tests pass (verified on an isolated VM build). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…eds the pushdown Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…y gate open; pushdown limit 20,000 (measured) The eligible-set pushdown removes the 1% stratum's early stops at 3M chunks (25% -> 0; adapter p50 618 ms / p95 827 ms vs 3.9 s / 4.5 s), but a 10% filter is slower pushed down (4.7 s vs 1.7 s), so the limit is 20,000 rows. The interactive p95 budget (~300 ms) is not met at 3M by the filtered or the unfiltered stratum; analysis §8.2 records the numbers and design-level options for the owner. Results and the recall gate run are archived under plan/analysis/data/. D142, design, plan and the review response are updated. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…us update Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…rywhere, typed timeouts, resolve accounts, survivor fact budget (review r2 P1-1..P1-5) - P1-1: bridge fact nomination no longer overrides the imported instant; fact confirmation applies facts_current's predicates at the request transaction's now() instead of the view's statement_timestamp(). - P1-2: fact/entity entry points derive their deadline from the operation; the loop re-clamps statement_timeout before attestation, every FETCH and every confirmation; the sandbox re-clamps before bridge confirmation and before the outer statement; standalone facts_context uses the operation deadline. - P1-3: 25P04 (transaction_timeout) is a deadline like 57014; nominate_claims/nominate_chunks and standalone facts_context answer a typed p1_deadline boundary; planner settings are restored only in a healthy transaction, so a cancelled EXPLAIN/DECLARE keeps its error. - P1-4: resolve runs in one operation, keeps the T3 account (boundary for a capped empty search, reason on a partial one); default_facts_context keeps the fact stop reason. Failing-first unit test for resolve. - P1-5: the scoped fact-scan budget counts the raw endpoints of every entity the requested survivors absorbed (the scoring scope), at most budget+1 rows across both tables. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…alidates each run's recorded identity (review r2 P2-1, P2-2) - The BM25 stop margin counts query terms with the real parser (ts_debug, compound tokens and their parts) before the loop; the epsilon derivation now proves both rounding directions with explicit denominators and holds exactly for m·u <= 1/4 (longer queries are refused). Domain tests at the boundary; a Postgres test checks the parser count (a-b -> 3). - The runner gains load_recorded_run: every self-consistency check of _load_run (recomputed fingerprint, hashes, rendered documents, state and judge/answer identity) without the current code's pins. The gate uses it and requires an answer and a judge for every question. The old-pin fixture is now prepared under that pin (a genuinely valid baseline); missing-answer, mismatched judge id and edited-fingerprint runs are refused. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…ted as float4; zero vectors never eligible (review r2 P2-3, P2-6) - _entity_tiers passes the remaining per-search work budget to every tier loop and stops with work_budget when it is spent; limits report the loop and HNSW settings. Unit test: two rejected large tiers get 20,000 then the remaining 5,000. - require_p1_vector checks the float4 values pgvector stores: underflow to zero and overflow are rejected before any write. - Zero-norm legacy vectors are excluded from every exact semantic path (testimony tiers, scoped fact scans), as HNSW already cannot reach them. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
… and traced-reuse proofs; sweep hydrates public results (review r2 P1-1..P1-5, P2-4, P2-5) - Bridge: two fact SRFs across an already-declared validity boundary that passes during nomination confirm at one request instant; SRFs that use up the request budget leave the outer statement a timeout, and a cancelled confirmation answers statement_timeout. - Adapter: real statement timeouts during attestation and confirmation answer p1_deadline through search_chunks; fact and entity searches inherit the operation deadline; a hub whose facts store an absorbed entity's id is entity_scope_too_broad directly and through predicate-filtered facts_context; the parser term count. - Reuse regression: every Selection and Claimify call traced to its target chunk; one call per new Selection/Claimify identity; Claimify reruns bounded to the known eight-chunk window; reuse identity and text origin carried; the expected failure holds only the requirement-vs-gap assertion. - Sweep: hydration ignores the absent embedding generation so public results hydrate; the plan proxy uses the production LIMIT without ANALYZE; per-query accounts are recorded. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…nding design; ef_search 200 with its evidence; correct stale claims (review r2 P2-7, nits) - Design §8.5 and D142 describe the implemented alternative: a survivor-expanded stored-endpoint budget (50,000 rows) counted first, the typed entity_scope_too_broad above it, exact scoring below it; not the tier loop, and not a 5,000-row tier. - Design §8.5 states hnsw.ef_search = 200 and links the synthetic recall evidence. - D142 names the vector write validation change and states exactly what the owner-invariant regression proves. - Plan and analysis: hydration and the spill-mixed test are no longer gaps; latency growth is sublinear, not corpus-independent; the 3M rerun is labelled diagnostic. Test docstrings match what they test. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
The deadline test's clock is keyed to the first confirmed round (the per-statement clamp also reads the clock); merged entities carry their status; the sandbox budget test uses only grammar-allowed SQL; the hub fixture scopes without requiring a mention-backed anchor. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
… with hydrated public results At 300k chunks no stratum stops early and public results hydrate; unfiltered p95 263-267 ms; filtered 351 ms to 2.1 s; the exact tier is slower than the pushdown on either side of its threshold (input to the owner's latency decision, review r2 P1-6, not changed here). Full integration suite on the built image: 1,231 passed, 2 skipped, 1 expected failure. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…s (review r3 P2-1, nits 1-4) - budget_exhausted unwraps SQLAlchemy-wrapped errors and recognises 57014, 25P04 and admission timeouts; nomination, confirmation, coordinate confirmation and body reads answer statement_timeout for them and keep p1_unavailable / confirmation_failed for genuine failures; the executor catches TransactionTimeout like QueryCanceled. Database-free tests through the public executor (9 of 11 fail on the previous code). - Design §9.1 states cursor_tuple_fraction = 1 and force_custom_plan with their rationale and the healthy-transaction restore. - The sweep docstring describes what it measures and what it does not. - The reuse regression compares a Counter of called chunk ids with the expected Selection and Claimify rerun ids, one chunk per call. - The BM25 margin domain is validated before the cursor opens. - Review r3 copied; response added. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…on reads; sweep every sandbox catch (review r4) _shared_snapshot and _pinned_generations answer statement_timeout for 57014/25P04 (cause kept) before their p1_unavailable / confirmation_failed mapping; the executor's format_type fallback re-raises a budget error instead of continuing in an aborted transaction. No other broad catch in the query sandbox maps a budget error to another code. Database-free public-executor tests for both SQLSTATEs at both points, with an imported_snapshot double and non-budget controls (the four budget cases fail on the previous bridge). Review r4 copied; response added. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…d classifier look-alikes (review r5 nit) An uncached result-type OID whose format_type lookup hits 57014 or 25P04 answers statement_timeout with no row fetched (both fail with the re-raise disabled). The classifier ignores timeout text in another error (raw and wrapped), lock timeouts, a built-in TimeoutError and an implicit context, and follows an explicit cause. Review r5 (approve pending the P1-6 owner decision) copied. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…S.11 follow-up (#508); post-merge gates The owner (2026-10-22) replaced the blanket p95 ≈ 300 ms scaling criterion with named size- and stratum-specific budgets measured at 300k chunks on the final configuration, each paired with completeness (0 early stops), with the public operation, corpus shape, machine and cache conditions, query population and repetitions stated. Multi-second filtered reads are accepted for now; 3M and 50M are ungated until measured; the 300 ms goal stays the target for WP-RS.11 (immutable doc_id on search rows + re-tuned document exact-tier threshold, issue #508, own gate). The paid LoCoMo gate and WP-RS.0 are post-merge follow-ups. Reconciled in D142 (status accepted), the binding P1 search design §9, the retrieval design's budget note, the plan and the analysis. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…he latency decision resolved (review r6) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
fazpu
marked this pull request as ready for review
October 22, 2026 09:44
Merged
1 task done
1 task done
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.
Fixes #504: ranked search scans every chunk instead of using its BM25/vector index. Design (approved in review round 3) plus implementation. Draft — do not merge; dual review (GPT-6.1 Sol + Antigravity) pending.
✅ Owner decision on P1-6 (2026-10-22): latency criterion amended; merge, then WP-RS.11
The owner's words: "definitely this way. It still sounds like a significant improvement. Let's get it in." The amendment is recorded in D142, in design §9 (the scaling gate), in the plan, in analysis §8.3, and in the retrieval design's budget note.
What changes. The blanket "p95 ≈ 300 ms at target size" criterion is replaced by measured budgets, per size and per stratum. They hold at 300k chunks only. The workload is public
search_chunks(BM25, k = 20) over a synthetic corpus: 6,000 lineages × 5 versions × 10 chunks, half periodised, half with duplicated editions. It ran on an n2-highmem-8 VM with a warm cache, using 40 fixed queries, each run once per stratum. Every stratum also requires 0 early stops.Next work item: WP-RS.11 (#508), not in this PR. It covers two things:
doc_idon the search rows;It has its own measured gate: p95 ≤ 300 ms for the filtered strata at 300k with 0 early stops, plus 3M on hydratable results.
Post-merge follow-ups (owner decision):
EXPLAINon a copy of a deployment;Review round 8 (GPT-6.1 Sol, on
cb437aa03): Approve (closure; review text kept outside the repo to avoid another CI cycle)Review round 7 (GPT-6.1 Sol, on
30228a419): one PR-description P2 (annotate historical pending headings) → fixed in this descriptionReview round 6 (GPT-6.1 Sol, on
cdc22288d): two documentation P2s (history eligible population 180,000; superseded pending statuses) → fixed in30228a419Review round 5 (GPT-6.1 Sol): Approve, pending the owner's P1-6 decision — resolved by the owner's amendment, 2026-10-22
The review is copied to
design/reviews/REVIEW_gpt-6.1-sol_d142_impl_r5_2026-10-22.md. Its one non-blocking nit is done, as a test-only change:The dynamic result-type lookup returns
statement_timeoutwith no row fetched, for both 57014 and 25P04. These tests fail if the re-raise is disabled.The timeout classifier now has negative controls: timeout wording inside other errors (raw and wrapped), a lock timeout, a built-in
TimeoutError, and an implicit exception context.CI: all green on
1223ba6f5; onlydeploywas skipped.Still open: R2 P1-6, the latency gate, waiting on the owner's decision.Resolved 2026-10-22 by the owner's amendment (top of this description).Review round 4 (GPT-6.1 Sol): one item left, now fixed; R2 P1-6 (latency) still open for the owner — resolved by the owner's amendment, 2026-10-22
The response is
design/reviews/RESPONSE_d142_impl_r4_2026-10-22.md, with the review copied next to it.statement_timeoutfor 57014 and 25P04, keeping the original cause, before their usualp1_unavailableorconfirmation_failedmapping. I also checked every other broad catch in the query sandbox. The only other one, the executor'sformat_typefallback, now re-raises a budget error instead of continuing in an aborted transaction. Database-free tests go throughquery_sql: both SQLSTATEs at both points, using a double that really exposesimported_snapshot, plusUndefinedColumncontrols. The four budget cases fail on the old bridge.fb90bfd24; onlydeploywas skipped.Review round 3 (GPT-6.1 Sol): round 2 closed apart from one P2 and four nits, now fixed; R2 P1-6 (latency) still open for the owner — resolved by the owner's amendment, 2026-10-22
The response is
design/reviews/RESPONSE_d142_impl_r3_2026-10-22.md, with the review copied next to it.statement_timeout. Genuine failures keepp1_unavailableandconfirmation_failed. Database-free tests run through the public executor: 9 of 11 fail on the old code.cursor_tuple_fraction = 1andforce_custom_plan, with the rationale.Counterof the chunks actually called must equal the expected Selection and Claimify rerun IDs, with one chunk per call. This sits outside the expected-failure test, and it passes in CI on Postgres.9ad1451bd; onlydeploywas skipped.Review round 2 (GPT-6.1 Sol, on
0ad5a0be9): REQUEST CHANGES → P1-1 to P1-5, every P2 and the nits addressed; P1-6 (latency) open for the owner — resolved by the owner's amendment, 2026-10-22The full response is
design/reviews/RESPONSE_d142_impl_r2_2026-10-22.md, with the review copied next to it.origin/mainis merged in, so Rule 4 and theAGENTS.mdpointer are present. Rule 4 holds: nothing here changes chunking, reuse keys or the Selection/Claimify/embedding inputs.facts_current's own predicates at the request'snow()instead ofstatement_timestamp(). Tested on Postgres: two SRFs across a validity boundary that passes during nomination keep the fact, at one reported instant.statement_timeoutbefore attestation, every FETCH and every confirmation. The sandbox re-clamps before confirmation and before the outer statement. Standalonefacts_contextuses the operation deadline. Covered by Postgres tests.nominate_*and standalonefacts_contextreturn typed boundaries. Settings are restored only in a healthy transaction, so the original error survives. Real timeouts during attestation and confirmation returnp1_deadline(Postgres tests).resolveruns in one operation and keeps the T3 account: a capped search with no hits is a boundary, notunknown_entity. The compound keeps the fact stop reason. The test fails on the old code.entity_scope_too_broad, both directly and throughfacts_context.doc_idon search rows plus a measured fix (or an owner amendment) for unfiltered p95. New data at 300k: unfiltered p95 263–267 ms; filtered 351 ms to 2.1 s; the exact tier is slower than the pushdown at its threshold (analysis §8.3).nis the parser's real term count (ts_debug, compound tokens included). The derivation has explicit denominators and is proved form·u ≤ 1/4; anything larger is refused.load_recorded_runreuses the runner's self-consistency checks without the current pins. Every question needs an answer and a judge. A genuine old-pin fixture loads; edited or mismatched runs are refused.Checks run (round 2)
156a9eb6c(onlydeployskipped).d142-r2, using the branch's built image: the full integration suite gives 1,231 passed, 2 skipped, 1 expected failure, and the 300k sweep was run. The VM was deleted, andgcloud compute instances listanddisks listboth come back empty.Review round 1 (GPT-6.1 Sol, implementation, on
304ada30b): REQUEST CHANGES → addressedAntigravity is still to review (its quota ran out). The full response is in
design/reviews/RESPONSE_d142_impl_r1_2026-10-22.md, with the review copied next to it.(1+ε(n))⁴/(1−1/9), withε(n) = 2(n+16)·2⁻²⁴(P1-2).69a68e407; design §8.3/§8.4, D142).hnsw.ef_search200 in the semantic loop (the §9 recall gate).facts_visible_history) applies before the fact nomination cut (§8.5).Status per finding
fetched/rejected). A capped search never yieldsknown_empty. Failing-first tests: 4 of 5 fail on the old code.ε(n). The reviewer's counterexample is emulated in float32. A built-image test runs a randomized half-spilled corpus and checks both inequalities and the index order againstbm25_get_current_score().nominate_*,claims_and_sources_context(entity check included) and standalonefacts_contextrun in one operation. Confirmation, hydration and pending/freshness reads use its connection. The sandbox import spans hydration. Document search is read-only REPEATABLE READ.evaluated_at, and the adapter defaults to it. The bridge exportsnow()with its snapshot.pg_confirmed_atreports the pinned instant.nominate_testimony_scored.entity_scope_too_broadis a typed boundary in every caller.statement_timeoutto the remaining time. The loop checks the deadline before every fetch. The SQL sandbox passes its one request deadline to every SRF. Covered by Postgres tests.doc_idsis applied before the cap, with one row read past it. An overflow setscomplete=falsein both surfaces.ef_search40 (0.887).plan/analysis/data/.cursor_tuple_fraction=1,force_custom_plan). The caller's planner settings are restored.Checks run
0ad5a0be9; onlydeploywas skipped.d142-r1(now deleted; no instances or disks remain), using the branch's built image:Owner-gated items still PENDING
EXPLAINcheck: not run. The harness is ready:benchmarks/p1_ranked/explain_real.py --deployment <uuid> --query … --out explain_real.json, run against a copy of a real deployment once the current LoCoMo run has finished.benchmarks/p1_ranked/locomo_gate.py --main <3 runs> --change <3 runs>. It implements the predeclared paired non-inferiority test and exits 0 for pass, 1 for fail, 2 for inconclusive.The round-3-approved design made the two BM25 scorers identical with a local pg_textsearch patch. During implementation that patch proved broad: the index accumulates float4 terms in index order on four scoring paths (memtable, segment WAND, single-term fast path, top-k heap), while the standalone operator accumulates float8 in query-term order. So the implementation uses bounded reconciliation instead, with no extension change:
FIELDNORM_DECODE_TABLEat the pinned revision. Hence, for every row,index ≤ canonical ≤ index/(1−1/9), give or take float slack.k_filledonly when the k-th canonical score is greater than(1+ε(n))⁴/(1−1/9)(≈ 1.126 for a 4,096-character query;ε(n)from the parser's term count) × the last fetched canonical score. No unfetched row can then enter the result or tie with it.BM25_BOUND_VERIFIED_REVISION.What is implemented (by WP)
fa142d04) is pinned, the D98 patch is deleted, and every pin, checksum and doc is updated. Writers reject zero-norm and non-finite vectors.REPEATABLE READpool snapshot. The SQL sandbox exports its snapshot and P1 imports it (SET TRANSACTION SNAPSHOT). The P1 reads ofclaims_and_sources_contextshare one snapshot.adapters/p1_ranked.py: nominate → confirm → continue. One streamed cursor per channel withLIMIT= the work budget. Planner controls are scoped to the statement, and the plan isEXPLAIN-attested (otherwiseplan_rejected). Fetches are disjoint and doubling from 4k. Terminations arek_filled/exhausted/work_budget/deadline/ann_scan_bound/plan_rejected. HNSW exhaustion is proven by an exact count. Covers chunk and claim searches, semantic and BM25.P1SearchResult/P1SearchIdswithP1SearchAccount. Envelopes disclosep1_<termination>truncation and return a boundary negative, notknown_empty, when a search was incomplete. Also covers testimony lists, sandboxSemanticInvocation, andscope_pending.complete(new field: OpenAPI, TS client and manifest regenerated).P1EntityScopeTooBroadError). Post-approval addition: document-filtered chunk searches with at most 5,000 eligible rows are scored exactly; the probe is driven from the matching versions.test_p1_ranked.py), Postgres proofs (test_p1_ranked_pg.py) and the owner's incremental-ingestion regression (below).llms-full.txt.Migrations: none. D142 adds no Alembic revision, so there is nothing to collide with #506 (WP-ET.7).
Owner invariant: incremental ingestion
D142 touches none of the following: anchor-stabilized chunking (D58), the
extraction_input_hash/reuse_identity_hashinputs, text-origin logic, embedding carry-forward, orsearch_text/embedding inputs. The only change near ingestion is that writers refuse zero-norm and non-finite vectors.New CI regression
test_reuse_lifecycle.py::test_one_paragraph_edit_reuses_every_chunk_outside_its_neighbourhood: v1 then v2 of a three-section document, with one paragraph of section B rewritten. It asserts:Scaling sweep (WP-RS.8)
See analysis §8.1 (the first run), §8.2 (the round-1 rerun at 3M, diagnostic) and §8.3 (the final-configuration 300k run that passes the amended criterion). Results are archived in
plan/analysis/data/.Deviations from the plan
entity_scope_too_broad).Hydration outside the snapshot: fixed in round 1 (P1-3).scope_pending.complete), so earlier run artifacts don't compare by hash.LATERALsubquery instead of= ANY(:batch_ids)(design §8.3 step 3, updated). It does not yet report the rejection class for each rejected ID; it reports counts only.Design history
Reviewed by GPT-6.1 Sol in three rounds; round 3 approved. Responses are in
design/reviews/RESPONSE_d142_design_r{1,2,3}_2026-10-21.md, with each review copied next to its response. Design:plan/designs/postgres_p1_search_projection_design.md§6, §8, §9, §12, §14. Analysis:plan/analysis/index_driven_ranked_search.md. Plan:plan/plans/index_driven_ranked_search.md. Decision: D142.🤖 Generated with Claude Code
https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF