Repository navigation
Cap token claims at the live grant, serialize grant changes, and bound all_mine search - #29
Merged
Merged
Conversation
zlareb1
force-pushed
the
fanout-gaps
branch
2 times, most recently
from
October 14, 2026 10:59
bb07ef1 to
34020bc
Compare
…ad the addressed one With auth off there is no token, and the fan-out read nobody's grants, so "search all my namespaces" never left the addressed namespace in the open-source default mode. The fan-out now reads the single user's grants when auth is off; with auth on, an unbound caller still resolves to nothing. The sweep had no bound: memory, knowledge and conversation search fanned out over every namespace the caller belongs to, and the knowledge leg runs two statements per namespace at once. It now stops at LOOM_MEMORY_SEARCH_FANOUT_MAX_NAMESPACES (32), and memory.search names the rest in `namespaces_skipped` so the cut is never silent. The MCP home pick still sees the whole list, so the cap cannot move an unaddressed search off the caller's own namespace. A fan-out only widens a search, so the addressed namespace is read by every leg even when the fan-out lacks it (cut, or of another kind); a scoped token keeps its order and reads it last. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rivate namespaces The scoped-token waterfall stops at the first confident tier, so reading an addressed namespace last meant it was often not read at all. Every leg now puts it first when the fan-out lacks it, through one helper. A flat list is sorted by name, so cutting it at the cap dropped namespaces by spelling. Before the cut, private namespaces move ahead of public ones, the order the search reads them in; a scoped token keeps its own order. The resolve_fanout_namespaces wrapper is gone: the legs call resolve_fanout or namespaces_to_search. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sorting private-first only when the cap fired made the order of a 33-name list differ from a 32-name one. Visibility now only picks what is kept; the kept and skipped lists stay in the caller's own order. The directory answers the fact (which namespaces are public) and the resolver applies the rule. The loom_search text names the namespaces left out, for clients that read only the text, and the docs no longer claim every leg reports the cut. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ut namespaces Docstrings still described all_mine as every readable namespace, and the visibility fallback as never searching less; neither holds under the cap. A caller in hundreds of namespaces would get every cut name in each loom_search summary, so the text names five and counts the rest. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ts its own module For a caller without a scoped token, an addressed public namespace waited for the public pass, which a confident private hit skips: a search aimed at a team namespace could come back with only the caller's private rows. The addressed namespace now joins the first pass in memory and knowledge search. The fan-out rules move to server/auth/fanout.py, leaving context.py the per-request identity; _scope_inputs returns the skipped list instead of writing it into the run. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A scoped token that listed the addressed namespace second still walked its own order, so a confident hit in the first tier ended the search before the namespace the caller asked for; unaddressed MCP searches addressed to the caller's home hit exactly that. The addressed namespace now always leads, and the rest follow in their order. Fanout carries whether its order is a priority, so the cap and the search tiers read one answer. Knowledge search reads visibility through the cached map instead of its own FINAL query. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The two legs carried their own copy of "addressed and private first, public after", and disagreed on an unreadable directory: memory read everything in one pass, knowledge in one traced "private" pass. Both now take their passes from fanout.private_first, which answers a flat read when nothing is known to be private. Fan-out imports are module-level, the resolver's docstring says only a scoped token's order is a priority, and the remaining "JWT + grants" scope texts point at the identity docs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…entry The split is search-tier policy, so it moves out of the auth package to namespace_visibility, which now also says what a missing answer means. _scope_inputs settles the whole namespace scope on the run. The MCP tool descriptions and the remaining field comments describe the capped, addressed-first fan-out, and every pointer to the docs uses one anchor. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The first pass now carries the addressed namespace whatever its visibility, so private_ns could hold a public namespace; the callers say first_pass and second_pass. The identity docs say namespaces_searched is the scope, not what was read, the knowledge field comment fits the generated reference, and the changelog's Changed list is one list. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The resolver cut the list before it knew which namespace a search addressed, so the addressed one used a cap slot when it was the caller's own (the usual MCP case) and was read on top otherwise. Fanout now keeps the uncut list and Fanout.reads(namespace) cuts the others per search, private ones first for anyone but a scoped token. The MCP home pick reads the uncut list. When loom_search cannot resolve the fan-out it now searches every leg as `this`, so no leg reads wider than the namespace consent was narrowed over. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-out is pinned The parameter held the list read, addressed namespace first, not the fan-out, so it is `namespaces` now. A test pins that an unresolvable fan-out searches every leg as `this`; Fanout.reads says it keeps private namespaces before public ones, and the identity docs say the cut goes by name within each. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fanout.reads and the identity docs read as if the kept list were private then public; visibility only decides what survives the cut, and the kept names stay in the caller's order (by name, or a token's own order). The memory.search scope comment loses its "search the union" leftover. Co-Authored-By: Claude Opus 5.5 <[email protected]>
"Kept ahead of" still read as a reading order. Docstring, docs and changelog now say what the cut does, the doc names each list order a token gives, and two new comments are reflowed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The loom_search tool description, its MCP reference line, the answer-first module, the graph leg's comment and one test docstring still described the fan-out as everything the caller can read. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The loom_search text told agents to pass a namespace its schema leaves out; it now only names what the cap skipped. memory.search's description claimed an all_mine default it does not have, procedure.fork promised org template libraries an all_mine search never sweeps, and the dashboard and the NAMESPACE_NOT_ACCESSIBLE message still said "every namespace you can read". namespaces_searched takes the scope as settled instead of re-pinning the addressed namespace, and the function-length baseline drops the entry this change cleared. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… does loom_search never reaches that refusal (its namespace argument is stripped first), so the advice is for the other tools, where an omitted namespace is the default one. The strip's comment and the Sharing page now describe the fan-out as the caller's own namespaces, the addressed one included. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The description named no cap and no kind filter, so an agent could not tell why a document in a code namespace or past the cap was missing. The loom_search fallback comment now reads in the order the code runs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d once A scoped or delegated claim may name a namespace twice, and the cut kept every copy, so the read could exceed the cap and search a namespace twice. Page two of a paged memory.search lost the first call's namespaces_skipped, and knowledge.search and conversation.search applied the cap without saying so: a caller could not tell a complete answer from a cut one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A flat or scoped token that names a namespace kept reaching it after the subject's grant there was revoked, until the token expired. The claim is now withdrawn when the subject's last grant on the namespace was revoked after the token was minted. A namespace never granted to the subject (an operator's mint) keeps its claim. The check reads ClickHouse only when the revocation snapshot, refreshed with the token revocations, shows a grant revoked there since the mint, so the scoped path stays free of I/O. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The withdrawal read the subject's current namespace_grants row, which the subject's own next row replaces: a pending join request or a viewer self-join put an old writer token back in business, a downgrade lowered nothing, and rejecting a join request withdrew a claim no grant ever backed. Every path that takes an active grant away or lowers it now writes a cutoff row to loom.revoked_tokens under each spelling of the subject, so older tokens reach the namespace only through the grant the subject holds now. The check is a lookup in the revocation snapshot, with no ClickHouse read, and the server that wrote the cutoff applies it at once. The conversation substring fallback now reads the same namespaces as the vector search, so its namespaces_skipped is true. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…econd An OAuth refresh re-minted the sign-in snapshot with a fresh iat, past the cutoff, so a withdrawn namespace came back on the next refresh; it now leaves the snapshot for good. Approving a request below the subject's current grant lowered it with no cutoff, so approval refuses that and points to grants.create replace=true. A restore that lowers a grant now cuts the older claims like any other downgrade. The cutoff is the next whole second, so a token minted in the second of the revocation is cut too, and the spellings it cuts are read strictly, never from a stale cache. A second namespace.join request on an approval namespace turned the first, still pending, request into an active grant with no approval; it now replaces the request. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The transport re-authorizes the namespace a page was parked under, but an all_mine page holds hits from every namespace the first call fanned out over. After a grant there was taken away, the next page still served them. Each foreign namespace on a page is now checked again before its hits go out. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Login names every namespace the person owns in the registry, with no grant check, so an owner a co-admin revoked got the namespace back on the next sign-in. An owned namespace whose grant was taken away is now left out until a grant is given back. A parked page whose rows came from a namespace the caller lost answered "exhausted" while more pages remained; it now reads on until it has readable hits, and those withheld hits leave candidates_total too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign-in kept a cut namespace whenever any live grant was left, but the login token is a flat writer, so an owner lowered to viewer got write back on the next sign-in. A cut namespace now leaves the claim of every token a sign-in, an OAuth code exchange or a refresh mints, and the grant the person holds now is what applies. These paths read the cutoffs from ClickHouse rather than the process snapshot: a token minted past a cutoff the snapshot had not seen yet would keep the namespace for good. context.fetch served a parked search page raw, hits from a lost namespace included, and context.offload let a writer forge one; page/ keys are now memory.search's alone. Later pages list only the namespaces still readable. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The cutoff read a sign-in or OAuth exchange makes could land on a replica the revocation had not reached, and mint past it; it now reads with sequential consistency. An OAuth refresh also checked a subject's revoke-token row against the process snapshot, so a refresh within the refresh interval escaped it for good, and the code exchange did not check it at all; both now read it from ClickHouse. An unreadable store answers 503 on /oauth/token and leaves the owned namespaces out of a sign-in, instead of a 500. A refresh dropped a cut restricted namespace that a viewer grant still covers, and a restricted namespace is read only by a token naming it; it is kept while that grant lives. Later pages filter namespaces_skipped too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The sync's docstring names every newer change it respects, the request included; a row per branch and subject needs no fold; the integration test asks with a role a code namespace allows, and a unit test pins the other side of the version boundary. The migration names the claim cap as the column's reader. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # CHANGELOG.md
Registering an account again under another owner dropped the tie between its old handle and its email, so a revoked grant under the email no longer capped the old handle's tokens; the old pair is now kept for the cap, as a release keeps it. Maintainer sync takes its sources from admin grants given on a branch, never from mirrors, so a mirror can take a fresh version and replace a pending request without outranking a later lowering elsewhere. Without a Keeper, a grant change waits for the in-process lock no longer than for a Keeper claim. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A request made on a branch after a maintainer's admin grant elsewhere is respected like a revoke: it replaces the revoke's row there, so answering it with admin let a revoked maintainer regain admin by asking for reader. An older request is still replaced by the mirror. Registering a person's account under another owner clears its email and password, so the old login no longer signs in as the new owner. A maintainer whose every row is a mirror is mirrored from one of them onto branches they have no row on. Co-Authored-By: Claude Opus 5.5 <[email protected]>
An agent account's claim code is its password, so a login is any stored email or password, and it no longer follows the account to another owner; the account's own handle or email as owner is no move and keeps it. A maintainer whose grant was given on a branch no longer configured is mirrored from a mirror of it, onto every branch without a row of theirs. The CHANGELOG names the register change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Clearing the login on an owner change locked the person out, and treating their email as their own handle cut them off from their own grants: the login signs in as the stored owner, which the claim cap ties to the email. namespace.register now refuses (409) to change the owner of an account with an email or a claim code; a release hands it on. Co-Authored-By: Claude Opus 5.5 <[email protected]>
An account's owner is its login's token subject, and subject revocations match it exactly, so an owner change that differs only in case is refused too. The refusal says to send the stored owner to update settings, and what a release would end; the owner_email field says an account keeps it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The operations reference keeps a field description's first sentence, so the rule that an account keeps its stored owner is now part of it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The doctor's problem list is /v1/health's, but it never asked for the grant change claims table, so a deployment without a Keeper heard of it only from /v1/health. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The doctor read the OAuth claims table through a copy of the query its KeeperClaims builds; it now reads it from the claims, as it does the grant change claims, so /v1/health and the doctor cannot disagree on its name. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A grant insert whose reply is lost after the row landed drops this process's grant cache too. The OAuth exchange claims are reached through their KeeperClaims, as the grant change claims are, without a module of pass-through wrappers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ache drop Two removals of different admins of one namespace each counted another admin left and both landed. Every change that may remove an admin (a revoke, a lowering, a leave, a maintainer's branch fan-out) now holds the namespace's admins claim and counts under it; lowering the last admin with replace=true is refused like revoking it. A grant write dropped every cached grant of its org in the writing process. Each entry now records the spellings its read covered, and a grant write drops only the entries holding the subject it wrote. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every non-admin grant and every leave queued on the namespace's admins claim; it is now taken only where admin can be lost (a replace=true lowering, an admin's leave), with a restart if the grant became admin meanwhile. Two maintainer removals in one repository could split the trunk from its branches: they now hold the repository's admins claim from the trunk's last-admin count through the fan-out, and a lowering reaches the branches as a revoke does. The admins claim has a key no subject can be. The grant cache is per process, so a revoke on one of a server's web processes left its siblings admitting the old grant for up to the TTL. A grant write now marks a file they share, and an entry read before the mark is read again. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The shared mark was one time for the whole server, so with several web processes every grant write in any org made every entry stale, a request could join a read begun before a sibling's write, and a coarse file time against a fine clock could keep a revoked grant for the TTL. Each org's writes are now counted in a file of its own, one byte each; an entry or a read in flight is served only while the count is the one its read began at, and this process's own write keeps the entries it did not drop. A revoke of a reader or a request, like a non-admin's leave, takes only the grant's claim, and the admins claims only if the grant became admin. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A failed re-read stood in with the cached entry even when a sibling web process's write had superseded it, so a revoke on one process left the others admitting the grant while ClickHouse was degraded; only an entry the TTL aged stands in now. An unreadable write count still shares one read in flight. Tests pin the revoke paths with and without the admins claims. Co-Authored-By: Claude Opus 5.5 <[email protected]>
An unreadable write count joined any read in flight, one begun before a sibling's revoke included; it now joins only a read begun on an unreadable count. The module says a sibling's write in an org takes the stale fallback from that org's entries. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tests Two tests replaced os.stat process-wide with a one-argument stub, so a failure in either crashed pytest's own reporting instead of naming the test. The stub now fails only the count files and passes the rest through. Co-Authored-By: Claude Opus 5.5 <[email protected]>
zlareb1
added a commit
that referenced
this pull request
Oct 15, 2026
#29 took migrations 028 to 030, so ours moves past them. Its CHANGELOG entries go with the file, which this branch deletes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
zlareb1
added a commit
that referenced
this pull request
Oct 15, 2026
The merge with #29 kept both parents' hash of schemas/schema.sql in tests/analyzer/shapes.txt; the merged file hashes to neither, so the corpus test failed. Writing the corpus again leaves the one current line. Co-Authored-By: Claude Opus 5.5 <[email protected]>
zlareb1
added a commit
that referenced
this pull request
Oct 15, 2026
The release job listed the bundle's required paths by hand, still in the layout before the bundle moved its ClickHouse config and lemmatizer model under deploy/, so the first release after this change would have refused its own bundle. PR CI never runs that step. It now takes the paths from build_stack_bundle.FILES, so the two cannot drift again. ch-setup's no-Keeper line now names the OAuth and grant claims #29 added to the fallbacks, and the live grants test grants what the admin SQL grants (GRANT CURRENT GRANTS), which Cloud accepts where GRANT ALL fails. Co-Authored-By: Claude Opus 5.5 <[email protected]>
zlareb1
added a commit
that referenced
this pull request
Oct 15, 2026
Main took migrations 028-030, so the bi-temporal migration moves to 031. The historical search legs use main's fan-out (namespaces_to_search) and report the namespaces they skipped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
zlareb1
added a commit
that referenced
this pull request
Oct 16, 2026
…#38) * Let a run carry a budget, and show Loom running behind AX tasks An unattended agent can loop and spend without limit, and nothing told it so. Loom already records each session's model spend and when each run started, but a run had no ceiling to compare them against. run.begin now takes an optional budget_usd / budget_seconds; run.get compares them against that spend and the run's age when the run is read, and names what was exceeded in over_budget, with a mentor hint the plugins hand to the model. Loom does not run the agent, so this is a signal, not a stop. AX runs agents in sandboxes that start empty and are thrown away, and it has no memory layer. integrations/ax shows how to give its tasks Loom: a Workspace that writes the MCP config and an AGENTS.md, a Task bound to it, an SDK example that uses the budget, and the token caveats that follow from AX's API having no authentication yet. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Drop the changelogs before the first release This is Loom's first release, so there is no history worth keeping by hand, and three files that had to be dated in step were a gate that could only stop a release, never improve one. The GitHub Release already generates its notes from the commits since the previous tag; operator steps and the wire diff (scripts/codegen/wire_changelog.py) go into those notes instead. Removed with the files: the release workflow's changelog gate, the version checks that compared against changelog entries (test_sdk_changelogs.py, the root-changelog test, the TypeScript check-version source) and every link to them in packaging metadata and docs. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Make the AX example work on a real AX and Substrate cluster Running it on kind (AX 22954f6, Substrate f6a1dc72) showed the first version could not start, and that it put the token where AX's unauthenticated API prints it: - Substrate refuses an image named by tag, and AX then falls back to a default template that does not exist, so the image is pinned by digest. - The command named agent.py relative to the workspace, where it is not; the image now carries it at a fixed path. - AX's published runner image is not publicly pullable, so the README builds the runner from AX's source. - Substrate denies all egress from an actor without a policy and AX creates none, so egress-policy.yaml allows Loom and GitHub. Its Loom rule has the egress gateway inject the token from a Kubernetes Secret, so the Task carries a placeholder and the sandbox never holds the token. The README records what still fails on that cluster: the workspace git clone through the TLS-passthrough rule, and AX reporting the workspace ready when the clone failed. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Explain why the AX workspace clone fails, and how to get the repository The clone failure was not the egress policy: Substrate turns on an actor's egress only after its wakeup probe passes, and AX probes /readyz, which waits for the clone. The README now says so, names the AX change that fixes it (tested on kind against the Substrate commit AX pins), and gives the workaround for an AX without it: clone from the agent's own command, when egress is up. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Record the run-ledger statements with the budget columns The analyzer's statement corpus keys each statement by its text, and the run-ledger SELECTs and the schema dump now carry budget_usd and budget_seconds. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Link the AX issue that proposes the workspace clone fix Co-Authored-By: Claude Opus 5.5 <[email protected]> * Count a run's spend from its own turns, and close the AX run however it ends Review found the cost budget compared against the session's whole history: a new run in a session that had already spent was over budget on its first read, and a closed run grew more expensive as the session went on. run.get now counts the session's turns between the run's start and its close, and a cost budget without a session is refused, since nothing could be counted. The over-budget hint asked the agent to wrap up and complete even when the run was already closed, and completing it again rewrote its status; it now fires only for an active run. The AX example left its run active when a step raised or the task was cancelled. It now closes the run as failed or cancelled and re-raises, and it uses a time budget only, because a sandboxed agent has no plugin recording its turns. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Keep a run's budget on retry, count spend on the server's clock, and show budgets From the second review: - A re-sent run.begin that names no budget keeps the one the run has, like the grade columns, instead of clearing it. - A run's spend is bounded by when Loom recorded each turn (ts), not by the client-stamped turn_at, so a client clock that runs behind cannot hide a turn from the cost budget. - The over-budget hint names only the budgets the run went past, and a blank session_id no longer passes for a session. - The run tools' MCP descriptions mention budgets, and /me shows a run's budget and what it went past; its cost is now the run's, not the session's. - The release workflow generates notes on the tag push only, since a later run appends them again, and the operator steps are written in the release pull request so they are reviewed before the tag. - The AX README says which files belong to the SDK path and which to an MCP agent, and keeps the clone problem to a short known issue. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Count a run's turns by their own time, time it on the server, and close AX runs on SIGTERM Reviews three and two of #38 found that bounding a run's spend by the server's insert time dropped every turn the Stop hook posts after run.complete, which is the normal Claude Code order, and let a re-sent turn move to a later run. Splitting the session at the next run's start instead would cut off a run another one is nested in. Each turn's own time (turn_at) handles all three cases; the docs say it relies on the client clock being roughly right. - A closed run is timed from start to close on the server's clock, not by the duration_ms the client reported. - A re-sent run.begin without a session keeps the run's session as well as its budget, so a cost budget never ends up without one. - The budget check moves to server/tasks/domain/budgets.py with one BudgetKind type, and the session check reports loc ["budget_usd"]. - RunScope maps a cancellation to cancelled and takes a settable status, so the AX example uses it instead of a hand-written try/finally, and turns SIGTERM, how AX stops a task, into a cancellation. - The release workflow generates notes only when the run creates the release, so a re-run of the tag push no longer appends them again. - The shipped AX Workspace leaves spec.git commented out until google/ax#482 lands, and the docs and the mentor's money formatting are tidied. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Refuse overlapping cost budgets in a session, and keep millisecond window bounds A further review of #38 found three gaps: - Two runs open at once in one session see the same turns, so a second cost-budgeted run was charged the first one's spend. run.begin now refuses a cost budget while another budgeted run is open in the session, naming it; each concurrent worker takes its own session. A time budget alone still overlaps freely. - clickhouse-connect 1.0 and 1.1 bind a datetime parameter to whole seconds, so a sub-second run window could miss a turn; the floor is now 1.2, where binding keeps the milliseconds (checked against 1.1.1 and 1.2.0). - AX kills a task 10 s after SIGTERM, and the SDK's default timeout is 60 s, so the AX example's Loom calls now time out at 5 s and the run's close lands before the kill. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Drop the per-session cost-budget guard, and say where cost budgets can be trusted Reviews four and five of #38: - The guard against two cost-budgeted runs in one session blocked the session for good after one abandoned run (only MCP runs are idle-swept), raced past concurrent begins, and could name another user's run. It is gone; the docs say runs open at once in one session share its turns, so concurrent workers with their own cost budgets need their own sessions. - The MCP tools no longer offer budget_usd: the model does not know the session id its turns are recorded under, so a cost budget there would silently never fire. budget_seconds stays. - run.get counts turns from unpriced models in unpriced_turns, and the docs say a cost budget is checked between prompts, since the plugins post turns when a prompt ends. - The session check runs after a re-sent begin's session is resolved, and cost and time read one window, from the row the run model already parsed. - cost.record_turns clamps a turn dated more than five minutes ahead. - The release step tells a missing release (404) from any other API error. - The AX example exits 143 on SIGTERM instead of a traceback, and its work() returns the statuses it can. - The Runs page shows elapsed time beside a time budget; the hint's spend is always two decimals; the migration comment is reflowed. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Require a clickhouse-connect that binds naive datetimes as UTC Loom passes naive UTC datetimes as query parameters. clickhouse-connect before 1.7 binds a naive datetime as the host's local time, so on a host not in UTC every such window shifts; under Asia/Kolkata a noon run window read as 06:30 and missed its turns (checked on 1.2 through 1.6, fixed in 1.7). The floor moves from 1.2 to 1.7, which also keeps milliseconds, and the window test now runs under a non-UTC timezone. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Clamp future turns to now, and refuse a sessionless cost budget before the claim Review six of #38: - The five-minute slack let a turn dated up to five minutes ahead fall after an open run's window, so a fast client clock still hid it; a turn is now clamped to the server's now. - The "budget_usd needs a session_id" 422 was raised after run.begin had claimed the run id, and a refused begin keeps its claim, so every such request left a Keeper key behind. The check is back on the request model, so it runs before the claim; a client that re-sends a budget re-sends its session. - The AX example makes one 5 s attempt per Loom call, since retries could outlast AX's 10 s kill. - The run window helper no longer pretends started_at can be missing, the workers integration test flushes the insert queue and checks both sides, the millisecond test removes its row, the Runs page grid fits its fifth cell, and the SDK's run.begin docstring says budget_usd needs session_id. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Name the budget a run went past, and pin the SDK the AX example needs Review seven of #38: - The over-budget hint now says how far over the run is ("$2.50 of $2.00 spent", "90 s of 60 s"), to four decimals for a sub-cent budget. - elapsed_seconds cannot go negative when a run's start came from a replica whose clock is ahead. - The AX image pins clickhouse-loom>=1.0, the release with run budgets, and the README says the server must be that new too. - The AX example drops the run id it passed by hand: inside the run scope, writes already carry it. - The docs say how to raise a run's budget (re-send run.begin with a larger one) and that a turn dated in the future is stamped again if re-sent. - The budget_usd field comment and the run_cost docstring are tightened. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Let the AX run's close survive a SIGTERM, and correct what an older server does Review eight of #38: - A SIGTERM that arrived after the work, while the run scope was closing the run, cancelled the close and left the run active. Once work() returns, SIGTERM is ignored, so the close (one 5 s attempt) lands inside AX's 10 s. - The AX README said an older server refuses the budget fields; it ignores them and lists them in ignored_args, so the run has no budget. - Both budgets are resolved together before the row is built, and each field comment's first sentence, which the reference keeps, carries its rules. - The Runs page shows a sub-cent budget to four decimals, the SyncRunScope docstring names status, and the clamp test checks a lower bound too. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Ignore SIGTERM for the AX run's close however its work ended Review nine of #38: the handler swap ran only when work() returned, so a SIGTERM during the failed or cancelled close still cancelled run.complete and left the run active. It now runs in a finally. Also from that review: the never-None guard on current_task() goes, the release step's comments sit above the steps they describe, the hint reads both budgets the same way, the integration test drops a poll the flush made redundant, and the Runs page reads over_budget once. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Store a run's session id as sent, and open the AX signal handler with the run Review ten of #38: - _open_run stored the session id stripped while cost.record_turns keeps it as sent, so a run begun with " s1 " never matched its own turns and a cost budget could not trip. It is stored as sent again; only the blank test strips. - The AX example installs its SIGTERM handler once the run is open, so a signal while the scope is still opening is the default exit, and the README says what that can leave behind. - Field comments say a retry that re-sends budget_usd must re-send session_id and that a begin naming no session keeps the run's; the docs say any non-zero budget replaces the old one; RunScope's outcome reads as one decision; the Runs page shows "0s elapsed"; two docs paragraphs are re-wrapped. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Stop advertising a re-sent begin as the way to change a budget, and name sessions once Review eleven of #38: - runs.md told users to change a budget by re-sending run.begin, but a re-sent begin replaces the row like any retry: on a closed run it reopens it, and on an open one it drops what the body does not restate. The docs now say to set the budget in the first run.begin and only describe what a retry does to it. - "Does the run name a session" is one helper, names_session, used by the request model, the row and both run-id claims, which disagreed on a blank session. - The release lookup matches "(HTTP 404)" as scripts/release does and prints the full error before a one-line annotation. - The release docs keep a dispatch command on one line, the budget_usd comment and a RunScope docstring paragraph are tidied, the AX example says why a CancelledError means SIGTERM, and runs.md notes the month-boundary case for a re-stamped turn. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Point the budget hint at loom_op, and give names_session its home in naming Review twelve of #38: - The over-budget hint tells a core-toolset agent to call run.complete via loom_op, as the other hints that name an unlisted op do, and the atomic run.begin description says run.get via loom_op reports over_budget. - run.get decides "has a session" with names_session like the request, the row and the claim; the helper moves to server/core/naming.py beside SENTINEL, since claims use it too. - The Budgets docs are one short paragraph per idea plus a bulleted list of limits, the AX README says plainly how a sandboxed agent could use a cost budget, the TZ test scopes its patch with MonkeyPatch.context, and the hint's time branch names one value per line. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Keep budget_usd off MCP's run.begin schema Review thirteen of #38: the MCP tool listing still offered budget_usd on run.begin (its schema comes from the request model), while MCP hides session_id from every tool, so a model could only meet the session rule by guessing an id whose turns never arrive. The field carries MCP_HIDDEN: it leaves the listing and the loom_op argument hints, and HTTP and the SDKs keep it. Its comment now opens with the session requirement, which is the sentence the generated reference keeps. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Say what the AX example's single attempt costs, and test MCP's real run.begin listing Review fourteen of #38: - The AX example's one 5 s attempt applies to every Loom call, not only the close, so its comment now says a transient error during the work fails the task, and how an agent that needs retries could close the run instead. - The MCP test checks loom_run_begin in the atomic and all listings that tools/list builds, rather than a private helper. - _complete decides "has a session" with names_session like the rest. - The budget_usd comment says plainly that a re-sent begin restating the budget restates the session; the migration says why budget_usd is a Float64 beside the Decimal cost it is compared with; the release docs say "paste the release notes" once, in the steps. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Say a retry keeps a run's session and budget only under the same run_id Review fifteen of #38: when run.begin moves a caller off a run_id another user holds, the id it hands back is derived from the session, so a retry that drops the session lands on a new run without the budget. The field comments and runs.md now say the session and budget are kept on a re-sent begin of the same run_id, and to re-send the run_id the server answered with. budgets_exceeded takes keywords, since its four numbers are two units; the AX README says a budget stop still exits 0; the budget_usd comment is two lines. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Keep a turn's time as sent, so a replay cannot move it to another run A review of #38 found that clamping a future turn_at to the server's now gave an identical turn a new time on every delivery while its own time was still ahead: run A was charged $2, and a replay of the same usage after B opened moved the $2 to B. Determinism matters more than covering a fast client clock, so cost.record_turns stores turn_at as sent again and reports such turns in turns_dated_ahead, and an integration test replays an hour-ahead turn across two runs (it fails with the clamp back). From review sixteen: elapsed_seconds is described as start to close on the server's clock rather than a "duration", the Runs page names unpriced turns and reads "has a session" as names_session does, and the sequential-runs test sets its budgets in units of one turn's price. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Show the spend to four decimals in the budget hint, and say budget_usd travels with its session Review seventeen of #38: the hint formatted the spend at the budget's precision, so $1.004 against a $1.00 budget read "$1.00 of $1.00 spent" in a message saying the run was over; the spend is now always four decimals. The rule checks the op before reading the result, the Retries bullet says a new budget_usd must be sent with its session_id, and the AX README no longer speaks of an older release when 1.0 is the first. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Drop a run's cost budget when a retry moves it to another session Review eighteen of #38: a re-sent run.begin naming a new session moved the run but kept its budget_usd, which was then measured against turns it was never set for, and an overrun vanished. The cost budget is kept only while the session is; the time budget still carries. The docs also stop saying turns_dated_ahead is how a fast clock shows: the plugins post turns without reading the answer, so only a caller that posts its own sees it. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Show a just-over spend to six places and say when a retry drops a budget Review nineteen of #38. run.get rounds cost to six places, so the hint's four missed a spend a few millionths past its budget; it now uses six, as does a sub-cent budget on the Runs page. A re-sent begin that moves sessions dropped budget_usd silently; its `next` now says so, and the docs no longer claim a budget can never be removed. turns_dated_ahead ignores 5 s of ordinary skew, so a client a few milliseconds fast is not flagged on every turn. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Never print a budget rounded past the spend that went over it Review twenty of #38. A $1.235 budget printed as $1.24 next to $1.23516 spent, and the Runs page still cut cost to four places. Both now show cost and budget to the six places they are kept at, dropping only zeros past the cents, and run.begin rounds the budget to those six places so it compares with run.get's rounded cost like for like. The dropped-budget note says how to set one again. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Refuse a budget too small to keep instead of reading it as none Review twenty-one of #38. A budget_usd under a millionth rounded to 0, and a re-sent begin then kept the run's old, larger budget; it is now refused, and the rounding happens on the field before the session check sees it. The Runs page spells dollars with thousands separators as the hint does, the dropped-budget note names the session to re-send with, and _usd moves up with the module's other small helpers. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Say in the docs that a cost budget is kept to six places Review twenty-two of #38: the rounding and the 0.000001 floor added in the last round were in the code only, so a caller could meet the 422 or read back a rounded budget with nothing in the docs to explain it. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Round a budget before refusing it, and spell a time budget as the page does Review twenty-three of #38. The floor refused 0.0000006, which rounds to the smallest budget the server keeps; it now refuses only a budget that rounds to nothing. The hint said "5400 s of 3600 s" where the Runs page shows "1h 30m" and "60m 0s"; it now uses the page's spelling. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Drop a hint assertion that counted words in the advice text Review twenty-four of #38: the cost-only case already pins its whole budget clause, so counting " of " across the hint added nothing and would fail on any rewording of the advice that follows it. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Regenerate the analyzer corpus for the merged schema dump The merge with #29 kept both parents' hash of schemas/schema.sql in tests/analyzer/shapes.txt; the merged file hashes to neither, so the corpus test failed. Writing the corpus again leaves the one current line. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Keep a turn's first time when it is re-sent without one A turn with no turn_at, or one that did not parse, was dated now on every delivery. With run cost counted by turn_at, a replay of the same usage after the run closed moved its cost into whatever run was open next: the first run dropped back under budget and the next one was charged for nothing new. Such a turn now takes the time its message_id was first recorded with in the session, and only a message never seen before gets now. The lookup is one read on the table's key, and only when a batch has an undated turn. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Date an undated replay by the turn's newest row, not its oldest Review twenty-eight of #38. min(turn_at) read the oldest unmerged row, but run cost reads FINAL, which keeps the newest; a turn first sent undated and then re-sent with a time went back to its first run on the next undated replay, and stayed there across partitions that never merge. argMax by version reads the row FINAL sees. The tests stop leaning on an AttributeError for the lookup's fallback, cover a failed lookup, and send the replay in a new block so insert dedup can't pass the test on its own. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Treat a turn time past the calendar's ends as no time, and log a failed lookup Review twenty-nine of #38. "0001-01-01T00:00:00+01:00" parsed but overflowed when converted to UTC, outside any try, so cost.record_turns answered 500; the parse helper now converts and treats the overflow as unparseable. A failed time lookup logs a warning instead of passing in silence, the lookup's alias no longer shadows turn_at (a later WHERE on it would read the aggregate), and it returns plain datetimes since the column is never null. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Check where an out-of-range turn time lands, and say it plainly Review thirty of #38: the overflow case only proved the lookup was asked about it, not that it was stored as now; and the parse helper's docstring had the year bounds the wrong way round. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
zlareb1
added a commit
that referenced
this pull request
Oct 16, 2026
…se Cloud (#35) * Install Loom against its own ClickHouse, a self-managed server or ClickHouse Cloud The installer could only start the bundled ClickHouse, nothing created the `loom` database on any other server, and the read-only reader user existed only in the bundled server's XML, so outside it caller-shaped reads ran as the read-write user. compose.yaml becomes the one shipped stack, with ClickHouse behind the `bundled` profile; install.sh --clickhouse points it elsewhere and runs the new `loom ch-setup`, which creates the database and the reader with SQL or prints the SQL for an admin, and never replaces a user it did not make. Boot, migrate and doctor share a preflight that stops before any DDL with the fix named, checking the grants the process needs (from 26.9 the ALTER group holds the global-only ALTER HANDLER, so the migration grants name ALTER TABLE and ALTER VIEW). Table settings that came from a server-wide config file now live on the tables, and every session on a pre-26.8 server turns the query condition cache off. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Address the third review of the ClickHouse targets A Loom user scoped to loom.* may not write ClickStack's default.otel_* tables, and the exporters logged a traceback on every batch; access denied now disables them with one warning, as a missing table does. The doctor no longer creates the loom database it checks for: it warns that boot will. The admin SQL grants READ ON REMOTE, since plain REMOTE on Cloud also allows writes to any host. Migration 028 also sets the dedup window on the `_`-prefixed tables the schema dump leaves out, and a test reads them from the migrations. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Let a hidden table carry the dedup window in its own CREATE Co-Authored-By: Claude Opus 5.5 <[email protected]> * Address the fourth review of the ClickHouse targets The doctor warned that boot would create a missing database even where the user may not; it now checks CREATE DATABASE and fails with the admin hint. The printed admin SQL says that it replaces any existing reader account, and the docs say the query-log grant shows every user's queries, with a row policy that keeps it to Loom's own where the server allows one. The needs-an-admin messages no longer send ch-setup's own output back to ch-setup, and name the command an installed stack runs. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Address the fifth review of the ClickHouse targets ch-setup printed "run ch-setup --print-sql" right above the SQL it printed; the pointer now rides only the boot, migrate and doctor messages. A cap set to 0 is written as no cap and checked like the others, so lifting one rebuilds the reader instead of leaving the old ceiling. The installer takes an empty password from `user:@host` or LOOM_CH_PASSWORD= without a terminal, and the missing-database branches of the preflight are nested. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Address the sixth review of the ClickHouse targets A login that may create users but not list them read "no such user" when it could not see who owned the reader, and replaced an unrelated account; ch-setup now refuses then and prints the SQL for an admin. A rerun of the installer for the same user and server keeps the password .env holds instead of asking again, so a scripted upgrade needs no terminal. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Address the seventh review of the ClickHouse targets The installer reused a saved password silently, for any port, even with a terminal, so a mistyped one could not be fixed by running it again; it now keeps one only without a terminal and for the same host, port and user, and says so. The docs say a worker-running process needs everything on loom.*, that a self-managed server still refuses writes through remote(), and that changing LOOM_CH_PASSWORD means running ch-setup again. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Address the eighth review of the ClickHouse targets On a server without Keeper, any upgrade that brought a migration failed to boot: the provider fence waited for a lock that is a KeeperMap key, which cannot exist there, so no provider configuration was ever published and there was nothing to fence. Boot now migrates without it when the KeeperMap lock table is absent. Enter at the installer's rerun prompt keeps the saved password instead of replacing it with an empty one, and the prompt says so. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Print ch-setup's admin SQL on the stream its reason went to Under docker compose run the two streams are relayed apart and the reason could land between the heading and the SQL. --print-sql still writes to stdout, for piping. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Address the tenth review of the ClickHouse targets The installer cut the URL at its first `/` before splitting off the user, so a raw `/` in a password put part of it in the host and in an error message; the user and password now go first, up to the last `@`. Workers booting together on a fresh Cloud service raced on CREATE DATABASE and the losers (code 341) crashed the start; a create that fails while the database now exists is not a failure. A serving process that cannot see the database says it may lack the grant, not only that it is missing. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Address the eleventh review of the ClickHouse targets An install from before profiles had its LOOM_CH_* lines in .env ignored, because the old compose file pinned the connection; an upgrade now comments them out, so it keeps reaching the bundled server. Boot no longer runs the preflight a second time inside the migration runner. A query string after the port is ignored, and the printed stop command also stops a bundled ClickHouse left from before a switch. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Address the twelfth review of the ClickHouse targets The upgrade commented out every LOOM_CH_* line in an old install's .env, but the old compose file pinned only the seven connection settings; tuned timeouts, pool sizes and caller-shaped caps reached Loom and now stay. The reader profile takes its caps from the client's own caller-shaped ceilings, so a new one is pinned too. A bracketed IPv6 host parses without a port, and the migration runner's flag no longer shadows the preflight module. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Stop treating a failed or partial probe as a ready ClickHouse A refused or failed clusterAllReplicas read was taken for a single server, so a user without REMOTE on a mixed-version cluster passed as the newest version and kept the pre-26.8 condition cache on; only a missing cluster now falls back, the preflight stops otherwise, and the sessions keep the cache off. The preflight probed one system table of the many the runner reads, so a migration could fail halfway; it now names every refused one before any DDL. A password ending in a backslash broke .env's single quotes; it is written double-quoted with \, " and $ escaped, and a test reads it back through Compose. ch-setup compared the reader's values but not its MIN/MAX and CONST constraints; both are checked now, and the PTY test's child is bounded, reaped and its exit checked. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Address the thirteenth review of the ClickHouse targets Since the replica check became strict, one replica that was down, or a user without REMOTE, kept even a serve-only process and `migrate --status` from starting, with a hint that blamed the host settings. The version query now skips unavailable shards, only a process about to migrate insists on every replica's version (the others fall back with a warning, and the sessions keep the condition cache off), the system-table probe runs only when migrating, and server-side errors no longer carry the connection hint. A reconnecting client gets its cache setting before other tasks can use it. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Address the fourteenth review of the ClickHouse targets A migrating boot refused to start unless every system table Loom ever reads was readable, though only the migration runner's need to be; an admin who withholds system.query_log (it shows every user's queries) got a server that would not start. The runner's tables still stop it; a refused telemetry table is a warning, and a doctor WARN. A restart with nothing pending is no longer held to the migrate-level replica check, so removing REMOTE from an up-to-date deployment does not stop it restarting. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Judge Loom's ownership, replica discovery and pending migrations from what the server proves A reader of Loom's name is taken as Loom's only when it logs in with LOOM_CH_PASSWORD, so ch-setup never replaces another team's user or profile that happens to share the name. Replica versions must come from every configured replica: a skipped shard is unverified, not absent. Pending migrations are counted from the directory the command will apply, and an unreadable ledger or an image that ships no migration files counts as pending, so ch-setup and doctor inside the image check what the migrating boot enforces. While nothing is pending, the doctor warns of what the next migration will refuse instead of passing silently. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Replace only a reader in ch-setup's own shape, and run the CLI from the server's tree Logging in with LOOM_CH_PASSWORD alone did not prove a loom_reader was Loom's: a no_password user accepts any password, and a probe that failed for another reason fell through to OR REPLACE. ch-setup now rebuilds an existing reader only when it is a password user on the settings profile of its own name and the probe actually logged in; anything else stops untouched. The recovery hint drops the profile too, since DROP USER alone left an orphan that blocked every rerun, and a reader created halfway is dropped so the next run starts clean. In the image the `loom` command imported the venv's copy of `server`, which ships no schemas/, so the CLI saw no migrations while boot did. PYTHONPATH=/app gives both one tree: doctor and `loom migrate` now judge the same journal as the server. ch-setup always checks as if a migration were pending, since preparing for the next one is its job, and the pending check reads the ledger through migrate's own reader. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Leave a working reader alone on a transient probe error, and clean up a half-made one fully A read timeout or 5xx while probing the reader proved nothing about who owns it, yet ch-setup advised dropping it, the account production reads run as. Only an authentication refusal now leads to the DROP hint; any other probe error asks for a rerun. The cleanup of a reader created halfway ran both DROPs in one try, and ClickHouse checks the DROP USER privilege even for a user that does not exist, so the orphaned profile survived and blocked the rerun; each DROP now stands alone. The doctor's WARN said the same prefix and SQL pointer once per reason, and the reader-step refusal blamed user creation when the GRANT was what failed. `make dev` printed a guessed ClickHouse port without the bundled profile. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Settle who owns the reader before logging in as it ch-setup probed the reader's login before looking at whose account it was, so it signed in to a foreign no-password account, and every first run left a failed login in the server's log. Ownership is now read first and the probe runs only for an account that may be Loom's. A reader from the server's config now gets the fix for what is actually wrong: a probe error asks for a rerun and a password mismatch names the password, where both used to say to raise the XML profile. The boot log names each refusal the next migration will hit once, with one pointer to the SQL. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Keep the preflight's warnings out of check(), and give each refusal the fix it needs check() logged what it deferred, so `loom doctor` printed every reason twice, once as a raw log line and again on its report. check() now only returns what it found, and preflight.warnings() renders it as one line that boot and `loom migrate` log and the doctor and ch-setup show. ch-setup's refusals named the wrong thing in three places: a reader it could not see the owner of hid that the probe said the password was wrong; a shared profile with no user was called an existing user; and a lowered cap was told to "raise" the XML profile. The reader step now handles a missing reader first and creates it straight away, so each later branch only deals with an account that exists. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Point a failing reader at ch-setup, and let an empty LOOM_CH_READER_USER opt out The health fix for a refused reader told every operator to install the bundled server's XML and restart ClickHouse, which Cloud cannot do and a self-managed server need not: `loom ch-setup` is the fix now everywhere but the bundled server. Compose's `:-` turned an empty LOOM_CH_READER_USER back into loom_reader, so the documented opt-out never took effect; `-` keeps an empty value. The preflight logged two raw driver errors of its own beside the line boot prints, so those go. Its warning says "the next migration" rather than "boot", since `loom migrate` prints it too; ch-setup names the GRANT for an unreadable telemetry table instead of pointing at itself, and flushes its progress before each refusal so a pipe keeps the order. A reader that may be missing is no longer reported as having a wrong password. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Let an empty LOOM_CH_READER_USER skip the reader in ch-setup too The empty value was documented as the opt-out, but ch-setup still read it as "use loom_reader", and the installer runs ch-setup on every install: a user who may not create users failed the install over a reader it would never use, and one who may got a second login on the shared password it had opted out of. Set but empty now skips the reader, in the printed SQL as well; unset still means the default reader. The boot test runs the real check so a log line put back inside it would fail it. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Pin complete replica discovery in the query, and refuse a profile assigned to others Dropping skip_unavailable_shards from the replica query still left it to the user's profile, which can turn it on and silently omit an unreachable replica from both the preflight and the condition-cache check; the query now sets it to 0 itself. A settings profile can reach other accounts by direct assignment (TO user, role or ALL) as well as by inheritance, and ch-setup only looked at inheritance, so it could replace another account's limits; such a profile is now foreign. The recovery hint quotes the reader's name, as the setup SQL does, so a hyphenated name runs as printed. The analyzer corpus still imported migrate._applied, and the dropped- response retry test read the server default window, which migration 028 no longer changes, so it skipped; it now reads the table's own. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Name system.processes beside query_log as an exposure, with a policy for both The admin SQL grants SELECT on system.processes, which Loom needs to see whether its own provider statements still run, and which shows every user's running queries with their literals as query_log shows past ones. Only query_log was named, so an operator who applied the row policy would think the exposure closed; the docs and the SQL comment now name both, and the policy covers both tables. A unit assert pins skip_unavailable_shards = 0 in the replica query, so dropping it fails a test; two docstrings no longer describe a warning that is not logged and a server config this branch removed. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Renumber the table settings migration past main's 028-030 Main took 028-030 for the OAuth and grant claims, so the table settings migration becomes 031; nothing outside this branch ever applied it under its old number. The new tables are KeeperMap and take no deduplication window. The requirements table carries main's new Keeper claims, and the analyzer's shapes file is regenerated for the merged schema dump. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Check the release bundle against the files the builder ships The release job listed the bundle's required paths by hand, still in the layout before the bundle moved its ClickHouse config and lemmatizer model under deploy/, so the first release after this change would have refused its own bundle. PR CI never runs that step. It now takes the paths from build_stack_bundle.FILES, so the two cannot drift again. ch-setup's no-Keeper line now names the OAuth and grant claims #29 added to the fallbacks, and the live grants test grants what the admin SQL grants (GRANT CURRENT GRANTS), which Cloud accepts where GRANT ALL fails. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Hold the reader to SELECT on loom.* alone, and correct what the docs say about --env-file ch-setup confirmed the reader could read loom.* but not that this was all it could do, so a reader someone had widened to SELECT ON *.* passed as ready while the docs promised it cannot read system.query_log. The check now reads the reader's own SHOW GRANTS and expects that one grant; a wider reader in ch-setup's shape is rebuilt like any other drift. With compose.yaml at the root as the first file, Compose finds the root .env itself, so the docs no longer call --env-file required; only the cloud stack, whose first file is under dev/, needs it. The condition cache note names where the guard lives, the reader step's docstring says what it settles before replacing anything, and the profile rows are a small NamedTuple rather than positional tuples. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Say that ch-setup resets a reader an admin changed, and pin the grant check's edges Since the reader is held to SELECT on loom.* alone, a role, grant or REVOKE an admin gives it is undone the next time ch-setup runs, which the installer does on every install and upgrade; the docs said only a profile mismatch was rebuilt. They now say so. The grant check's test now covers a reader name ClickHouse quotes and a narrowed reader. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Find the lightweight-UPDATE tables from the statements, and say where the installed .env belongs The block-column test named memory and memory_embeddings by hand; the server-wide XML that gave every table those columns is gone, so a new lightweight UPDATE on another table would quietly become a mutation per call. The test now takes the tables from the UPDATE statements in the analyzer corpus. A reader login that lands as another user (an auth mapping) is reported as that, not as a caps mismatch; the docs say the installed .env is read by Compose, whose escapes python-dotenv reads differently; env.example says how to switch a bundled install by hand. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Keep the port and image an install was given in its .env The installer honoured LOOM_PORT, LOOM_BIND_HOST and LOOM_IMAGE_REPOSITORY from the shell for its own run but left .env on the template's 7777 and the public image. Every later `docker compose` in the install directory, including the `ch-setup` rerun the installer prints, then bound 7777 and pulled the public image: on a host whose 7777 is taken by another Loom, a test install's bare `compose up` tried to publish on that port. The values given now go into .env, a rerun without them keeps them, and the health check reads the port from .env. A value .env cannot hold as written is refused before anything is written. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Poll Loom where it is published, and refuse a port Compose would reject With LOOM_BIND_HOST now kept in .env, every rerun of an install bound to a specific address waited three minutes on 127.0.0.1 before calling a healthy Loom unhealthy; the health check polls the published address (bracketed for IPv6), loopback when bound to every interface. A port outside 1-65535 passed the digits check and only failed at `compose up`, after .env was written; it is refused up front. The server stops warning on every boot about the Compose-only names an install's .env now carries. The docs say an install from an earlier release passes its port once more on upgrade, and the CHANGELOG lists the change. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Point the installer's health check and dashboard at the published address, and name ch-setup before a prepared start Docker publishes `::` on IPv6 only, so polling 127.0.0.1 for it timed out on a healthy Loom; it polls [::1] now. The dashboard line printed 127.0.0.1 whatever the bind address, and now prints the address polled. A prepared install (LOOM_SKIP_START=1) on an outside ClickHouse exited without saying the reader still had to be created, so the documented pull and up left every caller-shaped read failing; the installer and the quickstart name `ch-setup` as the step before `up`. The quickstart says a non-loopback LOOM_BIND_HOST needs LOOM_PUBLIC_BASE_URL and sign-in first, and the deployment docs give the order for a cap change. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Defer the DDL grants with the other migration checks, and refuse a URL .env cannot hold The replica and runner-table checks relaxed when nothing was pending, but the DDL grants stayed strict, so an up-to-date deployment on a DML-only user that booted on main stopped booting. They are now checked like the others: refused while a migration is pending, a doctor warning otherwise. A ClickHouse user or host from the URL went into .env as written, so a `$` or space there reached Loom mangled; both are now held to what .env and ch-setup's SQL take. Boot logs the preflight reason before the traceback, the docs give a failure-free order for raising and lowering a cap, the cloud stack's mount is named again, and the checkout recreate commands start the bundled profile like `make dev`. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Keep the DDL grants strict for a process that migrates, and name only the grants it misses Deferring them while nothing was pending let a DML-only user boot, but the running server's workers set retention TTLs, compact, refresh views and rebuild provider tables on those same grants, so it failed later on every pass instead of once at boot. The check is strict again; only the replica and runner-table checks, which only migrations use, relax. A refusal now names just the grants the user is missing rather than the whole set, so it no longer reads as if SELECT and INSERT were revoked, the warning line keeps each reason's own SQL advice apart, and brackets in a ClickHouse host are accepted only around an IPv6 address. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Check the grants the running workers use, and keep the installer's own version out of Compose The migrate check said the workers' grants were covered, but the set held only the migrations' privileges: a user with exactly those passed the preflight and the doctor, then compaction (OPTIMIZE), the provider rebuild (TRUNCATE) and view retirement (SYSTEM REFRESH VIEW) failed on every pass. They are in the set now; GRANT CURRENT GRANTS ON loom.* covers them on Cloud and on a self-managed server. The installer left its own LOOM_VERSION and an exported COMPOSE_PROJECT_NAME in the environment, where Compose prefers them to .env: a `v`-prefixed version pulled a tag that does not exist, and `latest` started a different image from the one .env pins. Both are unset with the other target settings. oldest_version records what a strict check would refuse instead of check() asking the server twice, and the one-function vector_floor module moves into ch.py, its only caller. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Check the workers' grants for a process that runs the workers, not for one that migrates The workers' OPTIMIZE, TRUNCATE and SYSTEM REFRESH VIEW sat in the migrate set, so a standalone `loom migrate` refused a migration-only user over grants no migration uses, while a server with boot migrations off and its workers on passed the check and failed on every worker pass. They are their own set now, checked whenever the process may run the workers (any LOOM_BACKGROUND_WORKERS but off, not a read replica), and by ch-setup, which prepares for a full server. The narrower SYSTEM REFRESH VIEW replaces the SYSTEM VIEWS group. The replica refusal names the call it could not run, the condition-cache probe tags its query, the deployment docs list the grants each process is checked for, and the CHANGELOG says what an upgrade on an outside ClickHouse needs first. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Check one grant set for every Loom process but a read replica The worker grants followed LOOM_BACKGROUND_WORKERS and the DDL grants followed LOOM_BOOT_MIGRATE, but neither matched what runs: provider rebuilds (CREATE, TRUNCATE, DROP) run in any process that can win the configuration lock, workers off or not, and a workers container with boot migrations off sets retention TTLs with ALTER TABLE, so following the documented grants left retention silently unenforced. Every process but a read replica is now checked for the DDL grants plus OPTIMIZE, TRUNCATE and SYSTEM REFRESH VIEW; LOOM_BOOT_MIGRATE only decides whether it creates the database and reads what the migrations read. The workers flag goes, the preflight's own queries carry a query tag, and the docs and CHANGELOG say which grants every boot needs. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Name the grant levels for the process, and warn rather than refuse without SYSTEM REFRESH VIEW `need="migrate"` had come to mean any Loom server but a read replica, so boot passed need="migrate" with migrates=False; the levels are now server, replica and read, and `migrates` alone decides what only a migrating process does. SYSTEM REFRESH VIEW's one runtime user tolerates a refusal (the scheduled refresh removes the rows), so lacking it is a warning instead of a stop. The installer keeps LOOM_CLICKHOUSE_IMAGE in .env as it does the Loom image, so a later bare `up` does not move the bundled server back to the pinned release over the same data. An OTel exporter that disables itself for want of the ClickStack tables says so at INFO unless the ClickHouse exporter was chosen. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Have ch-setup say when SYSTEM REFRESH VIEW is missing Once the grant became a warning, ch-setup, the installer's only check, stayed silent about it while migrate and the doctor warned, so an install finished without hearing of it. It now prints the grant to run, like an unreadable telemetry table. Test names use the server and replica terms, the exporter's test moves beside the other exporter tests, and the grant's comment and the docs read cleanly. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Say that a ClickHouse image given to the installer stays as a pin The installer keeps LOOM_CLICKHOUSE_IMAGE in .env, so a bare `up` never moves the bundled server off the release it ran, but the docs said only the port and Loom image were kept and that a newer Loom moves ClickHouse. The quickstart, CHANGELOG, environment reference and upgrade guide now say the saved line pins ClickHouse until it is deleted, and that one left exported in the shell is written back. The condition-cache tests move beside the code they test. Co-Authored-By: Claude Opus 5.5 <[email protected]> * List LOOM_CLICKHOUSE_IMAGE among the quickstart's non-setting variables The quickstart now names it as an installer variable, and the docs test counts only settings fields and the listed Compose and installer names. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Tag ch-setup's reader probe, read a quoted .env value, and name the replica retry The reader probe opened its own client without a query tag, so its statements reached query_log unattributed. The installer read COMPOSE_PROFILES with any quotes Compose accepts, so a hand-quoted "bundled" was taken for an outside server and ch-setup ran against a ClickHouse that was never started. A replica that does not answer during a rolling upgrade now says to retry once every replica is up, like every other refusal names its fix. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Tell ch-setup's caller to recreate Loom after a cap change, and round out the CHANGELOG A reader rebuilt for new caps leaves the running server's sessions on the old ones until it is recreated, and its caller-shaped reads fail on the bounds meanwhile; ch-setup now says so where it rebuilds. A read-only `loom migrate --status` no longer warns about telemetry tables it never reads. The installer reads an unquoted .env value without a trailing comment, as Compose does, and prints a stop command with the bundled profile only for a bundled install. The boot reader probe carries a query tag. The CHANGELOG lists the image's `loom migrate` fix and the exporters' quieter self-disable, as one list each. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Print the stop command with the bundled profile again, and the recreate hint only after a caps rebuild Dropping --profile bundled from the stop hint for an outside ClickHouse left a bundled server from before a switch running, and `down` then failed on its network; the profile only adds a stop for that container. The recreate hint came before the rebuild ran, and on rebuilds that changed no caps; it now follows a successful rebuild for a profile mismatch. A reader statement the server rejects for another reason than access is one refusal line, not a traceback. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Refuse a cap the reader profile cannot hold, and let the Loom user see who owns the reader A caller-shaped cap below its floor, or negative, was pinned as a constraint with its maximum under its minimum, so ch-setup reported the reader ready while every caller-shaped read then failed; it is refused with the value to use instead. The admin SQL now also grants SELECT on system.users and the settings-profile tables ch-setup reads to tell who owns a reader of the name, which it otherwise could never do without an admin, and the refusal names those tables. Driver errors reach every refusal as the server's own first line, without the driver's prefix and URL. After the admin path, ch-setup says to recreate Loom if the caps changed; the doctor names a URL given as LOOM_CH_HOST and grades a skipped preflight as a warning. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Drop the grants that only let the Loom user list every account, and restore two lost notes The ownership-table grants never let a user made by the admin SQL do anything: creating or replacing the reader takes global privileges it does not hold, while the grants showed it every account and settings profile on the server. They go, and the refusal says an admin has to run the SQL. The recreate hint after the admin SQL appears only when a reader already existed. The caps' floors live in one place for the profile and the check. Two notes the requirements rewrite dropped come back: how long a run id claim key lives, and what the reader probe reports before migrations have run. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Give the recreate hint on the unknown-owner path only for a reader that exists A Loom user made by the admin SQL cannot see who owns the reader, so a first install took that path and was told to recreate Loom after a cap change that never happened. The hint now needs a reader that logged in. The CHANGELOG says the installer replaces the old top-level config with the bundle's copies, as every rerun did, rather than moving it. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Say the installer recreates Loom itself after a cap rebuild, and log the cache probe's error plainly The rebuild hint told an installer run to recreate Loom, which the installer's own `up` had just done; it now says so, like the admin-SQL path. The condition-cache probe's failure log uses the server's first line instead of the driver's prefix and URL. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Renumber the table settings migration past main's 031 Main took 031 for the run budgets, so the table settings migration becomes 032; it was never applied under 031 outside this branch's test stacks. 031 only alters loom.agent_runs, which 032 already covers. The analyzer's shapes file is regenerated for the merged schema dump, and the CHANGELOG main removed stays removed. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
This started as a fix for
all_minesearch and grew into a fix for how token claims and grants interact, because the two share the same namespace resolver.all_mine search
Three problems:
all_mineonly ever searched the addressed namespace. It now reads the single user's grants.LOOM_MEMORY_SEARCH_FANOUT_MAX_NAMESPACES(default 32) caps it; a scoped token keeps its own order, otherwise public namespaces are dropped first. Whatever was cut is listed in a newnamespaces_skippedfield so an agent can tell "not searched" from "not found".Memory and knowledge search now share one private-first driver (
server/core/vectors/private_first.py). A parkedmemory.searchpage re-checks its namespaces against the caller's current fan-out before serving them.A token's claim no longer outlives the grant
Before this, a token that named a namespace kept reaching it after the subject's grant there was revoked or lowered, until the token expired.
Now, where the token's subject has a grant row on a namespace the token names, the claim is capped at that grant: a revoked or rejected row caps it at nothing, a lowered one at the lower role. If the subject never had a row there (a
loom mint-tokenservice token, for example), the claim stands as minted. That'sauthz.claim_cap.An earlier version of this branch did it differently: every revoke wrote a cutoff that invalidated older tokens. It worked, but every grant writer, every mint and every retry had to keep the cutoffs in step, and each review round found another interleaving. Capping at the live grant has one source of truth and needs nothing written for access to go away, so I replaced it.
The cost is a grant read on the request path, so it's cached (
server/core/grant_cache.py):LOOM_GRANT_CACHE_TTL_SECONDS(10 s). Concurrent misses share one read.released_aliasescolumn (migration 030) that only this read uses.jwt_revocation_max_stale_seconds, then 503. An entry that a write made stale is never served that way.Grant changes don't race each other
grants.create,revoke,approve, andnamespace.join/leave/cancel_requestall read a grant and then write it, and ClickHouse has no row lock, so an approval could overwrite a promotion or a revoke that landed in between. Each now holds a KeeperMap claim on (org, namespace, subject) from the read to the write (server/auth/grant_claims.py, migration 029). A second change waits up to 10 s, then gets a retryable 503GRANT_BUSY. Without a Keeper it falls back to an in-process lock with the same limit, and/v1/healthreportsgrant_changes_not_atomic.Changes that can take admin away (a revoke, a
replace=truelowering, an admin's leave) also hold a per-namespace admins claim and re-count admins under it, so two of them at once can't leave a namespace with no admin. Lowering the last admin withreplace=trueis now refused, the same way revoking them already was. A plain grant or a reader's revoke doesn't take that claim.The OAuth exchange used the same KeeperMap pattern for its own claims; both now share one class,
KeeperClaims.Repository maintainers
Maintainer sync keeps a repository's admins the same across its branches. This tightened it:
granted_atonly has whole seconds and a lowering and a promotion in the same second used to compare equal.OAuth and OIDC
/oauth/tokenruns one exchange per code or refresh token under a KeeperMap claim (migration 028). A concurrent presenter is told to retry, and the credential is only used up once the exchange has decided, so a failure leaves it usable for the retry. Without a Keeper it behaves as before, and health says so.Smaller fixes
namespace.restoreinto an existing namespace needs an admin of it.grants.approverefuses to approve below the current grant.namespace.registerrefuses to change the owner of an account that has a login (an email or an agent's claim code); the login would otherwise sign the new owner in.namespace.joinrequest no longer activates the first, still-pending one.context.fetchandcontext.offloadrefusepage/keys, which onlymemory.search(page=...)should serve.Behaviour changes worth knowing
loom mint-tokenclaim that goes beyond a grant the subject holds there is now capped at that grant.Not in this PR
claim_releasereads a namespace's grants and then tombstones them without holding a claim, so agrants.approveornamespace.jointhat lands in between can survive the release. That's how main works today; closing it needs a namespace-wide claim shared by release, join and approve, which I'd rather do separately.Testing
make format,make lint,make typecheckand the unit suite pass. New unit tests cover the cap, the cache (including cross-process counts and in-flight reads), the grant and admins claims, maintainer sync ordering and fan-out, and the OAuth claims. New integration tests run on a real ClickHouse with Keeper: grant revocation against an auth-on server, both claim tables, spelling ties, and maintainer ordering. The integration suite also passes against a three-process server started the way CI starts it.Please squash-merge; the "Answer review round N" commits are review history.
🤖 Generated with Claude Code