[Bug]: arbor observe and status sort node ids lexicographically, so n10 precedes n2
What happened
Node ids are minted as n1, n2, n3, … by an increasing counter, but the four places that render node lists sort those ids as strings:
for n in sorted(frontier, key=lambda x: x["id"]): # observe, active frontier
for n in sorted(executed, key=lambda x: x["id"]): # observe, evidence list
for n in sorted(pruned, key=lambda x: x["id"]): # observe, pruned lessons
kids = sorted(_children(tree, nid)) # status / renderA string sort only coincides with creation order up to n9. With eleven nodes the frontier comes out as:
n1, n10, n11, n2, n3, n4, n5, n6, n7, n8, n9What you expected instead
n1 … n11, in the order the nodes were created.
Steps to reproduce
tree.py --run-dir $d init --objective obj --dev-eval d --test-eval t
for i in $(seq 1 11); do tree.py --run-dir $d add-node --parent n0 --hypothesis "hyp$(printf %02d $((i-1)))"; done
for i in $(seq 1 11); do tree.py --run-dir $d set-status --node "n$i" --status running; done
tree.py --run-dir $d observeError output
No error — this is an ordering defect, not a crash. The rendered frontier is:
-- Active frontier (selectable hypotheses) --
n1 (depth 1, running): hyp00
n10 (depth 1, running): hyp09
n11 (depth 1, running): hyp10
n2 (depth 1, running): hyp01
n3 (depth 1, running): hyp02
...and status renders n0 n1 n10 n11 n2 n3 n4 n5 n6 n7 n8 n9.
Why it matters
observe is described in the module as "a compact projection the coordinator re-grounds on at the start of each cycle, so decisions come from the tree rather than from lossy conversation history". Reading the frontier out of order defeats the point of that view: the ordering carries no information the coordinator can use, and it does not match the order the hypotheses were proposed in.
This is also the normal case rather than an edge case. The defaults are --budget 20 cycles at --branching 3, so a real run passes nine nodes easily, and the divergence begins at exactly the tenth node.
Steps to reproduce the miss
The existing test_ids_are_sequential_and_depth_is_derived_from_the_parent builds a four-node tree, where string order and numeric order happen to agree, so the bug was invisible to the suite.
Environment
- Agent host: n/a (ran the script directly)
- Model: n/a
- Repository version or commit:
065b734(main) - Python version: 3.12.10
- Operating system: Windows 10
A fix is proposed alongside that adds one sort-key function and applies it at all four sites, with tests covering the frontier, the evidence list, the pruned list, the status render, and the key's behaviour on ids that do not follow the n<digits> pattern.
Source: K-Dense-AI/scientific-agent-skills