Repository navigation
Conversation
…a shared reply A host that answers one person in a private conversation and in a shared one had no example of keeping the shared reply to what its readers may see. The example plays the host with end-user tokens: the scope of a request is the destination's collections that the person may also read, passed to knowledge.search as namespace and namespaces. The guide says which checks Loom makes, which stay with the host, and that an end-user token cannot be held to a destination's collections. Closes: ClickHouse#1181 Signed-off-by: hskl18 <thb182003@gmail.com>
|
@hskl18 is attempting to deploy a commit to the ClickHouse Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
zlareb1
left a comment
There was a problem hiding this comment.
Three focused probes reproduce defects in the example: a reply can outlive its permitted audience, a wide scope exceeds the search request limit, and a note deletion error skips collection cleanup.
|
|
||
| def deliver(self, talk: Conversation, destination: str, reply: str) -> str: | ||
| """The last check before a reply leaves: it goes where its context was chosen for.""" | ||
| if destination != talk.destination: |
There was a problem hiding this comment.
P1 — A reply built before an audience change can still be delivered to the same channel. Retrieve a passage, replace the channel's destination record with one that adds a reader and removes the collection, then call deliver with the original conversation. A fresh search returns no passages, but delivery returns the old reply. Bind the draft to the audience and source scope it used, and discard it if that scope is no longer valid at delivery.
… change Delivery now recomputes the scope and refuses a reply whose destination gained a reader or lost a source since its passages were retrieved, also when the record changes while the collections are listed. A scope wider than one knowledge.search takes (namespace and 100 namespaces) is searched in batches. Each cleanup delete is tried on its own, so a failed one leaves nothing else behind. Signed-off-by: hskl18 <thb182003@gmail.com>
|
All three are fixed in edb37d5. P1, a reply outliving its audience. P2, more than 100 P2, cleanup after a failed The example's run now also checks that a reply drafted before the revoke is not delivered. The guide's delivery section and the README's recorded run are updated to match. Checks on Linux, Python 3.12, against a local Loom from source: the example's unit tests (12) and the doc tests pass, the live integration test and |
zlareb1
left a comment
There was a problem hiding this comment.
All 12 example unit tests pass, including the wide-scope and cleanup regressions. The delivery check still needs to bind the draft to the context that produced it.
| new_reader = talk.readers is not None and not where.members <= talk.readers | ||
| if new_reader or any(p["namespace"] not in scope for p in talk.passages.values()): | ||
| talk.passages.clear() | ||
| talk.readers = None |
There was a problem hiding this comment.
P1 — Clearing the conversation here also clears the evidence that made the draft invalid. The draft is a separate string, so a subsequent delivery attempt can accept that same draft after the passage list and reader snapshot have been cleared. Bind each draft to its context generation and reject drafts from a discarded generation. Cover a delivery retry after a reader joins or a source is removed.
| if passage["namespace"] not in await self.scope(talk.person, talk.destination): | ||
| raise ScopeRefused(f"{handle} is no longer in scope") | ||
| async with self.as_person(talk.person, passage["namespace"]) as loom: | ||
| document = await loom.knowledge.get(passage["source_uri"]) |
There was a problem hiding this comment.
P2 — The example aborts when collection.list still includes a collection after its grant is revoked. The integration job reports zero passages after the revoke, then knowledge.get raises AuthInsufficient past the tool boundary. A focused probe reproduces that sequence with the collection still listed. Convert the citation read's AuthInsufficient to ScopeRefused and cover this ordering in the unit test. Failed integration job.
…ead is a refusal A reply refused at delivery could be sent again and pass, because the refusal cleared the passages and readers it was checked against. A conversation now counts the contexts it dropped and delivery takes the count a draft was written under. collection.list can still name a collection whose grant was just revoked: a citation read or a search Loom answers 403 is now the host's own refusal and drops the context too. Signed-off-by: hskl18 <thb182003@gmail.com>
|
Both are fixed in f2d740d. P1, the same draft sent again. A conversation now counts how many times its context was dropped, and P2, a revoked collection that After the revoke, the example's run now refuses the old citation as one the conversation no longer holds, and the old draft by its count. The README's recorded run and the guide's delivery section are updated to match. The revoke step moved into its own function to stay under the function-length gate. Checks on Linux, Python 3.12, against a local Loom from source: the example's unit tests (16) pass, the live integration test and |
Closes: #1181
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):
None.
Why
A host that answers one person in a private conversation and in a shared one has no example of how to keep the shared reply to what its readers may see. The per-user support example keeps two users apart; here the user stays the same and the audience changes.
Scope and risk
No server change. New files:
sdk/python/examples/audience_scoped_retrieval.py,docs/guides/audience-scoped-retrieval.md, a unit test and an integration test. Edits: the examples README, the Python SDK reference's example list, a link each from the guides index, the tokens guide and the sharing page, and the regeneratedllms.txt.user:<id>, the private notes are@me, and two collections are granted to the person. ADestinationis the host's own record of who reads a reply and which collections they share.collection.list, called as the person, also returns. A private conversation gets everything the person reads. The host passes the scope toknowledge.searchasnamespaceandnamespaces, and never sendsnamespace_scope: "all_mine"for a shared destination.search(query)andopen_citation(handle). Any other tool name or argument is refused before a request is made.deliverrefuses a reply whose target is not the destination its context was chosen for.namespaces. A claim that caps an end-user token at named collections would move that check into Loom. I did not open an issue for it.--namespace-role) for a host that must hand a credential to the agent. On a local server, a scoped token whose subject held grants on two collections got 403 for the one its claim did not name.Left out, as the issue says: messaging, agent execution, channel membership, and any model call.
Compatibility, rollout and rollback
LOOM_JWT_END_USER_ISSUERS_JSON), which the README section shows for a local server.llms.txtline.Tests
Unit (
tests/unit/test_sdk_example_audience_scoped_retrieval.py, 6 tests, a scripted server that keeps grants per signed-in user): every check passes and the run removes what it made; the shared request names the support collection alone; a refused tool call and an unknown destination send nothing; a server that returns a hit from outside the named collections stops the run; a grant that stays after the revoke fails it, and so does a collection that is not deleted. With the search line changed tonamespace_scope="all_mine", four of the six fail.Integration (
tests/integration/test_sdk_example_audience_scoped_retrieval.py): the example against a live server with the test end-user issuer; it skips without one.By hand against a local Loom (ClickHouse 26.10.4 in Docker from
dev/ci_start_clickhouse.sh, migrations, oneuvicorn server.main:appwith auth on, thefake-ngram-1024embedder): with the test issuer oftests/end_user_issuer.py,pytest tests/integration/test_sdk_example_audience_scoped_retrieval.py tests/integration/test_knowledge_sharing.pyhas 34 passed. With a key fromopenssl genrsaregistered as the README shows, the README's command printed the run pasted there and exited 0.Repository checks (Linux, Python 3.12):
ruff format --check .,prettier@3.9.9 --check "**/*.{md,yml,yaml}",make lint(withdocs_reference.py --check, afterllms.txtwas regenerated) andmake typecheckpass;test_public_copy.pyandtest_doc_links.pypass;mkdocs build --strictbuilds the site with the new page. I did not run the biome, taplo and shfmt parts ofmake format-check; the diff has no file of theirs.pytest bench -qpasses (251).pytest tests/unit -n 16, run before the last review fixes, had 46,978 passed and 2 failed, both intest_cross_replica_auth.py(retiring 'k1' would leave no key), which also fail with this change stashed, on the base commit; after those fixes I reran the new test file and the two doc tests (285 passed).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 example, tests and guide, and Codex reviewed the diff. I checked each server behaviour the guide states against a local Loom (the search scope fields, the 403 on an unreadable collection,
@me, the revoke, the scoped token), ran the example and both tests there, and broke the scope line to see the tests fail.I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make test-unitand applicable integration results are reported by CI; a full local run is not required before pushing. (ruff, prettier, lint, typecheck and the focused tests pass; the biome, taplo and shfmt format checks were not run, see Tests)docs/reference/configuration.mdand thedocs/reference/tables (python scripts/codegen/docs_reference.py), the reach manifest,schemas/schema.sql(make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py). (llms.txtregenerated bydocs_reference.py; nothing else applies)main; no merged migration is edited. (no migration)hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version. (no plugin file)npm --prefix frontend run build) and its tests pass, iffrontend/changed. (not changed)docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.