2025 – 2026 · Updated 2026-02-23

CogniCode-MCTS

Inference-time code generation framework combining Monte Carlo Tree Search (PUCT) with AST sandbox verification.

My Role
Author & Research Engineer
Current Status
Research prototype · Open-source Python framework
Intended Users
Applied ML engineers and researchers exploring inference-time search and symbolic verification for code generation.

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.

LAYER 01

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.

LAYER 02

Proactive AST Sandbox

Structurally validates partial and complete Python candidates to supply deterministic symbolic feedback before reward backpropagation.

LAYER 03

Benchmarking & Inspection UI

Reproducible CLI scripts (benchmarks/ablation.py, benchmarks/runner.py) and a Streamlit explorer for comparing UCB1 against Neural-PUCT.

Technology Stack

  • Python
  • Monte Carlo Tree Search (PUCT)
  • Python AST
  • LLM APIs
  • Streamlit
  • Pandas
  • Matplotlib

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.