Skip to content

fix: prevent loop from getting stuck when research is complete#1

Closed
deividi86 wants to merge 1 commit intomainfrom
fix/loop-stuck-detection
Closed

fix: prevent loop from getting stuck when research is complete#1
deividi86 wants to merge 1 commit intomainfrom
fix/loop-stuck-detection

Conversation

@deividi86
Copy link

Summary

  • Root cause: Circuit breaker check ran before graceful exit check, so 3 "no progress" loops after research completion would halt the loop with an error instead of exiting cleanly
  • Fix: Swap priority order so should_exit_gracefully() (which calls is_research_complete()) runs before should_halt_execution() (circuit breaker)
  • Additional hardening: case-insensitive marker matching, multi-location SYNTHESIS.md search, exit_signal direct reading, CB research-awareness

Changes

File What
smithers_loop.sh Swap CB/exit check order, add exit_signal reading, fix --continue--resume, validate permission mode
lib/phase_state_machine.sh Case-insensitive grep, multi-location SYNTHESIS.md search
lib/circuit_breaker.sh SYNTHESIS.md progress detection, research-complete safety net
smithers_status.sh Case-insensitive grep
CLAUDE.md Document exit priority order and completion detection
tests/unit/test_circuit_breaker.bats 8 new tests (new file)
tests/unit/test_exit_detection.bats 2 new + 3 updated tests
tests/unit/test_phase_state_machine.bats 4 new tests + test isolation fix

Code review findings (addressed)

  • Critical: --continue "$session_id" was incorrect (--continue takes no args) → fixed to --resume "$session_id"
  • High: Added validation for CLAUDE_PERMISSION_MODE against allowlist (acceptEdits, default, plan)

Test plan

  • All 14 new tests pass
  • 107/108 existing tests pass (1 pre-existing failure in test 36 unrelated to this change)
  • Manual: create .smithers/evidence/SYNTHESIS.md with RESEARCH_COMPLETE, run smithers → should exit cleanly
  • Manual: test case-insensitive marker and alternate SYNTHESIS.md locations

🤖 Generated with Claude Code

The main research loop would exit with "circuit_breaker_open" errors even
when research was effectively complete. Root cause: circuit breaker check
ran before graceful exit check, so 3 "no progress" loops after completion
would halt the loop before detecting the RESEARCH_COMPLETE marker.

Changes:
- Swap exit check order: graceful_exit now runs BEFORE circuit_breaker
- Read exit_signal directly from .response_analysis in should_exit_gracefully()
- Case-insensitive RESEARCH_COMPLETE grep (handles Research_Complete, etc.)
- Multi-location SYNTHESIS.md search (evidence dir, parent dir, project root)
- Circuit breaker recognizes SYNTHESIS.md creation as research progress
- Circuit breaker won't open when is_research_complete() returns true
- Fix --continue to use --resume with session ID
- Validate CLAUDE_PERMISSION_MODE against allowlist
- Update CLAUDE.md with exit priority order and completion detection docs

14 new tests added across 3 test files (test_circuit_breaker.bats is new).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link

fatal: could not read Username for 'https://github.com': No such device or address

github run

@deividi86 deividi86 closed this Feb 23, 2026
@deividi86 deividi86 deleted the fix/loop-stuck-detection branch February 23, 2026 12:48
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.

1 participant