auto-optimize 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. auto_optimize/__init__.py +3 -0
  2. auto_optimize/__main__.py +5 -0
  3. auto_optimize/cli.py +651 -0
  4. auto_optimize/skills/auto-optimize-code/LICENSE +21 -0
  5. auto_optimize/skills/auto-optimize-code/SKILL.md +251 -0
  6. auto_optimize/skills/auto-optimize-code/VERSION +1 -0
  7. auto_optimize/skills/auto-optimize-code/references/algorithm.md +182 -0
  8. auto_optimize/skills/auto-optimize-code/references/changes.md +146 -0
  9. auto_optimize/skills/auto-optimize-code/references/cli.md +206 -0
  10. auto_optimize/skills/auto-optimize-code/references/dashboard.md +203 -0
  11. auto_optimize/skills/auto-optimize-code/references/documents.md +55 -0
  12. auto_optimize/skills/auto-optimize-code/references/extending.md +87 -0
  13. auto_optimize/skills/auto-optimize-code/references/external-validation.md +98 -0
  14. auto_optimize/skills/auto-optimize-code/references/glossary.md +134 -0
  15. auto_optimize/skills/auto-optimize-code/references/idea-miner.md +108 -0
  16. auto_optimize/skills/auto-optimize-code/references/issue-bugs.md +182 -0
  17. auto_optimize/skills/auto-optimize-code/references/layout.md +300 -0
  18. auto_optimize/skills/auto-optimize-code/references/main-session.md +45 -0
  19. auto_optimize/skills/auto-optimize-code/references/measuring.md +208 -0
  20. auto_optimize/skills/auto-optimize-code/references/pr-optimization.md +127 -0
  21. auto_optimize/skills/auto-optimize-code/references/pr-tests.md +254 -0
  22. auto_optimize/skills/auto-optimize-code/references/promotion.md +133 -0
  23. auto_optimize/skills/auto-optimize-code/references/reading-a-search.md +65 -0
  24. auto_optimize/skills/auto-optimize-code/references/repo-mode.md +224 -0
  25. auto_optimize/skills/auto-optimize-code/references/resume.md +81 -0
  26. auto_optimize/skills/auto-optimize-code/references/shared-knowledge.md +114 -0
  27. auto_optimize/skills/auto-optimize-code/references/step0-interview.md +298 -0
  28. auto_optimize/skills/auto-optimize-code/references/step1-unit-tests.md +136 -0
  29. auto_optimize/skills/auto-optimize-code/references/step2-baseline.md +708 -0
  30. auto_optimize/skills/auto-optimize-code/references/step3-rounds.md +350 -0
  31. auto_optimize/skills/auto-optimize-code/references/step4-final.md +121 -0
  32. auto_optimize/skills/auto-optimize-code/references/step5-ship.md +220 -0
  33. auto_optimize/skills/auto-optimize-code/references/step6-finish.md +67 -0
  34. auto_optimize/skills/auto-optimize-code/references/subagent.md +467 -0
  35. auto_optimize/skills/auto-optimize-code/references/symptoms.md +67 -0
  36. auto_optimize/skills/auto-optimize-code/references/writing-briefs.md +117 -0
  37. auto_optimize/skills/auto-optimize-code/scripts/attribution.py +156 -0
  38. auto_optimize/skills/auto-optimize-code/scripts/autoopt.py +12863 -0
  39. auto_optimize/skills/auto-optimize-code/scripts/check_seeding.py +334 -0
  40. auto_optimize/skills/auto-optimize-code/scripts/cold.py +90 -0
  41. auto_optimize/skills/auto-optimize-code/scripts/dashboard/README.md +165 -0
  42. auto_optimize/skills/auto-optimize-code/scripts/dashboard/autoopt_monitor.py +850 -0
  43. auto_optimize/skills/auto-optimize-code/scripts/dashboard/gpu_scan.py +954 -0
  44. auto_optimize/skills/auto-optimize-code/scripts/dashboard/monitor_writer.py +684 -0
  45. auto_optimize/skills/auto-optimize-code/scripts/dashboard/scan.py +1030 -0
  46. auto_optimize/skills/auto-optimize-code/scripts/dashboard/static/dashboard.css +775 -0
  47. auto_optimize/skills/auto-optimize-code/scripts/dashboard/static/dashboard.js +3652 -0
  48. auto_optimize/skills/auto-optimize-code/scripts/dashboard/static/index.html +191 -0
  49. auto_optimize/skills/auto-optimize-code/scripts/issue_body.py +2118 -0
  50. auto_optimize/skills/auto-optimize-code/scripts/lint_text.py +448 -0
  51. auto_optimize/skills/auto-optimize-code/scripts/opt_pr_body.py +894 -0
  52. auto_optimize/skills/auto-optimize-code/scripts/opt_pr_tables.py +367 -0
  53. auto_optimize/skills/auto-optimize-code/scripts/paired.py +188 -0
  54. auto_optimize/skills/auto-optimize-code/scripts/preflight.py +280 -0
  55. auto_optimize/skills/auto-optimize-code/scripts/probe_run.py +72 -0
  56. auto_optimize/skills/auto-optimize-code/scripts/publish.py +385 -0
  57. auto_optimize/skills/auto-optimize-code/scripts/run_iteration.py +1382 -0
  58. auto_optimize/skills/auto-optimize-code/scripts/ship.py +1193 -0
  59. auto_optimize/skills/auto-optimize-code/scripts/stages.py +651 -0
  60. auto_optimize/skills/auto-optimize-code/scripts/tests_pr_body.py +1267 -0
  61. auto_optimize/skills/auto-optimize-code/scripts/tests_pr_push.py +426 -0
  62. auto_optimize/skills/auto-optimize-code/scripts/tests_pr_tables.py +779 -0
  63. auto_optimize-1.0.0.dist-info/METADATA +610 -0
  64. auto_optimize-1.0.0.dist-info/RECORD +67 -0
  65. auto_optimize-1.0.0.dist-info/WHEEL +4 -0
  66. auto_optimize-1.0.0.dist-info/entry_points.txt +2 -0
  67. auto_optimize-1.0.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,350 @@
1
+ # Step 3 — running the rounds
2
+
3
+ The orchestrator's part is the loop below; what it never does is in
4
+ `SKILL.md`, *Rules that hold everywhere*. The idea miner fills `ideas.md`
5
+ (`references/idea-miner.md`), each iteration's runner promotes on the keep
6
+ rule unless `promote` is `orchestrator` (`references/promotion.md`), and
7
+ `autoopt.py` assembles each round's summary. Every file under `iterations/`
8
+ is written by a subagent, `run_iteration.py` or `autoopt.py`. The one runner
9
+ call the orchestrator makes is re-judging stored runs after a gate is changed
10
+ (`references/changes.md`).
11
+
12
+ **Read little.** Everything the orchestrator reads stays in its context, and
13
+ that context is rewritten in full at every wake-up after the prompt cache
14
+ expires. After each report, read `autoopt.py status --brief` and
15
+ the subagent's short report; do not read its logs, run outputs, probe files
16
+ or README, and do not read code. Cap any other output (`| tail -n 40`).
17
+
18
+ A0 carries **round 0**, which holds no ideas. Rounds of ideas are numbered
19
+ from 1, and a round closes when an iteration is promoted, so `summary --round 1` covers the iterations forked from A0 up to the first
20
+ promotion. A same-code control (`brief --control`, run by a subagent) is a row
21
+ in its round but tries no idea.
22
+
23
+ ## The orchestrator subagent
24
+
25
+ From the first iteration on, *The loop* is run by an orchestrator subagent, not
26
+ the main session. The main session carries the whole conversation, and every
27
+ wake-up after a quiet spell writes all of it to the prompt cache again, so
28
+ the rounds run in a context that holds only the search. What the main session
29
+ does from the first iteration on is `references/main-session.md`.
30
+
31
+ The orchestrator subagent reads its prompt (`briefs/loop-<n>.md`), `SKILL.md`
32
+ and this file, and runs *The loop*. Where this file says to tell or ask the
33
+ user, it puts that in its report, and asks nothing itself.
34
+
35
+ ## The loop
36
+
37
+ One iteration runs at a time. It is measured against the root the previous
38
+ one left, and when it passes the keep rule it becomes the root, so the next
39
+ iteration starts from it.
40
+
41
+ ```
42
+ start:
43
+ once status stops printing `first iteration: waiting for …`: the setup
44
+ subagent and the idea miner's S1 are both done
45
+ (references/step0-interview.md, *Handing off step 2*)
46
+ autoopt.py brief $WORK --next # a brief and a spawn prompt for the one
47
+ # slot, from the top untried idea
48
+ # (references/writing-briefs.md)
49
+ spawn the prompt it printed with the Agent tool, with the description and
50
+ model its stderr line names (`subagent_model`; the miner keeps the
51
+ session's). Every later iteration is spawned the same way
52
+ start the dashboard publisher (references/dashboard.md)
53
+
54
+ never end a turn with work in flight and nothing to wake the session:
55
+ a subagent's completion notification wakes it. The fallback, for one
56
+ that stalls without reporting: when `status` or `brief --next` prints
57
+ `watch: none running`, start `autoopt.py watch $WORK` with the Bash tool's
58
+ run_in_background. It returns only when status would flag something
59
+ (a subagent STALLED, a measured iteration with no README after an
60
+ hour), after 3 hours, or once nothing has been in flight for 30
61
+ minutes. Never a `sleep` timer: a wake-up after a quiet spell
62
+ rewrites the whole context, and a timer wakes the session to find
63
+ nothing to do
64
+
65
+ whenever the subagent reports, and at every wake-up:
66
+ autoopt.py brief $WORK --next # status --brief (working, STALLED,
67
+ # READMEs never written, dashboard,
68
+ # machine, ideas left, the miner's
69
+ # stage); the table of each round
70
+ # summary written since the last call,
71
+ # which you show the user; then a brief
72
+ # and a prompt for the free slot
73
+ spawn what it printed, as at the start
74
+ a STALLED subagent: hand its iteration to a new subagent (*A subagent that
75
+ goes quiet*); `brief --next` counts its slot as taken
76
+ `promote: auto`: the iteration's runner promoted it if it passed the keep
77
+ rule while its parent was still the root, and ran the closed round's
78
+ approved validation (its `keep:` line). Nothing to do, except for a
79
+ report whose `keep:` line reads `not promoted: …`: `promote --id <it>`
80
+ before the next `brief --next`
81
+ `promote: orchestrator` (a keep rule in the user's own words): read
82
+ `status --brief` first, promote, then `brief --next`, so the new brief
83
+ forks from the new root:
84
+ autoopt.py promote --id <it> # when it passes that rule and its
85
+ # parent is still the root
86
+ a refusal naming `run_iteration.py <dir> --full-tests` (a subset
87
+ test pass): ask its subagent (SendMessage), or a new one with the
88
+ prompt `brief --prompt <it>` prints, to run that command, then promote
89
+ autoopt.py validate --round N # only if configured and approved
90
+ status says fewer than 2 untried ideas, and no miner runs:
91
+ autoopt.py mine, and spawn the idea miner with what it prints
92
+ (*Keeping the ideas*); keep briefing from what is left meanwhile
93
+ a GPU search with GPU indices rather than an allocation command, or a
94
+ busy machine (*GPUs for each iteration*, *The machine during the
95
+ search*): `brief --next --gpus <its indices>`, or no brief yet
96
+ ```
97
+
98
+ The loop hands back after `loop_handback` settled iterations
99
+ (`autoopt.py loop`), at *When to stop*, and whenever `brief --next` says to
100
+ (a budget spent, or the main session's `loop --stop`).
101
+
102
+ ## Questions while the search runs
103
+
104
+ Nothing is spawned while a question waits, so one asked at night stalls the
105
+ search until morning. Once the first iteration is in flight:
106
+
107
+ 1. **Do not end a turn waiting for a reply.** What this skill already decides
108
+ is not a question: spawning goes on as usual, and the runner keeps
109
+ promoting on the keep rule.
110
+ 2. Take the answer that does the least damage if it is wrong: the reversible,
111
+ narrower, cheaper one, often not the one you would mark recommended. When
112
+ the question is whether to promote, delete, ship or change a gate, the
113
+ answer is no until the user replies; hold that one decision and keep
114
+ everything else moving.
115
+ 3. Write the question, the answer taken and why in `ideas.md` under
116
+ *Decisions taken while the user was away*, and say it in the next message.
117
+ 4. When the user answers, apply it and re-run what the default decided
118
+ wrongly, recording it first (`SKILL.md`, *Rules that hold everywhere*).
119
+
120
+ Claude Code's `askUserQuestionTimeout` setting (`60s`, `5m`, `10m`, or
121
+ `never`, in the user's `settings.json` or `/config`) lets an unanswered
122
+ question continue on its own. Offer it to the user before a long search; do
123
+ not change their settings yourself. A question that continued unanswered gets
124
+ the least-damage answer.
125
+
126
+ ## A subagent that goes quiet
127
+
128
+ `status` lists every subagent still working (`running` or `finishing`) with
129
+ the time since its last write, and marks one silent for over 15 minutes
130
+ `STALLED`; its `no README:` line names measured iterations nobody has written
131
+ up for over an hour. A subagent can write its logs and then go silent while
132
+ nothing runs. Do not wait for its report: its `report.txt`, the runner's
133
+ block, holds the `keep:` line it would have sent. The iteration goes to a new
134
+ subagent with the prompt `autoopt.py brief $WORK --prompt <id>` prints, which
135
+ tells it where the last one stopped (measured or not).
136
+
137
+ A stalled subagent's runner may still be running and holding its GPUs:
138
+ `status --resume` names a live runner by its pid
139
+ (`references/resume.md`). Leave a live one to finish, since resuming it runs
140
+ the same seeds twice. A round's summary waits for every README.
141
+
142
+ ## GPUs for each iteration
143
+
144
+ **Two iterations MUST NOT hold the same GPU** (`references/step2-baseline.md`,
145
+ *GPU leases*, has both rules). With `gpu_command` recorded, `brief` puts it in
146
+ the brief by itself and the runner leases through it. With none, you are the
147
+ allocator: read `nvidia-smi` once, give each brief its own indices (`brief
148
+ --gpus 2`), and reuse an index only after that iteration settles; a subagent
149
+ never picks one, since two launches seconds apart take the same free card.
150
+
151
+ ## The machine during the search
152
+
153
+ `spec.md`'s *Machine and environment* line says how many cores and how much
154
+ memory the search may use: keep the runs at once, and each run's threads,
155
+ inside it. Before every iteration, read `status`'s `machine:` line (`256 cores,
156
+ 86% idle, ~219 free over 0.1 s`), a short sample of the CPUs' idle share with
157
+ this search's runs included, never the load average, which counts threads a
158
+ container's quota holds back: an iteration that starts quiet can
159
+ finish contended. `gpus_per_agent` processes at about 100% are the iteration
160
+ working; anything above that is somebody else (`autoopt.py busy $WORK` names
161
+ them).
162
+
163
+ **The exact test is a same-code control.** The idle share is a hint; the objective is
164
+ the measurement. Brief the root unchanged and spawn a subagent with it, like
165
+ any iteration; you measure nothing yourself:
166
+
167
+ ```bash
168
+ python3 $AO/autoopt.py brief $WORK --id <next free> --control --title 'control: unchanged root' \
169
+ --category MISC --idea 'Change nothing: measure the root as it is.' --tried 'none'
170
+ ```
171
+
172
+ A median outside the noise band means the machine is not in the state the
173
+ frontier was measured in. Never `--rerun` the root itself: that overwrites
174
+ the measurement the frontier rests on. The control stays in the table, never
175
+ holds the frontier however it reads, and cannot be promoted.
176
+
177
+ **The machine is busy** when, on a CPU benchmark, any process outside this
178
+ search runs above `busy_percent` (110% of one core by default), or the control's median falls outside the
179
+ noise band. **When it is busy before the first iteration**, put the choice to the
180
+ user with `AskUserQuestion`, giving the idle share, what is running and, once there
181
+ is one, the control's median against the band. Do not narrow the runs
182
+ quietly.
183
+
184
+ | Option | What it means |
185
+ |---|---|
186
+ | Hold off for now | brief nothing until the machine is quiet; say what you will watch and check back |
187
+ | Proceed with one run at a time | `gpus_per_agent` set to 1 (`config --set`), which minimizes the contention this search adds; each iteration takes longer |
188
+ | Proceed as planned | the runs at once as configured; the round's numbers are inflated and not comparable to other rounds |
189
+
190
+ **Once iterations are in flight, do not ask:** take *Proceed with one
191
+ run at a time*, record it in `ideas.md` under *Decisions taken while the user was
192
+ away*, and tell the user. Either way, tell the user with the round's summary
193
+ that it was measured under contention.
194
+
195
+ ## Keeping the ideas
196
+
197
+ `autooptimize/ideas.md` holds one line per idea, in the form at its top
198
+ (`- [CATEGORY] where: what. Why: … Gain: … Exact: … (S<n>)`), so `status`
199
+ can count what is left. `brief --next` takes the top of the miner's latest
200
+ stage for the one free slot; do not pass `--count` above it. An idea that is
201
+ one parameter swept over four values is one iteration, not four. Pass `--idea-line` with text only that line holds (a
202
+ number shifts when lines are added above it) to choose another, and strike a
203
+ line whose premise is gone with `autoopt.py drop $WORK --idea-line <text>
204
+ --reason <why>`, or `brief --next` picks it again. The subagent's `finish` strikes the line with its label
205
+ and what became of it ("- ~~[MICRO] … (S1)~~ A12: kept out: its median is
206
+ within the noise band …").
207
+
208
+ **The idea miner writes the ideas.** It reviews the code, the ledger, the
209
+ gates and the READMEs' *What to try next* in a context of its own, so none of
210
+ that reading lands in the orchestrator's. It runs:
211
+
212
+ - **once setup has closed**, started by the main session: it prices ideas
213
+ against A0's profile (`references/step0-interview.md`, *Handing off step 2*);
214
+ - **whenever `status` says fewer than 2 untried ideas are left** and no
215
+ miner is running: `autoopt.py mine $WORK` opens the next stage and prints
216
+ the miner's prompt; spawn one subagent with it, unedited. Keep briefing from
217
+ what is left while it works. One miner runs at a time; if its subagent
218
+ died, `mine --force` opens the next stage.
219
+ - **never past the user's iteration budget**, `after.budget_iterations`:
220
+ once that many iterations are briefed, `brief --next` briefs nothing, `mine`
221
+ refuses, and the search stops for `budget` when they settle;
222
+ - **never past the user's stage budget**, `after.budget_stages`: once that
223
+ many stages have closed, `mine` refuses, `status` says the budget is spent,
224
+ and the ideas left are briefed until none is; then the search stops for
225
+ `budget` (*When to stop*).
226
+
227
+ Each stage is an `S<n>`: `new` stamps the last finished one on every
228
+ iteration, and the dashboard's stage boundaries mark where a fresh batch of
229
+ ideas begins, so a bump after a boundary is visible.
230
+
231
+ The orchestrator adds a line itself only for what a report hands it: a
232
+ follow-up to a gate that failed while the objective jumped, an idea a report
233
+ says should be split. A category that keeps winning deserves more of the next
234
+ briefs; one silent for two rounds, fewer. A *Gain* taken on an older root is stale
235
+ (`references/writing-briefs.md`, *What makes the supplied parts survive
236
+ contact*).
237
+
238
+ ## Ids, parents and briefs
239
+
240
+ Choose each iteration's id when you brief it: `status` prints the next free
241
+ one, and `brief` refuses a taken id and names the next free. The brief holds
242
+ the exact `new` command, the subagent runs it, and `new` takes a lock, so
243
+ two calls at the same moment are safe. Do not run `new`
244
+ yourself for a subagent's iteration: a second `new` makes a duplicate.
245
+
246
+ The parent is the current root, which `status` prints. A brief names another
247
+ parent only for a deliberate fork from an earlier iteration; `promote` refuses
248
+ an iteration that does not descend from the root.
249
+
250
+ **Never fork from an iteration that is not `ok`**, even when its failure looks
251
+ like a measurement artifact the user is still deciding about: everything built
252
+ on it inherits whatever broke the gate, and iterations built on a held iteration
253
+ may be rejected whole. A gate-failed change that is still wanted either waits,
254
+ held, until the user decides the gate, and is then promoted by the usual
255
+ rules, or is re-implemented from the root in a form that passes. `new` and
256
+ `brief` refuse it as the parent:
257
+
258
+ > `error: parent A13 is gate-failed: an iteration that is not ok (a gate failed, a run crashed, or it is held for the user) is never forked from; fork from the current root (A10) …`
259
+
260
+ ## Reading what comes back
261
+
262
+ The subagent returns what `references/subagent.md`, *What to report back*,
263
+ lists: its `report.txt` block, then a correction or a split first among at
264
+ most two sentences. Do not re-derive numbers from it:
265
+ `autoopt.py status` reads every `result.json`.
266
+
267
+ - **`keep: no`** is a result. Nothing promotes such an iteration, even one
268
+ with the best median so far: its gain is inside the noise band.
269
+ - **`status: error`.** When the report says the failure was environmental
270
+ (a full disk, a killed process), the idea is still untried: put it back on
271
+ the list with a note.
272
+ - **A gate failed but the objective jumped.** A follow-up that pays the cost
273
+ down is worth a slot.
274
+ - **A corrected premise.** Fix the `ideas.md` lines and later briefs that
275
+ quote it. The subagent corrected the ledger itself (`autoopt.py ledger`,
276
+ `references/shared-knowledge.md`); check none of the ledger or `tools/`.
277
+ - **A missing dependency.** The subagent installed nothing. If `spec.md`'s
278
+ *Off limits* rules out new dependencies, the idea is closed. Otherwise
279
+ install the package once into the search's environment, while nothing is
280
+ timing, and read what the installer changed: if it upgraded or removed
281
+ anything the benchmark imports, brief a same-code control of the root
282
+ (*The machine during the search*) before comparing across the install. Then put the idea back on the list.
283
+
284
+ When the user is away, the summary and anything decided go in the next
285
+ message; nothing waits for them to read it.
286
+
287
+ ## What an iteration and a round cost
288
+
289
+ An iteration is judged against its parent and the frontier as they stood when
290
+ it started. Each iteration costs `runs_per_iteration` runs, and a round
291
+ costs as many iterations as it takes to find one that passes the keep rule.
292
+
293
+ **Subagent time is usually the larger share of an iteration.** It takes
294
+ several times as long as its runs, reading code, building variants and
295
+ running its own checks, so more GPUs per iteration shorten the runs, not the
296
+ rest. The dashboard's iteration log breaks each iteration's time down.
297
+
298
+ ## When the objective moves by an order of magnitude
299
+
300
+ Two parts of the search are calibrated to the scale it started at, and an idea
301
+ that moves the objective tenfold or more leaves both behind:
302
+
303
+ - **The noise band's reference spread** is the baseline's until the first
304
+ phase, and the root's after: `autoopt.py loop` re-measures it from the
305
+ root's own runs each time a phase opens and holds it for the phase, so a
306
+ large speedup narrows the band by the next phase. Within a phase the band
307
+ stays as it was; if the objective moved tenfold inside one, hand back and
308
+ tell the user, and the next phase measures it again.
309
+ - **A timed call below about 10 ms** is mostly clock noise when the benchmark
310
+ times it once (`references/step2-baseline.md`, *One run is a warmup and one
311
+ timed call*). Changing the benchmark is a new search; propose one, seeded
312
+ from the current best, whose benchmark repeats the call.
313
+
314
+ ## The round summary
315
+
316
+ The `finish` that writes the last README of a closed round writes that
317
+ round's summary, `rounds/round-<N>.md`, as
318
+ `promote` does; nobody writes one by hand. It holds the table
319
+ with a column per gate and observer, the best of the round and overall, each
320
+ prediction beside its measured change, the round's validation, and three
321
+ sections assembled from the records: *What this round tested* (each
322
+ iteration's title and the first sentence of its README's *The idea*), *What
323
+ landed and why* (what became of each, from its keep verdict, and the first
324
+ sentence of *What happened*), *Next round* (the next untried ideas). Show the
325
+ user the table, with anything decided while they were away.
326
+
327
+ `summary overdue` in `status` names a closed round whose iterations have all
328
+ settled and not all written a README (*A subagent that goes quiet*).
329
+ `python3 $AO/autoopt.py summary $WORK --round 3` writes it at once, with
330
+ `(no README)` for an iteration that has none.
331
+
332
+ `no settled iteration carries round N` means none of the round's iterations
333
+ has settled yet.
334
+
335
+ ## When to stop
336
+
337
+ Stop and tell the user when one of these is reached. `autoopt.py end
338
+ --reason` records which, by the word in the first column:
339
+
340
+ | Word | Reached when |
341
+ |---|---|
342
+ | `stalled` | the root has not moved through a phase's worth of settled iterations (`loop_handback`) |
343
+ | `variations` | the remaining ideas are variations of ones that failed |
344
+ | `budget` | the compute spent has passed what the user agreed to: `after.budget_iterations` iterations have settled, every idea from the `after.budget_stages` idea-miner stages is tried or dropped (`status` says so, and `mine` refuses a further stage), or the wall clock since step 2 began has passed `after.budget_hours`. Once the iteration or hour budget is spent, or the stage budget's last idea is briefed, `brief --next` briefs nothing and says to hand back, so the phase hands back when the iteration in flight settles |
345
+ | `noise` | the frontier's improvements are smaller than the noise band |
346
+ | `floor` | a minimized objective's root is at or under `floor`, the smallest value the user called worth measuring (step 0). `stages.py next` stops for the user even under `after.stop=auto`: end, or a new search on a larger input seeded from this root (`references/changes.md`) |
347
+
348
+ The user's own words are a reason too, and so is a target they named at
349
+ step 0 (`spec.md`, *Goal and scope*) once the root reaches it. Then step 4, which ends the search on
350
+ the record (`references/step4-final.md`).
@@ -0,0 +1,121 @@
1
+ # Step 4 — end the search
2
+
3
+ The search ends on the record, once, by a command. Run it when *When to stop*
4
+ (`references/step3-rounds.md`) is reached and the user does not go on, or when
5
+ the user says the search is over. Nothing after it needs the search to run:
6
+ shipping (step 5) and finishing (step 6) read `ended.json`.
7
+
8
+ ```bash
9
+ python3 $AO/autoopt.py end $WORK --reason <stalled|variations|budget|noise|floor|"<the user's words>"> --background
10
+ python3 $AO/autoopt.py wait $WORK/autooptimize/end.log # again, until it prints `wait: finished`
11
+ ```
12
+
13
+ `--reason` is the word of the *When to stop* criterion reached (`references/step3-rounds.md`) or the user's own words. Without it, `end` records `floor` when the root is at the floor, `budget` when the idea-miner stage budget is closed with every idea tried or dropped, or `after.budget_iterations` iterations have settled, `stalled` when the open round holds a phase's worth of settled iterations, and `none stated` otherwise. `--id` names another winner than `best`.
14
+
15
+ ## Refusals
16
+
17
+ `end` changes nothing and says why while:
18
+
19
+ - an iteration is in flight: running (no `result.json`), finishing (measured,
20
+ no `README.md` yet) or briefed and not started. Let it settle; no new idea
21
+ starts. A brief that will never be spawned is withdrawn by deleting the
22
+ `briefs/<id>.md` the refusal names;
23
+ - a phase of the orchestrator subagent is open (the orchestrator closes it
24
+ when told to stop; `loop --done` after one that died);
25
+ - the search already ended (`end --reopen`);
26
+ - `--id 0` while a change was kept: A0 is never chosen over one.
27
+
28
+ A search that kept nothing ends on A0: there is no paired timing, `ended.md`
29
+ says "No change was kept", and step 5 has nothing to ship (`stages.py`
30
+ marks it complete), so the next step is step 6.
31
+
32
+ A failed `end` (`end.log` ends with a non-zero exit) makes `stages.py next`
33
+ return `stop` with the error, rather than run `end` again: fix what it names,
34
+ or tell the user, then run `end` again.
35
+
36
+ ## What it does, in order
37
+
38
+ 1. Runs `final`: the winner against A0 by paired timing (and at
39
+ `checks.threads`), written to `final.json`. A search with no timing probe
40
+ (`checks.time`) has none; its medians are the result. A paired run that
41
+ errors stops the ending before anything is written or deleted. Its two
42
+ unrecorded runs price it (`priced:` in `final/paired.log`): when the least
43
+ pairs would pass `after.pair_cap_hours` (4) it is `over cap` and the ending
44
+ stops there, to raise the cap or to point `checks.time` at a smaller input
45
+ the user agrees to. A recorded run past ten times its side's unrecorded
46
+ run plus 60 s is killed (`timed out`), which also stops the ending. The
47
+ `checks.threads` comparison runs only after the main one was made; `over
48
+ cap` or `timed out` there is recorded and does not stop the ending. On a GPU search
49
+ `end` and `final` take their lease through `gpu_command`.
50
+ 2. Writes the summary of the round still open, when its iterations all have
51
+ READMEs (`references/step3-rounds.md`, *The round summary*).
52
+ 3. Writes `autooptimize/ended.json` (below), then `ended.md`, and prints it: the median from A0 to the winner with each gate's status; the paired line, labeled "paired, on the search's own input"; the winning iterations by category with each one's change from its parent. Every number is read from `result.json` and `final.json`.
53
+ 4. Deletes the regenerable files (below) and records what it freed.
54
+ 5. Writes a static snapshot of the dashboard, `autooptimize/final/dashboard.html`,
55
+ and leaves the publisher running. Step 6 stops it. A missing `plotly`
56
+ leaves no snapshot and says so.
57
+ 6. Prints the next step: step 5, shipping, which starts by asking the user
58
+ how to ship (`references/step5-ship.md`), or step 6 when nothing was kept.
59
+
60
+ Show the user `ended.md`, the paired verdict beside the medians, and quote the
61
+ paired line in the final report.
62
+
63
+ ## ended.json
64
+
65
+ Read `autooptimize/ended.json` for the reason, the winner, the paired result, the medians, the clean-up counts and `winner_changes` (`[]`; one entry for each iteration made with `--after-end` and promoted).
66
+
67
+ After `end`, `--id best` means `ended.json`'s winner in every command.
68
+
69
+ ## The clean-up
70
+
71
+ Automatic, and the same as `prune --worktrees` with the winner protected:
72
+
73
+ | Goes | Stays |
74
+ |---|---|
75
+ | each run's output files, except `metrics.json`, `log.txt` and `commit`, in every iteration off the winner's path | `config.json`, `spec.md`, `state.json`, `ideas.md`, `knowledge.md`, `rounds/`, `briefs/`, every `README.md`, `meta.json`, `result.json`, `report.txt`, `notes.md`, `unit-tests/`, `probe/` files other than arrays |
76
+ | the compiler `cache/` and the exported `check/` trees of those iterations | `repo.git/`: every iteration's code, one branch each |
77
+ | the code checkout (worktree) of every iteration off the winner's path; `restore --id` brings one back | the winner's path in full: A0 and every iteration from it to the winner, with checkouts and run files; every root |
78
+ | saved output arrays (`--outputs-ext`, default `.npy,.npz`) in every settled iteration, as `prune` does | `harness/`, `checks/`, `reference/`, `tools/`, `final/`, `ended.*`, and everything outside `autooptimize/` (`tests/`, `interview/`, `inputs/`) |
79
+
80
+ What stays is what a reader of the ended search needs: the branches in
81
+ `repo.git/`, every `result.json` and `meta.json`, the winner's `unit-tests/`,
82
+ `reference/`, `harness/`, `checks/` and `final.json`. Cleanup is not undone by
83
+ reopening.
84
+
85
+ ## An iteration made after the end
86
+
87
+ A change the ended winner still needs (a notice, a fix, a clean-up
88
+ such as a comments-only iteration): after `end`, `new` and `brief` refuse
89
+ without `--after-end`, which stamps the iteration (`meta.json` `after_end`). It
90
+ is measured like any iteration (`run_iteration.py`). Its runner does not
91
+ promote it; `promote --id` runs the preflight on it
92
+ (`references/promotion.md`, *The preflight*), appends it to `winner_changes`
93
+ and makes it the winner in `ended.json` and `ended.md`. Anything checked on
94
+ or built from the earlier winner is then stale. `paired` in `ended.json` stays
95
+ the earlier winner's; `final` measures the new one. An iteration made without
96
+ `--after-end` is never promoted after `end`.
97
+
98
+ ## Reopening
99
+
100
+ ```bash
101
+ python3 $AO/autoopt.py end $WORK --reopen
102
+ ```
103
+
104
+ Archives `ended.json` as `ended-<n>.json` (and `ended.md`), restarts the
105
+ dashboard publisher and lets `loop`, `brief`, `new` and `mine` work again.
106
+ Reopen when the user wants the search itself to go on, then end again. The
107
+ clean-up stays done. `after.ship` goes back to `ask` (it answered for the
108
+ winner set aside), so the next `end` leads to step 5's question again; the
109
+ other `after` answers stay.
110
+
111
+ It is refused while `autooptimize/reopen-lock.json` holds a hold
112
+ (`{"holds": [{"by", "reason", "at"}]}`), printing each: step 5 writes one when it applies the change, makes a
113
+ branch or posts a document (`autoopt.hold_reopen(root, by, reason)`; a
114
+ `reason` of None withdraws it). A shipped winner changes only through an iteration made with
115
+ `--after-end` (above).
116
+
117
+ ## Paused, not finished
118
+
119
+ A search that is only paused is not ended: stop at *When to stop*, keep
120
+ `ideas.md` current and prune nothing. `status` and the round summaries hold
121
+ the state, and `references/resume.md` is what the next session reads.