Rediscovery costs on recurring tasks can justify gated code reuse
Type: types/note.md · Tags: learning-theory, continual-learning, self-improving-systems
This note states an engineering bet, not a measured result: on workloads with recurring similar tasks, admitting checked generated code into a callable library can reduce total work and repeated failures compared with regenerating procedures from scratch.
Episode-ephemeral runtimes — such as a recursive language model (RLM) configured to tear down its interactive Python session after each task — have no first-class reuse object in their execution model. Discoveries made during a run (decompositions, invariants, edge-case repairs) vanish when the episode ends. Generated and tested code is the starkest case because it is costly to produce and verify, and is already executable when the run finishes.
This is a cost and reliability bet, not an information-loss impossibility claim. A deployment can log full execution traces — including the generated code — or train weights offline from past trajectories. Once the information survives in logs or can be re-derived from weights, absolute claims that ephemeral execution prevents learning fail. The real comparison is economic: how much work and failure risk each reuse path charges over a stream of similar tasks.
Why rediscovery costs can be substantial
Treating regeneration as cheap confuses typing code with rediscovering a working procedure. Four costs compound when similar operations recur:
- Search and debugging against live inputs. Writing a first draft script is cheap; discovering a script that actually handles real data quirks, API constraints, and edge cases requires stochastic multi-turn search against execution feedback. Executing a previously checked fragment is deterministic and cheap — the procedural counterpart to LLM recompute cost shifting the store-vs-recompute balance.
- Repeated verification or silent regression. Suppose a run reconciles two collections of records: its first script matches on names and silently merges two people, while a corrected version uses stable identifiers and reports ambiguous matches. A later run calling the checked implementation keeps that fix and can rerun the regression case. A fresh generation either pays to re-verify every uncovered edge case or risks silently reintroducing the defect.
- Context, latency, and trajectory failure. Failed trial-and-error attempts consume bounded context, sub-agent calls, and timeout budgets. In a LongCoT-mini exercise, the author observed that the RLM failed the majority of
MATHandCStrajectories by attempting "a pure brute-force approach, crashing the REPL and failing the trajectory" (LongCoT-mini, verbatim). Rediscovery cost here was not minor token overhead; it was repeated task failure. - Trace excavation even when logs exist. Saving raw execution traces preserves the working script's bytes, but a trace entangles that code with failed attempts and episode-specific state. Finding the relevant trace, stripping one-off assumptions, and re-verifying fit still charges search and checking cost on reuse unless the runtime promotes recurring discoveries into named, callable artifacts.
Promotion requires a reject-capable gate
Promotion means making a fragment callable by later runs only after a check that can reject it. The original execution exercises one input; promotion still pays to identify what should generalize, remove input-specific assumptions, and verify behavior on fresh cases. Later runs pay to locate the fragment and judge fit, and maintainers pay to repair or retire it as interfaces drift. Moving a Python fragment into a library changes its persistence and checking boundary, not its representational form: it already ran under Python's rules, whereas codification moves a natural-language rule into symbolic form.
A successful run can also supply a bad candidate. In a Factorio episode, Prime Agent retained an RCON shortcut as a reusable skill; the report notes that "persistence preserved behavior that optimized the measured objective, including a specification exploit" (Prime Agent, verbatim). A promotion check that merely repeats the task's reward signal can approve the same shortcut. The gate needs evidence that the procedure achieved the intended result by permitted means. That episode illustrates the hazard of ungated admission; it did not test a reject-capable gate for executable fragments.
Alternative cross-run carriers
Cross-run learning remains available even when generated code is discarded after every run:
- Offline weight training can update policy parameters from trajectories, but collecting data, training, and deploying updates delays improvement, and the resulting procedure is hard to inspect, test, or revert per unit.
- External trace mining into prose tips avoids code maintenance. In the LongCoT-mini exercise, the author asked a separate agent to "look at the trajectories, write tips for the RLM to not make mistakes, and restart the run" (LongCoT-mini, verbatim). A prose tip lets the next model adapt advice across varied problems, but each run must re-interpret the tip and re-implement the edge-case handling. The exercise illustrates a viable alternative carrier; whether a callable helper would have outperformed tips there remains open.
The same promotion question arises outside RLMs when agents write ad hoc maintenance scripts. Commonplace keeps scripts expected to recur and uses stable core logic across unrelated sessions as a signal for promoting a script to an installed command (ADR 040). That local practice identifies candidates from ordinary work while leaving the economic bet unmeasured.
Scope
This bet applies only to streams of structurally recurring tasks identifiable from task requirements before testing. On unrelated one-offs, there is no later reuse to repay generalization, indexing, or maintenance. An RLM implementation enters this disposal comparison only when its post-run lifecycle is specified.
A direct test compares matched streams of held-out recurring tasks over a fixed horizon, giving both runtimes the same initial model, tools, traces, tests, and ability to learn from prose tips, while giving one runtime the additional option of promoting checked fragments. Total work must be counted from the first task onward — including failed promotion attempts, library lookup, maintenance, and retries — alongside independent correctness scoring and the rate of repeated failures on later applicable tasks.
The bet loses under any of three empirical outcomes:
- Total cost fails to drop: across representative recurring workloads, retrieval, generalization, and upkeep consume the savings of library calls at matched task quality.
- Reliability fails to improve: regeneration using the same surviving prose tips and tests matches or beats gated code reuse on repeated failures, either because the model reliably reconstructs repairs or because stale fragments reintroduce defects.
- Frequent weight updates dominate: cheap, rapid policy updates match or beat gated reuse on both total cost (including training) and repeated failures within that deployment regime.
Relevant Notes:
- A proposal-selection improvement loop requires search, evaluation, and operative retention — exemplifies: ordinary task execution supplies candidates, a reject-capable gate evaluates them, and later calls put accepted fragments to use.
- LLM recompute cost shifts the store-vs-recompute balance — extends: applies model-side recomputation economics from cached derived values to reusable generated procedures.
- Orchestration strategies and run-state have opposite persistence economics — extends: isolates which part of a host scheduler (
selectvs. run-stateK) recurs across tasks. - Regenerable software splits continuity across durable carriers — contrasts: asks which commitments must survive when old code is replaced rather than reused.
- History has one chance to become checkable — contrasts: separates true information-loss absolutes (unrecorded history) from the cost trade-off here, where traces or weights retain the information.
- ADR 040 on reusable ad hoc scripts — abstracted-from: a local repository practice for capturing recurring agent-written scripts without claiming to settle the economic bet.