Skip to content

namespace.tune drafts changes to the settings that create a namespace's memories - #188

Merged
zlareb1 merged 1 commit into
mainfrom
feat/i160-tune
Nov 3, 2026
Merged

zlareb1 merged 1 commit into
mainfrom
feat/i160-tune

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Related: #160

Changelog category (leave one):

  • New Feature

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):

namespace.tune (viewer, read-only) drafts changes to the settings that create a namespace's memories: extraction rules for the writer-side shapes namespace.audit found, categories for much-used tags, and a guide naming the key layout. Each draft names its real target, current and proposed value, the rows that support it and the rows it must keep working for, the agents it affects, that it changes future writes only, and the ordinary write (with its guard) that would apply it; nothing is applied and no model is called.

Why

Issue 160's Tune stage drafts category, extraction-instruction and setting changes from the evidence, read-only, for a person to approve. The pieces exist — the audit's findings, the taxonomy, categories, guide and the operator extraction policy — but nothing turns them into a proposal that says which setting it would change, from what to what, on what evidence, for whom, and with which write. A reviewer had to assemble that by hand, and an agent asked to "tune the namespace" had no read-only way to show a change before making it.

What changes

  • server/identity/api/models_namespace_tune.py, ops_namespace.py: namespace.tune, viewer, idempotent, not audited (so read_only). Inputs: window_seconds (the audit's ledger window), sample_limit (supporting rows cited per proposal, default 5), min_rows (the rows a tag or key prefix needs to be drafted, default 5), max_category_proposals (default 5).
  • server/identity/app/namespace_tune.py builds every draft from fixed rules, each section guarded (a failure lands in skipped and drafts nothing):
    • Extraction rules. One rule per audit finding that fired at warning or critical (double_encoded_values, json_prefix_excerpts, oversized_values, episodic_blobs, coordination_as_memory, hand_rolled_index_rows), drafted only when memory.set_from_messages' extraction writes into the namespace (rows whose source trace starts pipeline:set_from_messages, read across every live row) and at least one of the finding's cited rows carries that trace. A finding none of whose cited rows extraction wrote drafts nothing and is listed in skipped (extraction: no cited row of <code> was written by extraction), as does a namespace extraction writes nothing into (extraction: memory.set_from_messages writes no row here …), so the absence is not read as clean; a finding the audit cited no live row of (its evidence read failed, or the rows went away before it) is judged on nothing, drafts nothing and is listed in skipped on its own (extraction: the audit cited no live row of <code>); a failed read of either drafts nothing and is skipped. A row two checks flag is cited once. Per-request instructions reach nothing else (a conversation: or learning: trace, or a hand-written memory.set, never passes through it). The affected agents are the agents whose rows extraction wrote; the cited rows are the finding's evidence rows extraction wrote; the flagged counts, stated as counts over every writer, cover all writers. There is no rule for hash_keys: extracted keys are sanitized to [a-z0-9_], so a key's layout is the writer's. The target is always extraction_instructions.request, the instructions a memory.set_from_messages request sends (no user, agent or session setting stores them); apply.args is the part to merge into each request (args_complete: false). They are never drafted as the operator extraction policy: a policy in force overrides every other instruction and turns off extraction's recovery passes (preferences, costs, ages, corrections), so a style rule there would cost facts the namespace keeps today, and the draft's limits says so. For an org admin, tune reads the policy in force (the org's, then the namespace's, from the process's polled copy that extractions run under) and drops a rule whose exact text (case included) it contains; an unreadable grant is reported in skipped, not as a non-admin. That read goes through one helper, extraction_policy.for_caller, which memory.inspect now uses too. counter_count is a lower bound: the smallest population those checks read, less every row they flagged (None when the audit could not read any of those populations).
    • Categories. A tag on at least min_rows live rows with no category of its name drafts namespace.register_category; the counter count is the tagged rows already filed under another category, and the draft says registering files no row (memory.assign_category is a separate action).
    • A category draft names every other spelling of its tag (read with no row filter, each checked as a plain name) and that extraction tags new rows with the category's exact name. The extraction prompt offers the first OFFERED_CATEGORIES (32) categories by name; when the namespace has that many, the draft says whether the new one would be offered and which registered name it would push out (quoted only when it is a plain name, else named by its position, since category names are stored unchecked), or that it would not be offered (registered names counted exactly, so two that differ only in case are two). That number is now one named constant in server/memory/app/pipeline.py, bound into its statement, which tune reads.
    • Guide. A personal collection (col-me-…) has no guide, so none is drafted there. A draft that would push the guide past the 32,000 characters namespace.guide_set takes is not made, and skipped says why. With no guide, a guide listing the key prefixes (of keys that have a path) and tags on at least min_rows rows; with one, the prefixes it does not name as a path of their own (billing/, not inside subbilling/) appended. Applied with namespace.guide_set and expected_revision set to the current revision, so a guide written since refuses the write.
    • A tag or key prefix is drafted only when it matches a plain-name pattern ([A-Za-z0-9][A-Za-z0-9_.-]{0,63}), so text stored in rows or the guide cannot choose a target, an op or an argument; the unit tests feed it tags, prefixes and a guide that read as instructions. A <prefix>: tag (source: on every plugin capture, speaker:, agent:) says where a row came from, not what it is about, so it drafts no category and no guide line. A drafted guide lists tags on at least min_rows rows.
    • A check the audit could not run is listed in skipped as audit.<check>, so a missing draft is not read as nothing to draft. affected_agents lists at most 20 writers, with affected_agents_total.
    • Every cited row comes from the reports' citation read (finding_evidence.revisions_for, by whole identity): memory_id, version and the content_sha256 memory.get serves.
  • server/identity/store/namespace_tune.py: the writing agents (with their total) and the agents extraction writes for (with their total rows), the plain tags and the key prefixes (each only plain-named ones on at least min_rows rows, filtered in SQL before a limit of 500, so a plain tag or prefix is found however many others rank above it), every spelling of a drafted tag, which cited rows extraction wrote, the rows with a tag and how many of those another category holds. Each filters on (org, namespace), takes the request's read scope, binds its values, and reads no value.
  • server/identity/app/namespace_audit.py: namespace.tune and memory.inspect join the report ops whose own ledger rows do not close a telemetry gap. Tune runs the audit inside it, and an inspection is a read about the namespace, so a call of either from an SDK or the CLI would otherwise make a namespace whose writes left no ledger rows read as recorded, and the ledger checks report clean. telemetry_unavailable goes to rule_version 2.
  • namespace.tune joins the assistant MCP toolset with a description that says to show a proposal, never apply it; OP_BUDGETS_P99_MS gives it 5,000 ms. It is not a scoped op, so a token narrowed below the namespace is refused.
  • docs/features/namespaces-and-sharing.md: a row in the operations table and a section on what a proposal holds. SDKs, the operations reference and the SDK surface snapshot regenerated; the analyzer corpus gains the store's shapes.

Scope and risk

  • Measured locally (system.query_log, 200,000 live rows in one namespace across 20 agents, 30 key prefixes and 50 tags, a third of them written by extraction, default inputs so five category drafts): one call runs about 47 statements, most of them the audit it reads, reading about 2.7M rows and 154 MiB in all, 44 MiB peak, 1.1–1.2 s wall time warm (2.3 s on the first, cold call).
  • Read-only: no memory row, setting or category changed; the integration test compares the memory and category row counts before and after and finds no guide. It records no exposure-ledger row: like namespace.audit's samples, it cites at most sample_limit rows per proposal by key and identifiers, never a value or an excerpt.
  • Out of scope: drafting from one selected user, agent or session (tune reads the whole namespace; memory.inspect shows one subject's rows); cost, latency and validation results for a proposal; Apply (the issue's approval contract); a model-run preview of extraction outputs over a sample, so no before/after examples (with no model call, model_used is always false); and cited counterexample rows: a draft gives the rows it must keep working for as a count (counter_count, None when it could not be read or for a guide), since no store read can pick rows a check did not flag without repeating the check.

Compatibility, rollout and rollback

  • Wire: one op added (namespace.tune, maturity experimental); telemetry_unavailable goes to rule_version 2 (two more report ops left out of its gap check). Nothing removed.
  • A replica one release older answers UNKNOWN_OP, and its assistant listing does not carry the op.
  • Operator steps: none.
  • Rollback: revert; nothing is stored.

Tests

  • Unit (tests/unit/test_namespace_tune.py), the collaborators faked but for one case that runs the store's plain-name and row-count filter on clickhouse-local (skipped without the binary): a stored billing\n, source:x or a; b tag or key prefix, or one on too few rows, never leaves the read. With the collaborators faked: the op is a viewer read_only op; a writer and an org admin both get per-request instructions, never the operator policy, and the draft says why; only a fired finding with a cited row extraction wrote drafts a rule, citing only those rows (once each), a finding without one is named in skipped, a failed cited read drafts nothing, and a hash_keys finding drafts none; a clickhouse-local case shows only pipeline:set_from_messages traces count, not conversation: or learning:; and a rule the policy in force holds is not drafted again; supporting rows and counts, args_complete: false and the agent total; two findings share one draft with a true lower bound and one cited row each, and an unread population gives no bound; a rule the policy holds drops out of the evidence too; source: and speaker: tags draft nothing; a check the audit skipped is reported as audit.<check>; a plain much-used tag drafts a category, a registered one (any case) does not, and two tags that differ only in case draft one whose limits name the other spelling, however few rows carry it; a draft in a namespace with 32 categories says whether it would be offered and which name it would push out, a registered name that reads as an instruction is never quoted, and a draft that would not be offered never claims it would be; no guide drafts one at revision 0, a guide drafts only the prefixes it leaves out (a longer name ending in a prefix does not name it) and nothing when it names them all; tags, prefixes and a guide that read as instructions never change a target, an op or an argument; a failed section is skipped and an unread count is left out of the text, not stated as 0; a guide the addition would push past its limit is not drafted; an unreadable grant withholds the policy and says so. tests/unit/test_extraction_policy_for_caller.py covers the shared helper's four outcomes.
  • Unit (tests/unit/test_namespace_audit.py): a namespace.tune and a memory.inspect ledger row leave a telemetry gap open; the rule-version pin moves to 2.
  • Integration (tests/integration/test_namespace_tune.py, private ClickHouse and server with auth on, the drafts read with a viewer token): a namespace of hand-written double-encoded billing rows drafts no extraction rule while extraction writes nothing there, and none after one memory.set_from_messages call either, with skipped naming the finding none of whose cited rows extraction wrote; a billing category of 10 rows and a guide at revision 0; a cited row's memory_id, version and content_sha256 equal memory.get's; nothing is written; a token pinned with read_scope: own_user and a token for another namespace are refused with 403. The cross-principal walk lists the op among its core surfaces and passes, as does the assistant toolset suite; the audit-summary, findings-contract and labeled-cases suites pass on an auth-off server.
  • Analyzer corpus (tests/analyzer): a namespace_tune case drives every store read under the whole namespace and a narrowed scope; the analyzer passes its shapes against a migrated ClickHouse.
  • make format-check lint typecheck, the unit tests above and the generator checks.

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. Checked each statement against the tables it reads and the drafts against a live server.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed.
  • Generated files are regenerated in this PR, not by hand.
  • A new migration is additive and numbered after the latest on main; no merged migration is edited. (No migration.)
  • A behaviour change to any file a plugin ships bumps both plugin manifests' version, and no other open PR uses that version. (No plugin change.)
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed. (No frontend change.)
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers.
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

…'s memories

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit 7e89f14 into main Nov 3, 2026
21 of 22 checks passed
@zlareb1
zlareb1 deleted the feat/i160-tune branch November 3, 2026 14:49
@pufit pufit mentioned this pull request Nov 4, 2026
9 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant