Skip to content

feat(D140): in-force periods as an adjudication input, with fact window review (WP-ET.7) - #506

Merged
fazpu merged 15 commits into
mainfrom
feat/d140-wpet7-period-aware-adjudication
Oct 22, 2026
Merged

fazpu merged 15 commits into
mainfrom
feat/d140-wpet7-period-aware-adjudication

Conversation

@fazpu

@fazpu fazpu commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Review round 7 (GPT-6.1 Sol, on 292ab95f8): Approve (closure)

Review round 6 (GPT-6.1 Sol, on 44118ae07): no P0/P1; merge-interaction audit with D142 clean; one wording P2 and one nit → fixed in this round

✅ Owner decision on R3-P1-2 (2026-10-22): keep option (a)

A profile is re-embedded when its rendered (dated) text changes after a window review. The owner said: "Okay, leave it as is." This is a cheap projection refresh of text that really changed, and it re-processes no document text, so it sits outside CLAUDE.md Rule 4. It is recorded in decisions.md D140 and in design §8.2 (commit ac5366426). Option (b), a date-free embedded profile, was rejected: it saves only that call and shows no measured matching benefit. Backlog: #509, identity time for time-bound entities, to be built only if an eval shows distinct same-name events merged into one entity. origin/main (D142, #505) was merged in 44118ae07.

Implements WP-ET.7 of D140 (plan/plans/effective_time_and_section_references.md, design §8.2): a version's in-force periods become an input to E3 fact adjudication, and fact windows are reviewed when those periods change later. Ready for review; still a draft.

What it does

  • Adjudication input. A claim that occurs in versions with declared periods is shown to adjudication with source_in_force (the union of those versions' in-force intervals, current readings, current belief) and source_in_force_also_undated when the same text also occurs in an undated source. A prompt section explains when periods are world dates (rules/rates/obligations a document establishes) and when not (events it reports). D118 stays the only window authority. The jev engine's use_claim action dates an undated claim from a single in-force interval.

  • Undated parity. No new snapshot keys, so the fingerprint is unchanged; the prompt template is unchanged, and the section is spliced in only when a claim carries periods. There are no new jobs and no extra model calls. The only new work is one indexed existence probe (document_effective_time_events for the deployment) per snapshot and per apply.

  • Window review. relations/observations.period_basis fingerprints the in-force periods a window was adjudicated against. Every period-dependent input (bases, stale facts, shown periods, evidence digest) is read by one SQL statement. A basis is stored only from such a validated read: by every review, and by an applied adjudication for facts whose periods it saw unchanged through commit. A new review_fact_windows stage has two job kinds:

    • Lineage fan-out, queued by period writes, clear, version completion (reconcile), operator version deletion and document deletion, and only for lineages that ever had periods. It finds the facts whose basis moved.
    • Per-fact keep-or-replace review, grounded in supplied claims. It infers outside locks and re-checks the input fingerprint under the entity lock before applying. It applies the confidence floor and writes an adjudication-log row. On replacement it changes only the window and queues an entity-profile repair. That repair re-embeds a profile only if its rendered text changed.

    Duplicate triggers are free. Facts with no live evidence left are skipped.

  • Wiring. Migration p9_39_0060 (two nullable columns, one enum value); worker-review-fact-windows compose service; self-host handler; the label stage accepts single-fact targets.

Incremental ingestion is untouched (owner invariant)

WP-ET.7 changes no reuse input. It changes nothing in:

  • chunking (D58): core/chunker.py, workers/e1.py
  • the D56 extraction_input_hash or D140 reuse_identity_hash / text origin: core/text_origin.py, workers/e2.py
  • embedding inputs or D80 carry-forward: core/embedding_input_policy.py
  • chunk/claim catalogs

git diff origin/main...HEAD shows no change in those files. Periods are not inputs to any of them, and a window review only reads evidence and writes a fact window, an adjudication-log row, period_basis and a profile repair job. It never enqueues convert/structure/chunk/embed/extract work.

Regression proof src/tests/workers/test_d140_period_reuse_pg.py, a periodised dated lineage:

  1. v1 is ingested, then v2 with one changed paragraph plus a declared period. v2 extracts 1–3 chunks (the edit and its same-section neighbours), at least 70% of chunks are reused, and embeddings are no more than the extracted chunks + 1. This is the same bound as the undated D56 proof.
  2. A retroactive period correction then queues no pipeline work. Chunk, claim, chunk_claim, extraction-decision and search row counts are unchanged, with no extraction and no embedding call.
  3. Its lineage review finds the fact on a reused claim and reviews only its window: exactly one model call (the window review) and no extraction call.
  4. The production profile repair (LabelFactsHandler + EntityProfileRefresher, over a pre-built profile) makes exactly one embedding call: for the entity profile, because it displays the fact's window and that text changed. It embeds no fact, chunk or claim. A profile whose rendered text did not change costs no call (test_a_review_whose_window_leaves_profiles_unchanged_embeds_nothing).

Dual review round 1 (1c5cfc05): all findings addressed (head 3419f295)

Reviews and the per-finding response are in design/reviews/:
REVIEW_gpt-6.1-sol_d140_wpet7_r1_2026-10-21.md, REVIEW_agy-gemini-4-argon_d140_wpet7_r1_2026-10-21.md and RESPONSE_d140_wpet7_r1_2026-10-21.md.

  • First periodised fact: it is adjudicated (prompt engine) or dated from its single in-force interval (jev). It is never left undated by the novelty gate with its basis already stamped.
  • Period fence: decisions hold a per-deployment fence shared from final validation through commit, and the lineage fan-out passes it exclusively before reading stored bases. A stale window can no longer commit with no review pending.
  • Ingest declarations: a period declared or corrected on an existing (D55 no-op) version queues the review in the ingest transaction. New versions are reviewed on completion.
  • Owner invariant at the fact layer: a review changes only the window. It never clears, relabels or re-embeds the fact (the vector attests only the label text). The profile repair is keyed by the adjudication receipt, so A→B→A→B repairs every time.
  • Bounded work:
    • the period basis is computed in SQL
    • the fan-out is paged (500 per page, with continuation jobs)
    • review inputs fetch only the 40 claims shown, periodised claims first
  • Paid answers are durable: fact_window_review_attempts stores one answer per fact and fingerprint, and retries and duplicate jobs reuse it.
  • Deletion and forget:
    • the review is queued in the transaction of every deletion path (version, lineage, source-deletion finalisation, late-testimony retirement), and skipped during hard forget
    • hard forget clears period_basis and the review attempts
  • The owner regression is now non-vacuous. Moving version 2's start moves the fact's period. The review must replace the window, and the real label/profile repair runs with zero document, chunk, claim or fact embedding calls. (Superseded detail: the production-path test now also expects exactly one changed-profile embedding, as accepted by the owner on 2026-10-22.) No chunk, claim or search rows change and no extraction call is made.

Review round 4 (3b676c17): R4-P1-1 fixed structurally (head 17c81c1f)

Sol requested changes (one P1). The review and response are in design/reviews/: REVIEW_gpt-6.1-sol_d140_wpet7_r4_2026-10-21.md and RESPONSE_d140_wpet7_r4_2026-10-21.md.

R4-P1-1 was the third race of one family: certifying from two reads that agree across separate READ COMMITTED statements. The fix is one rule (design §8.2, "Consistency: certify only one consistent read"):

  • One read. Every period-dependent input is read by one SQL statement, read_period_inputs_on. That covers bases, stale facts, the shown claims' periods and the all-evidence digest. Preparation and validation both use it, in ordinary apply, review and the fan-out.
  • Certify only that read. A review stores the basis from its validated read. Ordinary apply stores the bases from its post-write verified read. This merges the earlier "record, then re-check" into one read, and record_period_basis_on is removed.
  • Order with the fence. A writer committing after the certifying read leaves a stale basis, which its fan-out, waiting at the barrier, reviews.

Period writers take no lock. This deliberately differs from the coordinator's suggested step 1.

  • In-force intervals also change on every extraction chunk_claims write, because a version's representation becomes current at structuring time, before extraction.
  • Freezing periods would therefore mean an exclusive deployment lock in all extraction writes, which serialises extraction, or unbounded per-lineage locks in every decision.
  • The one-read rule needs neither, and writer contention is unchanged.

The lock order is unchanged and there is no new lock.

Tests:

  • test_a_torn_review_read_cannot_certify_a_window_from_another_period, the reviewer's interleaving. It fails on 3b676c17 every time: a 2022 window is certified against 2023.
  • test_reviews_racing_real_period_writers_settle_on_the_final_periods: 48 real set_effective_periods transactions race the real worker, and every fact settles on its final periods.

The earlier race tests stay green, with two hooks moved to the renamed functions.

Review round 3 (dc44041f): P1-1 and P1-3 fixed, P1-2 awaiting an owner decision (head 3b676c17) — P1-2 resolved by the owner on 2026-10-22 (option a, see top)

Sol requested changes (three P1s, no P2s). The review and response are in design/reviews/: REVIEW_gpt-6.1-sol_d140_wpet7_r3_2026-10-21.md and RESPONSE_d140_wpet7_r3_2026-10-21.md.

Each new test fails on dc44041f's engine sources and passes here.

  • R3-P1-1, certification bound to the validated inputs:
    • The watch is anchored before final validation, reads the prepared inputs, and is one SQL statement, so its parts come from one database snapshot. It returns the stale candidates, one digest over all coverable claims' periods, and the shown claims' periods.
    • Validation also requires the validated shown periods to equal the watch's. Otherwise the decision is prepared again.
    • Bases are recorded only for changed facts that were not stale. The digest is then re-read over the same claims, and a difference rolls the application back.
    • Tests, one for each interleaving the reviewer reproduced: test_a_correction_after_final_validation_is_never_certified and test_a_correction_inside_the_watch_is_never_certified.
  • R3-P1-3, bounded watch:
    • The comparison stays in SQL. The worker receives only a digest, the stale ids and at most 100 shown claims' periods, with no truncation of evidence coverage.
    • Test: test_the_period_watch_stays_bounded_over_5001_evidence_claims. Peak traced memory stays under 256 KiB, and changes to the 5,001 unshown claims are still detected. On dc44041f the peak was 4.68 MB.
  • R3-P1-2, profile re-embedding on period-only corrections: owner decision pending resolved 2026-10-22, owner keeps option (a) (see top).
    • The current behaviour is option (a): a profile is re-embedded only when its rendered (dated) text changes.
    • Option (b) splits the entity profile into a date-free text that is embedded and the dated text that is displayed. Its estimate is in the coordinator report.

Dual review round 2 (3419f295): all findings addressed (head dc44041f)

Argon approved, with one nit. Sol requested changes (four P1s and a nit). The reviews and the per-finding response are in design/reviews/:
REVIEW_gpt-6.1-sol_d140_wpet7_r2_2026-10-21.md, REVIEW_agy-gemini-4-argon_d140_wpet7_r2_2026-10-21.md and RESPONSE_d140_wpet7_r2_2026-10-21.md.

Each P1 test fails on 3419f295's engine sources and passes here.

  • P1-1, ordinary apply certifies only what it saw:
    • Before writing, the application reads which candidate facts are already stale, and the periods of every claim its bases can cover. That includes all evidence of its candidate facts, not only the 100 claims shown.
    • It records the basis only for facts that were current, and re-reads those periods after recording. A change rolls the application back.
    • Tests: test_ordinary_apply_never_certifies_periods_its_decision_did_not_see and …_evidence_periods_it_was_not_shown.
  • P1-2, owner invariant through the production profile path:
    • Decision: profiles keep displaying windows, and a profile is re-embedded only when its rendered text changed. Review repairs no longer clear entity vectors. The production refresher embeds only on a changed input hash.
    • Tests: test_a_review_whose_window_leaves_profiles_unchanged_embeds_nothing (zero calls), and the owner regression now on the production refresher (exactly one call, for the changed profile text).
  • P1-3, transient failure:
    • Claims record their owner (the job's call key). A failed inference releases its claim.
    • Another job's live claim reschedules the work, due when that claim goes stale, instead of failing.
    • Tests: test_a_failed_inference_releases_its_claim_so_the_retry_succeeds (real Worker + WorkLedger: one retry, no dead letter) and test_another_jobs_live_claim_defers_instead_of_paying_or_failing.
  • P1-4, invalid citations:
    • Citations are validated before an answer is stored. An invalid answer is never stored, and the retry asks again.
    • Test: test_an_answer_citing_an_unsupplied_claim_is_never_replayed.
  • Nit: the migration docstring's NULL wording is fixed.
  • Migration: fact_window_review_attempts.claimed_by. Design §8.2 and the D140 note are updated in place.

Design refinement (please check)

D140 §8.2 promised that declaration changes "enqueue ordinary D118 re-adjudication". No mechanism re-adjudicates already-applied evidence, so this PR defines one: the window review. It refines §8.2, D140 (marked in place), mutable_fact_windows_design.md and the schema design, with no new decision number.

Checks run

  • GitHub CI on 17c81c1f: all green (20 pass, 1 skipped), CLA included.
  • Round-4 proofs (PostgreSQL 19 on Cloud Shell): test_d140_period_adjudication_pg.py (26 tests), the reuse regression and the forget proof: 28 passed. The torn-read test fails on 3b676c17 (shim: a stub verified_period_bases_on, for collection only).
  • Full suites on Cloud Shell: workers + spine: 967 passed; adapters, profiles, surfaces and core: 2646 passed, 6 skipped. test_graph_queries.py was deselected because it hits statement timeouts on the small VM; it passes in CI and this PR does not touch graph code.
  • Local: ruff and format, pyright (0 errors), generate_docs_llms --check.

Not done

  • No real-model benchmark of window decisions: the proofs use a canned model, so they show inputs and application, not answer quality.

Contributor agreement

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF

fazpu and others added 8 commits October 21, 2026 13:11
… review (WP-ET.7, WIP)

Claims from versions with declared periods carry their in-force intervals into E3 adjudication; undated attempts render and fingerprint exactly as before. A period basis on each fact records what its window was adjudicated against; a new review_fact_windows stage reviews facts whose basis moved after a period write, clear, version completion or deletion. Tests and docs follow.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
Work rows are unique per (target, stage, version), so each lineage request, per-fact review and relabel gets its own target id with the lineage/fact in the payload. Adds PG proofs (VAT example, retroactive correction, clear/redeclare, mixed support, deleting the closing edition, undated parity) and unit tests.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…, plan and public docs

§8.2 promised 'ordinary re-adjudication' on declaration changes, but no mechanism re-adjudicates already-applied evidence. The design now defines the window review (period basis, triggers, fan-out, keep-or-replace review) and D140 records the refinement in place. Public docs: the guide explains the input and the review; not-built-yet drops the item; install lists the new worker.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…fixes

A fact whose only source was deleted has nothing to review against; the lifecycle cascade already settled it, so the fan-out does not spend a model call on it. Test helpers order jobs by enqueued_at and resolve claims by handle.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…d inventories

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
Regression proof for the owner invariant: a periodised v1 -> v2 with one changed paragraph extracts and embeds only the edited chunk and its same-section neighbours (the undated bound); a later period correction queues no pipeline work, writes no chunk/claim/search rows and makes no extraction or embedding call; its window review is one model call. WP-ET.7 touches no chunking, reuse-key, text-origin or embedding input.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
- A first fact from periodised evidence is adjudicated (prompt engine) or dated from its single in-force interval (jev), never stamped by the novelty gate.
- A deployment period fence: decisions hold it shared from final validation through commit; the lineage fan-out passes it exclusively before reading stored bases.
- Ingest that declares or corrects a period on an existing version queues a review; new versions are reviewed on completion.
- A review changes only the window: no fact relabel or re-embedding; profile repair is keyed by the adjudication receipt.
- Bounded work: SQL-side period basis, paged fan-out with continuation jobs, bounded review inputs (periodised claims first).
- Completed review answers are stored per fact and fingerprint and reused; a live claim blocks duplicate paid calls.
- Crash-safe review requests on version, lineage and source deletion and late-testimony retirement; none during hard forget.
- Hard forget clears period_basis and review attempts.
- The owner regression now moves a fact's period, requires a replacement and proves no chunk, claim or fact re-embedding.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
…eviews and response

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
fazpu and others added 3 commits October 21, 2026 20:12
- Ordinary apply watches the in-force periods of every claim its bases can
  cover (shown claims and all candidate evidence), records bases only for
  facts that were current, and rolls back if those periods move before
  commit (Sol R2 P1-1).
- Review repairs no longer clear entity vectors; the production profile
  refresher re-embeds only profiles whose rendered text changed (P1-2).
- Review claims record their owning job; a failed inference releases its
  claim, and another job's live claim defers the work instead of failing
  (P1-3). Migration adds fact_window_review_attempts.claimed_by.
- Citations are validated before an answer is stored (P1-4).
- Migration docstring NULL wording (nit). Round-2 reviews and response.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
- The ordinary-apply watch reads the prepared inputs before final
  validation, in one SQL statement: stale candidates, one digest over the
  in-force periods of all coverable evidence, and the shown claims' periods.
  Validation also requires the shown periods to match the watch; bases are
  recorded only for non-stale facts and the digest is re-read after
  recording (Sol R3 P1-1).
- The comparison stays in SQL: the worker holds a digest, the stale ids and
  at most the shown claims' periods, however much evidence a fact has
  (R3 P1-3; 5,001-claim regression).
- R3 P1-2 (profile re-embedding) is awaiting an owner decision; behaviour
  unchanged. Round-3 review and response; design §8.2 protocol.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
R4-P1-1 was the third race of one family (certifying from reads that agree
across separate READ COMMITTED statements). Structural rule, D140 §8.2:

- Every period-dependent input (current bases, stale facts, shown claims'
  periods, all-evidence digest) is read by one SQL statement,
  read_period_inputs_on, at preparation and validation: ordinary apply,
  review and the fan-out's stored/current comparison.
- A basis is stored only from a validated one-statement read: reviews store
  the basis their validated read produced; ordinary apply stores the bases
  from its post-write verified read (record + re-check merged;
  record_period_basis_on removed).
- The fence orders certification before the fan-out of any later writer.
  Period writers take no lock: extraction's chunk_claims writes change
  in-force intervals, so freezing periods would serialise extraction.

Tests: the reviewer's torn A->B->A review interleaving (fails on 3b676c1)
and real concurrent period writers racing the worker. Removes a scratch
script committed by mistake in 3b676c1.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xd3Dz4iq5SKNAJcefffvqF
fazpu and others added 4 commits October 22, 2026 11:35
… window review (WP-ET.7 R3-P1-2)

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
…ngestion; note the accepted profile refresh (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
fazpu marked this pull request as ready for review October 22, 2026 09:55
@fazpu
fazpu merged commit 9810822 into main Oct 22, 2026
23 checks passed
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