Skip to content

skill.usage reports which revisions of a namespace's skills were fetched and which skills are stale - #2368

Merged
zlareb1 merged 5 commits into
mainfrom
feat/skill-usage
Dec 6, 2026
Merged

zlareb1 merged 5 commits into
mainfrom
feat/skill-usage

Conversation

@zlareb1

@zlareb1 zlareb1 commented Dec 6, 2026 •

Copy link
Copy Markdown
Member

Part of: #1143
Related: #1769

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

skill.usage reports which revisions of a namespace's skills were fetched from the server and which skills are stale, with every count given as a lower bound and a statement of what Loom cannot see. loom skill usage <namespace> prints the report, and a skill's page shows it on a Fetches tab.

Why

A team that publishes skills could not tell whether any session asked for one, or for which revision. Loom holds one record of that: the request ledger's row of each answered skill.get, with the content hash the read answered. This change reads it and reports it.

The report says "fetched" and nothing more, because that is all the ledger proves. A listing line shown to a session is not recorded, a copy pulled to a folder is read without a request, and no row says what a session did with the text. So every count is a lower bound, and the sentences that say what the numbers mean are built in one place on the server. The command and the dashboard print them.

Criteria of the linked issue that are met with this change:

  • Skills are versioned, and a revision is published only after an independent review.
  • A reader retrieves the published revision, or a revision by its number.
  • A session is told which skills exist.
  • A skill is pulled to a folder with a lock file.
  • A fetch answers one revision and one hash while a publish runs.
  • A served fetch writes a receipt that names its revision.
  • Usage is reported, as a lower bound (this change).

Criteria that stay open: a fork of a skill with its lineage, the evidence a draft was built from, and a draft written by the curator.

Design calls made here:

  • The stale codes are a closed set of two documented strings, draft_waiting and unknown_operation. Each is proven by rows the skill holds. A skill that was not fetched has no code, since a pulled copy is read without a fetch.
  • A publish row keeps its time in whole seconds, so a fetch counts from the second after it. A writer's read of the draft in that second is not counted, which keeps every count a lower bound.
  • The ledger read is one statement with a limit. It returns the most recent 10,000 groups, and the report's statement says when the read stopped there. A skill with no fetch among those groups is then said to have none among the rows read and that an older fetch may exist; it is not said to have none in the window. A skill that never published keeps the plain sentence, because the read asked for no hash of it.
  • A request that named no session, or sent a blank session_id, counts its principal only, so sessions is a lower bound as every other count is.
  • A ledger read that fails fails the op. A skill is never answered as not fetched because the ledger could not be read.
  • The Skills list reads the labels of the header namespace's skills in one request, only while it shows a skill of that namespace, and asks a one-day window because a row shows the codes and no count.
  • The dashboard keeps a short label for each stale code and shows the server's own sentence as its meaning. tests/unit/test_skill_usage.py fails when the two differ.

Scope and risk

  • Touches the identity plane (one handler, one domain module, one store module with the ledger statement, one read added to the skills store), the loom skill command, the Skills page and the skills docs.
  • Leaves alone the ledger's write path, read receipts, and what skill.list and skill.get answer. skill.list now calls the one rule of who lists which skill through listed_row, which the report shares. skill.list and skill.get read the caller's roles through reach, which the report shares too: one gate answers the reader, writer and by_subject admin checks of a request.
  • Stored data: none. The op reads loom.skills, the request ledger and the namespace's registry row, and writes nothing.
  • Tenant isolation: the op needs viewer on the namespace it names. A caller is reported the skills skill.list lists to it, so a reader below writer sees served skills only and no draft_waiting. The hashes of a skill the caller is not reported are not parameters of the ledger statement. A name the caller cannot list answers no skill, as a name that does not exist does. by_subject names principals, needs admin, and is refused with 403 to anyone else. tests/integration/test_cross_principal_leakage.py holds the case.
  • Cost: the ledger statement reads the namespace's ledger rows of the window by the key prefix (org, namespace), over at most 90 days and never more than the namespace keeps. The measurement is under Tests.
  • Concurrency: none, the op is a read. The acts are read with sequential consistency, so a reader is not reported a skill that an archive on another replica stopped.

Compatibility, rollout and rollback

  • Wire: one op added, skill.usage (experimental, viewer, a read, idempotent, not audited, not in the MCP tool listing and reachable through loom_op).
    • Input: org, namespace, name (default empty: every skill the caller can list), days (1 to 90, default 30), by_subject (default false, needs admin).
    • Output: window_days, statement, skills. Each skill: namespace, name, published_revision, published_at, fetches (revision, content_sha256, sessions, subjects, last_at, inspector_fetches), stale, statement, subjects (subject, revision, transport, consumer, first_at, last_at).
    • No field is changed or removed and no default changes.
    • Command added: loom skill usage <namespace>[/<name>] [--days N] [--by-subject] [--json].
    • The five generated SDKs carry the op. After regenerating, the registry holds 427 operations (313 experimental, 114 stable). No error code is added: docs/reference/errors.md and the SDK error tables are unchanged.
    • OP_BUDGETS_P99_MS gains skill.usage at 1000 ms.
  • Operator steps: none.
  • Rollback: reverting leaves no row, table or migration behind. A replica one release behind answers 404 for the op. The command then exits 2 and says the server does not serve it, and the dashboard shows no stale label and one line on the Fetches tab.

Tests

Unit, run locally:

  • pytest tests/unit/test_skill_usage.py: 13 passed. One of them runs the ledger statement on clickhouse local against the ledger's table definitions. It ran with the clickhouse binary of a private container, and skips where the binary is absent.
  • pytest tests/unit/test_sdk_skill_usage_command.py: 5 passed.
  • The skill unit tests that share the in-memory store, and tests/analyzer: 284 passed, 5 skipped. python -m tests.analyzer.corpus --check on a migrated private ClickHouse: 2,523 shapes checked, 0 rejected.
  • The unit tests that walk the operation registry, the generated-file checks, the docs and public-copy scans and the snapshots, after merging main: 1,119 passed, 2 skipped.
  • After the review fixes: the two files above with thirteen other skill test files that import the changed modules, 186 passed. The package-contract, transport-contract, tunable-constant, store-name, degraded-answer, public-copy, doc-link and agent-instruction scans with tests/analyzer: 625 passed, 2 skipped.

Integration, against a server started from source on a private ClickHouse:

  • pytest tests/integration/test_skill_independent_review.py: 5 passed. The new case counts a fetch once the ledger holds it, shows a look apart, prints the server's sentences through loom skill usage, and refuses by_subject below admin.
  • pytest tests/integration/test_cross_principal_leakage.py with sign-in required, as CI's isolation step runs it: 51 passed, 17 skipped. With sign-in off: the same result in a serial run.
  • After the review fixes, the usage case of each of the two files, with sign-in off: 2 passed. The first refuses by_subject to a reader and a writer and answers it to an administrator through the shared gate.
  • loom skill usage run by hand with an empty HOME, the server and the token given by environment: it printed the report, exited 1 with the refusal for a reader's --by-subject, printed who fetched for an administrator, and wrote nothing under HOME.

Dashboard:

  • npx vitest run src/views/skills src/views/Skills.test.tsx src/callBudget.test.tsx src/lib --maxWorkers=2: 82 files, 984 tests passed. FetchesTab.test.tsx holds "says fetched, never installed" and "shows who fetched only to an administrator".
  • npm --prefix frontend run build and node scripts/bundle_budget.mjs: the index chunk is within its budget. The Fetches tab is its own chunk, loaded when the tab is opened: 4.40 kB (1.84 kB gzip).
  • The browser suite could not start on this machine (the headless browser lacks a system library), so e2e/route-budget.spec.ts and e2e/skills.spec.ts run in CI only. Two tab lists in e2e/skills.spec.ts now name the Fetches tab. With the default fixtures the Skills route makes no new request, because its list holds built-in skills only.

Checks: make lint, make typecheck, ruff format --check ., the Biome format check and the Prettier check on docs/ pass. make format-check itself needs shfmt, which this machine lacks; no shell or TOML file changed. The Go and Rust SDKs were generated with gofmt from the golang:1.27.4 image and rustfmt from the rust:1.85.1-slim image, and every generator's --check passes. sdk/rust/src/wire_models.rs is 2,404,271 bytes. After the review fixes, make typecheck, ruff check and ruff format --check on the changed files and the Prettier check on the two edited docs pages pass. The fixes change no wire field, and every generator reports no change for them. main was merged again after the fixes: the operations index and the command help snapshot conflicted and were regenerated from the merged tree, every other generator (Go and Rust with the same gofmt and rustfmt images) reports no change, and pytest tests/unit/test_docs_reference.py tests/unit/test_cli_surface_snapshot.py gives 17 passed.

Measurement of the ledger statement, on a local ClickHouse and not a production figure. One namespace holds 3,000,000 ledger rows spread over 30 days: 150,000 of them answered skill.get calls over 40 hashes, 5,000 sessions and 300 principals. Twenty hashes are passed as published. From system.query_log, five runs each:

Window read_rows read_bytes query_duration_ms Groups answered
30 days 3,000,000 44,200,741 87 to 125 10,001 (cut)
1 day 866,107 13,810,966 58 to 67 4,275

To reproduce, insert the rows, run FETCHES from server/identity/store/skill_fetches.py with a log_comment, and read the log:

INSERT INTO loom.agent_events
    (ts, org, namespace, agent, user_id, session_id, operation, request_id, latency_ms,
     success, kind, args, consumer, subject, transport)
SELECT
    now64(3) - toIntervalSecond(number % 2592000),
    'bench', 'usage-busy', concat('agent-', toString(number % 50)), '-',
    concat('s-', toString(cityHash64(number) % 5000)),
    if(number % 20 = 0, 'skill.get', arrayElement(['memory.search', 'memory.set', 'context.pack', 'memory.get'], 1 + number % 4)),
    toString(generateUUIDv4()), toUInt32(number % 300), number % 97 != 0, 'request',
    if(number % 20 = 0,
       map('out_content_sha256', lower(hex(SHA256(toString(intDiv(number, 20) % 40))))),
       map('query', 'how do we deploy')),
    arrayElement(['user', 'user', 'user', 'loom-ui', 'loom-cli-inspect'], 1 + cityHash64(number, 1) % 5),
    concat('sa:bot-', toString(cityHash64(number, 2) % 300)),
    if(number % 3 = 0, 'http', 'mcp')
FROM numbers(3000000);

SYSTEM FLUSH LOGS;
SELECT max(read_rows), max(read_bytes), min(query_duration_ms), max(query_duration_ms)
FROM system.query_log
WHERE type = 'QueryFinish' AND log_comment = '<the comment the runs carried>';

The parameters of the runs: org = 'bench', ns = 'usage-busy', since 30 days or 1 day back, hashes the SHA-256 of '0' to '19' in hex, published ten days back for each, limit = 10001.

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. I ran the tests and checks listed above, read the whole diff, and ran the command and both integration files against a server started from this branch.

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

Checklist

  • Local format, lint, type checks and focused tests pass. The full make test-unit and applicable integration results are reported by CI; a full local run is not required before pushing.
  • Generated files are regenerated in this PR, not by hand: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump), the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py) and the standalone skill bundles (python3 scripts/codegen/standalone_skills.py).
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed.
  • 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; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.
  • I signed the Contributor License Agreement (CLA) if CLA assistant requested a signature.

🤖 Generated with Claude Code

zlareb1 and others added 2 commits December 6, 2026 07:57
`skill.usage` is a new experimental read that needs viewer on the namespace it
names. It folds the acts of the namespace's skills and one grouped statement over
the request ledger's answered `skill.get` rows. For each skill the caller can list
it answers the published revision, one entry for each fetched revision (sessions,
principals, the last fetch, and the looks of the dashboard, the assistant and a
command that shows a skill), the stale codes `draft_waiting` and
`unknown_operation`, and a statement in words. Every count is a lower bound, and
the report's statement says what the ledger cannot show. `by_subject` names who
fetched each revision and needs admin on the namespace.

`loom skill usage <namespace>[/<name>]` prints the report. A skill's page gains a
Fetches tab, and the Skills list and a skill's page label a stale skill. The five
generated SDKs carry the op.

Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Both sides add operations, so four generated files conflicted: the operations
index, the status page and the Ruby and TypeScript SDK bindings. Each was
regenerated from the merged registry, not merged by hand.

Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@vercel

vercel Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
loom-docs Ready Ready Preview Dec 6, 2026 9:49am UTC
loom-telemetry Ready Ready Preview Dec 6, 2026 9:49am UTC

Request Review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit caada5e. Configure here.

),
skills=[
_usage(input, name, *reported[name], groups, writer=writer, window=window, now=now)
for name in sorted(reported)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shared hashes inflate fetch counts

Medium Severity

Fetches are tied to skills only by content hash. since |= hash_times(...) keeps one publish time per hash, from whichever skill is folded last, and counts then assigns those same groups to every skill that published the hash. A skill can include fetches from before it was published, so a count is no longer only a lower bound.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit caada5e. Configure here.

zlareb1 and others added 3 commits December 6, 2026 09:15
A skill with no fetch among the groups of a cut ledger read is said to have
none among the rows read, and that an older fetch in the window may exist.
The read keeps the 10,000 most recent groups, so a skill whose groups are all
older got the sentence of a skill that was not fetched. A skill that never
published keeps that sentence: the read asked for no hash of it.

- A fetch whose request sent a blank `session_id` counts its principal only,
  as one that named no session does. The ledger stores a blank id as the
  empty string, which counted as one session.
- The report reads the registry once, over the operation names of every
  served revision. It built the registry's facts once for each skill.
- `skills.reach` is public and answers the `by_subject` admin check from the
  gate that answers the reader and writer checks. The report built a second
  gate through a copy of the helper.
- `loom skill usage --by-subject` prints `no sign-in` for a read with no
  subject, the dashboard's words.
- The ledger statement's test holds the guard against a read with no hash.
  The assertion ran the in-memory ledger, so removing the guard failed no
  test.
- `DAYS_MAX` had no caller and is removed. The comment on the masked ledger
  rows names the mark that masks a row, and the architecture page says which
  stale code depends on the answering build.

Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Both sides change the operation registry and the command tree, so two
generated files conflicted: the operations index and the command help
snapshot. Each was regenerated from the merged tree, not merged by hand.
Every other generator reports no change on the merged tree.

Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ched

In a report whose ledger read was cut, `skill.usage` says "no fetch is among
the rows read" only for a skill with a revision that is or was published. A
skill with no such revision, as one that never published, is answered as not
fetched in the window: the read looked for no fetch of it, so the cut hides
none.

The features page, the architecture page and the comment on the `statement`
field of a skill's usage stated the cut sentence for every skill with no
fetch. Each now names the condition. No behaviour and no wire field changes.

Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@cla-assistant

cla-assistant Bot commented Dec 6, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@zlareb1
zlareb1 merged commit ff9e202 into main Dec 6, 2026
93 of 97 checks passed
@zlareb1
zlareb1 deleted the feat/skill-usage branch December 6, 2026 10:20
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