Skip to content

feat(standard): send recorded model calls again under a spending cap, and compare them - #344

Open
pierreleca wants to merge 36 commits into
ThinkFlowLab:mainfrom
pierreleca:feat/replay-and-study
Open

pierreleca wants to merge 36 commits into
ThinkFlowLab:mainfrom
pierreleca:feat/replay-and-study

Conversation

@pierreleca

@pierreleca pierreleca commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Closes #343

What

  • Testing one step's prompt change meant rerunning the whole task.
  • nullius standard replay JOB TRIAL --call N --times K --max-usd USD rebuilds call N from the exchange record, checks its sha256, sends it K times.
  • Changes: system text, tools, replaced text, dropped messages, parameters, model, provider, pin, a command.
  • Its own relay at the job's provider and price; a send goes out only if its worst case fits the cap; --dry-run sends nothing.
  • Answers are labelled by first tool call or a command, and counted; a 200 ending in error fails.
  • study: many calls, named arms, one cap, a sign test; a rerun sends only the unanswered, under its cap or a higher one.
  • recount: a study or replay re-read by another rule; no send, no key.
  • One folder outside the job; no page reads it.

Verified

  • Backend 190 modules, 3,329 tests; routes 77, 848: nothing fails that main passes.
  • The review's cases, scripted: an 8,192-token limit under --max-usd 0.001 sends nothing; a stopped study resumes under a higher cap; a cut answer is resent.
  • Not checked: a real provider.

Risk

  • Paid calls with a key.
  • Can pass the cap:
    • pictures, or a changed prompt, above its estimate;
    • a provider's reported cost above the price list;
    • an answer past the request's output limit.
  • The key is never written; echoed credentials are cut out.
  • Undo: revert.

Agents

  • Claude Code, Opus 5.5
  • Codex, gpt-6-astra
  • Claude Code, Fable 5.2

@pierreleca
pierreleca force-pushed the feat/replay-and-study branch from d80823d to 847db95 Compare November 24, 2026 11:21
aitianshi added a commit that referenced this pull request Nov 24, 2026
Closes #379

## What

Before a live feed exists, a run now opens on Logs. Launch stages and
log output live there; the first usable feed switches to Live within the
same document, without reloading. Explicit tab choices are respected.
Restarted stages drop stale timing/detail, terminal executions settle
stage state, and unknown unit totals use an indeterminate bar.

The full-run overview shows identity cards with Runner first, then
Benchmark/Dataset, Agent/Model, and Trials/Duration. Task and All
attempts pages keep their own status and metrics without repeating run
identity.

Task overview cards put timing and Tool calls on the left and Model
usage on the right, stacking on narrow screens. Model usage combines a
compact token bar with Prompt growth when multiple calls were recorded.
Its labels and segments are input, cache, output; input means uncached
input, as its tooltip explains. Cache hit is plain text. Saved trial
totals provide a fallback when trajectory accounting is absent, and
missing usage is stated explicitly.

## Touches

backend · routes · templates and static · tests · field guide

No equivalent open or closed issue/PR was found in the repository or
private fork. Related open work: #336 (run facts), #338 (trial details),
#340 (task step progress). These have shared-file overlap, but implement
separate behavior. After merging main, pairwise merge checks are clean
for #332, #336, #338, #340, #342 and #344. Unmerged #352 and #354 still
require coordination in app/templates/runs/job.html and app/web/runs.py;
their features are not included here.

## Before and after

Task overview: the earlier real-run capture and the approved final
layout from that same saved run. Run identity is now kept on the
full-run overview.

| Before | After |
| --- | --- |
| <img width="430" alt="Earlier task overview with separate growth and
tool sections"
src="https://raw.githubusercontent.com/ThinkFlowLab/nullius/feat/run-logs-tab/app/ui_tests/evidence/run-logs/task-after.png">
| <img width="430" alt="Timing and Tool calls on the left, combined
Model usage on the right"
src="https://raw.githubusercontent.com/ThinkFlowLab/nullius/feat/run-logs-tab/app/ui_tests/evidence/run-logs/model-usage-after.png">
|

Full-run identity cards and Live/Results/Logs:

<img width="860" alt="Full-run overview with Runner first and benchmark,
dataset, agent, model, count and duration cards"
src="https://raw.githubusercontent.com/ThinkFlowLab/nullius/feat/run-logs-tab/app/ui_tests/evidence/run-logs/run-overview-after.png">

## Verified

- Backend suite: 2,856 tests in 173 modules passed after merging current
main outside the socket-restricted sandbox.
- Route suite: 660 tests in 68 modules passed after merging current
main.
- Focused progress and execution tests: 83 passed.
- Browser checks: desktop light/dark and narrow layout; automatic Logs →
Live retains the document and `performance.timeOrigin`; tab selection
and task metrics checked.
- Real τ³-bench Airline task using `meta/muse-spark-1.3-contributor`:
reward 1.0, 55.54 seconds agent time, 22 steps. Recorded uninterrupted
from cold setup through Logs → Live, Results and the task page. The
simulator and judge used `openai/gpt-4.1` because the configured dated
default alias was unavailable. The earlier refused attempt was not
counted as this successful run.
- Field-guide checks: 2 passed. Usage regression cases cover one call,
multiple calls, final metrics, trial totals, unreadable trajectories,
missing usage and output-only records.
- `git diff --check` passed.

## Risk

Feed readiness and polling changes could leave a preparing page on the
wrong tab; explicit choices must not be overridden. A terminal execution
now settles a remaining stage even if its final stage event was absent,
but does not manufacture a duration or unit count. Runs without launch
records have no Logs tab. The overview derives the benchmark from the
catalogue or a single recorded task source. The token summary preserves
existing trajectory cache accounting; partial per-call records can still
describe only the recorded subset. Revert to undo; no storage migration.
…ting

A custom provider without a key is sent a placeholder word. The run
wrote that word itself, while the launcher and the judge read it from
settings.MODEL_KEY_PLACEHOLDER. Reading it from the setting here too
lets every reader of a run's requests know which word is no secret.
…elay's record

A trial's call record keeps the last two messages of each model call,
cut to 2,000 characters and without pictures: what the model was shown
at a step is lost. Each unit's relay now also keeps every call of its
agent whole under the trial's .work/relay/exchanges: the request as
sent and its sha256, each distinct part and picture written once, and
the reply as it arrived. Only the relay's key is cut out. A failure to
write never changes or stops the reply, and each file names its format
so that a later one is refused rather than guessed.

run --exchanges whole|text|off (whole by default) and
--exchanges-max-mb N (256 a unit by default) choose and bound it; the
job's config records both and a recipe takes them. The judge's and the
simulated user's calls keep their call record alone.
… model calls

A recipe could take the exchange record's mode, but the builder had no
way to set it. The Limits step now has three small cards under the
spending caps: Pictures and text (the default), Text alone and Nothing.
A choice other than the default goes into the recipe and onto the run's
command line; the default adds nothing. A run that calls no model shows
no cards.
The record of a trial's calls is only useful once something reads it.
traces/calls.py builds a trial's conversation by model call from it:
each call's time, tokens and cost, what it sent that the call before
had not (pictures by their sha256), its answer whole and the steps of
the trajectory under it. A store of a later format is refused with a
notice, and a trial without a store reads as before.

runs show ... --calls prints that view as JSON, redacted.
runs show ... --call N --request prints call N's request rebuilt to the
bytes sent and says on stderr whether its sha256 is the recorded one.
Both find an earlier try of a trial by its NAME.try-N.
…ures

The Conversation tab lists the steps of a trajectory, and the pictures
an agent sent its model show nowhere. A trial with an exchange record
now opens the tab on its model calls, twelve a page: the selected call
shows what it sent that the call before had not, its answer and the
steps under it. A picture is served from the trial's own store by its
sha256, only when that store lists it and only as an image type; a
click opens it in a dialog over the page, and a click with a key held
opens it in a tab of its own. The Artifacts tab counts the pictures and
their size, with a link to the tab.
Testing a change of prompt on a model call that went wrong means
running the whole task again. replay rebuilds call N of a trial from
its exchange record, checks it against its recorded sha256 and sends it
K times, as it was or with named changes: the system text, the tools, a
tool's description, a replaced text, the last messages dropped, a
parameter, the model, the serving providers, the provider, or a command
of the user's. It goes through a relay of its own, under the job's
provider, model and price, and stops at the required --max-usd. Each
answer is read by a rule and the distinct answers are counted.

--list lists a trial's calls and --dry-run sends nothing. Everything is
kept in one folder outside the job. The key is read from the
environment or the saved settings and never written, and credentials
echoed in an answer are cut out. A new page documents the command and
its use from Python.
…nt them again

One replay shows how a single call answers; whether a change helps
needs many calls of several trials, each sent as recorded and changed,
compared call by call. study sends each target (lines of a file, or the
calls of a job's trials: all, every Nth, or those whose recorded answer
matches) K times as recorded and under each --arm NAME=CHANGES, under
one cap for the whole study. One reading rule, kept before the first
send, labels the answers; the counts give a table by target and arm,
and two arms are compared with an exact sign test. The same command
again goes on after a stop, and a changed plan is refused.

recount reads a kept study or replay again by another rule, with no
send and no key. The replay page gains a section with one worked study,
and a test runs the page's own reading script.
@pierreleca
pierreleca force-pushed the feat/replay-and-study branch from 847db95 to 6739601 Compare November 24, 2026 13:55
The Artifacts tab lists the pictures sent to the model first, then
Nullius's records, then the benchmark's own under their heading row.

The trial's page imports main's evidence reader beside the calls, and the
builder's Limits row keeps main's words on attempts and retries, with
what each trial keeps of its model calls after the cap on them.
The calls branch now stands on main with the trial's detail and records,
the builder's new words and the job's identity cards. Nothing of this
branch's conflicted.
The rows this branch added on the exchange record retold the relay's
code: its file layout, its version line, its retries and its failures.
The record's section keeps two sentences and the rows a user chooses or
meets: the text mode, off, the bound, what is not kept and where the
result names it. The read-jobs rows and the builder's Limits row each
say what the command or the choice is.

Two clauses of the standard's Progress and Outcomes rows described the
live feed's steps and a scored cut, which this branch does not hold; one
linked a section it does not have. They go back to main's words.
The calls branch cut its section on the exchange record to the rows a
user chooses or meets. This branch's row on a request sent again stays,
before the result's row.
The page retold the code: the folder's files one by one, the calls from a
program and a worked study of the same commands. It keeps the two
synopses, a row of ten to fifteen words for each option or rule a user
meets, and the reading script its test runs. The run page's row on a
request sent again links to it.
The calls branch this one builds on is now on main, with the reviewer's
own edits to the builder and the run page: main's text wins in every
file of that branch. This branch keeps only the replay and the study.

AGENTS.md takes main's shorter form, which has no module list: the
replay and study entries in it go. The run page's row on a request sent
again stays, before the result's row.
…age does

The run page and the builder now say a run saves its model calls. The
replay page used the older word for the same choice.
…in the replay and study

The run's choice of what its relay holds of each model call is now
named "Model calls saved", and the run page says the relay saves each
call. The replay and the study used the older word in their help, their
messages, their docstrings and their page, and the recount's count of
answers missing from the record was named not_kept. They now say saved.
Main changed its instructions and templates alone: no file of this
branch is touched, and nothing conflicted.
@pierreleca
pierreleca marked this pull request as ready for review November 25, 2026 10:16
@github-actions github-actions Bot added the needs review Tests pass, no conflict, no verdict on its latest commit label Nov 25, 2026
@aitianshi

Copy link
Copy Markdown
Collaborator

@pierreleca Tried at 7f62584 on GSM8K with a scripted model (no real provider). Three things to fix, and one question.

  1. The cap can be passed. replay --times 1 --max-usd 0.001, booked at 0.000272, got a 5,000-token answer: spent 0.0102 USD of 0.001. The issue asks that no send go past the cap. Could it be enforced, or the promise reworded?
  2. A study that reaches its cap cannot go on. The same command is refused again (the ledger is closed), and a higher --max-usd is refused too (has a cap of 0.001 USD). Could the cap be raised?
  3. An answer cut by an error counts as an answer. HTTP 200 with a partial text and finish_reason: "error" in the choice: study with --read counts it as not yes, says done, and a restart does not send it again. A reply that is only an error is retried correctly.

Question: how is a replay meant to be used? Today it is the command line only, and nothing follows the new answer: the task is not re-done from that step. Is a button planned on the trial page's call (edit the prompt, send K times, see the counts)? Re-doing the whole task with the changed prompt? Or is it command line only? Please say which, and what is left for a later PR.

A replay or a study booked a call at the ledger's estimate, a guess of its
answer's length, and a long answer could end past --max-usd: a cap of
0.001 USD spent 0.0102 on one answer of 5,000 tokens.

Each send is now booked at its prompt plus the most its answer can cost:
the request's own output limit, else the price list's, at the output rate.
The booking is held until the real cost replaces it, for every send in
flight. A send whose most does not fit what is left is not made, and the
refusal names the cap one send needs; a request whose answer nothing
bounds is refused with the change that bounds it. The dry run prints the
booking beside the estimate.

The relay takes this booking from its caller; a run's own booking is the
estimate as before.
A study stopped by its cap could not go on: the same command met a closed
ledger, and a higher --max-usd was refused because it differed from the
first one.

Each start now opens the study's ledger again under the cap it is given,
if that cap is above what was spent. The ledger keeps each cap it
replaced with the spend under it, and each start records its own cap. A
cap at or below the spend is refused with the amount spent; a changed plan
is still refused.
A reply of HTTP 200 whose choice ended with finish_reason "error", or
that held an error object beside a partial text, was read as an answer:
a study with a reading command counted it, said it was done, and never
sent it again. A reply that is only an error was already a failure.

Such a reply, and one that holds no choice at all, is now a failure as
well: not counted, sent again when a study goes on, and counted among the
failed sends; the default rule labels it as an error. A reply cut at its
output limit or by a content filter is still an answer.
…rt clause each

The rows the three fixes changed had grown past one clause. They now say
the rule alone: a send goes out only if its most cost fits, the dry run
shows the booking, and a study goes on under its cap or one above the
spend.
Targets whose requests have the same bytes share one booking in their
relay, by the request's sha256. The last target written set it: one
recorded without usage could replace the booking of one recorded with
10,000 input tokens, and the study then spent 0.024 USD under a cap of
0.018. The booking is now the largest of theirs.
A prompt token can be billed at the cached rate. A price row whose cached
rate is above its input rate let a reply cost ten times its booking.
The prompt's part of a send's most cost now uses the dearest of the
row's input rates, the cached one included.
Counting a reply that ends on an error changed the default reading
rule's code, and with it the fingerprint a study keeps in its plan. A
study planned before that change was refused on a restart as one with
another reading rule. The earlier default rule's fingerprint is now
taken as the same rule; a rule a user supplies is still compared as it
is.
A streamed chat reply whose events held no choice, or only an empty list
of choices, was counted as an answer. It is now a failure. The usual
last event that holds usage alone, after the choices, stays part of an
answer.
Replies saved before failures were marked carry no failed field, and a
restart kept those that ended on an error as answered. A saved reply
without that field is now classed from its end, its error and its body,
by the rule a new reply follows.
The five lines the last fixes added retold how a booking is computed and
how saved replies are read again. The page already states the rules they
serve: a send goes out only if the most it can cost fits under the cap,
and a reply that ends on an error or holds no choice is a failure that a
study sends again.
Brings the branch onto main for review. Git merged every file on its
own: main and the branch meet only in the standard CLI, in parts apart.
…red writer

Main now writes every record whole through ondisk.write_whole. The
replay's replay.json and the study's study.json were still written
beside and renamed by hand; they take the shared writer too.
@pierreleca

Copy link
Copy Markdown
Contributor Author

The three points are fixed in 07bb5aa8:

  1. The cap now holds against a long answer. Each send is booked before it leaves at the most it can cost: its prompt, plus its output limit. If that does not fit under the cap, nothing is sent, and the command says what cap one send needs. Your case now ends with nothing sent and nothing spent. Three cases can still pass it: a changed prompt that costs more than its estimate, a provider that bills above the price list, and a provider that answers past the request's output limit.
  2. A study's cap can be raised. The same plan run again with a higher --max-usd goes on and sends only what is unanswered. A cap at or below what is already spent is refused.
  3. An answer that ends on an error is not an answer. A partial text with finish_reason: "error" is not counted, and a restart sends it again.

How a replay is meant to be used: from the command line, on purpose. Its user is a person or an agent who studies one decision of a run. They change the prompt at one step, send that call K times, and count what the model does next, without paying for the whole task again. study does this over many calls and compares two arms.

It does not re-do the task from that step: the record holds the calls, not the environment's state at that step.

Why no page in this pull request: a button on the trial page's call (edit, send K times, see the counts) is hard to fit well into the pages for now. This pull request holds the library and its commands alone, as a safe first step. The button is left for a later pull request. Re-doing the whole task with a changed prompt is not planned.

@github-actions github-actions Bot added needs review Tests pass, no conflict, no verdict on its latest commit merge conflict Conflicts with its base: merge or rebase it and removed needs review Tests pass, no conflict, no verdict on its latest commit labels Nov 26, 2026
Brings the branch onto main for review. Main's task sets and the
branch's replay each added their commands to the standard CLI's table
of commands, on the same line: both are kept, main's first.
Main's task sets bind st to the set command's parser in the standard
CLI's main(). The study's parser took the same name further down, and
the checks after parsing read it by that name: they were right only
while the study's parser came after the set's. Each parser now has its
own name.
The standard run now takes --set NAME for a task set. Replay's
--set FIELD=JSON, which sets a top-level parameter of the request,
gave the same option a second meaning under one command group. It is
renamed --param, with its help, its refusals, its test and its page.
The values it takes and the change it records are unchanged.
… parser

The study's checks after parsing must call the study parser's error.
The test accepted any usage line, and a call to another parser's error
would still have passed. Each usage case now asserts the study's own
usage line and error prefix.
@github-actions github-actions Bot removed the merge conflict Conflicts with its base: merge or rebase it label Nov 27, 2026
@pierreleca

Copy link
Copy Markdown
Contributor Author

Merged main (bedda78f). One change with it: replay's --set FIELD=JSON is now --param FIELD=JSON, since run --set NAME names a task set.

@github-actions github-actions Bot added needs review Tests pass, no conflict, no verdict on its latest commit merge conflict Conflicts with its base: merge or rebase it and removed needs review Tests pass, no conflict, no verdict on its latest commit labels Nov 27, 2026
Main's run may now set each model's reasoning, which the relay takes as a
new keyword argument beside the replay's booking. Both are kept: the
relay sets the level on the request before its bytes are dumped, and the
booking then reads the bytes that go out.
Main now stops a run when the agent's first call is longer than the
model's context window, and the relay reads one more provider's words
for such an overflow. Replay and study count no unit's end: a send that
overflows is counted as failed, its booking is released, and the next
sends go out as before.
@github-actions github-actions Bot added needs review Tests pass, no conflict, no verdict on its latest commit merge conflict Conflicts with its base: merge or rebase it and removed merge conflict Conflicts with its base: merge or rebase it needs review Tests pass, no conflict, no verdict on its latest commit labels Nov 27, 2026
Main adds an HTTP API for other machines, and its paid action from a
shell, asking a judge, takes the exit codes' Paid actions row. Replay
and study keep their sentence in that same row, after main's.

Nothing else of main's reaches replay or study: LoCoMo's units, the
experiment judge and the release touch none of the modules they read.
@github-actions github-actions Bot added needs review Tests pass, no conflict, no verdict on its latest commit and removed merge conflict Conflicts with its base: merge or rebase it labels Nov 28, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs review Tests pass, no conflict, no verdict on its latest commit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A recorded model call cannot be sent again to test a change

2 participants