Small Models as Strategists: A Self-Improving Framework for Breaking Local Code-Patch Fixation

    This article presents a recursive self-improvement framework for automated code repair that separates strategic decision-making from implementation. It explains how shared experiment state, KL-UCB-based selection, policy memory, and a proposer-worker workflow help systems question the overall solution direction rather than repeatedly patching local errors. It also outlines evaluation methods and engineering safeguards for reliable deployment.

    1. Background: The Local-Patch Mindset

    When large models are asked to write and repair code automatically, a common inefficient pattern emerges. After a program reports an error, the model first modifies the location of the error. If the change does not work, it tries another patch. If it fails again, it continues patching under the same set of assumptions. Rarely does the process stop to ask whether the overall approach chosen at the beginning was wrong from the start.

    The root of this phenomenon lies in context structure. Recent error messages, existing code, and local changes dominate the model’s attention, making it difficult to step outside the current implementation and compare fundamentally different algorithmic routes. In experiments, the research team observed that a model with a smaller parameter scale was sometimes more likely to propose ideas substantially different from the original approach because it had not accumulated large amounts of code context.

    This yields an engineering insight: separating “what to try” from “how to implement it” and assigning these responsibilities to different roles may be more effective than having a single model handle everything end to end.

    2. Core Idea: Separating Decision-Making from Execution

    Recursive Self-Improvement (RSI) refers to a system using its own outputs to continuously improve the subsequent improvement process. In programming scenarios, two roles can be distinguished.

    Role Responsibility Resource characteristics
    Strategy decision-maker Reads tasks and historical experiments, identifies bottlenecks, and proposes directions Called frequently; inputs are mainly summaries and records; suitable for a smaller model
    Executor Writes code, debugs, runs tests, and returns structured results Computationally intensive; requires strong coding ability

    This division has two benefits. First, decision-making is called many times, but each input is relatively short, so using a smaller model can significantly reduce cost. Second, the executor can focus on implementing a clear hypothesis without also being responsible for direction-setting.

    The division also introduces new risks. The decision-maker may provide a wrong direction, so the system must rely on execution results to form a feedback loop and eliminate bad directions after multiple rounds of experiments.

    3. Shared Experiment State: Turning History into a Searchable Asset

    For the decision-maker to make evidence-based judgments, the system needs to maintain a continuously updated shared experiment state. It should include at least:

    • candidate versions that have been tried and their code summaries;
    • parent-child relationships between versions, i.e., which version each change originated from;
    • results of each experiment, including success, failure, and key metrics;
    • a list of directions not yet explored;
    • remaining experiment budget, such as rounds or compute resources.

    The pseudocode below shows the basic form of this structure:

    1. Experiment:
    2. exp_id unique identifier
    3. parent_id parent version identifier; empty for initial version
    4. summary brief description of change and hypothesis
    5. score evaluation score; empty if incomplete
    6. status success / failed / pending
    7. SearchState:
    8. experiments all experiment records indexed by exp_id
    9. open_dirs list of unexplored directions
    10. budget_left remaining experiment count

    The value of version lineage is often underestimated. When a route fails repeatedly, the system can trace back to an earlier fork point and continue from another branch instead of endlessly patching the failed route.

    4. Two Strategy-Learning Mechanisms

    History records alone are not enough; the system also needs to decide “which version to choose and which path to take” based on those records. The approach uses two complementary mechanisms.

    4.1 Selection Based on Upper Confidence Bounds

    The multi-armed bandit problem is a classic model for this type of decision. Each candidate action has an unknown success probability, and the system must balance exploiting known effective actions and exploring uncertain actions.

    Upper Confidence Bound (UCB) computes an optimistic estimate for each action and then selects the action with the highest estimate. The optimistic estimate consists of two parts: the observed average success rate plus an uncertainty bonus related to the number of attempts. The fewer the attempts, the larger the bonus, and the more willing the system is to explore.

    KL-UCB is an improvement on UCB. It uses Kullback-Leibler (KL) divergence to characterize differences in success-rate distributions. For binary outcomes such as success or failure, it usually gives tighter upper bounds than standard UCB. A common form is:

    1. index(a) = max { q ∈ [p̂_a, 1] : n_a · KL(p̂_a, q) ≤ ln(t) }

    where p̂_a is the empirical success rate of action a, n_a is the number of times action a has been tried, and t is the total number of rounds.

    Two points require attention when using this mechanism. First, rewards must be mapped to the [0, 1] interval, for example by using test pass rate or whether a target metric was achieved as the reward signal. Second, if tasks vary greatly, historical statistics may not transfer, so this mechanism should be used together with the next mechanism.

    4.2 Memory-Based Strategy Learning

    The second mechanism distills historical experience into “Policy Memory.” Unlike simple success/failure statistics, each memory entry needs to record the conditions under which a method applies and specific guidance. An entry can be organized as follows:

    1. PolicyEntry:
    2. method method name or change type
    3. applicable_when applicability conditions, e.g., data scale, error type, constraints
    4. guidance implementation advice and caveats
    5. successes number of successes under applicable conditions
    6. failures number of failures under applicable conditions
    7. last_updated most recent update time
    8. active whether the entry is still valid

    Memory entries change through three states as experiments accumulate. If a new experiment confirms the entry’s effectiveness again, the entry is reinforced. If results show that the condition description is incomplete, the applicability conditions are revised. If the entry repeatedly fails in similar scenarios, it is retired. Retirement does not mean deletion; keeping the record helps avoid repeatedly exploring the same dead end.

    The division between the two mechanisms can be understood as follows: the confidence bound answers “where should limited experiment budget be allocated,” while policy memory answers “under what conditions and in what manner should the work be done.” The former is good at quantitative allocation; the latter is good at preserving transferable qualitative experience.

    5. Research Workflow: Proposer and Worker

    Adjusting only the selection strategy is still insufficient to address structural flaws in the solution itself. If the existing framework already limits the upper bound of capability, patching code alone is unlikely to produce a breakthrough. Therefore, the workflow needs a role specifically responsible for proposing new approaches.

    5.1 Responsibilities of the Proposer

    The proposer receives three types of input: the current task description, the structure of the existing implementation, and historical experiment results plus relevant policy memories. It needs to:

    1. identify capability gaps in the current system, such as a high error rate on certain types of input or a module becoming a performance bottleneck;
    2. propose new solution ideas targeting those gaps;
    3. write the idea as a testable hypothesis.

    The third point is especially critical. Statements such as “optimize performance” cannot be judged true or false, whereas “replace the computation in a certain step with an approximate algorithm, expected to reduce runtime on large-scale inputs without changing test results” can be confirmed or refuted by experiments.

    5.2 Responsibilities of the Worker

    The worker is responsible for implementing the hypothesis: writing code, debugging, running tests, and returning structured results. The results should include whether tests passed, changes in key metrics, a summary of failure reasons, and the environment information needed for reproducibility. The more standardized the worker’s report, the more reliable the decision-maker’s judgment in the next round.

    The overall research round can be summarized as follows:

    1. function research_round(state, memory, proposer, worker):
    2. base = state.select_base_version() // Select the version to improve
    3. mode = state.choose_mode(memory) // Explore a new direction or improve current method
    4. relevant = memory.match(mode, base.context) // Retrieve applicable policy memories
    5. proposal = proposer.propose(base, state.history(), relevant, mode)
    6. result = worker.implement_and_test(base, proposal)
    7. state.record(base, proposal, result)
    8. memory.update(proposal, result)
    9. return result

    The key to this loop is that each round writes back state and memory. The next round’s decisions are therefore built on the previous round’s results, giving the system true recursiveness.

    6. Evaluation: Determining Whether the System Is Actually Learning

    The most common misjudgment in self-improving systems is mistaking “appearing to improve” for “actually learning.” It is advisable to build an evaluation system from the following aspects.

    • Learning curve: Record the best score in each round and compare it with baselines using random selection or a fixed strategy to see whether improvement is faster.
    • Ablation experiments: Remove the confidence-bound selection, policy memory, or proposer separately, and observe each module’s contribution to the final result.
    • Held-out tasks: Test on tasks not encountered during the training process to check whether learned experience transfers rather than only applying to a specific problem.
    • Cost efficiency: Count the number of rounds, calls, and compute resources consumed per effective improvement to determine whether the system is worth the investment.
    • Reward hacking check: Watch for behavior that passes tests by hard-coding special cases. Evaluation should use a hidden test set and check whether changes target only visible cases.

    7. Engineering Considerations for Deployment

    When applying this type of framework to real projects, pay attention to the following points.

    1. Budget control: Set limits on rounds, token usage, and compute time, and save the complete state when the budget is exhausted for easy recovery.
    2. Execution isolation: Automatically generated code should run in a sandbox with restricted file-system and network access to avoid accidental operations affecting the host environment.
    3. Versioning and reproducibility: Each candidate version should save a code snapshot, dependency versions, and random seeds to ensure that key results can be reproduced.
    4. Memory freshness: Policy memory should carry timestamps and usage statistics and be checked periodically for expiration to prevent old experience from misleading new tasks.
    5. Information boundary: The decision-maker should not have access to test-set labels or answers; otherwise, the system learns “test-taking tricks” rather than real capability.
    6. Human checkpoints: Changes involving production environments, data migration, or permission changes should be reviewed by humans before merging.

    8. Conclusion

    Separating decision-making from execution, shared experiment state, dual strategy learning, and the proposer-worker workflow form the main skeleton of this type of recursive self-improvement framework. Its core value lies in enabling the system to question the overall direction and correct judgments with experimental results. During deployment, quantifiable evaluation and strict isolation measures should be prerequisites to ensure that the improvement process is controllable and the results are credible.