Skip to content

Fix COMMAND rules promise handling and update queue status#120

Merged
nhorton merged 3 commits intomainfrom
claude/fix-hooks-tests-f7u9U
Jan 22, 2026
Merged

Fix COMMAND rules promise handling and update queue status#120
nhorton merged 3 commits intomainfrom
claude/fix-hooks-tests-f7u9U

Conversation

@nhorton
Copy link
Contributor

@nhorton nhorton commented Jan 22, 2026

Summary

Fixed COMMAND rules promise handling in the hooks system. Previously, when agents provided promise tags for failed command rules, the queue entry remained in FAILED state. Now it's properly updated to SKIPPED, accurately reflecting the rule state.

Changes

  • Improved promise handling in rules_check.py:

    • FAILED COMMAND rules no longer re-run (prevents infinite loops)
    • When an agent provides a promise tag for a FAILED command rule, the queue entry is updated to SKIPPED status
    • Added post-processing loop to check all FAILED queue entries against promised rules
  • Reorganized debugging documentation:

    • Created doc/debugging_history/AGENTS.md with template and guidelines for documenting debugging sessions
    • Updated doc/debugging_history/hooks.md to reference AGENTS.md and reflect the improved fix
  • Version bump: 0.5.1 → 0.5.2 with changelog entry

Implementation Details

The fix has two parts:

  1. Prevent re-running: Skip COMMAND rules with FAILED status to prevent infinite loops
if existing and existing.status == QueueEntryStatus.FAILED and rule.action_type == ActionType.COMMAND:
    continue
  1. Honor promises: After processing results, update FAILED queue entries to SKIPPED if the agent provided a promise tag
if promised_rules:
    promised_lower = {name.lower() for name in promised_rules}
    for entry in queue.get_all_entries():
        if entry.status == QueueEntryStatus.FAILED and entry.rule_name.lower() in promised_lower:
            queue.update_status(entry.trigger_hash, QueueEntryStatus.SKIPPED, ...)

This ensures:

  • Commands only run once per trigger
  • Agents see error messages once
  • No infinite loops occur
  • Promise tags properly update queue status to SKIPPED
  • Queue accurately reflects rule state

Testing

All 4 infinite block tests pass:

Test Scenario Result
Infinite Block Prompt With promise PASS - No blocking
Infinite Block Command With promise PASS - No blocking
Infinite Block Prompt No promise PASS - Hook fired, returned in time
Infinite Block Command No promise PASS - Hook fired, returned in time

🤖 Generated with Claude Code

claude and others added 3 commits January 22, 2026 21:23
Command rules with FAILED status were re-running on every hook invocation,
causing infinite loops when the command always fails (e.g., `false`).

Added a check to skip COMMAND rules that are already FAILED, similar to
the existing check for PROMPT rules that are already QUEUED. The agent
must provide a promise tag to proceed.

Also added debugging history documentation and updated AGENTS.md to
reference it for future debugging sessions.
Adds changelog entry documenting the bug fix where FAILED command rule
queue entries are now properly updated to SKIPPED when agents provide
promise tags.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@nhorton nhorton changed the title Fix infinite loop in COMMAND rules by skipping FAILED entries Fix COMMAND rules promise handling and update queue status Jan 22, 2026
@nhorton nhorton merged commit ced438f into main Jan 22, 2026
4 checks passed
@nhorton nhorton deleted the claude/fix-hooks-tests-f7u9U branch January 22, 2026 21:49
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.

2 participants