---
id: T-1360
name: "G-053-B: hook dispatcher degrades gracefully on missing script (unblocks stuck
  sessions)"
description: >
  G-053-B: hook dispatcher degrades gracefully on missing script (unblocks stuck sessions)

status: work-completed
workflow_type: build
owner: agent
horizon:
tags: []
components: []
related_tasks: []
created: 2026-04-20T14:18:59Z
last_update: '2026-06-11T22:23:46Z'
date_finished: 2026-04-20T14:26:48Z
bvp_scores_proposed:
  - ts: '2026-06-11T22:23:46Z'
    estimator: bvp-estimator-v1-heuristic
    scores:
      D1: 4
      D2: 1
      D3: 0
      D4: 3
      F-RECALL: 0
      F-ORCH: 0
      F3: 0
      F1: 0
      F2: 0
    rationale: D1=4 (body:structural-gate); D2=1 (body:log-or-error-line); D3=0 
      (no-signal); D4=3 (body:portability-abstraction); F-RECALL=0 (no-signal); 
      F-ORCH=0 (no-signal); F3=0 (no-signal); F1=0 (no-signal); F2=0 (no-signal)
    rubric_sha: e4a00f38e801
---

# T-1360: G-053-B: hook dispatcher degrades gracefully on missing script

## Context

Resolves G-053 item B (defense-in-depth fix for hook dispatch fragility).

The `bin/fw hook <name>` dispatcher at `bin/fw:3686-3690` exits with code 2 (BLOCK) when the hook script doesn't exist. Exit 2 in a PreToolUse hook blocks the tool call — so any configuration drift (missing script, typo, stale settings.json referencing a removed hook, session CWD pointing at an incomplete fixture) locks the human out of Bash/Write/Edit simultaneously. Recovery requires out-of-band repair tools (MCP, Grep, Read) that aren't PreToolUse-matched.

Incident: 2026-04-20 session — test fixture with incomplete `agents/` dir caused `fw hook budget-gate`/`check-project-boundary`/etc. to exit 2 on every Bash/Write/Edit. Session became unrecoverable via native tools; had to use `mcp__termlink__termlink_exec` to restore.

Fix: missing hook script → log once to hook-crash.log + exit 0 (allow). A missing hook is a configuration bug, never a reason to hard-lock the agent's tool surface.

## Acceptance Criteria

### Agent
- [x] `bin/fw hook <name>` exits 0 (not 2) when `$AGENTS_DIR/context/<name>.sh` doesn't exist
- [x] Still prints "WARNING: Hook script not found: <path>" to stderr for visibility
- [x] Logs the miss to `.context/working/hook-crashes.log` (append, one line per miss, rate-limit trivially via timestamp) so `fw doctor` can surface it
- [x] `fw doctor` shows missing-hook count when > 0
- [x] Bats test `tests/unit/hook_dispatcher.bats` covers: (a) known hook runs normally, (b) unknown hook exits 0 with stderr warning, (c) log entry is created
- [x] No regression: `bats tests/unit/` passes for prior tests

### Human
<!-- Criteria requiring human verification (UI/UX, subjective quality). Not blocking.
     Remove this section if all criteria are agent-verifiable.
     Each criterion MUST include Steps/Expected/If-not so the human can act without guessing.
     Optionally prefix with [RUBBER-STAMP] or [REVIEW] for prioritization.
     Example:
       - [ ] [REVIEW] Dashboard renders correctly
         **Steps:**
         1. Open https://example.com/dashboard in browser
         2. Verify all panels load within 2 seconds
         3. Check browser console for errors
         **Expected:** All panels visible, no console errors
         **If not:** Screenshot the broken panel and note the console error
-->

## Verification

bats tests/unit/hook_dispatcher.bats
bin/fw doctor >/dev/null 2>&1 || true
# Spot-check: calling a bogus hook name exits 0, not 2
bin/fw hook __nonexistent_hook_for_test__ 2>/dev/null; [ $? -eq 0 ]

## Decisions

<!-- Record decisions ONLY when choosing between alternatives.
     Skip for tasks with no meaningful choices.
     Format:
     ### [date] — [topic]
     - **Chose:** [what was decided]
     - **Why:** [rationale]
     - **Rejected:** [alternatives and why not]
-->

## Updates

### 2026-04-20T14:18:59Z — task-created [task-create-agent]
- **Action:** Created task via task-create agent
- **Output:** /opt/999-Agentic-Engineering-Framework/.tasks/active/T-1360-g-053-a-rewrite-hook-commands-to-absolut.md
- **Context:** Initial task creation

### 2026-04-20T14:26:48Z — status-update [task-update-agent]
- **Change:** status: started-work → work-completed

## Reviewer Verdict (v1.5)

- **Scan ID:** R-bad254a6
- **Timestamp:** 2026-06-02T18:58:50Z
- **Catalogue:** v1.3-seed
- **Overall:** PASS
- **Needs Human:** no
- **Findings:** none

- **Suppressed:** 2 (by override)
  - swallowed-errors @ Verification:line 2
  - AC-verify-mismatch @ AC#3 (Agent)
