CogniCode-MCTS
Inference-time code generation framework combining Monte Carlo Tree Search (PUCT) with AST sandbox verification.
Overview
CogniCode-MCTS explores inference-time compute scaling for code synthesis by framing program generation as a state-space tree search. Instead of single-pass autoregressive decoding, the engine uses PUCT selection, neural value scoring and proactive AST sandbox checks to prune broken branches and backtrack.
Problem Statement
Single-pass autoregressive code generation propagates early syntax or structural mistakes irreversibly, especially in smaller models where parameter scaling is constrained.
Technical Architecture
Modular Python MCTS engine implementing PUCT selection over candidate code expansions, an AST structural patching/validation sandbox for partial programs, an ablation runner comparing UCB1 vs Neural-PUCT and an interactive Streamlit inspection dashboard.
PUCT Tree Search Engine
Balances LLM prior probabilities P(s,a) with empirical backpropagated action values Q(s,a) across configurable exploration weights and search depths.
Proactive AST Sandbox
Structurally validates partial and complete Python candidates to supply deterministic symbolic feedback before reward backpropagation.
Benchmarking & Inspection UI
Reproducible CLI scripts (benchmarks/ablation.py, benchmarks/runner.py) and a Streamlit explorer for comparing UCB1 against Neural-PUCT.
Technology Stack
Key Engineering Decisions & Challenges
Engineering Decisions
- Used proactive AST validation on partial expansions so syntactically dead branches are penalized early without executing unsafe arbitrary shell commands.
- Provided offline-configurable ablation scripts separating UCB1 from Neural-PUCT heuristics.
Implementation Challenges
- Validating incomplete multi-line Python blocks with AST parsing without falsely rejecting valid prefix states.
- Controlling latency and token budgets across deeper tree rollouts.
Testing Strategy & Demonstrated Outcomes
Testing & Verification
- Controlled ablation comparisons between standard UCB1 and Neural-PUCT across varying exploration constants and iteration budgets.
Demonstrated Outcomes
- Published reproducible open-source research prototype with CLI benchmark runners and interactive search-tree inspection.
Lessons Learned
- Deterministic symbolic checks (such as AST and unit assertions) provide a much cleaner search signal than self-critique prompts alone.