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

docs(01-04): reconcile core.sh comment and D-02 with gated-trap semantics

six2dez17ae1e17e64f
diff --git a/.planning/phases/01-resilient-resume-timeout-safety/01-CONTEXT.md b/.planning/phases/01-resilient-resume-timeout-safety/01-CONTEXT.md
index 8bbb794..1fd2b22 100644
--- a/.planning/phases/01-resilient-resume-timeout-safety/01-CONTEXT.md
+++ b/.planning/phases/01-resilient-resume-timeout-safety/01-CONTEXT.md
@@ -22,7 +22,7 @@ In scope: lifecycle wrappers in `modules/core.sh`, parallel job machinery in `li
### `.inprogress` Sentinel Lifecycle (Plan 01-01, RESIL-01)
- **D-01:** Sentinel file is a plain empty `${called_fn_dir}/.inprogress_<fn>`. `start_func` `touch`es it; `end_func` removes it before `touch`ing the existing `.<fn>` success checkpoint. No JSON metadata, no PID, no timestamp inside.
-- **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.
+- **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`.
- **D-03:** Rationale for the trap approach (vs PID, timestamp, or "PRESERVE wipes all"): the project is single-operator per target (PROJECT.md constraint), so we never race a concurrent run for the same `called_fn_dir`. That makes "anything still here = crashed previously" a safe inference and removes the need for PID liveness checks or staleness windows. PID schemes also break on PID recycling for long-running boxes.
- **D-04:** Resume report on detection — when one or more `.inprogress_*` files are found at `start()` time, emit **one summary line** at the top of the recon banner: `WARN resume: N functions re-running after interruption (fn_a, fn_b)`. Then proceed silently — no per-function `RESUME` badges, no extra noise inside the module section. JSONL log gets `level=WARN func=resume reason=inprogress_leftover funcs=fn_a,fn_b`.
- **D-05:** `PRESERVE=false` (default) already clears `.<fn>` checkpoints before run start. Same loop must also clear any orphan `.inprogress_*` files so a `PRESERVE=false` run never reports a resume. With `PRESERVE=true`, the trap-cleanup + leftover-detection logic above is what makes resume work.
diff --git a/modules/core.sh b/modules/core.sh
index a651108..140b37b 100644
--- a/modules/core.sh
+++ b/modules/core.sh
@@ -1429,9 +1429,11 @@ function start_func() {
# Keep global $start for backward compat (serial mode)
start=$(date +%s)
# 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.
+ # 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).
if [[ -n "${called_fn_dir:-}" ]]; then
touch "$called_fn_dir/.inprogress_${1}" 2>/dev/null || true
fi