fix #317: suppress workflow context injection on terminal COMPLETE state#318
Conversation
When step_state.json has current_step_id or current_step_phase equal to
"COMPLETE", format_reminder() now returns None immediately via a terminal-
state guard, so the hook emits {} instead of a misleading
"REQUIRED: Complete phase COMPLETE" banner.
Add _TERMINAL_STEP_IDS frozenset constant and 9 regression tests covering
both the integration (subprocess) and unit (format_reminder) paths.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JfWuWC5LkLzZTU6xuLdvAE
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughAdds a ChangesTerminal state suppression
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant Hook as PreToolUse Hook
participant State as step_state.json
participant Formatter as format_reminder()
Hook->>State: read current_step_id, current_step_phase
Hook->>Formatter: format_reminder(state)
alt step_id or phase is terminal (COMPLETE)
Formatter-->>Hook: None
Hook-->>Hook: emit {} (no context injected)
else non-terminal state
Formatter-->>Hook: reminder text
Hook-->>Hook: inject additionalContext
end
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
When a MAP workflow finished and
step_state.jsonwas left withcurrent_step_id="COMPLETE"/current_step_phase="COMPLETE", theworkflow-context-injectorhook still injected a reminder. Becauserequired_action_for_step()had no terminal-state awareness, it fell through to the generic fallback and produced:This misleading banner appeared on every tool call in a new session on the same branch, even though the workflow was long finished.
Fix
Added
_TERMINAL_STEP_IDS: frozenset[str] = frozenset({"COMPLETE"})constant inworkflow-context-injector.py.jinjaand an early-return guard at the top offormat_reminder():The existing
main()logic already handlesNonefromformat_reminder()by printing{}(no injection), so no further changes were needed.The
.jinjasource was edited andmake render-templatespropagated the fix to all generated output trees (.claude/hooks/,src/mapify_cli/templates/hooks/).Tests
Added
TestTerminalStateSuppressclass (9 tests) totests/test_workflow_context_injector.py:{}step_id=COMPLETEor onlystep_phase=COMPLETEeach suppress"REQUIRED"and"Complete phase COMPLETE"must not appear in outputformat_reminder()returnsNonedirectly for both full-COMPLETE and phase-only-COMPLETE statesstep_id="2.3") still emits the[MAP]reminderAll 3234 tests pass (
make checkclean — ruff, mypy, pyright, pytest, check-render).Fixes #317
Generated by Claude Code
Summary by CodeRabbit
Bug Fixes
Tests