Skip to content

bench harnesses on the engine, and the CAL gaps that blocked them (#217) - #222

Merged
sathish-mg merged 10 commits into
mainfrom
bench/areev-surfaces
Sep 9, 2026
Merged

sathish-mg merged 10 commits into
mainfrom
bench/areev-surfaces

Conversation

@sathish-mg

@sathish-mg sathish-mg commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

The bench harnesses move onto the engine, and the engine grows the three
things that move blocked.

Closes #217.

The engine change (#217)

"Which tool fails most" is the first question anyone asks a memory of tool
calls, and #209 answered it. The message is the half that says what to do
about it — an agent told phone.login failed six times learns less than one
told it failed with a 401 — and CAL could name the endpoint or the message,
never both. Three gaps, each independently a silent no-op:

gap before
a Tool's body is unrenderable in a template {{grain.tool_content}} → CAL-E042; {{grain.content}} → empty, beside a FORMAT markdown render of the same grain that printed it
GROUP BY takes one field (tool_name, tool_content) cannot be a key, and tool_content was not groupable either (CAL-E060)
a LIMIT after COUNT does not bind the stage hit the inert-payload arm; every group came back

What lands:

  • GROUP BY a, b [, c, d] — up to four fields joined into one key with
    · (CAL-E123 past that). A composite row carries its parts as keys
    beside key; a single-key row keeps the exact shape 1.7.4 documented.
    {{group.key.<n>}} renders one part, numbered the way split(sep, n)
    numbers its fields. On a single-key row key.0 is the key, so one
    template renders both arities and the group. set stays closed.
  • tool_content joins the closed sets — the template variables and
    Tool's queryable fields — and §10.3.2's content projection for tool reads
    tool_content → content → object, the cascade the built-in renderers
    already used. So the surface that renders a grain and the surface that
    filters it agree on what a tool call says, and DESCRIBE FIELDS tools
    lists it.
  • LIMIT/OFFSET/FIRST bind to a grouped count. total_available
    keeps reporting how many groups the ranking has — a page that reported
    its own length would be a truncated answer indistinguishable from a whole
    one, which is what CAL-W015/CAL-W017 exist to prevent.
  • CAL-W018 when a group key names a field no grain carries. Every row
    then falls into one group under the empty key — exactly the shape of a
    ranking whose top value dominates. The issue found it as GROUP BY tool.
    WHERE has failed closed and said so since CAL: a WHERE predicate on a field the grain type does not carry silently matches everything (object on skills), against the fails-closed contract #207; the grouping path was
    silent.
RECALL tools WHERE is_error = true LIMIT 400 GROUP BY tool_name, tool_content COUNT LIMIT 12
- (6x) phone.login: Response status code is 401

The grammar change is spec-level, so it is written down.
docs/oms-1.7-amendments-cal-expressiveness.md gains B5/B6/B7 and
ARCHITECTURE.md §10 amends "CAL grows by closed sets". B6 relaxes an
existing rule rather than adding one — SELECT and PROJECT already take a
comma-separated field list in the same parse position — and no keyword,
statement form or operator is added. The JSON wire form still accepts the
singular "field": "x".

The bench half

Six earlier commits on this branch move receipts, tau2, appworld and
part of persist onto CAL — saved queries and registered templates the memory
file carries, rather than blocks composed in Python — and file the gaps that
blocked the rest. This branch's last commit takes the #217 fix back into
AppWorld's passive arm, which had lost its error messages on the way into CAL:

was:  - (6x) phone.login: Response status code is 401
then: - (6x) phone.login
now:  - (6x) phone.login: Response status code is 401

That direction is the point, and it is why the fix was worth doing before a
run rather than after. The passive arm is the baseline the governed arm
has to beat, so a block that says where an agent fails but not why makes the
baseline weaker — a bias in exactly the direction that would make the loop
look better. No run was produced under the endpoint-only block, so runs 1 and
2 stay comparable; AREEV.md and APPWORLD.md record that rather than
leaving it to be reconstructed.

parity_check's "200 distinct endpoints all reach the ranking" asserted the
pre-#217 shape. It becomes two checks worth more: the ranking is cut at
PASSIVE_TOP_N (a bound the block asked for, applied before the budget ever
sees it), and the most frequent pair leads — seeded to sort last by key,
so it can only lead if frequency really orders the rows.

Gates

  • cargo test --workspace — green (135 result blocks)
  • cargo clippy --workspace --all-targets -- -D warnings — clean
  • docs_examples (the executable ```sql fences in the CAL reference) — green
  • 9 new tests in cal_expressiveness.rs, a CAL-E123 repro in error_contract.rs
  • scripts/parity_check.py (all four tracks) and appworld/selftest.py — green
  • scripts/repo_stats.py --check and check_versions.py — current

https://claude.ai/code/session_016YzyEfdWprezzATrZGNtg8

Sathish Kumar Palanisamy and others added 8 commits September 9, 2026 00:16
## The result

Four arms on AppWorld's standard 168-task held-out split, zero worker
failures, $5.94 metered over 866 episodes.

  A  no memory        49 solved   TGC 29.2   SGC 14.3   147,087 tok/ep
  B  passive          52          31.0       16.1       128,872
  B2 passive, repeat  55          32.7       16.1       135,423
  C  governed         49          29.2       10.7       157,205

The noise floor is +1.8 points: two identical passes of one arm differ by 3
solved tasks and 31 discordant ones, p = 0.72. Nothing clears it. B vs A is
+1.8 at p = 0.74. C vs B is -1.8 at p = 0.71. C vs A is an exact tie, 49
each, 20 tasks won by each side -- the governed arm changed which tasks it
solved, not how many.

An apparent 12% cost saving does not survive pairing: B's median episode is
7.4% cheaper than A's, but 92 tasks got dearer against 76 cheaper (Wilcoxon
p = 0.68). The aggregate saving came from a few runaway episodes in A, not
from the typical task. The claim was made internally before it was paired,
and pairing refuses it.

What survives independent of the score is the gate's ledger: 100 rules
proposed, 4 approved, 44 refused with reasons, and five of those refusals
were rules that would have been actively wrong -- four inventing AppWorld
endpoints that do not exist, one contradicting the Spotify API. In an
ungoverned skill library those five reach the prompt.

It is not evidence the rules were bad. Four sensible rules on authentication
and parameter validity, drawn from the failures that dominate this agent's
transcript, read on every one of 168 episodes, converting into zero extra
solved tasks. The likely reading -- a reading, not a finding -- is that for
this model knowing the protocol was never the binding constraint:
phone.login fails on its own 13 times in the passive block, and an agent that
cannot authenticate is not helped by being told to authenticate first.

## What outlives the track

crates/areev-bench/CLAUDE.md -- the crate had none while six others do, which
is a plausible reason every harness in it drifted the same way. Five product
surfaces a harness keeps reimplementing (ASSEMBLE under a token budget, saved
queries, CAL's own renderers, record_tool_call's call/result lifecycle,
namespace prefix scope), each with what hand-rolling forfeits and -- checked,
not assumed -- who follows it today. Plus the seven rules that produced every
result in this crate: positive control before scoring, ceiling probe before
learning, pin every leg and verify it binds, never change a harness after
seeing its result, refuse a score over a short denominator, publish a null as
a null, keep a keyless floor.

scripts/cal_assemble.py -- the shared ASSEMBLE builder and the parity smoke
that must pass before a harness switches to it: same grains as the
hand-rolled path, byte-identical between calls, budget actually binds, no
format loses rows. Green on five real memories from four tracks. It also
corrected a claim: toon is not universally cheapest -- its tabular header
costs more than it saves under about four rows.

## Method, and the checks that make the null readable

AppWorld pinned at commit 42b5bcf (0.2.0.dev0, data 0.2.0), installed beside
the repo and unmodified. Agent qwen3-30b-a3b-instruct-2507 pinned to
OpenRouter's StreamLake upstream, temperature 0, seed 100. Learner and GROUND
gpt-oss-120b on deepinfra/bf16; reviewer gpt-4o called at api.openai.com
directly. Arms generated from one base by make_configs.py so the only
difference between them is the memory switch, asserted by a keyless test that
each arm's prompt is arm A's prompt plus its own block, byte for byte.

Before any arm ran: 147/147 ground-truth solutions scored TGC and SGC 100.0
(the scoring path can score); a ceiling probe returned non-zero (the domain is
reachable); the failure taxonomy found the lever (46 401s in 6 of 11 tasks);
and three workers were shown to score the probe identically to one, 319s
against 1300s.

Six defects were found before any arm was scored, three of which would have
produced a number rather than an error: the passive block assembling with
every error message empty (tool_content vs content), API errors attributed to
the last call in a chunk rather than the one that failed, and a dead worker a
sweep reported as success (usage: null plus POSIX wait returning 0) -- the
first parallel run scored 9 of 11 tasks and called it a result.

Recorded as a limitation while the arms were still running: both blocks are
assembled with RECALL plus host-side Python where CAL's ASSEMBLE is the
surface that exists for it. The comparison stays internally valid -- the arms
differ only in their block -- but the run demonstrates less of the system than
it should, and a re-run under ASSEMBLE is pre-registered.

No harness's production path is switched here: appworld's own blocks remain
hand-assembled and APPWORLD.md says so, receipts and tau2 have published
numbers from that path, and persist belongs to another session.

Granular history is preserved on branch bench/appworld.

Claude-Session: https://claude.ai/code/session_01JEcv3k8mMwZ5YAa26jdLc2
… them

`crates/areev-bench/CLAUDE.md` has graded this crate's adherence to Areev's
own surfaces for a while, and the grades were honest: ASSEMBLE **none**,
saved queries **none**, CAL rendering **partial**, tool-call lifecycle
**partial**, prefix namespaces **none**. Every step a harness hand-rolls in
Python is a step the published number does not demonstrate. This moves the
harnesses onto the surfaces, and the interesting part is what stood in the
way.

**A parenthesised ASSEMBLE source needed to carry its own pipeline.** Byte
parity needs rules sorted inside a section, which is `sorted(set(...))` in
every harness. CAL could not do it: `ORDER BY` inside a source was
`CAL-E002`, and at the statement level it is skipped with `CAL-W016` — whose
own remediation text says to "put the stage on that source's sub-query". The
warning named a fix the parser refused.

**That fix is NOT in this commit.** It was implemented here first, then the
same feature landed independently on main as #215 (for #209), and this branch
was rebased onto it with its own near-identical copy dropped rather than
merged — `crates/areev-cal/src` is byte-identical to main. What survives here
is the part main does not have: four integration tests covering ORDER BY
inside a source, two sources ordering opposite ways, a stage running before
the budget, and a LITERAL beside a staged source; plus the `cal-reference.md`
paragraph documenting the position. They pass against main's implementation,
which is the useful thing about having written them independently.

**`record_tool_call` takes `ns`, in both bindings.** It was the only write on
either surface that could not leave the session namespace, so a host
recording calls into per-domain child namespaces had to open a second handle
— which the single-writer registry refuses (STO-E002). Python `ns=`, Node
`ns`, `index.d.ts` regenerated by napi, a test each.

Every model-facing block that can be is a saved ASSEMBLE query registered in
the memory file and rendered by a registered template. That is the point of a
saved query: it persists as a `qry:<name>` meta row, travels with the `.db`
and replicates through bundles, so a memory handed to someone else carries
how to read it instead of stranding the knowledge in whichever harness wrote
the file.

Tool calls go through `record_tool_call` in tau2 and appworld, keeping the
input, the call/result join, the status and the failure cause that
`add("tool", …)` discarded. AppWorld writes into nine `appworld.<app>`
namespaces and reads `"appworld.*"`; run 1's four memories were migrated and
swapped into that shape (`migrate_ns.py --swap`), with the flat originals kept
beside them as `.flat.db` and both forms verified to render identical blocks.

The governed learning pass is an `areev run` workflow — propose → review →
apply, where `review` is a client node. The run parks, and answering it is
`run_respond`, which structurally refuses a responder equal to the principal
that triggered the ask (RUN-E012). Separation of duties was a convention of
each harness; it is now enforced and journaled by the runtime, and
`run_verify` byte-compares a replay.

**It is the only path.** `memory.learn()` in every track delegates to
`bench_run.learn()` and the unjournaled review loop each one carried is gone,
so there is no second way to approve a rule — which also collapsed three
near-identical review loops into one. The edge is `decided == true`, not
`approved == true`: `apply` records dismissals too, and the ledger of what was
turned down is half the evidence. There is no `evaluate` node: the held-out
pass is a separate phase, and a node that skipped itself every time is
furniture.

The engine already does this on the GENERATION side — it dedupes candidates
on `dedup_key` and starts an exponential rejection cooldown (7d, 14d, 28d,
capped at 90) whenever a recommendation is dismissed, which harnesses get for
free by dismissing through `dismiss_recommendation`.

Review had no equivalent. A reviewer judging each proposal against only the
rules in force will approve a REWORDING of something it declined last month:
the reword carries a different `dedup_key`, so the cooldown never sees it and
nothing else was looking. So `propose` now also returns `prior` (what this
reviewer ruled on in the last 90 days) and `outcomes` (the held-out series the
Verify gate reads), both from saved queries registered by every track, and
each reviewer consults `prior` before spending a judge call.

The window is a literal in the query body: `SINCE $window` is refused
(CAL-E059 → CAL-E002), so a different window is a different saved query.

Found by checking the migration rather than trusting it. `ASSEMBLE` applies a
token budget whether or not you ask for one — the default is 4000, the ceiling
16000 — and when it binds it drops grains with **no warning**, while
`total_available` reports the POST-budget count, so a caller cannot tell a
full answer from a truncated one. Wrapping AppWorld's error SELECTION in an
`ASSEMBLE` returned **79 of 229** grains on run 1's own memory, and the
small-seed parity case was far too small to notice.

Two fixes. A read that is not composing model-facing text is a saved `RECALL`,
not an `ASSEMBLE` — the passive arm's tally is the harness's, so its query
should never have carried budget semantics. And every section that IS a
rendered block now states `BUDGET n tokens` explicitly rather than inheriting
the default; the value is the ceiling, used as a stated bound and not a
squeeze, because a binding budget would change published prompt bytes.
`parity_check.py` seeds 200 grains past the default and was confirmed to FAIL
without the fix.

Rule 4 of this crate is that a harness is never changed after seeing its
result, so the move had to leave the prompt bytes untouched — and "it does"
is a claim about output. `scripts/parity_check.py` keeps the retired
renderers verbatim, imported by nothing, and fails if CAL's block differs.
32 checks across five harnesses.

The care is warranted rather than ceremonial: `structure.py` had already
measured that CAL's DEFAULT `FORMAT markdown` scores 35 on receipts' grains
against the hand-assembled prompt's 141, because it prefixes every rule with
its subject and relation. So each track registers a template that emits its
published bytes exactly. `{{#if assembly.grain_count}}` in the header is what
makes a rolled-back rule set render the EMPTY STRING rather than a heading
announcing rules that are gone — without it the paired evaluation stops being
causal.

`scripts/selftest_run.py` is the second keyless gate: the governed pass
parks, refuses self-approval, applies on the approved edge, and replays.

Recorded rather than worked around, because they are worth more to the next
harness than to this one:

  frequency ranking           GROUP BY reorders; it projects no per-group
                              count a template could render (appworld)
  `valid_to`                  not queryable on facts (CAL-E060), not a
                              template variable (CAL-E042) (persist notes)
  `description` on skills     not filterable (CAL-E060); filtering on
                              `object` instead matches everything and does
                              not warn (persist skills)
  one row per group, by regex no text extraction, no per-group projection
                              (persist session titles)
  reshaping a JSON payload    parse `object`, remove a key, re-serialise
                              (selfimprove `fails_with`)

persist is therefore one section of four and selfimprove is none of it. Both
say so where they live. Forcing either would have meant changing stored
fields, hence content addresses, hence the evidence behind published results.

`BENCH-TEMPLATE.md` is the blueprint: the shape of a track, the copy-paste
form of the six surfaces, and the checklist. Each track then records its own
answers in an `AREEV.md` beside its harness code — namespaces, grains, saved
queries, the plan, and every surface it skipped WITH its reason. Six of them,
one per harness.

No published number. Run 1's AppWorld memories are migrated to COPIES
(`appworld/migrate_ns.py`; a namespace is part of the content address, so
there is no in-place move) and the originals are untouched — verified to
produce identical blocks either way, since a prefix scope selects the base
namespace and its descendants alike. Each track's design document records the
change and which runs precede it, per rule 4.

The external agent loops stay theirs: AppWorld's ReAct loop, tau2's
conversation driver and PAST-Bench's runtime adapter own their control flow
and call us. Making those runs would mean maintaining forks of three upstream
benchmarks.

One correctness fix rode along: `tau2/episode.py` paired a `ToolMessage` with
the last call in the turn, so a multi-call turn attributed every result to
one of them — and that is the evidence the proposer reads. It now joins on
the `tool_call_id` the environment echoes back. No tau2 learning number is
published, and the ceiling-probe numbers precede it.

Gates: workspace tests, clippy -D warnings, 125 pytest, 72 node tests,
check_versions, repo_stats --check, the keyless A/B/A/B shape assertion, and
the two new keyless gates above — all re-run after the rebase onto 1.7.4.

Claude-Session: https://claude.ai/code/session_01DuZicDor5HvNyeRd1n2t74
This branch's AREEV.md files named five reads that could not move into CAL,
each with its error code. That precision is what got them fixed: all five
were filed as issues, and #206, #207, #208 and #209 are on main as of 1.7.4.
The notes said "cannot", and they now read as history rather than as a
constraint on the next bench.

Per file:

- persist/pastbench: `valid_to` is queryable and renderable (#206), and
  `description` is filterable on skills (#207) -- so two of that track's
  three harness-assembled sections can move into CAL. The second one mattered
  most: filtering on `object` instead used to match every row without
  warning, which would have put retired skills back in a prompt silently.
  Negations now fail closed on any type and any field. Session titles are
  still the harness's, for a narrower reason -- text extraction landed
  (#210), per-group counts landed (#209), but first-of-group did not.

- appworld: the passive arm's frequency ranking is expressible (#209), with
  the query and template written out. The run-1 and run-2 figures in
  APPWORLD.md came from the harness tally, so they are flagged as not-CAL-
  output and moving the block is left to the next run's pre-registration --
  it is an arm-defining change, not a doc sweep.

  Its ASSEMBLE note is updated rather than removed: the budget still binds
  and 79 of 229 is still the wrong answer for a selection, so keeping that
  read a saved RECALL still stands. What changed is that the drop is no
  longer silent (#208, CAL-W017, and a pre-budget total_available).

- src/selfimprove: reading into a JSON payload landed (#211), so the gap
  narrows to reshaping -- parse, remove a key, re-serialise -- which was
  declined on purpose rather than left undone. The five-gap table now carries
  a status column, plus the sixth (ASSEMBLE's silent drop) that surfaced
  while fixing the others.

Docs only; no harness behaviour changes here. The one cross-doc reference is
a plain path, not a link, because this branch predates that file's merge.

NOTE for whoever rebases this branch: 3ef70e4 adds `NamedSource.pipeline` and
runs it in `execute_source`. Main now has the same feature, from #215 (#209
needed it so a frequency roll-up could be an ASSEMBLE section). Drop this
branch's copy during the rebase rather than merging both.

Claude-Session: https://claude.ai/code/session_01JEcv3k8mMwZ5YAa26jdLc2
… raises

1.7.4 closed four of the five gaps these harnesses named (#206-#209), and
a fifth (#208) that surfaced while fixing them. The AREEV.md files already
say so. This is the code catching up -- and, as importantly, the part that
deliberately does NOT move.

## What moved

**persist's Skills section is CAL** (`persist_skills($ns)`). A retired skill
is marked by writing `description: "retired"`, and `description` was not
filterable on skills; #207 made it so, so the filter that had to live in
Python is a `WHERE` clause in the file. Byte-identical, and
`parity_check.py persist` asserts both halves: the block matches the renderer
it replaced, and a retired skill does not render. That second assertion is
the one that matters -- before #207, pushing this filter down on `object`
instead matched every row *without warning*, which would have put retired
skills back into an agent's prompt in silence.

## What a budget drop does now

`cal.section` and `cal.rows` **raise** on `CAL-W017`. Since #208 an
`ASSEMBLE` that trims to its budget says so; a harness that printed that and
carried on would be publishing a number produced from a truncated prompt,
which is the failure the ticket was filed for. `parity_check.py` now asserts
both directions -- 200 grains survive a stated budget, and a budget that
binds raises rather than quietly shortening the block.

Worth stating because the earlier note was too comfortable: the 16000-token
ceiling is a stated bound, **not** a guarantee of no trimming. 300 long
grains still trip it. That is why the warning is checked rather than assumed
away.

## What did not move, and why that is the right answer

Two reads are now expressible and are still harness-composed on purpose:

- **AppWorld's passive arm** (frequency ranking, #209) and **persist's Notes**
  (`valid_to`, #206). Moving either changes the prompt an arm was measured
  under. persist has published runs 1-4 and AppWorld a pre-registered null, so
  that belongs in the next run's pre-registration, not in a refactor (rule 4).
  Both queries are written out in the AREEV.md files, ready for whoever
  pre-registers them.

  persist's Notes has a second reason worth recording: the selection is
  expressible but the render is not. A note or lesson renders as its bare
  object while any other durable fact renders as `subject relation: object`,
  and the retired reader interleaved both shapes in one recall-ordered list.
  CAL orders *within* a section and a template branches only on truthiness --
  there is no value comparison -- so two sources would emit two runs of lines
  instead of one interleaved run.

- **persist's session titles** need FIRST-of-group, which #209 did not land,
  and **selfimprove** needs to reshape a JSON payload, which #211 declined on
  purpose. Both stay open in the docs as what they are.

## Housekeeping

`docs/repo-stats.*` and the two SVGs are regenerated: `--check` had drifted to
2.03% on `test_code`, past the 2% tolerance, mostly from 1.7.4's own new test
files (`cal_expressiveness.rs`, `assemble_budget_visibility.rs`) plus this
branch's. Generated, not hand-edited, as `CLAUDE.md` requires.

Gates: 2,704 workspace tests, clippy -D warnings, 125 pytest, 72 node tests,
`repo_stats --check`, `check_versions`, and the crate's two keyless gates
(36 parity checks, 22 governed-run checks).

Claude-Session: https://claude.ai/code/session_01DuZicDor5HvNyeRd1n2t74
The two reads that were expressible-but-deferred are now CAL. Neither is
byte-identical, which was the reason to defer them; that call was overridden
deliberately, so what follows is the record of what moved and in which
direction -- rule 4 asks for the reason and the runs that precede it, not for
the change never to happen.

## persist's Notes (#206)

`valid_to` filters, sorts and renders since 1.7.4, so an expired note is
excluded by the query and a live one carries its own `(until 2026-10-01)`
label from `{{grain.valid_to | date}}`. `session:` and `evalset:` subjects are
excluded in the `WHERE` rather than in Python.

**What changed**: two runs of lines instead of one interleaved run. A note or
lesson renders as its bare object, any other durable fact as
`subject relation: object`, and the retired reader interleaved both in one
recall-ordered list. CAL orders WITHIN a section and a template branches only
on truthiness, so the two shapes cannot share a source. Same grains, same
per-section order. Runs 1-4 precede it.

## AppWorld's passive arm (#209)

`GROUP BY tool_name COUNT` plus the `group.*` variables, rendered as
`- ({{group.count}}x) {{group.key}}`.

**What changed, and this one deserves the emphasis**: the block ranks
ENDPOINTS where it used to rank (endpoint, message) pairs and print the
message.

    was:  - (6x) phone.login: Response status code is 401:
    now:  - (6x) phone.login

Not a choice. A template cannot render a Tool grain's body -- `tool_content`
is rejected as a variable (CAL-E042) and `content`/`object` resolve empty,
while the built-in `markdown` renderer prints it happily -- and `GROUP BY`
takes one field, so `(tool_name, message)` cannot be a key. Filed as #217.

**The direction matters more than the size.** This is the BASELINE arm the
governed arm has to beat. Dropping the error message makes that baseline
weaker, which flatters the loop. An agent told `phone.login` failed six times
learns less than one told it failed with a 401. Any run under this block must
say so, and `APPWORLD.md` and `appworld/AREEV.md` both do; run 1 precedes it
and is not comparable on the passive arm's prompt.

## A bug in the shared reader, found by the new tests

`cal.section` quoted every saved-query parameter, so `$now = "1788922013848"`
compared a string against a numeric field and `valid_to > $now` selected the
wrong rows -- silently, since neither side errors. Literals are now rendered
by type. It only surfaced because #206 is the first read here to bind a
number.

## Reducing the stats drift

`repo_stats --check` went red at 2.03% on `test_code` last round, and the
cause was timing rather than tolerance: 1.7.4's #212/#213/#215 added 1,090
lines of test code between them without regenerating, and the next branch to
touch the tree inherited a gate it did not trip. `test_code` gets there first
because it is the smallest fast-growing denominator in a test-heavy repo --
~1,100 lines is already 2%.

So, two changes that attack the timing:

- `.githooks/pre-commit` (installed by `scripts/install-hooks.sh`) regenerates
  the artifacts when the tree has drifted past **1%**, half the gate, and only
  when the commit touches a file that can move the numbers. Most commits pay a
  few hundred milliseconds and print nothing; the numbers refresh in the
  commit that moved them. Verified both ways: silent on a current tree, and it
  fires and self-heals on a simulated 2.07% drift.
- CI warns at 1% before failing at 2%, so the news lands on the PR that added
  the code rather than on the next one.

Documented in `CONTRIBUTING.md` (getting started) and the root `CLAUDE.md`.

Gates: 2,704 workspace tests, clippy -D warnings, 125 pytest, 72 node tests,
repo_stats --check, check_versions, 41 parity checks, 22 governed-run checks.

Claude-Session: https://claude.ai/code/session_01DuZicDor5HvNyeRd1n2t74
`persist/pastbench/areev_backend.py` imports PAST-Bench and
`persist/horizon/areev_agent/agent.py` imports harbor, so neither loads in
this repo — which means a rename or an arity change in `prompt.py` would be
found by a paid run on somebody else's machine. That is the most expensive
place to find it, and this round created exactly that risk twice:
`skills_block` went from taking a dict to taking a handle, and `notes_block`
gained a parameter.

So parse them instead: resolve what the backend imports from `prompt`, and
check every call site's arity against the real signature. It cannot catch a
wrong value — only running the benchmark does that — but it catches the class
of break this crate's own refactors keep creating.

Claude-Session: https://claude.ai/code/session_01DuZicDor5HvNyeRd1n2t74
"Which tool fails most" is the first question anyone asks a memory of tool
calls, and #209 answered it. The message is the half that says what to DO
about it — an agent told `phone.login` failed six times learns less than one
told it failed with a 401 — and CAL could produce the endpoint or the
message, never both. Three gaps, each independently a silent-no-op:

- A template could not render a Tool grain's body. It is projected as
  `tool_content` (the compact key `cnt` expands to it), which every built-in
  format prints; the closed template-variable set did not contain the name,
  and §10.3.2's content projection for `tool` read `object`, which a tool
  call does not carry. So `{{grain.tool_content}}` was CAL-E042 and
  `{{grain.content}}` rendered the empty string beside a `FORMAT markdown`
  render of the same grain that printed the body happily.
- `GROUP BY` took one field, and `tool_content` was not a queryable field on
  Tool, so neither `(tool_name, tool_content)` nor the message alone could
  be a key.
- A `LIMIT` written after `COUNT` did not bind. It fell through to the
  inert-payload arm and every group came back, so a block asking for the
  worst twelve listed all of them.

What lands:

- `GROUP BY a, b [, c, d]` — up to four fields joined into one key with
  " · " (CAL-E123 past that, a new code). A composite row carries its parts
  as `keys` beside `key`; a single-key row keeps the exact shape 1.7.4
  documented. `{{group.key.<n>}}` renders one part, numbered the way
  `split(sep, n)` numbers its fields and the way a dotted path numbers an
  array segment. On a single-key row `key.0` IS the key, so one template
  renders both arities and the `group.` set stays closed.
- `tool_content` joins the template-variable sets and Tool's queryable
  fields, and the content projection for `tool` reads
  `tool_content → content → object` — the same cascade the built-in
  renderers use, so the surface that renders a grain and the surface that
  filters it agree on what a tool call says. `DESCRIBE FIELDS tools` lists
  it, which is what makes it discoverable rather than folklore.
- `LIMIT`/`OFFSET`/`FIRST` bind to a grouped count. `total_available` keeps
  reporting how many groups the ranking HAS — a page that reported its own
  length would be a truncated answer indistinguishable from a whole one,
  which is the failure CAL-W015 and CAL-W017 exist to prevent.
- CAL-W018 when a group key names a field no grain carries. Every row then
  falls into one group under the empty key, which is exactly the shape of a
  ranking whose top value dominates. The issue found it as `GROUP BY tool`
  (the registry advertises `tool`; the store projects `tool_name`). `WHERE`
  has failed closed and said so since #207; the grouping path was silent.

The grammar change is a spec-level decision, so it is written down:
docs/oms-1.7-amendments-cal-expressiveness.md gains B5/B6/B7, and
ARCHITECTURE.md §10 amends "CAL grows by closed sets". B6 relaxes an
existing rule rather than adding one — `SELECT` and `PROJECT` already take a
comma-separated field list in the same parse position, and no keyword,
statement form or operator is added. The JSON wire form still accepts the
singular `"field": "x"` spelling.

Tests pin the ranking rather than only its presence: the fixture ties on
count so the key-ascending tiebreak is exercised, asserts a single-key row
carries no `keys` array, asserts `key.1` is null where there is no part 1,
and renders the bounded composite ranking as an ASSEMBLE source — the shape
a prompt section actually has, and the one that needed all three halves to
land together.

Claude-Session: https://claude.ai/code/session_016YzyEfdWprezzATrZGNtg8
The passive arm moved into CAL when #209 landed and lost the error message on
the way, because a template could not render a Tool grain's body and a group
key could name one field. It ranked endpoints:

    was:  - (6x) phone.login: Response status code is 401
    then: - (6x) phone.login

That direction is the point. The passive arm is the BASELINE the governed arm
has to beat, so a block that says where an agent fails but not why makes the
baseline weaker — a bias in exactly the direction that would make the loop
look better. #217 closed the three gaps, and the block ranks what it always
ranked: `(endpoint, message)` pairs, most frequent first, cut at twelve.

    ranked: (RECALL tools WHERE namespace = $scope AND is_error = true
             LIMIT 400 GROUP BY tool_name, tool_content COUNT LIMIT 12)
    -- - ({{group.count}}x) {{group.key.0}}: {{group.key.1}}

The top-twelve cut is the engine's now rather than a Python slice, so the
whole read — scope, filter, ranking, bound, render — is one saved query the
memory file carries. No run was produced under the endpoint-only block, so
runs 1 and 2 stay comparable; AREEV.md and APPWORLD.md record that rather
than leaving it to be reconstructed.

parity_check's "200 distinct endpoints all reach the ranking" asserted the
pre-#217 shape, where the block listed everything because the bound did not
bind. It becomes two checks that are worth more: the ranking is cut at
PASSIVE_TOP_N (a bound the block ASKED for, applied before the budget ever
sees it), and the most frequent pair leads — seeded to sort LAST by key, so
it can only lead if frequency really orders the rows. The silent-budget-drop
case the old check guarded is still covered, by the 200-rule check beside it
and by cal.section raising on CAL-W017.

Also corrected: areev-bench/CLAUDE.md still said AppWorld's passive arm was
deliberately not moved. It moved in 31b4fc9; the bullet had not followed.

Claude-Session: https://claude.ai/code/session_016YzyEfdWprezzATrZGNtg8
`_next_run_id` read `db.run_list(500)` as a list of row objects and called
`.get("run_id")` on each. It answers `recent_runs` — a list of run ID
STRINGS — so the comprehension raised

    AttributeError: 'str' object has no attribute 'get'

The first `learn` of a pass returns early (no journal yet), so this only
fires on the second one, which is every dryrun with two checkpoints:
`receipts/dryrun.sh` and `dryrun_drift.sh` both died there, taking the CI
`python bindings` job with them on both runners. It went unseen because the
branch had not been pushed, and the whole point of that step is that a
harness producing a published number cannot rot silently between runs.

The set now takes the string when the row is one and still reads `run_id`
off an object, so a later shape change does not re-break it.

Claude-Session: https://claude.ai/code/session_016YzyEfdWprezzATrZGNtg8
@sathish-mg
sathish-mg merged commit 247393c into main Sep 9, 2026
19 checks passed
@sathish-mg
sathish-mg deleted the bench/areev-surfaces branch October 22, 2026 18:09
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.

CAL: a Tool grain body is unrenderable in templates and ungroupable, so a failure ranking can name the endpoint or the message but not both

1 participant