Repository navigation
memory.verify takes the content hash the caller read and refuses to attest or revoke other content - #2173
Open
zlareb1 wants to merge 9 commits into
Open
memory.verify takes the content hash the caller read and refuses to attest or revoke other content#2173zlareb1 wants to merge 9 commits into
zlareb1 wants to merge 9 commits into
Conversation
…ttest or revoke other content An attestation records who checked which content, and the content is the value the row holds when the server reads it. An edit that lands between the caller's read and the call is attested unseen. `if_match_sha256` on `memory.verify` names the `content_sha256` of that read. The handler compares it with the live hash before the revoke and no-op branches and answers 409 `PRECONDITION_FAILED` with `current_sha256` on another hash: no version row, no embeddings mirror. An empty field checks nothing: a call without it attests the row as the server reads it. The dashboard's Verify and Remove verification address the row the drawer shows and send the hash of the value shown; a 409 reads the memory again. `MemoryClient.verify` takes the field, and the generated SDKs and reference pages carry it. Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…s content_sha256 is refused The 409 of `if_match_sha256` returned the live hash of any row. For a `high` row that hash names a short secret as well as the value does, the refusal writes no audit row, and `memory.get` and `memory.get_by_id` serve the hash with a `memory.sensitive_read` row. The refusal of a `high` row carries an empty `current_sha256`, a shape the error already has. Every read serves the hash as `content_sha256`. Sent under that name, `memory.verify` served the call, attested with no precondition and named the key in `ignored_args`: the name heuristic of `arg_check` finds no near field. One entry in `SYNONYMS` reads `content_sha256` as `if_match_sha256`, so a write answers 422 `UNKNOWN_ARGUMENT` and writes nothing. The table is not keyed by op: `memory.set`, `memory.update`, `memory.update_by_id`, `memory.move`, `memory.pin` and `profile.set` take the same field and refuse the same key. The hash to send is the one `memory.get` or `memory.get_by_id` returned. `memory.set`, `memory.list` and `memory.bulk_get` report the hash of the value as it was sent, which is another hash for an object value whose numbers the JSON column renders in another form. The field comment, the feature pages, `MemoryClient.verify` and the MCP description name the two reads; the MCP description also says a search hit carries no hash. The Python SDK told a caller to retry a 409 with `.current_sha256`, which for `memory.verify` attests content nobody read. The `PreconditionFailed` docstring, its row in the Python reference and `MemoryClient.verify` say to read the row again first. The reviewed-sender pin of `sdk/python/loom/memory.py` is renewed for the docstring. Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…rify line carries the request id `memory.verify` answers 200 `found=false` for a row deleted after the drawer read it. The drawer did not read `found`: it showed "Verified as " with no name and kept the deleted row on screen. It says the memory is gone and reads it again, as Unlock and Delete do. The line for a 409 was a plain info toast: 3.5 s and no request id. The dashboard design guide sends a page's own line about a refused call through `toastWithId`, which gives it the request id and an error's reading time. The line is the only cue that the content changed under the reader. The drawer test for the 409 gave the refusal and the re-read the same hash, so it could not tell which one the retry sent, and its retry click had no answer of its own. The re-read returns a third hash, the retry is answered, and the test waits for the success toast. Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`sdk/go/wire/models.gen.go` records the SHA-256 of the registry's model schemas on its second line. `main` adds `memory_keys` and `actor` to the proposals models and this branch adds `if_match_sha256` to `MemoryVerifyInput`, so both rewrite that line and the merge conflicts on it. The file is written by `scripts.codegen.sdk_go_gen` on the merged tree, not merged by hand: against `main` it differs in the hash and the one field. The Python, TypeScript, Ruby and Rust generators and `docs_reference` write no diff on the merged tree, and the reach census passes. Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ha256 serves the key `SYNONYMS` in `server/transport/arg_check.py` is not keyed by op. The entry that read `content_sha256` as `if_match_sha256` therefore refused the key with 422 `UNKNOWN_ARGUMENT` on every op that takes the precondition: `memory.verify`, and also `memory.set`, `memory.update`, `memory.update_by_id`, `memory.move`, `memory.pin` and `profile.set`, which serve the key on `main` and name it in `ignored_args`. Four of those six are `stable`. That is a wire break on ops this change does not concern: it adds one optional field to `memory.verify` and changes no default. The entry, its two tests and its sentence in the writing page are removed. Refusing the key is its own change, with the break in its title and under its own changelog category. `memory.verify` treats a hash sent as `content_sha256` as any unknown key: it answers 200, names the key in `ignored_args` and checks no precondition. Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…the handler keeps The comment said only the audited read serves the hash of a `high` row. The handler's 200 answers return `content_sha256` for a `high` row under the op's own `memory.verify` audit row, with no `memory.sensitive_read` row. The rule the branch keeps is narrower: a refusal leaves no audit row, so it carries no hash of a `high` row. The comment says that. Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… source models too `main` changes the knowledge source models (`models_sources.py`, `models_worker_setup.py`), which rewrites the registry schema hash on the second line of `sdk/go/wire/models.gen.go`. This branch rewrites the same line for `if_match_sha256` on `MemoryVerifyInput`, so the merge conflicts on it. The file is written by `scripts.codegen.sdk_go_gen` on the merged tree: against `main` it differs in the hash and the one field. The other SDK generators and `docs_reference` write no diff there, and the reach census passes. Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…e regenerated statement shapes Two `ci` jobs fail on the head this merge replaces, for a cause on `main` at the commit that head merged. `pytest unit part 6` fails `tests/unit/test_degraded_unnoted.py` on two handlers of `server/knowledge/app/source_access.py`, and `pytest integration isolation gates` fails `tests/analyzer/test_corpus.py::test_shapes_file_matches_builders` on one statement that reads `loom.knowledge_sources`. `main` carries the repair: the handlers are listed in `tests/unit/degraded_unnoted.txt` and `tests/analyzer/shapes.txt` is regenerated. The merge has no conflict, and every generator writes no diff on the merged tree. Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… changes Two files conflict with `main`. `sdk/go/wire/models.gen.go`: `main` adds the `run.reliance` models, which rewrites the registry schema hash on the second line, the line this branch rewrites for `if_match_sha256` on `MemoryVerifyInput`. The file is written by `scripts.codegen.sdk_go_gen` on the merged tree. `tests/unit/session_content_senders.json`: `main` renews the pin of `sdk/python/loom/run.py` on the line next to the pin of `sdk/python/loom/memory.py`, which this branch renews. Each pin is the SHA-256 of its file on the merged tree: `main`'s for `run.py`, this branch's for `memory.py`, which `main` leaves unchanged. The other generators write no diff on the merged tree. Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This branch has not been deployed
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.
Part of: #1175
Part of: #1232
Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
memory.verifyacceptsif_match_sha256, thecontent_sha256thatmemory.getormemory.get_by_idreturned for the content being attested or revoked: when the row holds other content the call answers 409PRECONDITION_FAILEDand writes nothing, and the dashboard's Verify and Remove verification send the hash of the content shown.Why
An attestation records who checked which content, and the content is the value the row holds when the server reads it (
handle_memory_verifyinserver/memory/app/verify.py). A person reads a memory, an edit lands, the person confirms: the attestation binds to text they never saw and the row readshuman. The head fence of the insert covers a head that moves during the call. It does not cover an edit that landed before the call, because the server does not know what the caller read.This is the first slice of stewardship of shared knowledge (the linked issue). A later slice adds a review that records a result against the hash the reviewer read and attests through this handler, so the handler has to refuse content the caller did not read. The slice stands alone: every caller of
memory.verifycan bind the attestation to its own read.The rule, in
handle_memory_verify:if_match_sha256memory_id, also a row in a namespace the caller cannot writefound=false, unchangednamespaceandmemory_key, without writer on the namespaceFORBIDDEN, unchanged""(the default)changed=falsePRECONDITION_FAILEDwithdetail.current_sha256(empty for ahighrow); no version row, no embeddings mirrorcurrent_content_sha256(row), the valuememory.get,memory.get_by_idandmemory.verifyreturn ascontent_sha256.memory.set,memory.listandmemory.bulk_getreport the hash of the value as it was sent, which is another hash for an object value whose numbers the JSON column renders in another form (1.0as1). The field comment, the docs, the SDK docstring and the MCP description therefore namememory.getandmemory.get_by_idas the source of the hash.PreconditionFailedError, the shapememory.set,memory.update,memory.update_by_id,memory.moveandmemory.pinanswer for the same field. Its message does not print the hash.highrow carries an emptycurrent_sha256: the hash of a short secret names it, and the refusal writes no audit row. An empty hash is a shape the error already has (namespace.restore). The rule covers the refusal only: the op's 200 answers returncontent_sha256for ahighrow under the op'smemory.verifyaudit row, as onmain, andmemory.getandmemory.get_by_idserve it with amemory.sensitive_readrow.memory.update: a value that is no hash,absentincluded, is another hash and answers 409.ADMISSION_CONTENDEDfrom the head fence, with nothing written.Alternatives and their cost:
MemoryClient.verify(key), the importer's--verifyand an agent that attests by keyif_match_sha256memory.updatedoes not haveScope and risk
Surfaces:
if_match_sha256onPOST /v1/memory.verifyMemoryClient.verify(if_match_sha256=)in the hand-written Python layerloom call memory.verify memory_id=<id> if_match_sha256=<hash>loom_memory_verify(listed under?toolset=all) and throughloom_op; the tool description says to send the hashmemory.getreturned, that a search hit carries none, and that a 409 means show the current text and ask againmemory.verifydeclares noaudit_subject, so the default shaping recordsif_match_sha256as a hash and a length, like any other text input.verifyMemorytakes the row's identity (rowIdentity) where it took the drawer's agent with the row's user and session.memory.getcan answer with another agent's row; under the drawer's agent that call names no row and answersfound=false. The hash belongs to the row shown, so the call has to address that row.found=false(the row was deleted after the drawer read it) says "This memory is no longer live" and reads the memory again, where it showed the success toast with an empty attester. The 409 line goes throughtoastWithId, as the dashboard design guide asks of a page's own line about a refused call: it carries the request id and stays for an error's reading time.tests/unit/session_content_senders.jsonpins the SHA-256 ofsdk/python/loom/memory.py, a reviewed sender module. The pin is renewed: the diff to that file is theverifykeyword, its docstring and one payload field, and it touches neither the coalescer nor its body builders.memory.verifyattests content nobody read. ThePreconditionFaileddocstring (sdk/python/loom/errors.py), its row indocs/reference/python-sdk.mdandMemoryClient.verify's docstring say to read the row again first.Left alone:
--verifysends no hash.PreconditionFailedError's docstring, which the generated part ofdocs/reference/errors.mdprints, is not edited. The hand-writtenPRECONDITION_FAILEDrow above it gains the sentence formemory.verify.memory.updaterefuses the hashmemory.setreturned for the same object values onmain; one rule for every op that reportscontent_sha256is its own change.memory.set,memory.update,memory.update_by_idandmemory.movestill carries the hash of ahighrow, as onmain: there the returned hash is the documented retry without a second read.content_sha256, the name every read serves it under.memory.verifyserves that call as it serves any unknown key: 200, the key inignored_args, no precondition checked. The transport's table of argument synonyms (SYNONYMS,server/transport/arg_check.py) is not keyed by op, so an entry that refuses the key onmemory.verifyrefuses it onmemory.set,memory.update,memory.update_by_id,memory.move,memory.pinandprofile.settoo, which serve it onmain; four of those arestable. That refusal is a wire break on six ops this change does not concern, and is its own pull request underBackward Incompatible Change.Overlap with open pull requests, same files and another concern: #1510 (
models_crud.py,verify.pyand its unit tests,sdk/python/loom/memory.py,MemoryInspector.tsxand its lifecycle test,api.ts,history-and-provenance.md,rolling-upgrades.md), #2064 (models_crud.py,api.ts,memory-architecture.md,rolling-upgrades.md), #2158 (models_crud.py,api.ts), #1259 (sdk/python/loom/memory.py), #2148 (mcp_descriptions.py, the SDK snapshot) and #1947 (rolling-upgrades.md, the SDK snapshot). In #1510 theverify.pyhunks change the embeddings mirror and its signature, and no hunk touchesMemoryVerifyInput,verifyMemoryor the drawer'sonVerify; the new unit tests record the mirror with a function that takes any arguments. The others were checked by file list. Whichever merges second rebases, and regenerates the SDK files and the snapshot.Compatibility, rollout and rollback
if_match_sha256: str = "", onmemory.verify. No default changes. The op answers 409PRECONDITION_FAILEDonly when the field is sent. No op, output field, table or setting is added, changed or removed.main's.MemoryClient.verifygains the keywordif_match_sha256(tests/unit/snapshots/sdk_public_api.json).verifyMemory(id, key, { revoke, ifMatchSha256 }); theuserIdandsessionIdoptions are gone, andidcarries them (the drawer is the one caller).ignored_argsand attests or revokes the row it reads (rule 12 ofdocs/architecture/rolling-upgrades.mdgains the sentence). The dashboard does nothing with that answer.Tests
Written first and seen to fail, then run on this branch against a ClickHouse and a server started for it.
tests/unit/test_memory_verify.py(25 passed):test_another_hash_than_the_live_one_is_refused_and_writes_nothing:PreconditionFailedError,current_sha256is the live hash, the message does not contain it, nothing inserted, no mirror scheduled.test_a_refusal_on_a_high_row_carries_no_hash: the same refusal on ahighrow carries an emptycurrent_sha256. It failed before the check onrow.sensitivity.test_the_live_hash_attests: one inserted version row,human.test_a_repeat_verify_still_checks_the_hash: a row this actor already attested, sent with another hash, raises where it answeredchanged=false.test_a_revoke_checks_the_hash_when_sent: another hash raises and inserts nothing; the live hash readsnone.test_a_missing_row_answers_not_found_whatever_the_hash: a missing id and a row the caller cannot write both answerfound=false.test_registered_audited_and_callable_by_name_over_mcpalso holds the tool description to naming the field.tests/unit/test_sdk_write_kwargs.py::test_verify_sends_the_hash_it_is_given: the payload carries the field when given and omits it otherwise.tests/integration/test_memory_verify.py::test_verify_refuses_the_hash_of_an_edited_row(the file: 4 passed): set, keep the hash, update the value. A verify with the first hash raisesPreconditionFailedwhosecurrent_sha256is the new hash, andmemory.getreadsnoneat the update's version. A verify with the new hash readshuman. A revoke with the first hash raises, andmemory.getreadshumanat the attestation's version. The file is in the Postgres-profile list ofci.yml.npx vitest run src/api.memory.test.ts src/components/MemoryInspector.lifecycle.test.tsx(56 passed):verifyMemory"sends the hash of the content shown, at the row's own agent, user and session" and "sends no precondition when the read carried no hash"; the drawer "verifies the row it shows with the hash of the value it shows", "reads the memory again when a verify is refused because the content changed" and "says a memory is gone when the verify finds no row". In the second of these the refusal returns one hash and the re-read another, the retry has its own answer, and the test holds the retry to the re-read's hash and to the success toast; it also holds the 409 line totoastWithIdwith the refused error, and a 503 to the old error toast. The last two failed before the drawer change. The nineMemoryInspectortest files and the two copy rule files (views/copy.rules.test.ts,lib/errorWords.rules.test.ts) pass (115 tests).loom call memory.verify memory_id=<id> if_match_sha256=0000prints[PRECONDITION_FAILED]and exits 1, and with the live hash answersverification: human; the MCP toolsloom_memory_verifyandloom_opanswer the same 409 withcurrent_sha256, andtools/listunder?toolset=allshows the field and the description; the default listing reaches the op throughloom_op. Over HTTP, another hash on ahighrow answers 409 withcurrent_sha256: ""and the live hash attests it;memory.verify,memory.updateandmemory.update_by_idwith a straycontent_sha256answer 200 and name the key inignored_args, as onmain.make lint(ruff, the function-length and secret gates, every generator--check, Biome's accessibility rules) andmake typecheck: pass.pytest -n 2over the 346 unit test files of the areas this change touches (test_memory_*,test_mcp_*,test_sdk_*,test_op_*,test_audit_*,test_doc*,test_dashboard_*, the snapshot, release and translation files, and the repository-wide scanstest_package_contracts.py,test_tunable_constants.py,test_store_names_refused.py,test_degraded_unnoted.py,test_public_copy.py,test_doc_links.py,test_agent_instructions.pyandtest_session_content_senders.py): 9,580 passed, 40 skipped, 1 xfailed.test_direct_audit_hash_only.pypasses too. An earlier run oftest_session_content_senders.pyfailed on the pin named above, which is how the pin was found.pytest -n 2over 164 unit test files (test_mcp_*,test_transport_*,test_http_*,test_sdk_*,test_op_*,test_audit_*,test_dashboard_*,test_store_names_refused.py,test_read_ops_never_5xx.py): 3,094 passed, 13 skipped. The 21 files nearest the change, among themtest_memory_verify.py,test_arg_feedback.py,test_session_content_senders.py,test_mcp_listing_budget.py,test_public_copy.py,test_doc_links.pyandtest_package_contracts.py: 1,071 passed.tests/integration/test_memory_verify.py: 4 passed.main:make lintandmake typecheckpass, and ruff, Biome and Prettier are clean on the whole tree. The nine unit files nearest the change (test_memory_verify.py,test_arg_feedback.py,test_sdk_write_kwargs.py,test_sdk_surface_contract.py,test_session_content_senders.py,test_mcp_listing_budget.py,test_public_copy.py,test_doc_links.py,test_degraded_unnoted.py): 569 passed.tests/integration/test_memory_verify.py: 4 passed against a server started from that head. Dashboard,api.memory.test.ts, the nineMemoryInspectortest files and the two copy rule files: 127 passed; a first run on the loaded machine failed "names no operation and no API path" inviews/copy.rules.test.ts, which passes alone and in the rerun. No wider unit run was made on that head: CI's is the full one.pytest tests/analyzer -n 2: 12 passed. No statement changes, sotests/analyzer/shapes.txtdoes not move.npm --prefix frontend run build: builds.npm --prefix frontend run budget: OK, index chunk 118.8 kB of 120 kB on the head that mergesmain.verifyMemorybuilds its body from the identity it is given, asunpinMemorydoes; against the base this branch started from, that left the chunk 51 bytes smaller.npm --prefix frontend run test, the whole suite: two runs on a loaded shared machine failed 17 and then 8 of 3,884 tests, none in a file this change touches. The seven files that failed in the second run pass when run alone (157 passed). CI's run decides.npm --prefix sdk/typescript run check: 40 files, 794 tests passed, no type errors.rustfmtandgofmt, which this machine has no install of. They ran through the toolchain images CI pins (Rust 1.85.1 with therustfmtcomponent, Go 1.27.4);make lint's--checkof both passes with the same wrappers, and the generated diff is the one field.cion an earlier head of the branch,eddf2c3ec, which holds every change of this diff: 44 jobs passed and two failed for a cause onmain.pytest unit part 6failedtests/unit/test_degraded_unnoted.py::test_every_broad_handler_notes_its_fallback_or_says_why_it_need_noton two handlers ofserver/knowledge/app/source_access.py(1 failed, 10,076 passed), andpytest integration isolation gatesfailedtests/analyzer/test_corpus.py::test_shapes_file_matches_builderson one statement that readsloom.knowledge_sources.main's owncirun at the merged commit failed the same two tests, and this diff touches neither that module,tests/unit/degraded_unnoted.txtnortests/analyzer/shapes.txt. The worker copy read gate's broad handlers are listed and the statement shapes regenerated #2193 repairs both onmain, and the head merges it:tests/unit/test_degraded_unnoted.pyandpytest tests/analyzer(12 passed) pass on the head.introduced dependency vulnerabilities(dependency-review.yml) exits 2 withDependency review could not complete: Dependency snapshots are incomplete and snapshot inputs changed. A pull request head has no dependency snapshot (rust-dependency-graph.ymlsubmits one only on a push tomain), and the fallback refuses any non-Markdown change undersdk/rust/, which the regeneratedsdk/rust/src/wire_models.rsis. The diff adds, removes and bumps no dependency: no manifest or lockfile is in it. The merge decision on this check is the maintainer's.AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated (an agent wrote most of the diff): Claude Code wrote the diff from a reviewed design. Each new test was run and seen to fail before the code it covers; the generated files were read after regenerating; the CLI, MCP and dashboard paths were exercised as listed above.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make formatas a whole needsshfmt, which this machine has no install of; no shell file changed. The fullmake test-unitand applicable integration results are reported by CI; a full local run is not required before pushing.docs/reference/tables (python scripts/codegen/docs_reference.py). The reach manifest,schemas/schema.sql, the plugin copies and the skill bundles are not affected. The branch mergesmain: both sides rewrite the schema hash on line 2 ofsdk/go/wire/models.gen.go, so that file is written byscripts.codegen.sdk_go_genon the merged tree, and the other generators write no diff there. Intests/unit/session_content_senders.jsoneach pin is the SHA-256 of its file on the merged tree.main; no merged migration is edited. None added.npm --prefix frontend run build), the bundle budget holds, and the tests of the two changed modules pass. The whole suite did not pass on this machine, as named under Tests; CI runs it.docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.pypasses).git commit -s), as CONTRIBUTING.md asks.Later slices
Each is one pull request and one concern; none is in this diff.
memory.verifywithif_match_sha256.main.🤖 Generated with Claude Code