Skip to content

reconFTW is a tool designed to perform automated recon on a target domain by running the best set of tools to perform scanning and finding out vulnerabilities

40.7 KB
Raw Blame

id: 01-04 phase: 01 plan: 04 type: execute wave: 3 depends_on: [] requirements: [RESIL-01] gap_closure: true closes_gaps: [CR-01] files_modified:

  • modules/modes.sh
  • modules/utils.sh
  • modules/core.sh
  • .planning/phases/01-resilient-resume-timeout-safety/01-CONTEXT.md autonomous: true must_haves: truths:
    • "On SIGINT/SIGTERM during a running recon, .inprogress_<fn> sentinels remain on disk so the next invocation's WARN resume banner fires (closes CR-01 / SC1 indicator gap)"
    • "Sentinels are still cleared on normal end-of-run via the EXIT trap so a clean shell exit leaves the called_fn_dir tidy (preserves the original D-02 intent for the happy path)"
    • "cleanup_on_exit body remains unchanged — INT/TERM still print 'Interrupted. Cleaning up...' and exit 130 (the user-visible interruption signal is load-bearing and must not regress)"
    • "Start of start() initialises _RECON_CLEAN_EXIT=false; _cleanup_inprogress is gated on the flag being true; the existing successful return path of start() sets the flag to true immediately before its final non-trap exit point so a clean traversal wipes sentinels"
    • "The misleading comment at modules/core.sh:1431-1434 ('EXIT trap clears it on graceful exit') is updated so the documented behavior matches the implemented gated-trap behavior (anti-pattern WR/INFO finding from 01-VERIFICATION.md anti-pattern table at :137)"
    • "01-CONTEXT.md D-02 wording is clarified so its 'trap on EXIT INT TERM clears sentinels' phrasing is reconciled with SC1 — the resolved semantics are 'EXIT trap clears sentinels only on clean exit; SIGINT/SIGTERM preserves sentinels so the next run's resume banner fires'" code_landmarks:
    • "_RECON_CLEAN_EXIT module-level flag declared at the top of start() in modules/modes.sh (immediately after global_start=$(date +%s) at :15 and before set +m) with default false"
    • "Gated body of _cleanup_inprogress in modules/utils.sh:149-152 — early-return when ${_RECON_CLEAN_EXIT:-false} != true, otherwise sweep .inprogress_* files; return 0 to never propagate non-zero through the EXIT trap chain"
    • "Flag-set _RECON_CLEAN_EXIT=true at the end of start() is NOT the right anchor — start() returns to its caller (which then runs the workflow). The flag must be set at the end-of-run point that maps to a clean exit. The orchestrator-level end-of-run is the bottom of the matching workflow function (recon(), passive(), all(), vulns(), osint(), subs_menu(), webs_menu(), zen_menu(), monitor_mode() in modules/modes.sh). The most reliable single anchor is inside end() (the canonical wrap-up function called by every workflow function); set _RECON_CLEAN_EXIT=true as the LAST executable statement of end() so that whichever workflow path the run takes, a successful traversal flips the flag immediately before start()'s caller returns and the shell exits normally"
    • "Comment update at modules/core.sh:1431-1434 — replace 'EXIT trap clears it on graceful exit' with explicit clean-exit-flag semantics: 'EXIT trap clears it ONLY when _RECON_CLEAN_EXIT=true is set by end() (clean traversal); SIGINT/SIGTERM via cleanup_on_exit does NOT set the flag, so sentinels survive and the next run\'s resume banner fires'"
    • "D-02 wording in 01-CONTEXT.md updated to match implemented semantics — keep the decision ID, change the body from 'trap on EXIT INT TERM clears sentinels' to the clean-exit-flag wording so future verifiers do not flag the same inconsistency" behavioral_checks:
    • "Smoke 1 (SIGINT preserves sentinel — the CR-01 reproduction inverted): seed ${tmpd}/.inprogress_sub_brute and ${tmpd}/.sub_passive in a fresh called_fn_dir=$(mktemp -d), source the project via ./reconftw.sh --source-only, install BOTH traps in a bash -c subshell that does NOT call end() (simulates a real Ctrl+C mid-recon), send SIGINT to the subshell. Afterward, ls ${tmpd} MUST still show .inprogress_sub_brute AND .sub_passive. With the current code (pre-patch) the same script wipes .inprogress_sub_brute."
    • "Smoke 2 (clean exit clears sentinel): same setup as Smoke 1 but the subshell calls start() and the workflow's end() function before exiting normally. Afterward, ls ${tmpd}/.inprogress_* MUST be empty (clean traversal flips _RECON_CLEAN_EXIT=true so the EXIT trap sweeps)."
    • "Smoke 3 (INT/TERM banner unchanged): a bash -c './reconftw.sh -d test.local -p' (replace with a smoke target that is safe in the agent's environment, e.g., --health-check if -d is unsafe) sent SIGINT MUST still print the red Interrupted. Cleaning up... banner from cleanup_on_exit and exit with code 130. The new clean-exit-flag must not interfere with this user-facing behavior."
    • "Smoke 4 (bats baseline holds): bats tests/unit/ reports 246/246 PASS (same count as pre-patch). No new tests are added in this plan per CONTEXT.md §Claude's Discretion (Phase 4 owns coverage)."

Restore the `.inprogress_` resume indicator for SIGINT/SIGTERM interruptions (Gap A / CR-01 / SC1 partial). Closes the gap by introducing a `_RECON_CLEAN_EXIT` flag that gates `_cleanup_inprogress` — the EXIT trap sweeps sentinels only when a clean traversal explicitly opts in. SIGINT/SIGTERM does not set the flag, so the `.inprogress_` files survive `cleanup_on_exit`'s `exit 130` and the next run's WARN resume banner fires correctly. Also updates the misleading start_func comment at `modules/core.sh:1431-1434` and reconciles `01-CONTEXT.md` D-02 wording with implemented semantics.

Purpose: 01-VERIFICATION.md marked SC1 PARTIAL because cleanup_on_exit (INT/TERM handler) ends in exit "$exit_code" (modules/utils.sh:145). Per Bash semantics, an explicit exit from inside an INT/TERM trap fires the EXIT trap, which currently runs _cleanup_inprogress unconditionally and wipes every .inprogress_<fn> (verified empirically by /tmp/sc1_v3.sh). Result: Ctrl+C resume indicator never appears — the most common interruption path silently fails the SC1 indicator guarantee. The verifier flagged this exact gap and the 01-REVIEW.md CR-01 advisory described the clean-exit-flag fix; this plan implements it.

Output:

  • modules/modes.sh: declare _RECON_CLEAN_EXIT=false at the top of start() (after global_start=$(date +%s) and before set +m).
  • modules/modes.sh: at the END of end() (the canonical workflow wrap-up), set _RECON_CLEAN_EXIT=true as the last executable statement so any successful traversal flips the flag before the shell exits.
  • modules/utils.sh: gate _cleanup_inprogress body on ${_RECON_CLEAN_EXIT:-false} == "true"; early-return otherwise. cleanup_on_exit itself is NOT modified.
  • modules/core.sh:1431-1434: rewrite the start_func comment to reflect the gated-trap semantics.
  • 01-CONTEXT.md §Decisions D-02: rewrite the body sentence so the locked decision matches the implemented behavior. Decision ID and intent are preserved; only wording changes.

No new tests; Phase 4 owns coverage (/gsd-verifier will not re-flag SC1 once smoke 1 passes).

@$HOME/.claude/get-shit-done/workflows/execute-plan.md @$HOME/.claude/get-shit-done/templates/summary.md @.planning/PROJECT.md @.planning/ROADMAP.md @.planning/STATE.md @.planning/phases/01-resilient-resume-timeout-safety/01-CONTEXT.md @.planning/phases/01-resilient-resume-timeout-safety/01-PATTERNS.md @.planning/phases/01-resilient-resume-timeout-safety/01-VERIFICATION.md @.planning/phases/01-resilient-resume-timeout-safety/01-REVIEW.md @.planning/phases/01-resilient-resume-timeout-safety/01-01-SUMMARY.md @.planning/codebase/CONVENTIONS.md

From modules/modes.sh:

  • function start() — :13-189. Existing INT/TERM trap at :121: trap 'cleanup_on_exit' INT TERM. Existing EXIT trap at :122: trap '_cleanup_inprogress' EXIT # silent EXIT-only sentinel sweep (D-02). Top of start() at :13-16 is the insertion site for _RECON_CLEAN_EXIT=false (must appear BEFORE the trap install at :121).
  • function end() — defined in modules/modes.sh (search for ^function end() or ^end\(\)). This is the canonical wrap-up function called by every workflow function (recon, passive, all, etc.). The LAST executable statement of end() is the insertion site for _RECON_CLEAN_EXIT=true. The location is roughly modules/modes.sh:280-380 per CONTEXT §Established Patterns; executor must locate it via grep before editing.

From modules/utils.sh:

  • function cleanup_on_exit() — :116-146. UNCHANGED in this plan. Currently registered for INT/TERM only via the trap at modules/modes.sh:121. Body prints "Interrupted. Cleaning up...", kills tracked PIDs, and calls exit "$exit_code". Per Bash semantics that exit fires the EXIT trap; that is the exact mechanism that today defeats SC1. We do NOT remove the exit; we make the EXIT trap a no-op for the non-clean case.
  • function _cleanup_inprogress() — :148-152. Current single-line body: [[ -n "${called_fn_dir:-}" ]] && rm -f "${called_fn_dir}"/.inprogress_* 2>/dev/null; return 0. This is the function to GATE on _RECON_CLEAN_EXIT.

From modules/core.sh:

  • function start_func() — :1419-1445. Existing comment block at :1431-1434: 4 lines of doc comment with the misleading "EXIT trap clears it on graceful exit" phrasing. The sentinel touch at :1436 is unchanged; only the comment block above it is rewritten.

From .planning/phases/01-resilient-resume-timeout-safety/01-CONTEXT.md:

  • §Decisions block at :19-61. D-02 is the second decision at approximately :25. Current body says "trap on EXIT INT TERM clears sentinels". This plan rewrites the body sentence (preserving the D-02 ID and decision intent of "graceful exits leave NO .inprogress_* files") to reflect the clean-exit-flag implementation.
Task 1: Initialise `_RECON_CLEAN_EXIT=false` in `start()` and gate `_cleanup_inprogress` in `modules/utils.sh` modules/modes.sh, modules/utils.sh - modules/modes.sh (entire start() body at :13-189 — note `global_start=$(date +%s)` at :15, `set +m 2>/dev/null || true` at :16, the INT/TERM trap at :121, the new EXIT trap at :122 from plan 01-01; insertion is BEFORE :121 and ideally between :15 and :16) - modules/utils.sh (cleanup_on_exit body at :116-146 — DO NOT modify; _cleanup_inprogress body at :148-152 — THIS is what gets gated) - .planning/phases/01-resilient-resume-timeout-safety/01-VERIFICATION.md (verifier's empirical reproduction at the `/tmp/sc1_v3.sh` line of the gaps table — "BEFORE: .inprogress_sub_brute .sub_passive. AFTER SIGINT: .sub_passive. FAIL: .inprogress_sub_brute deleted by EXIT trap") - .planning/phases/01-resilient-resume-timeout-safety/01-CONTEXT.md (D-02 — locked decision body and its inconsistency with SC1) - .planning/phases/01-resilient-resume-timeout-safety/01-REVIEW.md (CR-01 — advisory description of the clean-exit-flag fix; orchestrator chose the clean-exit-flag approach over "drop EXIT trap entirely" because it preserves the D-02 graceful-exit cleanup intent) - .planning/codebase/CONVENTIONS.md (Function Naming, Trap composition, Variable Naming — `_RECON_CLEAN_EXIT` follows the existing UPPER_SNAKE_CASE pattern for runtime-state globals like `LOGFILE`, `DIFF`, `AXIOM`) Step A — Initialise `_RECON_CLEAN_EXIT=false` at the top of `start()` in `modules/modes.sh`. Insert the new line IMMEDIATELY AFTER the existing `global_start=$(date +%s)` line at :15 and BEFORE the existing `set +m 2>/dev/null || true` line at :16. The exact insertion produces a 3-line block at the top of `start()`:
```
    global_start=$(date +%s)                                    # :15 (unchanged)
    _RECON_CLEAN_EXIT=false  # CR-01 fix: gate _cleanup_inprogress so SIGINT/SIGTERM preserve .inprogress_* sentinels (D-02 clean-exit semantics)
    set +m 2>/dev/null || true                                  # :16 (unchanged, shifts to :17)
```

The flag is a function-scope-less global (no `local` keyword) so it is visible to `_cleanup_inprogress` running under the EXIT trap. The default `false` value means any unexpected exit path that does not flip the flag (SIGINT, SIGTERM, SIGKILL-then-the-shell-handler, internal abort like `_abort_disk_full`) leaves sentinels in place. Per CONVENTIONS.md §Variable Naming the UPPER_SNAKE_CASE name matches other runtime-state globals (`LOGFILE`, `DIFF`, `AXIOM`, `FORCE_RESCAN`).

DO NOT modify the trap install at :121 or :122 — they remain `trap 'cleanup_on_exit' INT TERM` and `trap '_cleanup_inprogress' EXIT  # silent EXIT-only sentinel sweep (D-02)`. DO NOT remove the EXIT trap entirely (the orchestrator chose the clean-exit-flag approach over "drop the EXIT trap" specifically so the happy-path cleanup behavior is preserved; the verifier and reviewer both noted that option but recommended the gated approach).

Step B — Gate `_cleanup_inprogress` body on the clean-exit flag in `modules/utils.sh`. The current function body at :148-152 is:

```
# Remove stale .inprogress_<fn> sentinels on EXIT (D-02). Does not call exit/kill/print — safe to fire on every shell exit, including successful runs.
function _cleanup_inprogress() {
    [[ -n "${called_fn_dir:-}" ]] && rm -f "${called_fn_dir}"/.inprogress_* 2>/dev/null
    return 0
}
```

Rewrite to:

```
# Remove stale .inprogress_<fn> sentinels on EXIT (D-02 clean-exit-only).
# Gated on _RECON_CLEAN_EXIT: only sweeps when the workflow's end() set the
# flag (clean traversal). SIGINT/SIGTERM via cleanup_on_exit does NOT set the
# flag, so the sentinel survives and the next run's resume banner fires
# (CR-01 fix; closes SC1 indicator gap from 01-VERIFICATION.md).
function _cleanup_inprogress() {
    [[ "${_RECON_CLEAN_EXIT:-false}" == "true" ]] || return 0
    [[ -n "${called_fn_dir:-}" ]] && rm -f "${called_fn_dir}"/.inprogress_* 2>/dev/null
    return 0
}
```

The `return 0` early-exit on the non-clean case is mandatory — it preserves the existing contract that `_cleanup_inprogress` never propagates a non-zero exit code through the EXIT trap chain (which would alter `$?` on shell exit, affecting CI return-code checks). DO NOT call `exit`, `kill`, `_print_*`, or `log_json` in either branch. DO NOT add stderr output (the EXIT trap must remain silent on graceful exits per the original D-02 intent).

DO NOT touch `cleanup_on_exit` (:116-146). DO NOT touch `rotate_logs` (:154) or any other helper. The change is scoped to the `_cleanup_inprogress` body only.

Constraint check: per CLAUDE.md §Constraints (Bash 4.3+, single-operator) the gated-flag approach is safe — no concurrent runs against the same `called_fn_dir`, so there is no race window where two simultaneous shells could observe different `_RECON_CLEAN_EXIT` values for the same target directory.
bash -n /Users/six2dez/Tools/reconftw/modules/modes.sh && bash -n /Users/six2dez/Tools/reconftw/modules/utils.sh && shellcheck -s bash --severity=error /Users/six2dez/Tools/reconftw/modules/modes.sh /Users/six2dez/Tools/reconftw/modules/utils.sh - `grep -n '_RECON_CLEAN_EXIT=false' /Users/six2dez/Tools/reconftw/modules/modes.sh` returns exactly one match inside the `start()` function body. Confirm the match line number is greater than the line containing `global_start=$(date +%s)` and less than the line containing `set +m 2>/dev/null || true`. Use: `awk '/global_start=\$\(date \+%s\)/{g=NR} /_RECON_CLEAN_EXIT=false/{f=NR} /set \+m 2>\/dev\/null/{s=NR} END{print (g && f && s && g=1, `grep -c 'exit "\$exit_code"' /Users/six2dez/Tools/reconftw/modules/utils.sh` returns >=1, AND `awk '/^function cleanup_on_exit\(\) \{/,/^}/' /Users/six2dez/Tools/reconftw/modules/utils.sh | grep -c '_RECON_CLEAN_EXIT'` returns exactly 0 (the flag must NOT leak into `cleanup_on_exit`). - The INT/TERM trap line is UNCHANGED: `grep -c "^[[:space:]]*trap 'cleanup_on_exit' INT TERM$" /Users/six2dez/Tools/reconftw/modules/modes.sh` returns exactly 1. - The EXIT trap line is UNCHANGED: `grep -nE "^[[:space:]]*trap '_cleanup_inprogress' EXIT" /Users/six2dez/Tools/reconftw/modules/modes.sh` returns exactly 1. - `bash -n modules/modes.sh modules/utils.sh` exits 0. - `shellcheck -s bash --severity=error modules/modes.sh modules/utils.sh` exits 0 (no NEW error-level findings vs baseline). - Behavior smoke (CR-01 inverted reproduction — the SC1 indicator-preserved test): write a temporary script `/tmp/sc1_recheck.sh` that (1) sources `./reconftw.sh --source-only`, (2) `tmpd=$(mktemp -d); called_fn_dir=$tmpd; touch $tmpd/.inprogress_sub_brute $tmpd/.sub_passive`, (3) installs BOTH traps as `start()` does (`trap 'cleanup_on_exit' INT TERM; trap '_cleanup_inprogress' EXIT`) AND initialises `_RECON_CLEAN_EXIT=false`, (4) sends itself SIGINT and exits. After the subshell exits, `ls $tmpd` MUST list BOTH `.inprogress_sub_brute` AND `.sub_passive` (with the pre-patch code only `.sub_passive` survives; the patch must restore the `.inprogress_sub_brute`). Run the script in `bash -c` to get a clean environment. Confirm with `[[ -f $tmpd/.inprogress_sub_brute ]] && [[ -f $tmpd/.sub_passive ]] && echo SC1_OK || echo SC1_FAIL`. - Behavior smoke (clean-exit DOES NOT clear in Task 1 alone — verifies the flag-default invariant): same script but with `_RECON_CLEAN_EXIT=false` and a normal `exit 0` (no SIGINT, no `_RECON_CLEAN_EXIT=true` flip). `ls $tmpd/.inprogress_*` MUST still show the sentinel. This proves Task 1's gate works as a no-op and the sweep behavior depends on Task 2 setting the flag. (Task 2 supplies the clean-exit flag-set.) `_RECON_CLEAN_EXIT=false` initialised at the top of `start()` between `global_start=$(date +%s)` and `set +m`; `_cleanup_inprogress` body gated on `${_RECON_CLEAN_EXIT:-false} == "true"` with `return 0` early-exit otherwise; `cleanup_on_exit` body untouched; INT/TERM and EXIT trap install lines untouched; SIGINT-preserves-sentinel smoke passes; `bash -n` and `shellcheck` clean. Task 2: Set `_RECON_CLEAN_EXIT=true` at the end of `end()` (clean traversal flag-flip) modules/modes.sh - modules/modes.sh (locate the `end()` function definition via `grep -n '^function end()' modules/modes.sh` or `grep -n '^end()' modules/modes.sh`; read the entire body — typically 50-150 lines depending on how many wrap-up activities it performs) - .planning/phases/01-resilient-resume-timeout-safety/01-CONTEXT.md (Integration Points §"start() in modules/modes.sh:13 — installs the EXIT/INT/TERM trap..."; the canonical end-of-run point is the workflow's `end()` function, not the bottom of `start()`) - .planning/phases/01-resilient-resume-timeout-safety/01-VERIFICATION.md (Required Artifacts table — confirms `modules/modes.sh` is where the trap registration and resume banner live; this task adds the matching clean-exit flag-flip in the same file) - .planning/codebase/CONVENTIONS.md (Function Lifecycle — `end()` is the canonical workflow wrap-up; called by every workflow function in `modules/modes.sh`) Step A — Locate the `end()` function in `modules/modes.sh`. Use `grep -n '^function end()' modules/modes.sh` (preferred) or `grep -nE '^[[:space:]]*end\(\)[[:space:]]*\{' modules/modes.sh` if the bare form is used (CONVENTIONS.md mandates the `function name()` form for new code, but pre-existing siblings may use the bare form; honor whichever form is currently in the file).
Find the LAST executable statement before the closing `}` of `end()`. This is typically a `return 0`, a logging call, an `export_reports` invocation, or similar. Insert the flag-flip on the line IMMEDIATELY BEFORE the closing `}`.

The exact insertion:

```
    # Mark clean traversal so the EXIT trap's _cleanup_inprogress sweeps
    # .inprogress_* sentinels (D-02 clean-exit semantics; CR-01 fix). Any
    # path that bypasses end() — SIGINT/SIGTERM via cleanup_on_exit, an
    # internal abort like _abort_disk_full's exit 1, or an unhandled error
    # — leaves the flag at false and the sentinels survive to drive the
    # next run's resume banner.
    _RECON_CLEAN_EXIT=true
}
```

The closing `}` is the existing line, unchanged. The 6-line comment block above the assignment documents the asymmetric semantics (flag-set ONLY on clean traversal) so a future maintainer does not "helpfully" move the assignment to `cleanup_on_exit` or duplicate it in error paths — that would re-introduce the bug.

DO NOT add the flag-flip anywhere else: not inside `cleanup_on_exit`, not inside `_abort_disk_full` (which is in `modules/utils.sh:445-455`; its `exit 1` deliberately bypasses the clean-exit path so post-disk-full re-runs see a fake resume — but per D-09 + the EXIT trap chain, the sentinels survive and on re-run the banner correctly fires, then the user re-tries with more disk; this is the desired UX), and not inside any per-workflow function (`recon`, `passive`, `all`, etc.). The single anchor inside `end()` is sufficient because every workflow function ends with a call to `end()` (this is the project's lifecycle contract per CONVENTIONS.md §Function Lifecycle).

Step B — Sanity-check that every workflow function in `modules/modes.sh` calls `end()`. Run a verification grep BEFORE editing: `grep -nE '^[[:space:]]+end[[:space:]]*$|^[[:space:]]+end[[:space:]]*&&|^[[:space:]]+end$' modules/modes.sh` should return matches inside `recon`, `passive`, `all`, `vulns`, `osint`, `subs_menu`, `webs_menu`, `zen_menu`, and `monitor_mode`. If any workflow function does NOT call `end()`, document the gap in the SUMMARY.md as a separate finding (do NOT add a per-workflow flag-flip in this task — that would multiply the maintenance burden and re-introduce the duplicate-anchor problem). Per CONTEXT.md §Integration Points the project's lifecycle contract is that `end()` is universally called; if a workflow violates it, that is a pre-existing audit gap separate from CR-01.

Constraint check: per the orchestrator's gap-closure context, no new bats tests are added in this phase (Phase 4 owns coverage). The behavioral smoke is the source of truth for "did the flag-flip land correctly."
bash -n /Users/six2dez/Tools/reconftw/modules/modes.sh && shellcheck -s bash --severity=error /Users/six2dez/Tools/reconftw/modules/modes.sh - `grep -c '_RECON_CLEAN_EXIT=true' /Users/six2dez/Tools/reconftw/modules/modes.sh` returns exactly 1 (the flag-flip in `end()`). - The flag-flip is INSIDE the `end()` function body: `awk '/^function end\(\)|^end\(\)[[:space:]]*\{/,/^}/' /Users/six2dez/Tools/reconftw/modules/modes.sh | grep -c '_RECON_CLEAN_EXIT=true'` returns exactly 1. - The flag-flip is the LAST executable statement of `end()` (immediately before the closing `}`): extract `end()` body, find the line of the assignment, find the line of the closing `}`, assert that no other executable line (non-comment, non-blank) appears between them. Verification command: `awk '/^function end\(\)|^end\(\)[[:space:]]*\{/{inblock=1} inblock{print NR": "$0} /^}/ && inblock{inblock=0}' /Users/six2dez/Tools/reconftw/modules/modes.sh | awk '/_RECON_CLEAN_EXIT=true/{f=NR} /^[0-9]+: \}$/{c=NR} END{print (f && c && c == f+1) ? "LAST_OK" : "LAST_FAIL"}'` returns `LAST_OK` (or `LAST_OK` after a single blank/comment line is also acceptable; planner intent is "no other executable statement between flag-flip and `}`"). - The flag-flip line is preceded by a comment block referencing CR-01: `awk '/^function end\(\)|^end\(\)[[:space:]]*\{/,/^}/' /Users/six2dez/Tools/reconftw/modules/modes.sh | grep -B6 '_RECON_CLEAN_EXIT=true' | grep -cE 'CR-01|clean traversal|D-02 clean-exit'` returns >=1. - No flag-flip leaked into `cleanup_on_exit`: `awk '/^function cleanup_on_exit\(\) \{/,/^}/' /Users/six2dez/Tools/reconftw/modules/utils.sh | grep -c '_RECON_CLEAN_EXIT=true'` returns 0. - No flag-flip leaked into `_abort_disk_full`: `awk '/^function _abort_disk_full\(\) \{/,/^}/' /Users/six2dez/Tools/reconftw/modules/utils.sh | grep -c '_RECON_CLEAN_EXIT=true'` returns 0. - `bash -n modules/modes.sh` exits 0. - `shellcheck -s bash --severity=error modules/modes.sh` exits 0 (no NEW error-level findings). - Behavior smoke (clean traversal flag-flip clears sentinels): write a temporary script `/tmp/clean_recheck.sh` that (1) sources `./reconftw.sh --source-only`, (2) `tmpd=$(mktemp -d); called_fn_dir=$tmpd; touch $tmpd/.inprogress_sub_brute`, (3) `_RECON_CLEAN_EXIT=false`, (4) installs the EXIT trap `trap '_cleanup_inprogress' EXIT`, (5) flips `_RECON_CLEAN_EXIT=true` (simulates `end()` running), (6) `exit 0`. After the subshell exits, `ls $tmpd/.inprogress_*` MUST be empty (the EXIT trap saw the flag=true and swept). Confirm with `[[ -z "$(ls $tmpd/.inprogress_* 2>/dev/null)" ]] && echo CLEAN_OK || echo CLEAN_FAIL`. - Behavior smoke (SIGINT path still preserves sentinel — combined with Task 1): repeat the `/tmp/sc1_recheck.sh` smoke from Task 1 acceptance criteria. With Task 2 also landed, the result MUST still be `SC1_OK` (sentinel preserved on SIGINT). This guards against the regression where the developer accidentally flips the flag too early (e.g., at the top of `start()` or inside `cleanup_on_exit`). - bats baseline holds: `bats tests/unit/` reports 246/246 PASS (no regressions from the flag-flip). - Workflow-coverage spot check: `grep -nE '^[[:space:]]+end[[:space:]]*$|^[[:space:]]+end[[:space:]]*&&|^[[:space:]]+end$' /Users/six2dez/Tools/reconftw/modules/modes.sh` returns matches in at least 5 workflow functions (recon, passive, all, vulns, osint or similar). If any expected workflow function is missing, note in SUMMARY.md as a pre-existing gap but DO NOT add per-workflow flag-flips in this task. `_RECON_CLEAN_EXIT=true` set as the last executable statement of `end()`, with a 6-line comment block above it documenting the clean-exit-only intent and the asymmetric placement rationale; no flag-flip leaked into error/abort paths; clean-exit smoke clears sentinels; SIGINT smoke still preserves them (combined Task 1+2 behavior); `bash -n` and `shellcheck` clean; 246/246 bats unit tests pass. Task 3: Update the misleading comment at `modules/core.sh:1431-1434` and reconcile `01-CONTEXT.md` D-02 wording modules/core.sh, .planning/phases/01-resilient-resume-timeout-safety/01-CONTEXT.md - modules/core.sh (lines 1419-1445 around `start_func`, especially the 4-line comment block at :1431-1434 with the "EXIT trap clears it on graceful exit" phrasing flagged by 01-VERIFICATION.md anti-pattern table) - .planning/phases/01-resilient-resume-timeout-safety/01-VERIFICATION.md (anti-pattern row at :136-137 — "modules/core.sh:1431-1434 Misleading comment 'EXIT trap clears it on graceful exit' INFO Documentation drift vs implementation") - .planning/phases/01-resilient-resume-timeout-safety/01-CONTEXT.md (D-02 at the second decision in the §Decisions block — current body says "Staleness detection uses trap-on-exit cleanup. start() in modules/modes.sh installs a trap on EXIT INT TERM that calls _cleanup_inprogress to rm -f $called_fn_dir/.inprogress_*. Graceful exits leave NO .inprogress_* files." The decision INTENT (graceful exits leave a tidy directory) is unchanged; the implementation MECHANISM (gated EXIT trap, not a chained INT/TERM/EXIT trap) is what needs rewording.) Step A — Rewrite the comment block at `modules/core.sh:1431-1434`. The current 4 lines (read with `awk 'NR>=1431 && NR<=1434' modules/core.sh`) are:
```
    # Resume sentinel (RESIL-01 / D-01): touch .inprogress_<fn> as a crash-leftover
    # marker. end_func removes it before touching .<fn>; EXIT trap clears it on
    # graceful exit. A leftover on the next run signals the function was killed
    # mid-execution and must re-run.
```

Replace with (preserves the leading "Resume sentinel (RESIL-01 / D-01)" header but rewords the EXIT-trap sentence so SIGINT/SIGTERM semantics are explicit):

```
    # Resume sentinel (RESIL-01 / D-01): touch .inprogress_<fn> as a crash-leftover
    # marker. end_func removes it before touching .<fn>. The EXIT trap clears it
    # ONLY when end() sets _RECON_CLEAN_EXIT=true (clean traversal). SIGINT/SIGTERM
    # via cleanup_on_exit does NOT set the flag, so the sentinel survives and the
    # next run's resume banner fires (CR-01 / SC1 fix; see modules/modes.sh start()
    # and end() for the flag set/init points).
```

The new block is 6 lines (was 4). DO NOT modify the `if [[ -n "${called_fn_dir:-}" ]]; then` block at :1435-1437 or the `log_json "INFO"` call at :1438 — only the comment block above the touch is rewritten.

Step B — Update D-02 wording in `01-CONTEXT.md` to match implemented semantics. The current D-02 body (read at `awk '/^- \*\*D-02:\*\*/,/^- \*\*D-03:/' .planning/phases/01-resilient-resume-timeout-safety/01-CONTEXT.md`) reads:

```
- **D-02:** Staleness detection uses **trap-on-exit cleanup**. `start()` in `modules/modes.sh` installs a trap on `EXIT INT TERM` that calls `_cleanup_inprogress` to `rm -f $called_fn_dir/.inprogress_*`. Graceful exits leave NO `.inprogress_*` files. Any leftover on the next invocation is a crash-leftover from a prior run and means the corresponding function must re-execute.
```

Replace the body sentence-block (keep the `- **D-02:**` header) with:

```
- **D-02:** Staleness detection uses **clean-exit-gated trap cleanup**. `start()` in `modules/modes.sh` initialises a module-level `_RECON_CLEAN_EXIT=false` flag and installs a separate EXIT-only trap calling `_cleanup_inprogress`. The trap sweep is gated on `_RECON_CLEAN_EXIT=true`, which is set as the last executable statement of `end()` (the canonical workflow wrap-up). Clean traversals therefore leave NO `.inprogress_*` files. SIGINT/SIGTERM (via the separate `cleanup_on_exit` trap that calls `exit 130`) does NOT flip the flag, so the EXIT trap fires with `_RECON_CLEAN_EXIT=false` and the sentinels SURVIVE — the next run sees them and emits the WARN resume banner (CR-01 / SC1 fix). The single-operator-per-target constraint (PROJECT.md) makes this race-free: no concurrent shell can observe a different flag value for the same `called_fn_dir`.
```

Preserve the existing list-item dash and bold-header form so the §Decisions block remains parseable. Do NOT renumber D-03 onward — only D-02's body is rewritten.

DO NOT modify any other decision (D-01, D-03..D-17). DO NOT remove the "Claude's Discretion" section or any other CONTEXT.md content. DO NOT modify the `<canonical_refs>` or `<code_context>` blocks — those describe artifacts and patterns that are still accurate.

Step C — Append a one-line note to the §Implementation Decisions opening sentence noting that D-02 was clarified post-implementation. Find the line `### `.inprogress` Sentinel Lifecycle (Plan 01-01, RESIL-01)` (currently at `01-CONTEXT.md` around `:21`) and leave it unchanged; the D-02 reword above is the only edit in §Decisions. The clarification is recorded in this plan's SUMMARY.md (see <output> section), not in CONTEXT.md itself — CONTEXT.md represents the LOCKED decisions post-resolution.
bash -n /Users/six2dez/Tools/reconftw/modules/core.sh && shellcheck -s bash --severity=error /Users/six2dez/Tools/reconftw/modules/core.sh - The misleading sentence is removed from `modules/core.sh:1431-1434`: `grep -c 'EXIT trap clears it on graceful exit' /Users/six2dez/Tools/reconftw/modules/core.sh` returns exactly 0. - The new clean-exit-flag wording is present in `modules/core.sh` around the start_func sentinel comment: `grep -c '_RECON_CLEAN_EXIT=true' /Users/six2dez/Tools/reconftw/modules/core.sh` returns >=1 (the comment block now references the flag name); `grep -c 'CR-01' /Users/six2dez/Tools/reconftw/modules/core.sh` returns >=1. - The header `# Resume sentinel (RESIL-01 / D-01)` is preserved: `grep -c '# Resume sentinel (RESIL-01 / D-01)' /Users/six2dez/Tools/reconftw/modules/core.sh` returns exactly 1. - The sentinel touch logic is UNCHANGED: `grep -c 'touch "\$called_fn_dir/\.inprogress_\${1}" 2>/dev/null || true' /Users/six2dez/Tools/reconftw/modules/core.sh` returns exactly 1 (the existing line at :1436, unchanged in payload). - D-02 wording is updated in `01-CONTEXT.md`: `grep -c 'clean-exit-gated trap cleanup' /Users/six2dez/Tools/reconftw/.planning/phases/01-resilient-resume-timeout-safety/01-CONTEXT.md` returns exactly 1; `grep -c 'CR-01 / SC1 fix' /Users/six2dez/Tools/reconftw/.planning/phases/01-resilient-resume-timeout-safety/01-CONTEXT.md` returns exactly 1. - The original "trap on `EXIT INT TERM`" wording is removed from D-02: `awk '/^- \*\*D-02:\*\*/,/^- \*\*D-03:/' /Users/six2dez/Tools/reconftw/.planning/phases/01-resilient-resume-timeout-safety/01-CONTEXT.md | grep -c 'EXIT INC TERM\|EXIT INT TERM'` returns exactly 0. - D-02 still references `_cleanup_inprogress` (the implemented helper name): `awk '/^- \*\*D-02:\*\*/,/^- \*\*D-03:/' /Users/six2dez/Tools/reconftw/.planning/phases/01-resilient-resume-timeout-safety/01-CONTEXT.md | grep -c '_cleanup_inprogress'` returns >=1. - Other decisions are unchanged: `grep -c '^- \*\*D-01:\*\*' /Users/six2dez/Tools/reconftw/.planning/phases/01-resilient-resume-timeout-safety/01-CONTEXT.md` returns 1; `grep -c '^- \*\*D-03:\*\*' ...` returns 1; through D-17 each returns 1 (no decisions added, removed, or renumbered). Use: `for i in 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17; do printf "D-%s: " "$i"; grep -c "^- \*\*D-$i:\*\*" /Users/six2dez/Tools/reconftw/.planning/phases/01-resilient-resume-timeout-safety/01-CONTEXT.md; done` MUST report `D-01: 1`, `D-02: 1`, ... `D-17: 1`. - `bash -n modules/core.sh` exits 0 (comment-only change must not break syntax). - `shellcheck -s bash --severity=error modules/core.sh` exits 0 (no new findings; comment text is irrelevant to shellcheck). - Combined-plan smoke (Task 1 + 2 + 3): a fresh `bash -c './reconftw.sh --health-check'` (a safe entry that runs `start()` and `end()` cleanly) must (1) exit 0, (2) NOT leave any `.inprogress_*` files in the resolved `called_fn_dir`, (3) NOT print "Interrupted. Cleaning up..." anywhere. This is the happy-path regression check. - Final SC1 reproduction (from 01-VERIFICATION.md `/tmp/sc1_v3.sh`): re-run the verifier's exact reproduction script with `--gaps-only`-equivalent setup. Seed `.inprogress_sub_brute` and `.sub_passive`, install both traps with `_RECON_CLEAN_EXIT=false` default, send SIGINT, list `called_fn_dir`. The output MUST list BOTH files (with the pre-patch code only `.sub_passive` survived). This single test transitions SC1 from PARTIAL → VERIFIED for the next verifier run. Comment block at `modules/core.sh:1431-1434` rewritten so the documented behavior matches the gated-trap implementation (no more "EXIT trap clears on graceful exit" misleading phrasing); `01-CONTEXT.md` D-02 body rewritten to reflect clean-exit-gated semantics, the `_RECON_CLEAN_EXIT` flag, and the SC1 indicator survival on SIGINT/SIGTERM; all other decisions (D-01, D-03..D-17) unchanged; SC1 reproduction now shows the indicator surviving SIGINT. - `bash -n modules/core.sh modules/modes.sh modules/utils.sh` → exit 0. - `shellcheck -s bash --severity=error modules/core.sh modules/modes.sh modules/utils.sh` → exit 0 (no NEW error-level findings vs baseline). - `bats tests/unit/` → 246/246 PASS (no new tests in this phase per CONTEXT.md §Claude's Discretion; the baseline must hold). - `bats tests/security/` → 34/34 PASS (or whatever the current security-bats count is; verify no regressions). - Behavioral smokes (composed Task 1 + 2 + 3): 1. SC1 indicator survives SIGINT (the verifier's CR-01 reproduction inverted): seed `${tmpd}/.inprogress_sub_brute` and `${tmpd}/.sub_passive`, source `./reconftw.sh --source-only`, install both traps with `_RECON_CLEAN_EXIT=false`, send SIGINT. After the subshell exits, `ls ${tmpd}` MUST list BOTH files. Pre-patch the same script wipes `.inprogress_sub_brute`; post-patch both survive. 2. Clean traversal sweeps sentinels (the happy-path invariant): same setup but the subshell calls `_RECON_CLEAN_EXIT=true; exit 0` (simulating `end()` flipping the flag). After exit, `ls ${tmpd}/.inprogress_*` MUST be empty. 3. INT/TERM banner unchanged: a real or simulated `./reconftw.sh ... ` SIGINT MUST still print "Interrupted. Cleaning up..." from `cleanup_on_exit` and exit 130. The new flag must not interfere with the existing user-visible interruption signal. 4. `--health-check` happy path: `./reconftw.sh --health-check` (the safest existing entry) exits 0, leaves no `.inprogress_*`, does NOT print "Interrupted...". 5. CONTEXT.md D-02 reword: `awk '/^- \*\*D-02:\*\*/,/^- \*\*D-03:/' .planning/phases/01-resilient-resume-timeout-safety/01-CONTEXT.md` prints the new clean-exit-gated phrasing and references `_RECON_CLEAN_EXIT`. 6. core.sh comment reword: `awk 'NR>=1430 && NR<=1442' modules/core.sh` shows the new 6-line block referencing `_RECON_CLEAN_EXIT=true`, `clean traversal`, and `CR-01`. The line `EXIT trap clears it on graceful exit` MUST NOT appear anywhere in the file. - Gap A from `01-VERIFICATION.md` is closed: SC1 transitions PARTIAL → VERIFIED. The `.inprogress_` indicator survives SIGINT/SIGTERM so the next run's WARN resume banner fires correctly. - `cleanup_on_exit` is NOT modified — the loud "Interrupted. Cleaning up..." banner and forced `exit 130` remain the user-facing interruption signal. - The EXIT trap is NOT removed entirely — the orchestrator's chosen clean-exit-flag approach preserves the original D-02 intent (graceful runs leave a tidy directory) while honoring SC1 (Ctrl+C leaves the indicator). - `_RECON_CLEAN_EXIT` flag follows the project's UPPER_SNAKE_CASE runtime-state global naming convention (CONVENTIONS.md §Variable Naming). - No new bats tests are added in this phase (Phase 4 owns test coverage per CONTEXT.md §Claude's Discretion; the 246/246 bats unit count is preserved as the baseline-hold check). - `01-CONTEXT.md` D-02 wording is consistent with the implemented semantics — future verifiers do not flag the same inconsistency. - The misleading comment at `modules/core.sh:1431-1434` is updated; the anti-pattern row in 01-VERIFICATION.md (line 137) is resolved. - All three smokes (SC1 survival, clean sweep, INT banner unchanged) pass. After completion, create `.planning/phases/01-resilient-resume-timeout-safety/01-04-SUMMARY.md`.

The SUMMARY should explicitly note:

  • Gap A (CR-01) closed; SC1 verifier status transitions PARTIAL → VERIFIED on next verifier run
  • _RECON_CLEAN_EXIT flag pattern established for future gated-trap work (Phase 5 documentation candidate)
  • 01-CONTEXT.md D-02 was rewritten in-place — the locked decision intent is preserved, only the implementation-mechanism phrasing changed; downstream consumers of CONTEXT.md (researchers, planners, verifiers) read the updated body and see the gated-trap semantics directly
  • The behavioral smoke /tmp/sc1_v3.sh (or local equivalent) reproduces the SC1 indicator-survives behavior; this is the next verifier's check
  • No bats tests added; Phase 4 owns coverage