Skip to content

refactor(standard): sort the package into folders, share the file writer and split the trace reader - #290

Merged
aitianshi merged 17 commits into
mainfrom
refactor/standard-file-topology
Nov 23, 2026
Merged

aitianshi merged 17 commits into
mainfrom
refactor/standard-file-topology

Conversation

@aitianshi

@aitianshi aitianshi commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #289

What

Reorganises code without changing what it does; the few differences are under Risk. Four parts:

  • The standard. The 36 modules of app/nullius/standard/ move from one folder into eight, one per purpose; cli.py and kits/ stay at the top. No module is renamed. Every import, the wheel's package list, the docs, the skills and AGENTS.md follow. test_layering.StandardFolders keeps a new module out of the top of the package and keeps the folders importing one way.
  • nullius/ondisk.py (54 lines): a file written whole then renamed into place, a file lock, a sha256. It replaces the hand-written copies in 13 modules, four of which used one fixed temporary name that two writers at once collided on.
  • The trace reader. traces/trace.py (1,447 lines) becomes spans, fold, breakdown, waterfall and trace, its code moved whole.
  • Routes. The loopback-client guard sits beside the form-token guard (shared._local_client), and execute.begin checks and starts plans for the builder's Run, the Agents page's check and the Benchmarks page's proof.
  • What follows the moves. OSWorld1's driver asks the package for its folder, where it counted folders up from a file that moved. The check of an environment's network field moves beside the other field checks in definitions, so no two folders import each other. The field contract pins the moved classes under their new modules, with the same fields. NoFlask moves from test_charts.py to test_layering.py, and test_trace.py uses the builders tracedata.py already had.

Why now: main gained five loose modules in the standard in five days, and #282, #283, #284 and #286 are built on this layout.

Touches

backend · routes · the standard · catalogue (drivers' import lines) · docs and skills (paths) · CI (one import line in docker-tests.yml, the judge's path floor, the wheel's package list) · templates and static (four comments that name a moved module)

Before and after

Nothing visible changes. Of 450 pages fetched from this branch and from main over the same jobs, 442 are identical and 8 differ only by a moved address: seven kit pages print their driver's source, and one is a stylesheet comment.

Before: 36 modules, cli.py and kits/ in one folder. After:

app/nullius/standard/
  cli.py  kits/
  contract/      ports  names  definitions  match
  requirements/  install  hostreq  network_requirements
  protocols/     acp  jsonl  cancellation  computer_port  computer_pipe
  calls/         relay  ledger
  backends/      container  boat  setup_container  forward  egress  mcp_machine  mcp_bridge  web_services
  runner/        run  job  pace  retries  shard  merge  payload  boat_units
  proofs/        conform  fidelity  prove  pins
  pages/         recipe  howto

Verified

  • Backend suite 3,146 tests and route suite 715: pass. The docker tier's 11 modules (388 tests) pass with real containers.
  • The wheel builds with the eight folders in it and app/packaging/verify.py passes.
  • The tests main had when the modules moved are the same cases after: same ids and outcomes, each function compared by syntax tree, the same planted faults failing the same tests. Each later merge of main was checked file by file against main's own change.
  • The upstream-gated OSWorld1 tests, skipped in CI, run by hand with the upstream present: 13 of 14, as on main.
  • Real runs on meta/muse-spark-1.3-contributor through OpenRouter, agents in containers: the reference agent, Goose and OpenCode on GSM8K, HumanEval and τ³-bench, two shards and their merge, a recipe started from Review, the conformance kits. 36 trials, all pass. Mem0 on LoCoMo scores here as on main.
  • Against main on those runs' output: the trace reader gives the same result on 1,212 views of 42 traces, and 21 commands of the CLI that call no model print the same.
  • Four independent reviews of the diff; each finding is fixed with a test that fails on the old code.

Risk

Undone by reverting the squash commit; branches built on the layout would then move their imports back.

app/nullius/standard held 32 modules side by side. They are now eight
folders, each one purpose, with cli.py left at the top because
`python3 -m nullius.standard.cli` is documented and the host snapshot and
the recipe launcher look for that file:

  contract/      ports, names, definitions, match
  requirements/  install, hostreq, network_requirements
  protocols/     acp, jsonl, cancellation
  calls/         relay, ledger
  containers/    container, setup_container, forward, egress,
                 mcp_machine, mcp_bridge, web_services
  runner/        run, job, pace, shard, merge, payload
  proofs/        conform, fidelity, prove, pins
  pages/         recipe, howto

No module is renamed and none changes what it does. What follows the
move: every import, the two module names a container is started by
(the relay and the setup driver), the three constants a module derives
from its own path (definitions, run, payload), the wheel's package list,
the PR judge's path floor for the relay, and the paths named in the
docs, the skills and AGENTS.md, whose map now names pace too. A new
trace names runner/job.py as its producer.

Import paths change without aliases: a driver kept in user storage that
imports nullius.standard.jsonl or nullius.standard.container must follow.
Thirteen modules each wrote a file under a temporary name and renamed it
into place, in three ways: some with a name of their own and a clean-up,
some with a name of their own and none, and four (the judge's store, a
run's record, a definition, a Harbor pin's record) with one fixed name,
which is what workspace.py documented as the cause of a 500 when two
writers met. Three modules each held an flock the same way, and two read
a file's sha256 with the same loop.

nullius/ondisk.py does each once: write_whole, locked, sha256_of. Every
site calls it and keeps what it wrote before. The same bytes and the same
permissions were checked site by site against the previous code: 0600
for settings, licences, the constraints store and a Harbor entry, the
mode given for a migrated file, the process default elsewhere.

What changes: every temporary file is now `.<name>.<random>.part` beside
its target, its own for each write, and removed when the write fails.
Two tests that looked for a left-over `.tmp` look for `.part`.

The module is not named `files`: 174 local variables are, and one of
them hid it in the container backend.
traces/trace.py was 1,477 lines doing five jobs. The code is moved whole,
statement by statement with the comments above it, and not edited:

  spans.py      the span model, the two walks, labels, namespace groups
  fold.py       LLM request spans folded under the call they belong to
  breakdown.py  time accounting: Totals, Breakdown, partition, breakdown
  waterfall.py  the axis, the rows, the ticks
  trace.py      Trace, Filter, parse, load, the saved view

spans.py imports none of the others, the next three import only it, and
trace.py imports all four. Callers take a name from the module that
defines it: the two trace producers (standard/runner/job.py,
traces/otel.py) now import the accounting alone instead of the whole
reader.

The field contract pins a class under the module that defines it, so
Span, Totals, Breakdown, Extent, Row and Tick move to three new keys.
Every pinned field is the same as before. Parsing the two fixture traces
whole and filtered, their charts and their saved views gives the same
output as the previous reader, byte for byte.
Four small things that were written more than once or sat in the wrong
file.

The loopback guard lived in the settings page's module and five other
route modules reached in for it; the builder kept a wrapper named
shared_local_client() to do so. It is shared._local_client() now, beside
the form-token guard.

Four places checked a plan and started it: the builder's Run, the
standard's run over several machines, the Agents page's check and the
Benchmarks page's proof. execute.begin() does it once, every plan
checked before any starts. The two page routes did not ask whether a run
of that name was already going; they do now, as the builder did.

test_charts.py held NoFlask, the rule that the backend imports no Flask.
It is tests/test_layering.py, and AGENTS.md names it there.

test_trace.py carried its own copies of the span and document builders
that tests/tracedata.py already provides.
The cache test held its two writers with their temporary file open by a
gate in workspace._now, which the write called from inside. Since the
cache is written through ondisk.write_whole, the stamp is taken before
the write, so the gate held them before either had opened anything. The
test still passed, but with one shared temporary name put back it failed
38 or 39 runs in 40 where it had failed all 40.

The gate is on the rename now, in this test and in ondisk's own test of
several writers. Both fail every run on a shared name.
No route test failed when the start stopped looking for a run of the
same name still going, or for a run folder of that name: not while each
route had its own copy of those checks, and not since they are one
function, execute.begin.

One test now asks both through /run, and that of several plans none
starts unless every one may.
main moved 65 commits since this branch left it. 24 files conflicted,
most on an import line both sides had edited: those take main's names,
written by folder.

Resolved by hand:

- judge/store.py: main's save, which makes overlapping saves take turns
  and keeps each try, written through ondisk.write_whole, owner-only as
  the temporary file it replaces was.
- workspace.py: main's _write_cache called _write_atomically, which this
  branch replaced with ondisk.write_whole; it writes through it too.
- importers/atif.py: main's _dump is kept, the importer's own digest
  stays dropped.
- web: seven calls in routes main added or rewrote (settings, builder,
  runs, workspaces) ask the local-client guard where it now lives,
  web.shared.
- AGENTS.md: runs/ gains attempts; standard/ stays one clause per folder
  and names at its top the five modules main added, which no folder holds
  yet.

The references main's new code makes to a moved module are rewritten by
folder, in 59 files.
main added five modules to the top of standard/ after this branch sorted
it into folders. Each goes where its code says, and no two folders come
to import each other:

- boat is a second backend, each unit's agent in a Boat VM, beside the
  container one. The folder that held the container backend and its doors
  was named for Docker alone: it is backends/ now.
- boat_units sends this runner's snapshot to a Boat VM per unit and merges
  the shards that come back: with shard, merge and payload in runner/.
  Beside boat, backends/ and runner/ would import each other.
- retries says which failed attempt is tried again: with pace in runner/.
- computer_port and computer_pipe are the computer port's MCP server and
  the session's pipe to it: with acp and jsonl in protocols/. The kit's
  pipe.py and three tests name the pipe's file by its place, and follow.

References follow in 71 files, written as the first move writes them.
The driver found that folder by going three folders up from the computer
port's file. The port now sits one folder deeper, in protocols/, so the
runner was started with the package's inside as its import path: its first
import failed (No module named 'nullius'), and nullius/secrets.py stood in
front of the standard library's. Every OSWorld1 unit run by an agent failed
at setup; the controls and the Original setups start no runner.

No test that runs without the upstream started the runner, so both suites
stayed green. The folder is now asked of the package itself, and a test
that needs no upstream starts a Python with the runner's import path.

With the upstream's loop present (OSWORLD_DIR, OSWORLD_PYTHON), the 14
tests it gates give 13 passed, as on main; the one that fails,
AgentSide.test_the_password_file_is_private_and_read_once, fails on main
too.
…ength

Three things write_whole did that main's writers did not.

It made a missing folder. Four writers refused one on main: a definition's
save, a licence, a Harbor entry, the ledger. A proof that ended after its
user entry was removed ("Use bundled entry") therefore brought the folder
back holding the definition alone: the entry left the Benchmarks page and
its own page answered 404. The folder is the caller's to make again: the
nine callers that made theirs on main do, and a folder that is gone is an
error, as it was.

Its temporary name carried the file's own, so a file whose name was 217 to
255 bytes long could not be written: a migrated file, a judgement of a
trial with a long name. The name is now as long for every file.

It set the mode with fchmod even when the file already had it. Three files
got 0600 from mkstemp alone on main (the constraints store, a Harbor
entry, a judgement); where fchmod is refused they were written there and
not here. The mode is set only when the umask took bits off, and a refusal
no longer leaves a descriptor open.

Tests hold each: a folder that is gone, a name as long as a name may be, a
mode the umask leaves whole, a refused mode, the temporary file beside its
path with its mode before the rename, and the mode of the three files.
The Agents page's check and the Benchmarks page's proof refuse to start
while a run of that name is going, since they start through execute.begin.
Only the builder's route was tested for it. Both pages are now asked with
such a run going: nothing starts, and the page comes back with the reason.
The Agents test also counts one start, not at least one.
standard.ledger and standard.relay are calls.ledger and calls.relay, and
standard.retries is runner.retries. Three folder docstrings say what they
left out: proofs/ also holds a check that proves nothing (pins), egress is
also an agent's way to the public web, and requirements/ says how it
differs from nullius.prerequisites.
main added five modules loose at the top of the package in five days. A
test now keeps the sorting: only the cli and the kits sit at the top, and
no folder imports one that imports it, at a module's top or inside a
function. It reads the sources and imports none of them.

One pair of folders imported each other: contract/definitions asked
requirements/network_requirements for the check of an environment's
network field, and requirements/install imports definitions. The check,
twelve lines, moves beside the other field checks in definitions, where
the host check already is; network_requirements keeps the connectivity
check a run makes before its first unit. Same messages, same test cases.
main moved three commits (#276, #277, #279). They add no file; the five
modules they change (acp, conform, fidelity, prove, recipe) are followed
into their folders.

One conflict, in pages/recipe.py: main shortened the docstring above an
import this branch had written by folder. It takes main's docstring and
keeps the folder's import.
main moved three commits (#236, #281, #285). They add no file. #281
shortens comments and prose in 302 files, among them most of the
modules this branch moved.

24 files conflicted. In 16, main had shortened a sentence in which this
branch had changed an address: they take main's sentence with the
address by folder.

Resolved by hand:

- traces: main shortened comments in code this branch had moved out of
  trace.py. The four modules it went to are the split of main's new
  trace.py; trace.py keeps this branch's opening paragraph. charts.py
  and otel.py take main's sentences and name spans, breakdown and
  waterfall where they named trace.
- workspace.py: main shortened the docstring of _write_atomically, which
  this branch replaced with ondisk.write_whole; it stays removed.
- contract/definitions.py: main's docstring for _locked, without the
  fcntl import ondisk.locked made unnecessary.
- web/execute.py: main's shortened comment, in the shared run start.
- AGENTS.md, .claude/rules/traces.md: main's sentences, naming
  test_layering.NoFlask and the reader's five modules.

One import main added in test_computer_kit.py is written by folder.
Each folder's description keeps its first line and the one constraint
that binds a reader. ondisk, the reader's four modules, the layering
test and a few test comments lose what restated a name or a line.
Comments and docstrings only.
… path resolves

A review found two places where ondisk.write_whole did not do what main did.

The workspace's cache, index and record were serialised whole before the
write, where main streamed them into the file: a 29 MB cache took 58 MB of
memory to write, against 3 MB. write_whole takes a function that writes into
the file, and the three calls pass main's own. The cache's concurrency test
is main's again, since its gate is inside the write again.

The temporary file was placed by a path Python had flattened, so a file
written as link/../name was staged beside the link and not beside the file:
a read-only folder there refused a write main accepted. It is staged by the
path as given.
@aitianshi aitianshi self-assigned this Nov 23, 2026
@github-actions

Copy link
Copy Markdown

🔴 PR judge · 5 of 8 yes · #290 ↔ #289

Merge risk ⛔ SEVERE a workflow changed: .github/workflows/docker-tests.yml
Priority 🔴 EXTREME the deepest path is .github/scripts/judge_pr.py
Question Verdict
Changes do what the issue asks · 7 of 7 criteria ✅ yes
Issue and pull request describe the same change ✅ yes
Description matches the diff, no more, no less ⚠️ partly
Diff stays in scope ⚠️ partly
Tests cover the change, or Verified says how ✅ yes
Docs follow the change ✅ yes
Risk named in the description ✅ yes
Before and after shown · 0 images · the diff touches what is visible ❌ no
Acceptance criteria, 7 of 7 met
# Criterion Verdict
1 app/nullius/standard/ holds only __init__.py, cli.py, kits/ and the eight folders, and no module is renamed ✅ met (cut)
2 a test fails when a module is added at the top of the package or when two folders import each other ✅ met (cut)
3 nothing in the repository names a moved module by its old address: imports, docs, skills, AGENTS.md, workflows, `pypr… ✅ met (cut)
4 nullius/ondisk.py writes a file whole, locks and digests for the sites it replaces, and each site keeps its bytes, it… ✅ met (cut)
5 traces/trace.py is split into spans, fold, breakdown, waterfall and trace with no statement edited, and the… ✅ met (cut)
6 the builder's Run, the Agents page's check and the Benchmarks page's proof start through one function, which refuses a … ✅ met (cut)
7 both suites pass ✅ met (cut)
Checks the script runs itself, 3 of 4 pass
No machine attribution trailer in the commits or the description ✓
New code under app/, docs/, .github/ or .claude/ · pyproject.toml ✗
No Flask import under the backend package ✓
No key-shaped string in the diff ✓

some of the diff was cut before the judge read it

@aitianshi
aitianshi merged commit dab3ec0 into main Nov 23, 2026
2 checks passed
@aitianshi
aitianshi deleted the refactor/standard-file-topology branch November 23, 2026 09:07
aitianshi added a commit that referenced this pull request Nov 23, 2026
…l steps (#288)

Closes #287

## What

An agent's `install` block may now list `commands`, its upstream's own
install steps. They run last, in the install folder, under the same lock
and `.installed` marker as its packages; each is an argv list of plain
words whose only slot is `{install}`, never a shell, and a failed one
leaves no marker. DigitalMate `v0.1.12` uses three: add its service
package (`services/agent_bridge[geo]`), create the runtime venv, run the
release's own `deploy/install_runtime.py`. So DigitalMate installs
through the standard like every other agent, with no prepare script. Its
adapter is glue only: start the Personal Agent service on 127.0.0.1 with
a per-trial state folder, submit the task through the Gateway WebSocket,
return the final answer. The release runs as published, same commit, no
patches; no upstream code is copied here. Container backend only;
`agent.task/v1` proven.

## Touches

The standard (install, definition checks) · catalogue (DigitalMate
entry, its `run` and `gateway`) · docs (`docs/standard.md` install
table, generated agent pages, AGENTS.md map) · backend tests

## Verified

- Install through the standard, in the container base image, from a
neutral folder: complete in 29 min (almost all of it the release's
runtime installer); the runtime's `pip check` clean.
- `nullius.standard.cli conform digitalmate --port agent.task/v1
--backend container` with OpenRouter `meta/muse-spark-1.3-contributor`
on that install: 3/3, about $0.014 in total. Recorded in `agent.json`.
- On the standard's new folders (#290): backend suite (`python3
app/tests/parallel.py`) 3168 tests OK, route suite 716 tests OK.
- New tests: the checker accepts plain `{install}` commands and refuses
others; the commands run last in the install folder; a failed command
leaves no marker. With the command loop removed, the two install tests
fail.
- `catalogue_docs.py --write` and the field contract: no change after
the rebase.

## Risk

- `install.commands` runs what a definition lists, at install time. It
is limited to plain words and `{install}`, but a catalogue entry can
still run its upstream's code there, as `project` and `pip` already do.
An install that worked before is unchanged: the step only runs when
`commands` is present.
- DigitalMate's repository is private: installing it needs read access,
and its page links there.
- DigitalMate's task deadline is a fixed 600 s.
- Undone by a revert; existing installs are not touched (the install
folder is keyed by the definition's digest).
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.

Backend: the standard's 36 modules share one folder, and files are written, locked and digested in hand-written copies

1 participant