Skip to content

[hold until #573 cutover] feat(python): keyed blind indices client wiring (internal#573) - #848

Draft
p-diogo wants to merge 7 commits into
mainfrom
feat/573-python-keyed-tags
Draft

p-diogo wants to merge 7 commits into
mainfrom
feat/573-python-keyed-tags

Conversation

@p-diogo

@p-diogo p-diogo commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Held for the #573 cutover. Do not merge. main must stay releasable for the backlog RC.

Python / Hermes / enclave client wiring for keyed blind indices (internal#573). Draft. No version bump, no publish, no labels.

What changed

  • P1 tag module. New python/src/totalreclaw/blind_tags.py: the only producer of tags, trapdoors and content fingerprints. It calls totalreclaw_core only (BlindIndexer, hash_keyed, sort_dedup_tags, generate_search_trapdoors_keyed, generate_content_fingerprint_v2). No hashing and no key derivation in client code. LSHHasher.hash is removed; hash_keyed and a read-only core property are added.
  • P2 encoders. encode_fact_protobuf_keyed and encode_tombstone_protobuf_keyed replace the legacy encoders. Field 5 sorted and deduplicated, version forced to 4, field 14 = 1 written last; tags must be 64 lowercase hex and the blob must be valid hex (both rejected without echoing the value). Tombstone: empty blob, decay_score 0, is_active 0, version 4, field 14 = 1. Byte-identical to core on valid input.
  • P3 call sites. All of P-1 to P-22 rewired (table below). Batch sizing takes an optional tag_count; client.remember_batch and the import engine pass one built from the client's keys.
  • P4 header. X-TotalReclaw-Index-Scheme: 1 on RelayClient._base_headers() (subgraph, billing) and userop._make_ctx() (every bundler and paymaster JSON-RPC call). Constants live in relay.py.
  • P5 guard. require_keyed_fact with the dedicated FactIndexScheme query, IndexSchemeUnconfirmedError(ValueError), KeyedWriteRecord / keyed_writes_for in write_gate.py (ids only, 15 min, 256 entries), writers in client.py, and wrote_here plumbing through pin, unpin, retype and set_scope. Fails closed; a read block propagates.
  • P6 tests. Wire-boundary test 6, the grep gate, changelog entry.
  • P7 (core floor in pyproject.toml) is deliberately not done.

Call-site table

# Site Status
P-1..P-5 operations.store_fact: tags, entity tags, sort/dedup, fp v2 done
P-6 store_fact encoder done
P-7 store_fact_batch (same as P-1..P-6) done
P-8 search_facts trapdoors via blind_tags.query_trapdoors; 5-per-batch split kept; comment reworded done
P-9 forget tombstone done
P-10 pin/unpin tags + guard done
P-11 pin/unpin tombstone + fact encoders done
P-12 estimate_payload_bytes(payload, tag_count=None), docstring reworded done
P-13, P-14 retype/set_scope tags, guard, encoders done
P-15 contradiction: no hashing, tests entity_names is non-empty done
P-16, P-17 DIGEST_TRAPDOOR, compute_entity_trapdoor(s) deleted done
P-18 find_duplicate_texts uses fp v2 done
P-19, P-20 crypto wrappers deleted done
P-21 LSHHasher.hash_keyed + core property, no hash done
P-22 keyed-only encoders done

Tests

Added: test_keyed_tags_573.py, test_protobuf_keyed_573.py, test_index_scheme_header_573.py, test_index_scheme_guard_573.py, test_wire_no_unkeyed_573.py (includes raw and hex positive controls and a half-ported-write control), test_no_client_hashing_573.py (with positive controls).

Existing tests updated, and what replaces the deleted ones:

  • test_claims_helper.py: compute_entity_trapdoor(s) and DIGEST_TRAPDOOR tests replaced by entity_names tests; hash parity moved to test_keyed_tags_573.py (entity vectors) and the grep gate.
  • test_crypto.py: unkeyed generate_blind_indices / fp v1 wrapper tests replaced by keyed-tag and fp v2 tests.
  • test_entity_trapdoor_roundtrip.py, test_search_entity_trapdoors.py: now keyed entity_tag; asserts the unkeyed sha256 form is not sent.
  • test_lsh.py: unkeyed bucket parity replaced by hash_keyed plus a no-hash check; keyed parity in test_keyed_tags_573.py.
  • test_protobuf.py, test_v1_parity.py, test_pin_batch_cross_impl_parity.py, tests/parity/test_outer_protobuf_parity.py (Python leg): legacy goldens replaced by comparison with the core keyed encoders; field 14 present, 9/11 absent.
  • test_batch_sizing_rc4.py: est >= real keyed payload, entity tags counted; test_search_concurrency.py / test_search_read_short_circuit.py: chunk-count preconditions lowered (stems-only roughly halves trapdoors).
  • test_pin_unpin.py, test_retype_setscope.py, test_wave2a_hermes_fixes.py, test_remember_derives_entities_728.py: mocks answer the guard query with indexScheme: 1; the v3 tombstone test now asserts the scheme-1 tombstone.
  • test_client_bundle_mode.py, test_importance_scale.py, test_decay_score_789.py, test_rc13_import_wave.py, test_search_pin_state.py, generate_py_vectors.py (calls core directly): renamed APIs.

Full suite (CI command): 4527 passed, 17 skipped, 0 failed. Untouched main at 39cd8ea1: 4423 passed, 17 skipped, 0 failed (no pre-existing failures). Parity: test_outer_protobuf_parity.py, test_keyed_blind_indices_parity.py, test_decay_score_parity.py 18 passed.

Guard message (user-facing copy, needs owner approval)

This memory can't be changed right now because its storage format could not be confirmed. Nothing was changed. Try again later.

Marked user-facing copy, needs owner approval.

Spec deviations

  1. Guard before the pinned-fact confirmation. The Hermes unpin/retype/set_scope tools ask the user to confirm on a pinned fact in pin_confirm.pinned_change_notice, before the client call. To keep "no confirmation token on refusal", pinned_change_notice now runs the guard first for those three actions via a new TotalReclaw.ensure_keyed_fact. A refusal raises IndexSchemeUnconfirmedError (a ValueError, shown as {"error": MSG}). Costs one extra guard query on unpin/retype/set_scope of a pinned fact (the operation's own guard queries again).
  2. blind_tags.tag_counter(keys) helper added (not in the 5.1 API list) to build the tag_count callable; entity_names also skips whitespace-only names (the old helper hashed them).
  3. The shared tests/parity/fixtures/outer-protobuf-v1.json still holds legacy bytes (used by the MCP and Rust legs, and I did not edit it), so the Python leg compares with core keyed output per vector instead of the fixture hex.
  4. Pin/unpin and retype/set_scope in client.py still pass no LSH hasher (unchanged from before), so rewritten facts carry stem and entity tags but no LSH tags, as today.

CI note

The Python tests need a totalreclaw-core with the keyed API, which no published core has (internal#573 blocker B1). The python-tests job builds core from source (maturin wheel, then pip install --force-reinstall), so it can pass. The dependency floor in pyproject.toml is unchanged (P7 deferred). Locally: build the wheel, uv pip install --force-reinstall it, then uv run --no-sync.

🤖 Generated with Claude Code

p-diogo and others added 4 commits December 5, 2026 01:01
Add blind_tags.py (the single producer of tags, trapdoors and fp v2, all via
totalreclaw_core) and LSHHasher.hash_keyed; remove the unkeyed LSHHasher.hash.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace the legacy fact and tombstone encoders with encode_fact_protobuf_keyed
and encode_tombstone_protobuf_keyed (sorted field 5, version 4, field 14 = 1,
empty-blob inactive tombstone), byte-identical to core.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… calls (internal#573, P4)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… (internal#573, P5)

KeyedWriteRecord (facts this process wrote skip the query), the dedicated
FactIndexScheme query, and the pre-confirmation check in pin_confirm. The
operations/client/retype hooks land in the rewire commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@p-diogo
p-diogo force-pushed the feat/573-python-keyed-tags branch from cb2d9f8 to de3aede Compare December 5, 2026 02:24
@p-diogo

p-diogo commented Dec 5, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased onto main 77a3daaa (4 Dec). Keyed tags now also cover the judge (#853), the stop-word query path (#875) and fact-id lookups (#874). The query path uses core query_stem_tags once the core pin carries it.

p-diogo and others added 3 commits December 5, 2026 02:55
…ternal#573, P6)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
operations, retype_setscope, contradiction, claims_helper, client, crypto and the
import engine now use blind_tags and the keyed encoders; fact and trapdoor
hashing is gone from client code. Includes the guard hooks (require_keyed_fact,
wrote_here plumbing, client writers) and the updated existing tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… conditional

Review nits: the pin and retype comments still described the legacy v=3
tombstone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@p-diogo
p-diogo force-pushed the feat/573-python-keyed-tags branch from de3aede to 61763f3 Compare December 5, 2026 02:56

This branch has not been deployed

No deployments
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