Skip to content

feat(tags): filter the context operations by D156 tags (step 3) - #615

Merged
fazpu merged 8 commits into
mainfrom
feat/document-tags-context-ops
Nov 14, 2026
Merged

fazpu merged 8 commits into
mainfrom
feat/document-tags-context-ops

Conversation

@fazpu

@fazpu fazpu commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Summary

D156 delivery step 3 (builds on #606 and #614, both merged): the documents filter on the three context operations, and with it the §4.4 fact-evidence rule.

Design: plan/designs/document_tags_design.md §4 / §6 / §8, decisions.md D156, plan/designs/open_query_space_design.md §3.1. Plan: plan/plans/document_tags.md (now: all steps implemented).

What changes

Operations. claims_and_sources_context@5, facts_context@5, combined_context@6 take an optional documents object — the same D134/D156 filter search takes, tags included. Validated before retrieval (invalid_parameter for shape errors, unknown_tag 422 naming every unregistered tag). combined_context passes it unchanged to both children. With entity_ids an item must satisfy both. The other inputs (time, hops, predicate, entity caps) are unchanged. surface_manifest_hash rolls; the operation linter's canonical versions follow.

Eligibility before ranking (D142/D153), reusing the step 2 compiler — no new filter path, no post-filtering.

  • Claims/chunks: global nomination channels already took documents (step 2); the entity-scoped nominate_testimony_scored now applies it too (claims through claim_selected_matching, i.e. the same-occurrence D140 rule; chunks on the candidate version), including the §3.7 pending-probe replay. Confirmation (_confirm_claims / _confirm_chunks) re-checks it, now also with entity_ids.
  • Facts: under a filter, nomination takes search_facts_scored (the path predicate already used), so step 2's exact tier for a selective filter and its loop for a broad one both apply; the entity-profile channel too. Confirmation re-checks the filter. The fast base-table support probe from D156 step 2: filter search and search_documents by document tags #614 is now the shared document_filters.fact_supported_matching, used by P1, confirmation and the co-member marks.

§4.4 in the facts_context evidence path. One templated evidence statement (_fact_evidence_statement): with a filter, each lineage gets in_filter (a matching occurrence that also passes the time scope's evidence gate), its representative claim is a matching one when it has one, matching lineages rank first in each stance (so they are allocated first within the unchanged max(60, 2k) budget), supporting rows from non-matching lineages are dropped (they still count), and each row carries the stance's matching-lineage count. Output: fact_evidence[].in_documents_filter, evidence_totals[].in_documents_filter_total beside the unchanged deployment-wide D54 total, and contradiction.co_members[].in_documents_filter (co-members come from everywhere, as before). Fact value, window, support state, contradiction status and evidence_count are never touched.

Unfiltered responses. I chose to omit the new fields when no documents filter is given (Field(default=None, exclude_if=lambda v: v is None)), so unfiltered payloads are byte-identical to before (only the operation/tool versions in descriptors change). Evidence: test_d143_default_operations_pg.py (real PostgreSQL operation responses vs. the pre-D143 capture, incl. fact_evidence/evidence_totals) passes unchanged, and test_a_filtered_fact_is_never_re_adjudicated asserts the unfiltered JSON has no filter keys. OpenAPI gains the three optional properties (stripped in the D143 additivity test like the other D156 additions).

§4.5. A completed empty filtered read's known_empty explanation ends with "no live document matches the documents filter" or "live documents match the documents filter, but none of them says anything relevant"; incomplete reads keep boundary.

Surfaces. HTTP POST /operations/{name} maps UnknownTagError to 422 unknown_tag; in-process MCP maps it to unknown_tag; MCP tool_version 5/5/6 with a documents schema (the tags object is literally search_documents' schema) and descriptions telling agents to call list_tags before filtering by tag; SDK documents= (model or dict, validated locally) on the three context methods; CLI --tag / --any-tag / --not-tag on remember query (text, --combined, --layers); TypeScript documents on factsContext / claimsAndSourcesContext / combinedContext plus the matching-total validator. OpenAPI, TS contracts/parity fixtures, D143 fixtures, manifest, storage-capture source pin and LoCoMo protocol hash regenerated.

Docs (D66). Assured operations (new "The documents filter" section, versions, params), HTTP operations, MCP, Python/TypeScript SDK, CLI, result types, search page, tag guide ("Ask about one project"), cloud compatibility, not-built-yet (now only fact lookups and SQL functions lack the filter), llms*.txt.

Tests

  • src/tests/surfaces/test_document_tag_context_pg.py (integration inventory): the design's Autoboard 12h vs Legalit 6h example end to end (support only from Autoboard, Legalit contradiction and 6h co-member marked out, totals (2,3,2)/(1,1,0) equal hand-counted lineages); fact value/support identical to unfiltered; testimony strictly limited; combined_context children equal direct calls; each grain before the cut at k=1 (facts on both the exact tier and the loop); entity_ids + documents; unknown_tag before any embedding call and invalid_parameter shapes; §4.5 both explanations; work-bounded read → boundary; resolve_entity unaffected by tag state.
  • src/tests/surfaces/test_document_tag_context_surfaces.py (unit inventory): catalogue/schemas/versions, coercion, executor passes the same filter to both children, HTTP + SDK + unknown_tag, in-process MCP, CLI flags, optional fields absent when unfiltered.

Deviations

  • Facts under a filter nominate through search_facts_scored instead of nominate_facts_scored (same as the predicate path) so the filter reuses step 2's qualified exact-tier/loop execution rather than adding a second filtered fact nomination.
  • New response fields are omitted (not null) on unfiltered reads, to keep those payloads byte-identical.
  • The consumption skill text is unchanged (the MCP tool descriptions carry the list_tags guidance).

Rule 4 / D56: read-path only; no ingestion, chunking, extraction or reuse-key code is touched.

Review fixes (GPT 6.1 sol, three rounds, approved on bf84c68)

  • Pydantic floor raised to >=2.12, which exclude_if requires, so unfiltered reads omit the new fields at every allowed version.
  • The TypeScript client omits these fields the way Python does: the exporter marks them x-exclude-if-none, and dump() drops a null but keeps false and 0. Parity fixtures cover unfiltered and filtered fact reads.
  • Merged step 2's final head: filtered fact reads use its claim-keyed fact enumeration, and main is on PostgreSQL 18.

Verification

  • ruff format and ruff check are clean; pyright reports 0 errors. Unit suite: 3,601 passed.
  • PostgreSQL retrieval and tag suites (23 files, including the two new test files) pass.
  • TypeScript client: check:generated, check:parity, typecheck, npm test all pass. Website builds (public and cloud) and the docs truth checks pass.
  • GitHub CI on bf84c68: green.

Contributor agreement

Signing on behalf of a legal entity (leave blank if accepting individually):

🤖 Generated with Claude Code

https://claude.ai/code/session_01VYytLf2PUQ2RVpEZYENzsq

fazpu and others added 7 commits November 14, 2026 06:04
….4 fact evidence (checkpoint)

claims_and_sources_context@5, facts_context@5 and combined_context@6 take
the D134/D156 documents filter as an eligibility input of every nomination
channel and re-check it at confirmation. Filtered fact reads draw support
from matching documents only, contradictions and co-members from every
document marked in_documents_filter, with two-sided evidence totals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VYytLf2PUQ2RVpEZYENzsq
…t parity for the context filter

Operation versions 5/5/6 roll surface_manifest_hash. The TypeScript client
takes documents on factsContext, combinedContext and claimsAndSourcesContext
and checks the matching evidence total like the Python model.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VYytLf2PUQ2RVpEZYENzsq
…plan step 3 status

Assured operations, MCP, HTTP operations, SDK, TypeScript, CLI and result
types document the filter, its §4.4 evidence marks and two-sided totals;
not-built-yet no longer lists it. The tag guide gains 'Ask about one project'.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VYytLf2PUQ2RVpEZYENzsq
… roll; meaningful resolve_entity check

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VYytLf2PUQ2RVpEZYENzsq
…-context-ops

Takes step 2's review rounds. Facts under a documents filter now nominate
through search_facts_scored (with its exact tier for a selective filter);
its fast base-table support probe becomes the shared
document_filters.fact_supported_matching used by confirmation and co-member
marks too. Generated contracts, manifest, fixtures and docs regenerated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VYytLf2PUQ2RVpEZYENzsq
The D156 filter disclosures are omitted from unfiltered reads with
Field(exclude_if=...), which Pydantic supports from 2.12. Serialization and
schema generation were checked at 2.12.0 (OpenAPI byte-identical).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VYytLf2PUQ2RVpEZYENzsq
…tered and filtered fact reads (PR #615 review r1)

The contracts exporter marks Pydantic exclude_if-None fields with
x-exclude-if-none (refusing any other exclude_if rule). The TypeScript
validator no longer fills their null default and dump() drops a null, so
False and 0 survive. The facts_context parity fixtures now return a fact
with evidence, totals and a co-member, unfiltered and filtered.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VYytLf2PUQ2RVpEZYENzsq
@fazpu
fazpu changed the base branch from feat/document-tags-search-filter to main November 14, 2026 20:57
…ument-tags-context-ops

Takes step 2's claim-keyed fact enumeration and main's PostgreSQL 18 baseline
(#616). fact_supported_matching stays in core/document_filters. Manifest,
OpenAPI, TypeScript contracts and parity, D143 fixtures, storage-capture pin,
LoCoMo/open-query hash pins and llms*.txt regenerated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VYytLf2PUQ2RVpEZYENzsq
@fazpu
fazpu marked this pull request as ready for review November 14, 2026 21:42
@fazpu
fazpu merged commit 4951e0d into main Nov 14, 2026
19 of 20 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