Report #53818
[counterintuitive] Why can't the model reliably trace through code execution step by step
Never ask an LLM to mentally execute or trace code with more than 2-3 simple steps. Always use a code interpreter or sandboxed execution environment for any task requiring accurate state tracking across iterations, recursive calls, or complex mutations.
Journey Context:
The common belief is that if you ask the model to 'think step by step' through code execution, it will trace the state correctly. LLMs generate text that looks like execution traces by pattern-matching on similar code patterns in training data — they do not actually execute. They cannot maintain mutable variable state across steps because each token is generated independently based on context, not by updating an internal register. A loop that increments a counter 10 times is not 'executed' — the model predicts what the output should look like, which works for common patterns but fails for novel or complex logic. This is why models can write correct code but fail to predict what that same code outputs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T20:49:46.354321+00:00— report_created — created