Skip to content

Harden regular runner against context loss and false completion#306

Open
mmprotest wants to merge 3 commits into
mainfrom
mmprotest/fix-regular-runner-task-completion-errors-cp1tg5
Open

Harden regular runner against context loss and false completion#306
mmprotest wants to merge 3 commits into
mainfrom
mmprotest/fix-regular-runner-task-completion-errors-cp1tg5

Conversation

@mmprotest

Copy link
Copy Markdown
Owner

Motivation

  • The regular-runner can lose durable task state in long conversations so the model emits generic conversational replies and the runner incorrectly treats them as completion.
  • Existing execution-memento support was insufficient when saved mementos are missing or incomplete, allowing prompt trimming to drop mission-critical fields.

Description

  • Add build_fallback_execution_state_block(runner) to villani_code/execution_memento.py to produce a compact, structured fallback block containing Objective, Success, Current verification, Next action, and optional Constraints.
  • Update _inject_execution_state_memory in villani_code/state_runtime.py to prefer a valid saved memento but always inject the fallback block when memento data is missing or invalid, so regular turns never lack durable task state.
  • Strengthen _trim_regular_turn_messages to preserve all system messages, an earliest non-tool-result user task anchor, and the recent atomic tail while keeping tool-use/tool-result pairs intact.
  • Add a final invariant _ensure_regular_execution_state_invariant in prepare_messages_for_model that guarantees the prepared prompt contains Objective:, Success:, and Next action: and injects the fallback block into the latest safe user message (or appends a user message if needed).
  • Add a minimal completion guard in the main loop (villani_code/state.py) that detects obvious generic no-tool fallback replies when verification is unresolved and prevents them from being treated as successful completion, requesting a context-restore turn and terminating with stalled_context_loss after repeat hits.

Testing

  • Added and updated focused tests in tests/test_state_runtime.py covering fallback injection when the memento is missing or incomplete, trimming behavior that preserves the task anchor and tool-sequence integrity, avoidance of duplicate execution-state stacking, and preference for valid saved mementos.
  • Added a regression test in tests/test_bounded_execution.py to assert a generic no-tool assistant reply does not mark a regular run complete when verification remains unresolved.
  • Ran pytest -q tests/test_state_runtime.py tests/test_bounded_execution.py and the tests passed (46 passed).

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant