Skip to content

D156 document tags: registry, assignments and SQL views (steps 1 and 4) - #606

Merged
fazpu merged 15 commits into
mainfrom
feat/document-tags-registry
Nov 14, 2026
Merged

fazpu merged 15 commits into
mainfrom
feat/document-tags-registry

Conversation

@fazpu

@fazpu fazpu commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Summary

Implements delivery steps 1 and 4 of D156 (document tags): plan/plans/document_tags.md, binding design plan/designs/document_tags_design.md. Read filters by tags (steps 2 and 3) are not in this PR.

What ships

  • Storage. Migration p9_53_0074 adds tags and document_tags exactly as design §5. It also adds the memory_v1.tags_current and memory_v1.document_tags_live views, with view-owner and query-role grants.
  • Registry. TagCatalog (spine/tags.py) provides list_tags(query?), create_tag, update_tag and delete_tag.
    • Duplicate names are compared ignoring case and refused with conflict.
    • Names are stored in NFC: 1–128 characters with no whitespace or control characters.
    • Limits: 10,000 tags per deployment, 64 per document, descriptions up to 2,000 characters.
  • Strictness. Ingest and update_document_tags refuse unregistered tags with unknown_tag and list every one. Ingest checks this, and the per-document limit, before any bytes or rows are stored; the write transaction checks both again.
  • Ingest. tags is optional and only adds tags. Tags never decide whether a version is created: a no-op resubmission with tags still returns created=false.
  • update_document_tags. It is atomic and takes add/remove, or set, which excludes the other two. An empty set clears the tags. Removing an absent tag is fine. A deleted document returns not_found.
  • Reads. GET /documents items and search_documents results now include tags.
  • Deletion. Normal deletion keeps the assignment rows but hides them. Hard forget deletes them and leaves the registry unchanged.
  • Surfaces.
    • HTTP: GET /tags is a read; POST /tags, PATCH /tags/{tag_id}, DELETE /tags/{tag_id} and POST /documents/{doc_id}/tags need write scope. POST /ingest takes a repeated tags parameter. None of the tag routes takes a spend hold.
    • Python SDK: the five methods plus the UnknownTag error. Methods that address one tag resolve a name to its id.
    • CLI: remember tags …, remember ingest --tag and remember documents tag.
    • MCP: five tools, and ingest is now tool_version 3. delete_tag is marked destructive.
    • TypeScript client: brought to parity.
  • Query space. The two views are in the manifest, so surface_manifest_hash rolls, the D48 deletion matrix and the D143 layer map. The new saved query examples.facts_by_tag joins facts to tags through their supporting claims; there are now 19 examples.
  • Docs. A new guide, guides/tag-documents. The HTTP, CLI, MCP, Python and TypeScript, errors, result-types and query-space reference pages are updated, and not-built-yet says filtering by tag is not built.

D56 / Rule 4

test_reuse_lifecycle.py gains two tests:

  • Registering, renaming and deleting tags, and tagging, retagging and clearing a ready lineage, make zero generation, Selection, Claimify or embedding calls. They also add no versions, readings, chunks, claims or work rows. An identical resubmission that carries tags stays a no-op.
  • Two versions ingested with different tags have per-stage call deltas and per-chunk Selection, Claimify and embedding identities equal to the same edit made untagged.

No reuse key, header fact, embedding input or extraction window reads tags. No reuse boundary moves.

Review fixes (GPT 6.1 sol, four rounds, approved on e434647)

  • Tag ID routes in HTTP look tags up by ID only.
  • Assigning a tag locks its registry row, so a concurrent delete can't break the assignment. Renames and deletes lock FOR UPDATE in one statement, so two concurrent renames can't deadlock.
  • An ingest refused after its bytes were stored leaves them in place. The engine already treats an unreferenced raw original as a known storage state (raw.unregistered_original), and re-sending the same bytes reuses it.
  • Both SDKs resolve a tag name through GET /tags?name=, which compares the way the registry does (NFC normalisation, then PostgreSQL lower()).
  • Tag names and tag references both have their length checked after NFC normalisation.

Verification

  • uv run ruff format --check src/ benchmarks/, uv run ruff check src/ benchmarks/, uv run pyright src/ benchmarks/ --pythonversion 3.13: clean.

  • The full pytest src/tests against PostgreSQL 19 on the previous merge head (before the last two fixes) had 7 failures, all in test_d153_eligibility_pg.py (its oracle snapshot read the new views). That is now fixed; the file alone has 29 passing. On 8aa7884, pytest src/tests/spine src/tests/workers src/tests/profiles src/tests/adapters against PostgreSQL 19: 2180 passed, 125 skipped, 2 xfailed, 0 failed.

  • TypeScript client: check:generated, check:parity, typecheck, npm test (596 pass) and check:package all pass.

  • Docs: check_docs_truth.py (public and --cloud) passes, generate_docs_llms.py was rerun, and the website build passed earlier.

  • GitHub CI on 8aa7884: green except CLA.

  • After the review fixes (head e434647): ruff, pyright, TypeScript checks and the PostgreSQL tag/migration/storage-capture suites pass locally. GitHub CI is all green except CLA, which this PR's agreement box fixes.

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 12 commits November 13, 2026 17:05
Registry (tags) and per-lineage assignments (document_tags) with the
p9_49_0070 migration; TagCatalog list/create/update/delete and
update_document_tags with unknown_tag strictness and the D156 limits;
ingest adds tags without deciding versions; tags returned by GET /documents
and search_documents; hard forget deletes a lineage's assignments.
HTTP routes, SDK, CLI and MCP tools. Tests and docs follow.

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VYytLf2PUQ2RVpEZYENzsq
…ples.facts_by_tag (D156 step 4)

The two views join the query-space manifest (surface_manifest_hash rolls),
the D48 deletion matrix (document_tags_live is a lineage-target surface) and
the D143 layer map; examples.facts_by_tag joins facts to tags through
supporting claims and passes the four-class fixture proofs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VYytLf2PUQ2RVpEZYENzsq
…fore ingest stores bytes

The ingest pre-check now refuses the per-document tag limit, like an
unknown tag, before raw bytes or rows are stored. Adds the Tag documents
guide and updates the HTTP, CLI, MCP, Python and TypeScript SDK, errors,
query-space and not-built-yet pages; marks steps 1 and 4 implemented in the
delivery plan and lists examples.facts_by_tag in the open query space design.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VYytLf2PUQ2RVpEZYENzsq
Renumbers the D156 migration to p9_50_0071 (main added p9_49_0070), advances
the storage-capture schema-head checks, and regenerates the query-space
manifest, deletion matrix, openapi.json, the D143 defaults fixture, the
TypeScript contracts and parity fixtures and the docs llms files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VYytLf2PUQ2RVpEZYENzsq
…us tags only where the tables exist

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VYytLf2PUQ2RVpEZYENzsq
Renumbers the D156 migration to p9_52_0073 after main's p9_50_0071 and
p9_51_0072 corpus migrations and regenerates the query-space manifest,
deletion matrix, openapi.json, the D143 defaults fixture, the TypeScript
contracts and parity fixtures and the docs llms files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VYytLf2PUQ2RVpEZYENzsq
… D153 oracle to the relations it predates

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VYytLf2PUQ2RVpEZYENzsq
Renumbers the D156 migration to p9_53_0074 after main's p9_52_0073 corpus
reconcile, points the compose upgrade gate and head pins at it, and
regenerates the query-space manifest, deletion matrix, openapi.json, the
D143 and D155 catalogue fixtures, the TypeScript contracts and parity
fixtures and the docs llms files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VYytLf2PUQ2RVpEZYENzsq
fazpu and others added 3 commits November 14, 2026 02:53
…s and name resolution

- Ingest removes the raw object it wrote when recording fails after storage
  (a tag deleted or a tag limit reached since the pre-check), so refused
  uploads leave no unreferenced bytes; tested on both ingest paths.
- update_tag and delete_tag address a UUID-shaped reference by id only, so
  a tag named like another tag's id is never hit once that id is gone.
- Resolved tags are share-locked until the writing transaction commits, so
  a concurrent delete_tag either waits (and cascades) or makes the write an
  unknown_tag refusal instead of a foreign-key error.
- The Python and TypeScript SDKs search the registry with the NFC spelling
  when resolving a tag name.
- create_tag and update_tag drop their unneeded savepoints.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VYytLf2PUQ2RVpEZYENzsq
- Merges origin/main (live corpus capture) and moves the storage-capture
  schema-head checks to p9_53_0074; the tag tables join the catalog
  contract (tables, indexes, constraint counts, D156 objects) and the
  storage-capture source closure, and the generated capture profile is
  refreshed.
- Ingest no longer deletes raw bytes after a refusal inside the write
  transaction: an unreferenced original from a refused attempt is already a
  tolerated, classified storage state (raw.unregistered_original), and the
  purge could delete a concurrent successful ingest's object. A refused
  ingest records nothing and a retry registers the same object (tested on
  both ingest paths).
- update_tag and delete_tag lock their tag FOR UPDATE in one statement
  (by id, or by NFC name ignoring case), so concurrent name-addressed
  mutations queue instead of deadlocking on a share-to-update upgrade.
- GET /tags takes name=, an exact match by the registry's own rule; both
  SDKs resolve a tag name through it instead of comparing case locally.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VYytLf2PUQ2RVpEZYENzsq
…(review round 3)

A tag reference was length-checked on the raw string while a declared
name is checked after NFC, so a valid name spelled with combining
characters (65 x "e\u0301": 130 characters sent, 65 after NFC) could be
registered but not referenced. References now use the same rule as names:
1-128 characters after NFC, with a 512-character cap on the string as
sent. This covers the HTTP models and ingest/name query parameters, the
SDK models, the MCP argument parsing and schemas, and the TypeScript
client and catalogue. Regression through HTTP update_document_tags, the
SDK update/delete by name and the in-process MCP tools.

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 05:16
@fazpu
fazpu merged commit e0dddb3 into main Nov 14, 2026
20 of 22 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