Skip to content

A bug report's pointers carry what a whole run of a slow test file costs in the repository - #2140

Merged
zlareb1 merged 30 commits into
mainfrom
feat/test-cost-note
Dec 5, 2026
Merged

zlareb1 merged 30 commits into
mainfrom
feat/test-cost-note

Conversation

@zlareb1

@zlareb1 zlareb1 commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

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

In a repository where an earlier Claude Code session ran a whole pytest file that took a minute or more, a prompt that reads as a bug report carries one more line under its code pointers: what a whole run of that file costs, what a run filtered with -k costs, and to check a change with -k selections. The Claude Code and Codex plugins are 1.2.186 and the line needs the memory plane and the test report; namespace.audit leaves reads of that row's key out of its exact-key counts and the mentor out of an agent's exact-key reads, which needs the next server release: an older server counts one read a session and checkout in both.

Why

In a long bug-fix session most of the wall time can be test runs, and most of that one kind of run: the whole of a data-driven test module with thousands of cases. It takes longer than the default timeout of a shell call, so it goes to the background and the session waits for it. A -k selection of the cases the change affects answers in seconds. The session picks the whole-file run because nothing tells it what that run costs in this repository.

The plugin already has the number. The test report has pytest write a result file for the session (--junitxml through PYTEST_ADDOPTS), and the first testsuite of that file holds tests= and time=. The digest reads the file for failures and drops the time, nothing keeps it, and the file is removed when the session ends.

This change keeps it and says it where the session reads its first instructions for the task:

  1. Note. After a shell command that holds one pytest run naming one test file, with nothing before the run but cd, export, source and . and nothing after it but what reads its output, hooks/loom-test-report.mjs reads the case count and the seconds from the head of the result file (also for a file over the digest's 2 MB bound) and keeps them in the session's private state, by the file: the costliest whole run of two cases or more in which no case failed, and the case count and seconds of its last 15 runs filtered with -k. A run that skipped more than a tenth of its cases is not kept. The state holds eight files: the one with the costliest whole run, which is what the session's end stores, and the seven others run last. fileRun in lib/test-gate.mjs classifies the command with the rules the test gate already has (PYTEST, PARTIAL, CD, onlyRuns) and one for what may stand before the run (onlySetsUp). The note is made where the session's end may store it: with the memory plane on and session memory not switched off.
  2. Print. hooks/loom-prompt-pack.mjs reads the repository's row by its key with one memory.get, sent beside a bug report's search, and appends one line under the pointer block and the test line:
Test cost in this repository (measured in earlier sessions): a whole run of tests/test_big.py collects about 8000 cases and takes about 140 s, longer than the default 120 s timeout of a shell call. A run filtered with -k takes about 2 s. Check a change with -k selections of the cases it affects.

The clause about the timeout is printed for a run over 120 s, and the middle sentence where a filtered run was measured. A row whose whole run is under 60 s, or whose file the checkout does not hold, prints nothing.

  1. Store. At the session's end hooks/loom-session-memory.mjs hands one memory.set to the flusher, in the hand-off that carries the session's turns and alone where the turns are not sent, where the session ends in the checkout of the row a prompt read last (a miss included) and the session's runs say something the row does not. The key is repo:<id>/test-cost/pytest, one row a repository in the session's namespace. The value is one sentence: In the repository tagged repo:<id>, a whole run of <path> collects about <N> cases and takes about <S> s; a run of it filtered with -k takes about <s> s.

Design points that the code decided:

  • A report belongs to a command only on evidence. pytest writes the result file when its run ends. So the report counts for a command only when the command's visible output shows pytest's last line with the cases, the failures and the seconds the report holds (the seconds within a second, or a twentieth of them, compared as the summary and the file write them) and the report's first case is in the file the command names. The last line is read whatever it counts: a run that selected nothing ends with 8000 deselected in 1.20s or no tests ran in 0.01s, and has ended. It is read without its colours: a pytest told to colour its output (--color=yes in addopts, PY_COLORS=1) writes an escape sequence before each count, and fileRun removes those from the output before it reads the last line and the line above it. A run the option did not reach (one in the sandbox, one that sets its own PYTEST_ADDOPTS) writes no report, and the earlier report read after it does not hold the cases, the failures and the seconds of its summary. The seconds alone do not tell two short runs apart: without the counts, the report an unread -k run left (12 cases, 1.4 s) would be counted for a whole run that wrote none and stopped at an error in half a second, and the session's end would lower the row to it. Nor does the report count for a run that anything follows in its command but tail, head, grep and echo, a redirect of the run to a file aside (the gate's onlyRuns). A runner started after the run (pytest <file> -q && make test, ; tox, a script) writes the session's result file and prints the last line, so the two agree, and where that report's first case is in the named file the wrapper's cases and seconds would be stored as the file's whole run. The same holds for a command before the run where the run then does not start: in make test || pytest <file> a suite that passes skips the named run, and in make test; python3.9 -m pytest <file> an interpreter with no pytest prints no last line, so the suite's report and last line are read. A wrapper is not known by its name (./scripts/check.sh), so the run counts only where nothing stands before it in the command but cd, export, source and ., with no backquote (onlySetsUp). The cases of the last line are every outcome it counts but the deselected ones, which is what the file counts in tests, with one exception: a case whose teardown raised an error after the case passed or failed is counted twice on the line and once in the file, and such a run is not counted.
  • A run that outlives its shell call is the slow whole run this change is about. It writes the file after that call's hook ran. A run whose output shows no summary is kept as the session's pending run, with the time its command returned. A report read later, with another command or by the launcher at SessionEnd before it removes the file, is the pending run's when its first case is in the pending run's file and the run that wrote it began by that time. pytest began it at the time the file was written less the seconds of its testsuite: the moment the suite's timestamp names, with no time zone to read. A run that a later command started began after the pending run's command returned, whatever launched it (time pytest, bash -c, a script no hook is run for), so its report counts for no run and the pending run stays. No reading of the later command is needed, and none is done. The rule has one counterexample: a run of the same file that something else started while the pending run was in its call, such as a script in the background, began before that time too, and its report is taken for the pending run's when a command that is not that run reads it. A run with no summary in sight that ended in its call is not kept: the report read with its command is of its file and no pending run's, so the run wrote it in its call and the command cut the summary (| head -30, | grep FAILED). That report is counted for no run. A run that is kept takes the place of a pending run of another file, whose report names another file and is then no run's. A run that lost its place, replaced or dropped, may still write its report, so the session's state keeps the time by which it had begun: the time the replaced run's command returned, or the later run's where both are dropped. A report of a run that began by then counts for no later pending run. Without that time the late report of a -k run that was dropped would be stored as the whole run of the file's next pending run. The cost: a run the session puts in the background at once returns before pytest began and is not counted; a run of the other kind of the pending run's file, whole after -k or -k after whole, drops both, since the pending run's report would be counted as the later run's; a run that ended in its call with no summary and no report, such as one whose pytest refused an option of the command, is pending like an open one; a run that went to the background after an earlier run of its file left the report unread is taken to have ended, and is not counted; and a pytest run that ends before a hook has read the pending run's report replaces it (the session has one result file), so the pending run is then not counted.
  • Only what the line says is counted. A whole run counts when it ran two cases or more and no case failed, and no run counts that skipped more than a tenth of its cases: pytest counts a skipped case in tests, and a run on a machine where the cases skip takes a fraction of the time. A file of one case has no -k selection smaller than itself, and the line tells a session to make one: without the floor a run that ends 1 passed in 300.00s would be stored as about 1 cases, and would take the row from a file of 8000 cases that takes 140 s. The skipped cases are the ones pytest's last line counts, because the result file's skipped also holds the expected failures (xfail), which ran. A filtered run is one with -k that ran fewer cases than the whole file. --lf, --sw, --deselect and -m may run every case, and a node id is not -k: a run with one of them is neither whole nor filtered. Neither is a run with no -k among its words whose last line counts deselected cases: a selection in PYTEST_ADDOPTS or the settings file is in no command. Without that rule one such run, a few seconds long, would be stored as the file's whole run. A redirect between descriptors (2>&1) is left out of the command before the run's words are read, so a -k or a second path written after one is among them. Nor is a run that pytest ended before its last case, at a failure limit, an error during collection, an interrupt or pytest.exit: it prints an ordinary last line (120 passed in 30.00s) and writes the result file with the cases it got to, and the line it prints above the last one, the reason between two runs of !, is the only sign. Without that rule a whole run that an interrupt ended would lower a stored 140 s to its 30 s, and each -k -x run that stopped at its first failure would pull the filtered time toward a second. A -k run that failed and ran its whole selection stays a filtered run. The word after a long flag is the flag's value or, where the flag takes none (--no-header), a second path: a run with such a word that names a Python file or a folder of the checkout is no run of one file.
  • The file is a file of the checkout. The hook resolves the path the command names from the payload's folder and the command's one cd, and notes a run only where that file is there. The session's end sends the path relative to the checkout root, for a file that is still there and that git lists in the checkout, tracked or untracked (one git ls-files in the detached copy, 1,000 ms at most; a call that fails stores nothing): a file under the root is not always the checkout's own, and a run of a file in a worktree or a submodule under it, or of one git ignores, is not stored. The prompt hook prints a row only where the checkout holds its file.
  • The row follows the file. With no row, the session's costliest whole run is stored when it took 60 s or more. The row's own file is revised when the session's whole run of it is more than a quarter and two seconds away from the stored seconds, down as well as up, and its filtered time when the row has none or the session's is more than a quarter and two seconds away. A row lowered under 60 s stays as the measurement and prints nothing. Another file takes the row with a whole run of 60 s or more that is over a quarter longer, and any such run takes a row whose file the checkout no longer holds.
  • The write is not in a hook the session waits for, and reads nothing. It goes through the flusher that already delivers the session's turns. The session-memory hook removes the session's cost state, what it noted and the row it read, whether or not it stores: a resumed session reads the row again. It revises the row the session read at a prompt (if_match_sha256), under the agent that wrote that row (memory.get falls back across agents, the conditional write does not), and is create-only (absent) after a miss. It names the key, the scope and the repository id of the prompt's read, which the session's state keeps with the row: the checkout's scope is not resolved again at the session's end. A second resolution can name another remote of the checkout, where the index's match is cached no longer and the checkout has an upstream remote, and a first row under that remote's key is one no prompt of the checkout reads. A session none of whose prompts read the row stores nothing, so where no prompt can read the row no session writes one.
  • Under the launcher the read does not hold the pointers back. It starts once the search is sent, shares the search's bound, and is not waited for after the search answers: a read that has not answered by then, an error and a miss add nothing, and the pointer block is the same bytes with or without the line. The launcher, which is how Claude Code starts the prompt hook, exits with the prompt's answer. A prompt hook started on its own prints the pointers and stays until the read has settled or its exit grace has passed; the Codex plugin starts it that way and has no test report, so it sends no read. What can hold the pointers back is the scope lookup before the read: costLine resolves the checkout's scope in the hook's thread, and where no script of the prompt has done so in the process that is git calls of 1,500 ms at most each (one git config where the index's match is cached), with the search's answer taken after them. At a session's first prompt the launcher has resolved the scope itself where it keeps the run's begin (the run ledger on, a token at hand), and the read asks for the scope only until one read has answered. The row as read, a miss too, is kept in the session's state with the checkout it was read in, whenever the read answers before the process exits: a read that answers after the search, while the launcher still waits for the prompt's recall or a script started on its own waits for it, prints nothing at that prompt, and the next bug report prints the line from the state with no read. A read that failed, or had not answered when the process exited, is asked again at the next bug report. The state keeps one row, the one read last: a later bug report in that checkout sends no read, and a session whose folder moves to another checkout reads that repository's row in its place and, where it ends there, writes it.
  • Neither the audit nor the mentor counts the read. The prompt's memory.get is the plugin's first read by an exact key that no agent chose, and namespace.audit counted every memory.get whose caller is not the dashboard or the assistant and whose key is not a live procedure. Its exact_key_store finding is critical from 200 such reads in the window that are also 20 times the memory.search and memory.ask calls, and the plugin's other reads (context.pack, memory.for_file) are not counted as searches. In a namespace shared by many sessions the hook's reads alone could reach that: the namespace-health hook then holds one Stop in every session of the namespace with the /loom-optimize line, and context.pack carries the health block. The audit now leaves reads of a key like repo:%/test-cost/pytest out of summary.gets, summary.typed_gets and the hot-key listing of exact_key_store (HOOK_READ_KEYS in server/memory/domain/namespace_shapes.py, the module the audit and the mentor share). exact_key_store is rule version 3 and intentional_exact_key_reads version 2, and each names the exception in its exceptions text. The reads still count among the calls that say the ledger recorded the window. The read is matched by its key, not by a consumer the hook would name: the server takes a token's consumer claim over the one a request names, so under such a token the read would be counted all the same. Reading the row through an op the audit does not count was the other way: memory.list by prefix is the widest read a token makes, and it leaves out rows by status (duplicate, superseded, proposed) unless asked for each, where memory.get reads the exact row its key names. The mentor profile counted the read too, against the session's agent, which the hook's request names, and from fewer reads: 50 exact-key reads in its 7-day window that are 5 times the agent's memory.search, memory.ask and search.query calls give recall_by_key_only, and 50 keys asked of which a fifth found no row give reads_miss. Both are warnings that context.pack, a call's hint and mentor.brief serve, and in a repository with no row every read misses. The profile's calls by operation and its keys asked and missed now leave out a memory.get of a key like the pattern (op_counts and key_reads in server/insights/store/mentor.py). The profile's reads by session, a session's first call and the key read most in one session, need no exception: the hook's request names no session. The brief's evidence ladder still counts the read, as it counts every row the ledger records under the agent.
  • The line is made of numbers, not of stored text. The hook parses the stored sentence into a repository id, a path and two or three integers, and renders the line from those. A value that is not that sentence, or names another repository, prints nothing and is never overwritten.
  • The stored sentence names its repository. The row is an ordinary memory row, which recall can serve in another repository of the namespace. The sentence names the repository by the repo:<id> tag the session's start prints, which is already in the row's key and tags.

Not in this change: the per-test line after an edit and at the test gate, a server-side table or op field for the cost, runners other than pytest, and Codex, which names no file for the result-file option and so has no report to read. Nor a read of a pending run's report before the session's next pytest run: the report is read only after a shell command that starts a test runner and at the session's end, the plugin's one hook before a shell command runs for gh commands only, and one added for test commands is a process the session waits for before every test command. Nor a read of it before a compaction.

Scope and risk

  • Touches the plugin's test report hook, launcher, session-memory hook and prompt hook, one new module (lib/test-cost.mjs), lib/test-report.mjs (runCost; newReport also returns the file's head and its modification time, and reads the head of a file over the 2 MB bound), one helper in lib/test-gate.mjs (fileRun, with its rule for what may stand before a run, onlySetsUp, and a bound on the pytest runs onlyRuns lets through, which fileRun sets to its own) and two file checks that are now exported (isFile there, isDirectory in lib/loom-client.mjs), their Codex copies, a fixture of the two requests and the reply the prompt hook reads (tests/fixtures/test-cost-wire.json in the plugin) with a unit test that holds it to the server's models (tests/unit/test_plugin_memory_contract.py), the reviewed-sender manifest (tests/unit/session_content_senders.json), the hooks reference, the plugin README, the Claude Code page and the test_report option's title and text. Server code: the exact-key counts of namespace.audit (server/identity/app/namespace_audit.py) and of the mentor profile (server/insights/store/mentor.py), the key pattern both match (server/memory/domain/namespace_shapes.py), their tests, the field comments of mentor.brief usage and planes and of the audit summary's gets, which name the reads left out, the regenerated mentor reference page, the namespace guide and the mentor section of the namespaces page.
  • What leaves the machine. For this feature: the test file's path in the checkout, the case count and the seconds, in a memory.set body with the scope, key and tags repo:<id>, source:<client> and pytest-cost; the sentence repeats the repository id of the key. A path that holds a character outside letters, digits and ._/-, is over 160 characters or is changed by the secret redaction is not sent, and neither is a file git does not list in the checkout. The memory.get sends the scope, the key and a field list. Neither request carries X-Loom-Session-Protection.
  • Hooks in a session. Every new path is inside a try that ends silently. The hooks the session waits for gain no request that they wait for: the test report hook adds a few file checks and a read and a write of a small state file, the launcher at SessionEnd one bounded read of the session's own result file when a run is pending (it loads lib/test-cost.mjs for that event only), and the prompt hook one request that it does not wait for past the search's answer, and before it the scope lookup named above. The test report hook's note and the launcher's read at SessionEnd read no token: a measured path is checked against the secret redaction in the detached copy, before it is sent, so an agent's SessionEnd launcher starts no token exchange. The prompt hook checks the stored row's path against the redaction once its read has answered, and the redaction reads the token as the hook's requests do.
  • Modes. The note, the write and the read are the memory plane's. In code-only mode nothing is noted, stored or printed. LOOM_TEST_REPORT=off stops all of it, the prompt's memory.get included, and LOOM_SESSION_MEMORY=off the note and the write. A session that ends with no credential starts no detached copy, so its cost state stays until the stale sweep, a day after its last write, as the session's other state files do. With LOOM_PROMPT_PACK=off, in memory mode and in a repository this Loom does not index no prompt reads the row, so nothing is printed and nothing is stored.
  • Limits. It is one row a repository and names one test file, the costliest a session ran whole. The session's state holds eight files, the one with the costliest whole run and the seven others run last, so the runs of any other file are dropped: a row's own file that got faster is then not lowered. A whole run started with xdist workers (-n) counts with the seconds it took, and the row does not say how its run was started: a session that runs the file only in parallel lowers a row that a serial run made, a row under 60 s prints nothing, and the next serial run raises it again. Such a run is counted because the check line the plugin prints after an edit gives -n auto in a repository that runs pytest that way, and a whole run there is a parallel one. A session with no prompt that reads as a bug report stores nothing: the row is read for such a prompt beside its search, whether or not the search returns pointers. The session keeps one row, the one a bug report read last, and stores only where it ends in that row's checkout: a session that goes back to a checkout whose row it read before a bug report in another one reads that row again at its next bug report there, and stores nothing where it ends there with no such bug report. A row for each checkout would need a bound and a rule for which one to drop. A session that stays open for more than a day loses what it keeps for this, since any session's start removes the state files untouched for a day: the row is written when a bug report reads it and not again, so once it is removed the session stores nothing unless a later bug report reads the row again; what it noted of its runs goes a day after the last run it noted; and a session that runs no pytest for a day has no test report after that, so its bug reports read no row and print no line and its runs are not noted. A run that outlives its shell call is noted when pytest began it before that call returned: a run put in the background at once is not. The session keeps one run that outlives its call: a later one of another test file takes its place, and a later one of the same file and the other kind drops both. The result file of a run that was replaced or dropped counts for no run the session keeps later. A run that ended in its call with no summary line and no result file is kept as if it were open. A run with no summary line is taken to have ended in its call when the hook reads a result file of its test file with it: where an earlier run of that file left the result file unread and the run itself went to the background, it is not counted. The session has one result file, read only after a shell command that names a test runner and at the session's end. So a whole run that went to the background is counted where it is the session's last pytest run, or where a command that names a runner and starts no pytest (pgrep -f pytest) comes before the next one; where a -k run follows it at once, that run's report replaces it and the whole run is not counted. The SessionStart hook runs again after a compaction and empties the result file, as it did before this change: a run that outlived its shell call and ended before the compaction, with its result file not yet read, is not counted. Two runs in the background at once write one result file, and the one written last is read. The result file of a run of the same file that something else started while a run that outlived its shell call was in that call is counted as that run's, with its case count and seconds, when a command that is not the other run reads it. A whole run that skipped up to a tenth of its cases counts with the seconds it took. A run pytest ended early is counted with the cases it got to where the command cut pytest's line about it from its output (| tail -1), or where the run outlived its shell call: the result file does not say that a run was ended. A run that outlived its shell call has no last line to read, and the result file counts an expected failure as skipped: such a run of a file where more than a tenth of the cases are expected failures is not counted. The result file does not count the deselected cases either: a run that outlived its shell call with a selection its command does not show is counted as a whole run, with the cases it ran. A row whose file was removed stays, unprinted, until a session measures a slow whole run of another file. The row is an ordinary memory row of the default type: recall can serve its sentence, two repositories' rows in one namespace read alike, and the write-time conflict check can mark one conflicted; both are still read by key. Where the other repository's row is pinned, the check refuses the write (409 PINNED_CONFLICT), and the repository has no row and no line until that row is unpinned. files: [] keeps the row out of a file's memory, since the sentence names a path. A run that a wrapper starts (make, a script) and a move the hook cannot follow are not noted: a second cd, pushd, or a cd to a folder written with anything but letters, digits and ._/- (a quoted or escaped name, which the hook would cut at its space, an option such as -P, a folder the shell expands). Neither is a run with anything after it in its command but tail, head, grep and echo: pytest <file> -q || true and pytest <file> | tee log are not noted. Nor is a run with anything before it but cd, export, source and .: make build && pytest <file> and pip install -e . && pytest <file> are not noted. Quotes are not read, so a |, ;, &, <, backquote or parenthesis inside one counts as if unquoted: a run piped into grep -E "passed|failed" and one with -k "parse and (empty or nested)" are not noted either.
  • The exception is a key. A read of repo:<id>/test-cost/pytest is left out of the audit's exact-key counts and the mentor's whoever sent it, an agent's own memory.get of that key included. The read-count arm of coordination_as_memory still counts reads of the key: it matches a row under 160 characters and 8 words that is read 20 times in the window, which the stored sentence is not, and it is a warning at most. The mentor's coordination_loop counts the reads of one key in one named session, and the hook's read names no session. Against a server before this change the audit counts the hook's read, one a session and checkout, and a namespace whose sessions send 200 in a day beside few searches gets the namespace-health line in each of them; the mentor counts it under the session's agent, and an agent whose sessions send 50 in a week beside few searches gets recall_by_key_only, with reads_miss where a fifth of them found no row. LOOM_TEST_REPORT=off stops the read and LOOM_NAMESPACE_HEALTH=off the namespace-health line.
  • The write is one of the agent's writes, and not one about tests. The session-end memory.set goes under the agent of the row it revises, or the session's agent for a first row, and the mentor counts it in usage as it counts any write. The mentor also counts a write whose tag holds a word such as test, flaky or ci among the agent's test writes, and one such write gives an agent that made no tracker.* call the tracker_unused warning where the deployment has a tracker source. The row's tag is therefore pytest-cost, which that pattern does not match, and not the test-cost of its key: that count reads tags only, so the key does not enter it.
  • A wrong or stale row costs one misleading line on bug reports until a session that read it runs the file whole, or a slower one, or someone removes it with memory.delete on the key.

Compatibility, rollout and rollback

  • Wire: no op or field added, changed or removed. namespace.audit reports exact_key_store at rule_version 3 and intentional_exact_key_reads at 2: their counts, and summary.gets and summary.typed_gets, leave out reads of a key like repo:%/test-cost/pytest, so a report is compared with an earlier one only at the same version. mentor.brief leaves the same reads out of usage, out of the calls of the plane planes sums them into and out of the evidence of recall_by_key_only and reads_miss. The plugin hooks now call memory.get and memory.set, with fields the minimum supported server serves; a server before this change counts the memory.get in its audit and its mentor profile. tests/unit/test_plugin_memory_contract.py validates the two request bodies and the reply against MemoryGetInput, MemoryGetOutput and MemorySetInput, and the plugin's tests hold the hooks to the same fixture.
  • Operator steps: none.
  • Rollback: reverting leaves the rows already written, one a repository and namespace under repo:<id>/test-cost/pytest. Nothing reads them by key after a revert; memory.delete removes one.

Tests

  • node --test --test-concurrency=4 integrations/claude-code-plugin/tests/*.test.mjs: 1302 tests, 1295 pass, 7 skipped (the Windows cases). The new file is tests/test-cost.test.mjs, 40 tests:
    • the head of a report with tests="8000" time="140.2" gives 8000 cases and 140 s, with its failed and skipped counts, also for a report over the 2 MB bound;
    • a whole run and a -k run of the same file are classified, with the seconds, the cases, the failures and the skipped cases of pytest's last line, whatever it counts (8000 deselected in 1.20s, 12 skipped in 0.31s, 3 xfailed in 0.50s, no tests ran in 0.01s); a command with two pytest runs, with a space before the second or none (-q;pytest <file>::test_one, -x -q||pytest, -q&&py.test, -q|pytest, ; echo $(pytest <file>::test_one -q)), two paths, --lf, --sw, --deselect, -m, a node id, a run that only collects, a run that names its own result file, a move the hook cannot follow (a second cd, pushd, a cd in a subshell that closed, cd "$PKG", a cd to a quoted or escaped folder name with a space, cd -P) or a runner started after the run (&& make test, 2>&1 | tail -3; tox, > /tmp/out.txt; ./run_tests.sh, >/dev/null;make test) is no file run, nor is a run after another command (make test ||, make test; python3.9 -m pytest, ./scripts/check.sh &&, make build &&, export OUT=$(make test);, the same in backquotes), while a run after source .venv/bin/activate && export PYTHONPATH=src; or . .venv/bin/activate; is one; nor is one with a | or a parenthesis inside a quote (| grep -E "passed|failed", -k "parse and (empty or nested)"), and a run whose output goes to a file that tail and echo then read is one; a run with no -k among its words is whole where its last line counts no deselected case and no file run where it counts one (a selection added to PYTEST_ADDOPTS); a -k written after 2>&1 makes a filtered run (pytest <file> 2>&1 -k parse | tail -3), and a second path written there no file run (pytest <file> 2>&1 tests/test_small.py | tail -3), which leaves no state; neither is a run with a Python file after a flag (--no-header tests/test_small.py), and one with a folder after a long flag leaves no state, as do a second run with no space before it and a run after a cd to a quoted folder name with a space, whose path the session's folder holds too; a run whose output holds the line pytest prints above the last line of a run it ended early (KeyboardInterrupt, _pytest.outcomes.Exit, stopping after 1 failures, Interrupted: 1 error during collection, between runs of ! or two single ones) is no file run, with -k or without; a last line in colour gives the same seconds, cases and failures as the plain one (8000 passed, 1 failed, 7999 passed, no tests ran), and a run whose line above the last one, or whose count of deselected cases, is in colour is no file run;
    • the stored sentence and the prompt's line, byte for byte, with and without the clause about the timeout and the filtered sentence; a sentence that names another repository is no claim;
    • a first row needs a whole run of 60 s, and a stored value within a quarter is not rewritten; a file that got faster lowers its row, under 60 s too; a row whose file is gone is replaced; a -k run that ran every case is no filtered time, and a stored filtered time far from the session's is replaced;
    • a report whose seconds are not the summary's is counted for no run: the two are compared as written, so a report 1.49 s from the summary is not the command's (2.00s against time="0.51") and one 0.96 s from it is (1.45s against time="0.49"); neither is the report an earlier -k run left (12 cases, 1.4 s) read with a run that wrote none and ended 1 error in 0.52s or 1 failed in 0.80s, nor a report of one passed case read with a run that ended 1 error in 0.52s; a whole run of one case (1 passed in 300.00s) is not kept and one of two cases is; a whole run that skipped 801 of 8000 cases is not counted, and one that skipped 800 is; a whole run whose report counts 1000 of 8000 cases as skipped and whose last line says 100 skipped and 900 xfailed is counted; a whole run and a -k -x run that pytest ended early are counted for nothing, and a -k run that failed and ran its whole selection is a filtered time; a -k run whose cases skipped is no filtered time, and neither is one whose last line counts a case twice (12 passed, 7988 deselected, 1 error) over a report of 12 cases; a later command keeps the pending run, and so does a run of the file that ended with every case deselected or skipped, and a report of a run that began before the pending run's command returned is that run's; the report of a -k run that began after it is counted for no run, read with time pytest, nohup python -u -m pytest, hatch run pytest, bash -c "pytest", pgrep -f pytest or make test, and at the session's end; a run that ended in its call with its summary cut (| head -30 of another file, | grep FAILED of a -k run of the same file) leaves nothing pending, the whole run that outlives its call after it is counted, and such a run leaves an open run of the other kind pending; an open run takes the place of a pending run of another file, whose report leaves it pending, and its own report, of a run that began after the replaced run's command returned, is counted; after a whole run and a -k run of one file were dropped together, the report the -k run wrote late (12 cases, 400 s) is not counted for the whole run that is pending next, at a later command or at the session's end, and neither is it after a run of another file took the -k run's place and a whole run that one's, while the pending run's own report is counted; the state holds eight files and the last 15 filtered runs of each: the files run last, and the file with the costliest whole run after eight other files were run;
    • the hooks started as the host starts them against a stub server: a slow whole run and a filtered one end in exactly one memory.set with the body the fixture holds; a session that measured a slow whole run and whose prompts read no row stores nothing; a run that outlived its call is stored from the report it wrote before the session's end, and is not counted where a -k run's report replaced it first; a stored 140 s is not lowered by a whole run that an interrupt ended 120 cases in, nor by one that skipped 7988 of 8000 cases in 2 s, nor by the report of an earlier short run read after a short run that wrote none, nor by pytest <file> 2>&1 -k parse | tail -3 whose last line counts 7988 deselected cases; a session that read a miss and measured a slow whole run of a file whose path holds +, is over 160 characters or is changed by the secret redaction ends with no memory.set, and so does one whose slow whole run, after a cd, was of a file in a worktree of the repository under the checkout or in a folder git ignores; a stored 140 s is not lowered by the report of a later -k run, read after time pytest or left by a script until the session's end; a session whose folder moves to another checkout reads that repository's row and writes its first row, one that ends in a checkout whose row no prompt read stores nothing, and one whose bug reports go from a first checkout to a second, back and to the second again sends four reads and stores nothing where it ends in the first; a session whose checkout loses its cached index match and gains an upstream remote after its prompt read a miss writes its first row under the key, the sentence and the tag of that read; the launcher at an agent's SessionEnd starts no token exchange while it reads that report; a revision goes under the agent that wrote the row; a row is lowered and a row for a missing file replaced; a row under 60 s or for a missing file prints nothing; code-only mode notes, stores and prints nothing in a session that has a row to print and a run to store; a whole run under 60 s, a whole run of one case that took 300 s, a command of two runs or two paths, --lf, make test || pytest <file> read with the suite's report and last line, and LOOM_SESSION_MEMORY=off store nothing, each in a session whose prompt read the row, and with LOOM_SESSION_MEMORY=off the run is not noted; with LOOM_TEST_REPORT=off a prompt sends no memory.get, and a session's end stores nothing; the session's cost state is gone after SessionEnd in each of those sessions, in code-only mode and for an agent whose token exchange fails; a bug report prints the line after the block from one memory.get while the session stays in the checkout, with the body the fixture holds; a read that fails, and under the launcher one that answers five seconds after the search, leave the block unchanged and do not delay it. No test runs the prompt hook with a slow git, or on its own with a slow read.
  • tests/unit/test_namespace_audit.py, on the release's clickhouse binary: the ledger summary and exact_key_store over 280 memory.get rows of three repositories' test cost keys, one of them a live procedural row, three reads of another key and one memory.bulk_get count four gets and no typed get, grade info and sample no key, while all 284 rows count as recorded calls; with the pattern set to match no key the same rows count 284 gets, 30 of them typed, and grade critical. The pin of each rule's version holds the pattern. tests/unit/test_plugin_memory_contract.py holds the key in the hook's fixture to the pattern.
  • tests/unit/test_mentor.py, on the same binary: over 50 memory.get rows of one repository's test cost key that missed, two of another's that answered, one read of the key recorded as an MCP argument, two reads of other keys, one memory.bulk_get of five keys and one search, the profile counts two memory.get calls, seven keys asked and two missed, and neither recall_by_key_only nor reads_miss fires; with the pattern set to match no key the same rows count 55 memory.get calls, 60 keys asked and 53 missed, and both fire. The ledger row of the memory.set the fixture holds, its arguments projected as the ledger keeps them, counts as no test write and brings no hint with a tracker source configured; the same request with a test-cost tag added counts as one and brings tracker_unused.
  • make format lint typecheck: pass.
  • pytest tests/unit/test_mentor.py tests/unit/test_namespace_audit.py tests/unit/test_namespace_health.py tests/unit/test_namespace_tune.py tests/unit/test_skill_eval.py tests/unit/test_plugin_memory_contract.py tests/unit/test_session_content_senders.py tests/unit/test_codex_plugin.py tests/unit/test_agent_plugin.py tests/unit/test_cursor_plugin.py tests/unit/test_op_reach_census.py tests/unit/test_plugin_checkout_bytes.py tests/unit/test_plugin_code_query_contract.py tests/unit/test_plugin_eval_mocks.py tests/unit/test_doc_links.py tests/unit/test_public_copy.py tests/unit/test_agent_instructions.py tests/unit/test_package_contracts.py tests/unit/test_call_site_knobs.py tests/unit/test_release_prepare.py: 1047 passed. tests/unit/session_content_senders.json holds the reviewed exception for the memory.get call site in both plugin copies and the pins of the changed files.
  • node --check over both plugins' hooks/, lib/ and bin/: pass.
  • No test runs a real pytest: the tests write the result file pytest would write. One run of pytest 9.1.1 with --junitxml by hand: the file's modification time less the suite's time is the suite's timestamp, a few hundred milliseconds after the process started. pytest's result-file writer adds an expected failure to the suite's skipped count (append_skipped in _pytest/junitxml.py, read in pytest 9.2.0). Two runs of pytest 9.2.0 by hand. A file with a passed, a failed, a skipped, an expected-failure and an unexpectedly passed case, a setup error and a teardown error after a pass: the last line counts eight cases and three failures and errors, the file tests="7" and three (the case whose teardown raised is one testcase). A file that fails at collection ends 1 error with tests="1" errors="1". Four more runs of pytest 9.2.0 by hand, each of which prints the line between runs of ! above an ordinary last line and writes the result file with the cases it got to: a whole run that an interrupt ended after seven cases (7 passed in 1.12s, tests="7"), a -k -x run that stopped at its first failure, a run that pytest.exit ended, and a -k run of a file that fails at collection. A pytest.exit message as wide as the terminal stands between two single !. Two runs of pytest 9.2.0 with --color=yes by hand: each count of the last line and the whole line between runs of ! stand between escape sequences that end in m. Whether Claude Code hands those sequences to a hook in the command's output was not checked in a session; where it removes them, the line is the plain one. The effect of the line on a session's choice of run is not measured here.

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 by reading the server's memory.get and memory.set models, the audit's and the mentor's ledger reads and the launcher's waited and detached paths against the design, and by the tests above.

  • 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 4, 2026 16:19
…sts in the repository

A session that does not know what a whole run of a data-driven test file
costs runs the whole file to check a change, where a -k selection of its
cases answers in seconds. The plugin's pytest result file holds the case
count and the run's seconds, and nothing kept them.

The test report hook now notes them for a shell command that is one pytest
run of one test file, in the session's private state. The session's end
hands one memory row a repository to the flusher for a whole run of 60 s or
more, and the prompt hook reads that row beside a bug report's search and
prints one line under the pointers. The read is never waited for past the
search's answer. Code-only mode notes, stores and prints nothing.

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

vercel Bot commented Dec 4, 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.

zlareb1 and others added 2 commits December 4, 2026 17:32
A row could not be lowered or replaced once its file got faster, was renamed
or was removed, and the prompt kept printing it. The session now keeps its
runs by file: the row's own file is revised by a whole run more than a quarter
away, down as well as up, another file takes the row with a run over a quarter
longer, and any slow run takes a row whose file the checkout no longer holds.
The prompt prints no row under 60 s or for a file that is not there. The path
is the file's in the checkout, resolved from the command's folder.

--lf, --sw, --deselect and -m may run every case, so only a -k run that ran
fewer cases than the whole file is a filtered time, and a stored one more than
a quarter and two seconds from the session's is replaced.

A report is a command's only when its seconds are the ones the command's
summary shows: a run the option did not reach writes none. A command that
names a runner and starts none keeps the pending run and credits it the
report that came.

The launcher at SessionEnd no longer resolves a token while it reads the
pending run's report: the redaction check runs in the detached copy, before
the path is sent, so an agent's hook starts no token exchange.

Only a session whose prompt read the row writes, under the agent that wrote
the row, so no row is written where no prompt can read it and a revision is
not refused for another agent's row. The stored sentence names the repository
by its tag, since recall can serve the row in another repository of the
namespace. The line says "the default 120 s timeout", which a call can raise.

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

A run whose output shows no summary is kept as the session's pending run.
Its report was told from a later run's by reading the later command: one
that names a runner and starts none left the report to the pending run.
`time pytest`, `nohup`, `bash -c "pytest"` and a script no hook is run for
all read as starting none, so a -k run's count and seconds were stored as
the file's whole run.

The report now says whose it is. pytest began the run that wrote it at the
time the file was written less the seconds of its testsuite. The pending
run keeps the time its command returned, and a report counts for it only
when its run began by then: a run any later command started began after
it. `mayRunTests` is removed. A run put in the background before pytest
began is no longer counted.

A word after a long flag that names a Python file or a folder makes a run
no run of one file: the flag may take no value (`--no-header tests`).

The row a session read is kept with the checkout it was read in, so a
session whose folder moves to another checkout reads and writes that
repository's row.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.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.

… follows the test report's switch

A whole run counts for its file only when no more than a tenth of its
cases were skipped: pytest counts a skipped case in `tests`, so a run on
a machine where the cases skip read as the file's whole run and lowered
the repository's row under the 60 s a line needs.

`costLine` reads LOOM_TEST_REPORT and the `test_report` option, so a
session that has the report's state and the switch off sends no
`memory.get`. The switch is read in the library a bug report loads, which
keeps the test gate's library out of every other prompt.

The session has one result file, and no hook runs before a shell
command: a pytest run that ends before a hook read the report of a run
that outlived its call replaces it. The docs state it, and a test holds
it.

The tests that asserted only that nothing was stored assert what the
session read and noted first.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.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.

zlareb1 and others added 2 commits December 4, 2026 19:29
…s how many cases were skipped

A run that ended with no case passed or failed (every case deselected,
skipped or an expected failure) was read as a run that had not ended, and
dropped a pending whole run of the same file. The suite's skipped count
holds the expected failures too, so a whole run of a file with many of
them was never counted: a run whose summary is in sight now takes the
skipped cases from that line. A run that skipped more than a tenth of its
cases is no filtered time either.

The docs name the bound of 15 filtered runs a file, the report of an
overlapping run that is taken for a pending run's, and that the test cost
write does not depend on the session's turns.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <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.

zlareb1 and others added 4 commits December 4, 2026 20:17
…d the costliest whole run stays in the session's state

A pytest run's words end at the first `&`, so a `-k` written after `2>&1`
was not among them, and a selection in `PYTEST_ADDOPTS` is in no command:
such a run was read as a whole run and its few seconds replaced the stored
time. A run with no `-k` whose last line counts deselected cases is now
neither whole nor filtered.

The session's state dropped the file least recently run, which could be the
one with the slow whole run the session's end stores. The file with the
costliest whole run is now never the one dropped.

A hook-level test covers the paths that are not sent: one with another
character, one over 160 characters and one the secret redaction changes.
The docs name the eight-file bound, a run that outlived its call with a
selection its command does not show, and a whole run under xdist workers.

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

The seconds alone do not tell two short runs apart: the report an unread
-k run left was counted for a later whole run that wrote none and ended
within a second of it, and the session's end lowered the repository's row
to that run. The command's last line now has to count the cases and the
failures the report holds as well.

The page and the README say that a pinned row of another repository in the
namespace refuses the write, and the test_report option's title names the
test cost.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
pytest prints an ordinary last line and writes its result file for a run
it ended before the last case: at a failure limit, an error during
collection, an interrupt or pytest.exit. Such a whole run was kept as the
file's whole run and lowered the stored seconds, and such a -k run was
kept as a filtered sample. fileRun now reads the line pytest prints above
the last one, the reason between runs of `!`, and such a run is neither.

The launcher loads lib/test-cost.mjs at SessionEnd only, so the prompt
hook's own load of it is the only one at a prompt. noteCommand takes the
caller's cwd as it is.

The prompt hook's comments, the hooks reference and the Claude Code page
say what the cost line's read can hold back: the git calls that resolve
the checkout's scope before the read is sent, and, for a script started
on its own, the read until it settles or the exit grace passes.

The two requests of the cost hooks and the reply the prompt hook reads
are a fixture: the plugin's tests hold the hooks to it, and
tests/unit/test_plugin_memory_contract.py holds it to MemoryGetInput,
MemoryGetOutput and MemorySetInput.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.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.

…cost state ends with the session

fileRun read the command only up to its one pytest run. A runner started
after the run (`pytest <file> -q && make test`, `; tox`, a script) writes
the session's result file and prints the last line, so the two agreed and
the wrapper's cases and seconds could be stored as the named file's whole
run. Only what the gate's onlyRuns allows may follow the run now: tail,
head, grep and echo, with a redirect of the run to a file read past.

The session's cost state was removed only by costPost, behind the
switches of the write. loom-session-memory now removes it for every
session (endCost), and the test report hook notes a run only where the
session's end may store it: with LOOM_SESSION_MEMORY=off nothing is
noted.

The comments and the paragraphs of the hooks reference that held a line
broken mid-sentence are rewrapped.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.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.

if (stores) {
const posts = [await handOff(payload, journal, recalledKeys), cost].filter(Boolean);
// Spawn failure: nothing is lost that the next session cannot say again.
if (posts.length) dispatchFlush({ posts });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cost state removed before flush

Medium Severity

endCost deletes the session's measured runs and the row it read before handOff is awaited and before dispatchFlush queues the memory.set. costPost has already built that post, but a throw or a crash inside handOff never sends it. A replay of the SessionEnd job then finds no cost state, so the repository row is not written.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 61c3699. Configure here.

zlareb1 and others added 11 commits December 4, 2026 23:07
… an open run

A pytest run of one file whose output shows no summary was kept as the
session's pending run, also when it had ended in its call and the command
cut the summary (`| head -30`, `| grep FAILED`). The next run that outlived
its call was then dropped with it when it was of another file or of the
file's other kind, so a slow whole run that was the session's last pytest
run was not counted.

Such a run is no longer kept where the report read with its command is of
its file and no pending run's: the run wrote it in its call. An open run
takes the place of a pending run of another file, and a report of another
file leaves the pending run as it is. An open run of the other kind of the
pending run's file still drops both.

The docs name what is left: a run that ended in its call with no summary
and no report is pending like an open one, and a run that went to the
background after an earlier run of its file left the report unread is not
counted.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A pytest told to colour its output (`--color=yes` in `addopts`,
`PY_COLORS=1`) writes an escape sequence before each part of its last
line and around the line it prints above it for a run it ended early.
The escape ends in `m`, so the word boundary before the count did not
match and the run read as one that had not ended: a run that finished in
its call was counted as nothing, and the line between runs of `!` was
not seen. fileRun now removes the colour escapes from the output before
it reads the two lines.

The docs and the module comment name one more limit: the SessionStart
hook runs again after a compaction and empties the session's result
file, so a run that outlived its shell call and ended before the
compaction with its report unread is not counted.

The comment above the branch of noteCommand that keeps an open run says
what the branch does.

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

A run piped into grep -E "passed|failed", or filtered with
-k "parse and (empty or nested)", is no file run: a |, ;, &, <, backquote
or parenthesis inside a quote counts as if unquoted. The docs page,
HOOKS.md, the README and the comment on fileRun now say so, and the test
of what is no file run holds both commands.

The session's state holds the file with the costliest whole run and the
seven others run last. The docs page said a file's runs are dropped after
eight later files; it is seven where the costliest file ran earlier.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ites to the key its prompt read

A command before the named pytest run may start pytest itself. Where the
named run then does not start (make test || pytest <file> with a suite that
passes, an interpreter with no pytest), the result file and the last line
are that command's, and were counted as the file's whole run. fileRun now
reads a run only where nothing stands before it but cd, export, source and
"." (onlySetsUp): a wrapper is not known by its name, so a build step
before the run is no file run either.

costPost resolved the checkout's scope again at SessionEnd and built the
row's key from it. Where that resolution named another remote than the
prompt's (the index's match cached no longer, an upstream remote), the
first row went under a key no prompt of the checkout reads. The row state
now keeps the identity and the repository id of the read, and the write
names them.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…session keeps the row it read last

The check that a result file is the command's compared the summary's
seconds with the file's seconds rounded to a whole one, so the tolerance
of a second was off by up to half a second either way: `1.45s` against
`time="0.49"` was refused and `2.00s` against `time="0.51"` accepted.
It now compares with the seconds as the file writes them.

The session's state holds one row, the one a bug report read last, with
the checkout it was read in. The comments, the README, the hooks
reference and the Claude Code page said the row is read once a session
and checkout and stored where a prompt read it. They now say what the
state does: a bug report in another checkout reads that repository's row
in its place, a bug report back in the first checkout reads again, and
the session's end stores only in the checkout of the row kept. A test
holds both.

The README's rule for the filtered time is the one the code has: the
row's is replaced when it has none or the session's is more than a
quarter and two seconds away.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…lder not written plainly, are no file run

fileRun counted one run for a command such as `pytest <file> -q;pytest <file>::test_one -q`: the pattern
that finds a run does not start after `;`, `&`, `|` or `(`, and the check of what follows the run let that
part through as a run. The second run's summary and result file were then kept as the whole run of the file.
Only the run's own simple command may now be a pytest run; every part after it reads output.

A `cd` is followed only to a folder written with letters, digits and `._/-`. A quoted or escaped name was
cut at its space and an option (`-P`) was read as the folder, so the run was noted for the file of the same
path in the session's folder.

The hooks reference says that a result file over 2 MB gets no digest and that its first 4,096 bytes are read
for the run's cost.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The session's end kept every measured file that lies under the checkout
root. A whole run started after `cd .claude/worktrees/fix`, or of a file
in a submodule or a folder git ignores, was then stored as the
repository's row under that path: the row printed nothing in a clone
that does not hold the path, and in the checkout a whole run of the
same length of the checkout's own file could not take it.

`measured` now keeps only the paths git lists in the checkout, tracked
or untracked: one `git ls-files` for all of them, bounded at 1,000 ms,
in the detached copy. A call that fails stores nothing. A test notes a
slow whole run in a worktree under the checkout and in an ignored
folder, and ends with no `memory.set`.

The README's hook table and the Claude Code page said the cost line
costs one `memory.get` a session. They now say what the hook does: one
read, unless the session keeps the row it read in that checkout.

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

The prompt hook reads the repository's test cost row with `memory.get`
by its key, once in a session and checkout, whatever the session's
agent does. The audit counted that read as an agent's exact-key read.
In a namespace whose sessions sent 200 of them in a day and fewer than
a twentieth as many `memory.search` or `memory.ask` calls,
`exact_key_store` turned critical: the namespace-health hook then held
one Stop in every session with the `/loom-optimize` line, and
`context.pack` carried the health block.

The audit now leaves reads of a key like `repo:%/test-cost/pytest` out
of `gets`, `typed_gets` and the hot-key listing of `exact_key_store`
(`HOOK_READ_KEYS`). The read is matched by its key: the hook's request
names no consumer. `exact_key_store` is rule version 3 and
`intentional_exact_key_reads` version 2. The reads still count as calls
the ledger recorded. A test runs the summary and the check over 250
such reads, three other reads and one `memory.bulk_get`, and a contract
test holds the key the hook's fixture names to the audit's pattern.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The test of the audit's test cost exception wrote its one cost row as
`semantic`, so `typed_gets` was 0 whether or not the typed count left the
key out. It now also writes a second repository's cost row as `procedural`
and reads it 30 times: the typed count stays 0, and with the pattern set to
match no key those 30 reads are typed gets.

The hooks reference names `fileRun` in lib/test-gate.mjs for the runs of a
part of a file, of two runs and of two paths, which is where they are
refused.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…nt's exact-key reads

The prompt hook's memory.get names the session's agent and no consumer, so
the mentor profile counted it among that agent's calls: 50 sessions in a
week that each missed the row gave the agent the recall_by_key_only and
reads_miss warnings, which grade it by the plugin it runs.

The profile's operation counts and its keys asked and missed now leave out
a memory.get whose key is like HOOK_READ_KEYS, the pattern namespace.audit
already matches. The pattern moves to the module the audit and the mentor
share, so the two read one value.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`mentor.brief` `usage` and the `gets` of the `namespace.audit` summary leave
out a `memory.get` of a repository's test cost row, and their field comments
still read as counts of every call. Both now name the exception, the comment
on `planes` says its calls are summed from `usage`, and the mentor reference
page is regenerated.

The prompt hook's `testLine` comment said the test gate's library is loaded
only for a prompt that has a test file. A bug report's cost line loads it
too, with lib/test-cost.mjs, whether or not the session has a test report:
the two comments say so. No behaviour changes; the file pins follow the new
bytes.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
zlareb1 and others added 3 commits December 5, 2026 06:28
…or no later run

The session's cost state keeps the time by which a pending run that was
replaced or dropped had begun, and `settle` counts no report of a run that
began by then. Without it the late report of a dropped `-k` run was stored as
the whole run of the file's next pending run, and a whole run's as a filtered
time.

`fileRun` leaves a redirect between descriptors (`2>&1`) out of the command
before it reads the run's words: `PYTEST` ended them at the `&`, so a second
path written after one was not read and both files' cases counted as the
first file's whole run. Such a command is now no file run, and a `-k` written
there makes a filtered run.

The settings table of HOOKS.md names the test report hook as a reader of
`LOOM_SESSION_MEMORY`. The Codex copy and the file pins follow the new bytes.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A file of one case has no -k selection smaller than itself, and the prompt
line tells a session to check a change with one. `add` now keeps a whole
run only from two cases, so a run that ends `1 passed in 300.00s` writes no
first row, takes no row from a slower file and revises none.

The docs now say three things the code already did:

- the whole run's revision rule has the two-second floor of the filtered
  time (`apart`);
- a read of the row that answers after the search and before the process
  exits is kept, and the next bug report prints its line with no read;
- a session open for more than a day loses its cost state to the sweep of
  day-old state files, and then stores nothing or prints no line.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The plugin manifests take 1.2.184, above main's 1.2.181 and the versions
other open pull requests use.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.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 1 potential issue.

There are 2 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 72f7d65. Configure here.

/** Whether the report of `cost` (`runCost`) is one a run of `run`'s file
* wrote: its first case is in that file. pytest names the file from its
* root, a folder at or above the file's. */
const ofFile = (run, cost) => Boolean(cost.file) && run.file.split(path.sep).join("/").endsWith(`/${cost.file}`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Report matched to wrong test file

Medium Severity

ofFile treats a result file as the command's file when the absolute path merely ends with / plus the report's file attribute. That attribute is relative to pytest's root, often just a basename, so another module with the same suffix matches. add and settle then keep that run's case count and seconds, and a background run has no summary counts to reject the swap.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 72f7d65. Configure here.

zlareb1 and others added 4 commits December 5, 2026 08:08
The test report's section said that no hook runs between two commands.
The launcher runs after every tool call, and a PreToolUse hook runs
before a `gh` shell command. What limits the read is narrower: the test
report hook reads the result file after a shell command that starts a
test runner, and the launcher reads it at SessionEnd. The section now
says that, as the Claude Code page and the plugin's README do.

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

The session-end hook tagged its `memory.set` `test-cost`. The mentor counts a
write whose tag holds the word `test` among the agent's test writes, and one
such write gives an agent that made no tracker call the `tracker_unused`
warning where the deployment has a tracker source. The tag is `pytest-cost`,
which the pattern does not match. A mentor test reads the tags from the
plugin's fixture and runs the profile's statement over the ledger row of that
request.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
main holds plugin version 1.2.185, so both plugin manifests take 1.2.186,
which no open pull request uses. The pin of the prompt hook stays the
sha256 of this branch's file and the pin of the session-start hook is
main's.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@zlareb1
zlareb1 merged commit 4e8978f into main Dec 5, 2026
92 of 93 checks passed
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