Guides
An agent checking its own change
A coding agent records the program before and after its change and reads ormaos diff to see what the change did in the execution.
A coding agent that changes code can see whether the tests pass and what the program printed. With Ormaos it can also see what the change did in the execution: which calls now run, which no longer do, which exceptions, I/O and log records appeared or went away. The example is agent-change: a billing tool in a git repository, and a change that an agent made to it (change.patch).
Before the change#
ormaos run -- python run.py$ ormaos run -- python run.py
12 invoices, 3 refunds written
ormaos: r1 exit 0 in …: 1 Python process, 75 calls, 0 exceptions, 6 io
ormaos: not collected: io: writes to the 2 files opened at run.py:18: opened for writing, and no `write` call by Python code was seen on a file of that name: if it was written, that was inside C code (`print(..., file=f)`, `csv.writer`)
ormaos: saved in .ormaos/r1, next: ormaos tree r1:c1The change#
git apply change.patch
git diff --stat$ git diff --stat
billing.py | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)After the change, the same command#
The program prints the same line as before; the summary has more calls and more I/O:
$ ormaos run -- python run.py
12 invoices, 3 refunds written
ormaos: r2 exit 0 in …: 1 Python process, 113 calls, 0 exceptions, 82 io
ormaos: not collected: io: writes to the 2 files opened at run.py:18: opened for writing, and no `write` call by Python code was seen on a file of that name: if it was written, that was inside C code (`print(..., file=f)`, `csv.writer`)
ormaos: saved in .ormaos/r2, next: ormaos tree r2:c1What does the execution do differently?#
$ ormaos diff r1 r2
r1 -> r2, matched by place in the code and order, not by address
r1: exit 0, 75 calls, 0 exceptions, 6 io events
r2: exit 0, 113 calls, 0 exceptions, 82 io events
code: the two code versions differ: the same git commit 5b23406de1, and the uncommitted changes are not the same (none in r1, 1 file changed in r2)
calls: 1 of 11 places differ
discount_percent at billing.py:10: none in r1, 38 in r2 [r2:c9]
exceptions: the same in both (0 groups)
io: 2 of 8 groups differ
file open tiers.json (read) at billing.py:11 in discount_percent: none in r1, 38 in r2 [r2:i5]
file read tiers.json at billing.py:12 in discount_percent: none in r1, 38 in r2 [r2:i6]
logs: the same in both (0 groups)
data: the same in both (0 places)
not compared: values, shapes of arguments and results, durations, cpu and memory, the lines of `path`, which process or thread an event was in
next: ormaos tree r2:c9 | ormaos io r2:i5 | ormaos io r2:i6 | ormaos show r1 | ormaos show r2code:the two recordings ran different versions of the code: the same commit, and different uncommitted changes.calls:discount_percentdid not run inr1and ran 38 times inr2.io:each of those calls opened and readtiers.json: 38 opens and 38 reads inr2.
Whether reading the file 38 times is what the change should do is for the agent, or the developer, to decide. The diff gives the places and the counts.
Did the new function run at all? How often?#
$ ormaos tree r2 --function discount_percent --limit 3
r2: 38 of the 113 calls match --function discount_percent (38 discount_percent; 0 raised)
r2:c9 discount_percent(customer: str[8]) -> int billing.py:10 … io 2
r2:c11 discount_percent(customer: str[8]) -> int billing.py:10 … io 2
r2:c15 discount_percent(customer: str[5]) -> int billing.py:10 … io 2
... 35 more: --offset 3
next: ormaos tree r2:c9 | ormaos tree r2:c11 | ormaos tree r2 --offset 3 --function discount_percent | ormaos tree r2 | ormaos exceptions r2$ ormaos tree r2:c9
inside: r2:c1 <module> > r2:c3 main > r2:c6 invoice_total > r2:c7 invoice_total.<locals>.<genexpr> > r2:c8 line_price
r2:c9 discount_percent(customer: str[8]) -> int billing.py:10 … io 2
next: ormaos tree r2:c8 | ormaos exceptions r2:c9$ ormaos io r2:i5
r2:i5 file open tiers.json (read)
caused at billing.py:11 in discount_percent [r2:c9]
inside r2:c1 <module> > r2:c3 main > r2:c6 invoice_total > r2:c7 invoice_total.<locals>.<genexpr> > r2:c8 line_price
next: ormaos io r2:c9 | ormaos tree r2:c9 | ormaos io r2Does the new code catch exceptions that are never shown?#
$ ormaos exceptions r1
r1: 0 exceptions (0 swallowed, 0 uncaught)
next: ormaos tree r1None in r1, and the diff says the exceptions are the same in both.
The loop#
ormaos guideonce, to learn the installed version.ormaos run -- <command>before the change.- Change the code.
ormaos run -- <command>again, same command, same input.ormaos diff r1 r2, then follownext:for each difference.