Skip to content

A dispatched hosted workflow measures how many source worker copies one Loom process keeps served - #2196

Open
zlareb1 wants to merge 11 commits into
mainfrom
bench/mcp-source-worker-capacity
Open

zlareb1 wants to merge 11 commits into
mainfrom
bench/mcp-source-worker-capacity

Conversation

@zlareb1

@zlareb1 zlareb1 commented Dec 5, 2026 •

Copy link
Copy Markdown
Member

Related: #2165

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

None: a dispatched qualification workflow only.

Why

The source worker copy path keeps copies served only while each one's access is confirmed within knowledge_source_acl_stale_seconds. A process sends copies and checks one at a time within the mirrored phase, so the number of copies one deployment keeps served has a bound (the boundary page's Capacity paragraph), and nothing measures it yet. This workflow measures it on a free GitHub-hosted runner with owned synthetic upstreams, so the next change can be sized from numbers, not estimates. It measures; it gates nothing.

Scope and risk

  • Workflow: .github/workflows/mcp-source-worker-capacity.yml runs on workflow_dispatch only, on ubuntu-24.04, with a 90-minute limit and the same pinned action shas as ci.yml.

    • It starts ClickHouse and Postgres with dev/ci_start_*.sh, the fixture, and Loom from source with knowledge_source_worker_copies_enabled on. Loom's own sync worker is off, so the driver runs every pass.
    • It uploads the metrics JSON and the server, fixture and ClickHouse logs.
  • Fixture (bench/source_worker_copies_fixture.py), run in the source worker's own environment:

    • prepare writes keys and certificates, the worker config with a resource profile and a mapped-tool profile, the routes file, and one synthetic account per collection and profile.
    • serve runs the bundled worker's read and enrollment services behind an mTLS listener, the two synthetic MCP upstreams over TLS with configurable latency and fault kinds, and a loopback stats endpoint.
    • It assembles the worker's own services with an in-memory credential store and a direct listener, so Vault and the proxy are not measured. A credential-latency input stands in for the store.
  • Driver (bench/source_worker_copies.py):

    • Before setup the driver loads the signing keyring inside its connected command, as an enrolled CLI mint does (kid default when it cannot be read), since it mints the harness's tokens outside the server.
    • Setup goes through the real operations: collection create, grant, worker profiles, approve, enroll, preview and register.
    • Session protection is declared only by the harness's own client, exactly as tests/integration/crawl_native_privacy.py does. No shipped client changes.
    • Faults switch on only after the first pass at whose end every faulted resource holds a stored copy, so the retirement paths are exercised; the document records the pass they switched on after, or that they never did.
    • Each pass runs under knowledge_source_sync_max_pass_seconds, as the supervisor bounds it, and a pass that hits it is recorded as timed out. No pass starts that could end past the step's budget, and setup runs under a 900 s allowance; either stop is recorded in the document's run section.
    • It runs run_sync() a fixed number of times in its own process and times each copy and check by wrapping the turn's exchange. A unit test pins both hooks so a rename fails loudly.
  • Metrics: schema loom.bench.source_worker_copies.v1, per pass and in total:

    • copy and check latency percentiles, and outcome counts;
    • copies confirmed, written and retired;
    • pass-bound marks, sources a pass did not reach, and whether the pass was cut;
    • per-turn seconds;
    • sources served, unserved or never listed, and lapses;
    • Loom-side overloaded and worker-side 429 counts;
    • setup op statuses and latency.

    The driver writes the whole document before setup, after setup and after every pass, so a stopped run keeps what it measured. A turn that raises is recorded as raised:<Type> and counts as reached, so sources_not_reached counts sources whose turn never started: the mirrored phase's time ran out first, another copy held the source's lease (not counted in errors), taking the lease failed (counted there), or the pass timed out; a timed-out pass reads errors 0. A routes file other than the fixture's is a harness error, since every turn would then answer unavailable. It refuses runs whose passes times pass interval exceed 3600 s (the 75-minute step less a setup allowance). The run fails only on harness errors, which are recorded in the document, never on capacity figures.

  • LOOM_KNOWLEDGE_SOURCE_SYNC_INTERVAL_SECONDS is set to 60 although the server's own sync is off: the copy path's lapsing age reads it during every pass, so it shapes how a copy that keeps answering unsupported is retired. The workflow comment and the docs say so.

  • Docs: a "Source worker copy capacity" section in docs/benchmarks/running.md, an entry in bench/README.md, and one linking sentence in the boundary page's Capacity paragraph. No results are claimed.

What this harness could not do without a server change, for a later PR:

  • No operation or status exposes per-request latency, pass-bound marks or listing times, so the driver times the turn in its own process.
  • The bundled worker's entry point hard-codes its paths, credential store and socket, so the fixture assembles its services directly.
  • Worker 429s only appear when live reads compete for the worker's slots. This run sends none, so expect worker 429 counts near zero.

Compatibility, rollout and rollback

  • Wire: none.
  • Operator steps: none. Dispatch with, for example, gh workflow run mcp-source-worker-capacity.yml -f sources=200 -f resources=20. The inputs are listed in the docs section.
  • Rollback: reverting removes the workflow and its files.

Tests

  • tests/unit/test_bench_source_worker_copies.py (42 test functions) covers the metrics schema, percentile math, input parsing and the run-length budget, the fault table, unreached sources counting as a cut pass, a raising turn counting as reached, an unexpected error keeping the finished passes, faults switching on only after every faulted resource is stored, the pass and setup time bounds, a failure after the run keeping its document and never taking an earlier run's, the sync hooks and copy-state keys the driver reads, the step budget matching the workflow's Measure step limit, the keyring loaded before setup (a token minted after it verifies with kid default), the document written after every pass, harness errors recorded in the document, and the hooks the driver wraps, checked by behaviour: the sync runs the wrapped turn, a worker request a turn makes is recorded with its outcome, and a copy the real write stores is one the recorder counts as stored.
  • Through the focused gate, together with test_public_copy.py and test_doc_links.py: 348 passed.
  • ruff format and ruff check on the new Python files, and the prose checker on the new doc section.
  • The fixture's prepare runs in the worker venv, and Loom's load_worker_routes loads its routes file. The upstream app answers each fault kind as expected when driven in-process.
  • The workflow itself has not run yet. It can only be dispatched once it is on the default branch, and the first dispatch is its end-to-end test.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code wrote the workflow, fixture, driver and tests. I set the scope (measure, do not gate; no shipped client declares session protection) and checked the setup path against the operations.

  • 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.
  • No generated file is affected.
  • No migration.
  • No plugin-shipped file changed.
  • No frontend change.
  • Docs under docs/ describe the system as it now is.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers.
  • Commits are signed off.

🤖 Generated with Claude Code


Note

Low Risk
Additive benchmark harness, fixture, docs, and optional workflow_dispatch CI only; no production API, schema, or default runtime behavior changes.

Overview
Adds a manual-only GitHub Actions workflow (mcp-source-worker-capacity.yml) that spins up ClickHouse, Postgres, Loom, a bundled source worker, and synthetic MCP upstreams on one hosted runner to measure how many owner-only source worker copies a single Loom process can keep served.

The new driver bench/source_worker_copies.py provisions sources through real HTTP setup ops, runs sync passes in-process (with the server's background sync off), instruments copy/check latency via hooks on the existing sync worker, switches upstream faults only after stored copies exist, and writes incremental JSON metrics (loom.bench.source_worker_copies.v1); capacity numbers never fail the job. bench/source_worker_copies_fixture.py generates TLS keys/config and runs the worker plus two fault-injectable upstreams in the worker's own venv.

Documentation is extended in bench/README.md, docs/benchmarks/running.md, and a link from the MCP source worker boundary capacity paragraph. tests/unit/test_bench_source_worker_copies.py covers config, metrics schema, pass/setup time budgets, fault timing, and harness error handling.

Reviewed by Cursor Bugbot for commit 3197e0a. Bugbot is set up for automated code reviews on this repo. Configure here.

…ne Loom process keeps served

The MCP source worker copy capacity workflow starts ClickHouse and Postgres, Loom
from the checkout with worker copies on, the bundled worker's read and enrollment
service and two owned synthetic MCP upstreams (resource and mapped tool) with set
latencies and per-resource faults. bench/source_worker_copies.py registers N
snapshot and selected_refresh sources of M resources each through the setup
operations, runs a fixed number of sync passes in its own process, and writes one
JSON file of fixed shape: per-copy and per-check latency, copies confirmed per
pass, listing lapses, pass bound marks and the worker's 429s. Only a harness error
fails the run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
@vercel

vercel Bot commented Dec 5, 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 5, 2026 4:05am UTC
loom-telemetry Ready Ready Preview Dec 5, 2026 4:05am 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.

Stale Bugbot comment from a previous run.

LOOM_KNOWLEDGE_SOURCE_SYNC_ENABLED: "false"
LOOM_KNOWLEDGE_MIRRORED_SOURCES_ENABLED: "true"
LOOM_KNOWLEDGE_SOURCE_WORKER_COPIES_ENABLED: "true"
LOOM_KNOWLEDGE_SOURCE_SYNC_INTERVAL_SECONDS: "60"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pass spacing ignores sync interval

Medium Severity

pass_interval is a workflow input and the driver spaces run_sync() with it, including back-to-back when it is 0. LOOM_KNOWLEDGE_SOURCE_SYNC_INTERVAL_SECONDS stays hardcoded at 60, and the copy turn uses that setting for how soon an unconfirmable copy would lapse before the next pass. A non-default spacing retires or keeps copies on a cadence the harness is not actually running, so served-copy and lapse figures no longer match the pass schedule.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c8562ce. Configure here.

…its document through a stopped run

Every worker source is mirrored, so the pass result never records the mirrored
phase running out of time. The driver now counts the sources with no turn in a
pass (`sources_not_reached`, per pass and in total) and calls a pass cut when one
is left or a turn was cut. It writes the metrics document after every pass by
replacing the file whole, refuses passes times the pass interval beyond the
Measure step's budget less a setup allowance, records an HTTP failure or an
unreadable harness file as a harness error in the document instead of exiting
with a traceback, and reports per-turn time percentiles in place of turn
fields it never emitted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>

@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.

Stale Bugbot comment from a previous run.

Comment thread bench/source_worker_copies.py Resolved
Comment thread bench/source_worker_copies.py Resolved
zlareb1 and others added 2 commits December 5, 2026 02:36
…ts document through any failure

A turn the sync records as failed after it raised is now a recorded turn with the
status raised:<ExceptionName>, so it no longer counts as a source the pass ran
out of time before. Any failure of the run is recorded beside the passes already
finished instead of replacing them, and the document is written before and after
setup too. The running guide says what a pass bound mark means for each bound,
names the raised outcome and the ClickHouse log, wraps at the house width, and
says why the sync interval stays set though the server's sync is off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…tup by the step's time

The fault table now goes on after the first pass at whose end every faulted
resource holds a stored copy, as the turns' copy state shows, so the upstream's
denial retires a copy and an unsupported copy lapses; the document names that
pass or says the faults never went on. Each pass is cancelled at the sync's own
pass bound and recorded as timed out, no pass starts when one more bound would
end past the step, and setup past its allowance stops the run, each recorded in
a new run section with the passes run. A failure after the run returned adds
its error to the last document instead of replacing it. The running guide
describes the per-pass errors, timeouts and fault state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>

@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 2 potential issues.

There are 3 total unresolved issues (including 1 from previous review).

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 d42f250. Configure here.

start_at = max(time.monotonic(), origin + index * config.pass_interval)
if start_at + loop.max_pass_seconds > loop.deadline:
state.stopped = "step_time"
return

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pass budget overlaps the end margin

Medium Severity

PASS_BUDGET_SECONDS still accepts passes * pass_interval up to 3600s after a 15-minute setup, but the new deadline is only 74 minutes from process start. Once setup uses that allowance, later passes are skipped with step_time because each start also has to fit a full max_pass_seconds, even when the passes themselves are short.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d42f250. Configure here.

Comment thread bench/source_worker_copies.py Resolved
zlareb1 and others added 7 commits December 5, 2026 03:04
…out inside setup from the allowance

The run writes its final snapshot before the connection closes, and main
replaces any earlier document at --out before connecting, so a failure after
the run keeps this run's state and never an earlier run's. A timeout raised
inside setup is recorded as itself, not as the setup allowance running out.
The totals add errors, written and retired; the running guide lists what each
pass carries and what the totals and run sections sum, and the fixture says
when the driver writes its fault table. A unit test pins the copy-state key
and the stored-copy digest the fault switch reads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
Without the fixture's routes every turn answers unavailable, which read as a
figure from a run that measured nothing; it is now a harness error. The docs say
a source not reached may also be one whose lease could not be taken, and a type
check reads through one small helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
A source another copy held the lease of is not counted in errors, one whose lease
failed is, and a timed-out pass reads errors 0 with the sources after its
cancelled turn not reached; the docs and the driver's docstrings now say so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…rkflow

The collection loop and the source loop each minted the same writer token; one
mapping now serves both. The pass_cut docstring names every cause of a source
not reached, and a test holds the driver's step budget to the workflow's Measure
step limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…okens

Outside the server nothing loaded the keyring, so the first token mint would have
failed and the run measured nothing. The connected command now loads it, signing
as kid default when it cannot be read, and a test checks the order. The step
budget test reads the Measure step's own limit from the workflow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…aviour, not source text

The keyring test starts from an unloaded keyring, shows a setup token cannot be
minted then, and mints one through `_connected` with an unreadable keyring
that verifies under kid `default`. The seam tests run the sync's own turn
lookup against a replaced turn, and carry a copy `_write` stores through
`_keep` into the stored digests `timed_turn` reads, in place of searching the
source for those lines. The running guide says `confirmed` counts answers with
content or a confirmed check whether or not the copy was then written.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…defines each copy count once

A test installs the recorder over a turn whose worker request times out and
checks the request is recorded as a copy with outcome timeout. The run_sync
parameter check goes, since the driver calls it with no arguments. The running
guide defines `written` once and `confirmed` beside it, and names the test file
without listing its cases; the test module's docstring says what it covers.
bench/README.md keeps an inline code span on one line so Prettier leaves it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>

This branch has not been deployed

No deployments
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