Skip to content

[codex] Harden reflection lessons with source context - #65

Draft
sayhiben wants to merge 4 commits into
cuneytozseker:mainfrom
sayhiben:codex/issue-55-reflection-non-lessons
Draft

[codex] Harden reflection lessons with source context#65
sayhiben wants to merge 4 commits into
cuneytozseker:mainfrom
sayhiben:codex/issue-55-reflection-non-lessons

Conversation

@sayhiben

@sayhiben sayhiben commented May 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add source-aware reflection prompts with program type, result, canvas size, a cleaned bounded code excerpt, and explicit drawing-object API context
  • buffer reflection output before displaying it so missing-context non-lessons are never typed or saved
  • replace obvious missing-context responses with deterministic success/failure fallbacks that do not rely on unexplained TinyCanvas terminology
  • add stdlib tests for prompt shape, source truncation, exact issue [bug] Reflection sometimes says there is no code to review #55 wording, and close missing-context variants

Root Cause

_do_reflect() only sent a success/error result, while build_reflection_prompt() asked the model to review code execution. Some models responded that no code was available, and any non-empty response was persisted to lessons.md.

The first fix added source context and a guard, but review found two remaining gaps: the guard did not catch the exact issue wording (I don't have any code to review and pull lessons from), and the prompt/fallbacks leaned on "TinyCanvas" without explaining that this is a local drawing helper API.

Validation

  • python3.12 -m unittest discover -s tests
  • python3.12 -m py_compile programmer/brain.py llm/generator.py archive/learning.py
  • git diff --check

Fixes #55

@sayhiben sayhiben changed the title [codex] Fix reflection non-lessons [codex] Harden reflection lessons with source context May 25, 2026
cuneytozseker added a commit that referenced this pull request Jun 15, 2026
build_reflection_prompt previously claimed to be reviewing code but
only received the execution result string, so models periodically
refused with "I don't have any code to review" and the refusal got
saved into lessons.md as if it were a lesson.

Now passes self.current_program.code and program_type alongside the
result, mirroring how build_fix_prompt already includes the code. The
raw (unsanitized) code is intentional — the LLM only reads it as
context, never executes it, and bundling a sanitization step here
would entangle this with the still-unresolved archive sanitizer work
(#49).

Addresses #55. PR #65 is a heavier independent fix that also adds
non-lesson guards as defense in depth.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Reflection sometimes says there is no code to review

1 participant