From 29a153616c85b7297f1a627a2f7adc7bcb8fc705 Mon Sep 17 00:00:00 2001 From: Farouk Adeleke Date: Sat, 24 Jan 2026 02:29:36 -0800 Subject: [PATCH] Fix config override bug by recreating LMs after load_state --- nanocode.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/nanocode.py b/nanocode.py index 638c36b..c2dc7b1 100644 --- a/nanocode.py +++ b/nanocode.py @@ -4,6 +4,7 @@ from modaic import PrecompiledProgram, PrecompiledConfig import dspy import re import subprocess +from dspy.utils.callback import BaseCallback # --- Modaic --- @@ -23,6 +24,7 @@ MAGENTA = "\033[35m" # --- File operations --- + def read_file(path: str, offset: int = 0, limit: int = None) -> str: """Read file contents with line numbers. @@ -163,8 +165,15 @@ def run_bash(cmd: str) -> str: return "".join(output_lines).strip() or "(empty output)" +class RLMReasoningCallback(BaseCallback): + def on_module_end(self, call_id, outputs, exception): + if outputs and hasattr(outputs, "reasoning") and hasattr(outputs, "code"): + print(f"\n[REASONING STEP] reasoning: {outputs.reasoning}\n") + + # -- Program --- + class CodingAssistant(dspy.Signature): """You are a concise coding assistant with access to sub agents.""" @@ -279,13 +288,18 @@ class RLMCodingProgram(PrecompiledProgram): PrecompiledProgram.from_precompiled() calls load_state() AFTER __init__, which overwrites our LMs with saved state. We fix this by recreating - the LMs from self.config after the parent load_state runs. Modaic will + the LMs from self.config after the parent load_state runs. Modaic will fix this in a later patch for future devs. """ - super().load_state(state) + super().load_state(state) # recreate LMs from config (not from saved state) self.reload_lms() + if __name__ == "__main__": agent = RLMCodingProgram(RLMCodingConfig()) - agent.push_to_hub(MODAIC_REPO_PATH, commit_message="Fix config override bug by recreating LMs after load_state", branch="prod") + agent.push_to_hub( + MODAIC_REPO_PATH, + commit_message="Fix config override bug by recreating LMs after load_state", + branch="prod" + )