Phase 1: Resilient Resume & Timeout Safety - Context
Gathered: 2026-05-13 Status: Ready for planning
## Phase BoundaryLong-running scans survive interruptions, disk pressure, and stuck tools without silently producing truncated output or wasting hours of re-work on resume. Three plans cover four v1 requirements:
- 01-01 —
.inprogresssentinel lifecycle instart_func/end_funcwith resume detection (RESIL-01) - 01-02 — Disk-full mid-run guard via periodic
dfcheck at function boundaries (RESIL-02) - 01-03 —
PARALLEL_JOB_TIMEOUT_SECONDSenforcement inlib/parallel.shand DNS timeout defaults inreconftw.cfg(RESIL-03, PERF-02)
In scope: lifecycle wrappers in modules/core.sh, parallel job machinery in lib/parallel.sh, disk-space helper in modules/utils.sh, and the four config defaults in reconftw.cfg. Out of scope (deferred to other phases): the MIN_DISK_SPACE_GB 2-vs-5 discrepancy (DOCS-02, Phase 5), per-tool thread caps (PERF-01, Phase 3), and parallel-coverage tests for the new timeout/heartbeat paths (TEST-01, Phase 4).
.inprogress Sentinel Lifecycle (Plan 01-01, RESIL-01)
- D-01: Sentinel file is a plain empty
${called_fn_dir}/.inprogress_<fn>.start_functouches it;end_funcremoves it beforetouching the existing.<fn>success checkpoint. No JSON metadata, no PID, no timestamp inside. - D-02: Staleness detection uses clean-exit-gated trap cleanup.
start()inmodules/modes.shinitialises a module-level_RECON_CLEAN_EXIT=falseflag 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 ofend()(the canonical workflow wrap-up). Clean traversals therefore leave NO.inprogress_*files. SIGINT/SIGTERM (via the separatecleanup_on_exittrap that callsexit 130) does NOT flip the flag, so the EXIT trap fires with_RECON_CLEAN_EXIT=falseand 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 samecalled_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 atstart()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-functionRESUMEbadges, no extra noise inside the module section. JSONL log getslevel=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 aPRESERVE=falserun never reports a resume. WithPRESERVE=true, the trap-cleanup + leftover-detection logic above is what makes resume work. - D-06: Function re-execution on leftover is transparent — the existing checkpoint guard (
[[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]) already re-runs functions whose.<fn>doesn't exist. Because a crashed function never reachedend_func, its.<fn>is absent, so the guard naturally re-enters. The.inprogress_*file is purely for surface-level "what happened?" reporting; it does not drive control flow.
Disk-Full Mid-Run Guard (Plan 01-02, RESIL-02)
- D-07: Check cadence is at every
start_func/end_funcboundary. New helper_check_disk_mid_runinmodules/utils.sh(alongside existingcheck_disk_space()).start_funccalls it BEFORE the existing body;end_funccalls it AFTER touching the checkpoint. ~1ms per call × ~100 function boundaries per scan = negligible overhead. No background watcher process. - D-08: Threshold is the same
MIN_DISK_SPACE_GBused by the pre-flight check atmodules/modes.sh:23. One source of truth. The Phase 5 DOCS-02 work (reconftw.cfg:39says2,modes.sh:23defaults to5) will resolve the discrepancy; Phase 1 does NOT touch that line and does NOT introduce a separate mid-run knob. - D-09: Abort policy is hard abort of the whole run.
_check_disk_mid_runreturns non-zero → caller calls_abort_disk_fullwhich emits_print_error "disk_full: aborting (avail=${avail}GB, req=${MIN_DISK_SPACE_GB}GB at ${dir})", logslog_json ERROR disk_full abort_run, thenexit 1. The BashEXITtrap from D-02 fires on the way out, clearing all.inprogress_*(so a subsequent run does NOT see a fake resume condition). Soft-abort and pause-and-wait were both rejected — single-operator project, fail-fast is correct. - D-10: ENOSPC detection mechanism is boundary
dfonly. Norun_commandstderr scanning forNo space left on device, no per-redirect failure traps. Acknowledged trade-off: a tool that exhausts disk inside a single function (e.g.,gotatorwriting a 2GB wordlist) may produce truncated output for THAT function before the next boundary check catches it. The nextstart_funcaborts the run before any further damage. Pre-flight 5GB margin + DOCS-02 alignment in Phase 5 make this a rare edge case; full per-write trapping is overengineered for v1.
PARALLEL_JOB_TIMEOUT_SECONDS Enforcement (Plan 01-03, RESIL-03)
- D-11: Default value is
PARALLEL_JOB_TIMEOUT_SECONDS=0(disabled, opt-in). Ships inreconftw.cfgwith a doc comment explicitly suggesting3600for long scans and600for CI runs. Zero risk of an in-flight scan getting killed because the default was too aggressive. Backwards-compatible. - D-12: Enforcement point is inside the existing batch-flush heartbeat loop in
lib/parallel.sh:432-465. Today that loop pollskill -0 ${batch_pids[$idx]}everyPARALLEL_HEARTBEAT_SECONDS(default 20s). Extend it: for each alive PID, computenow - batch_starts[$idx]; if> PARALLEL_JOB_TIMEOUT_SECONDS(and the var is> 0), call_timeout_kill_job. - D-13: Kill behavior is TERM then KILL after grace. New knob
PARALLEL_KILL_GRACE_SECONDS=10(also inreconftw.cfgwith doc comment)._timeout_kill_jobsendskill -TERM $pid, pollskill -0 $pidonce per second up to the grace seconds, thenkill -KILL $pidif still alive. Aligns with Unix shutdown semantics and protects against tools that ignore TERM. - D-14: Reporting on timeout — the killed job's badge in
_parallel_emit_job_outputisFAILwith reasontimeout. Persisted to.status_<fn>asFAILand.status_reason_<fn>astimeout(reuses the existing pattern atmodules/core.sh:1505-1509).failed++in the batch counter, soRECON_PARTIAL_RUN=truefollows automatically via the existing aggregator. Console badge:FAIL func_name 600s (timeout). - D-15: Timeout applies to both local and axiom-distributed jobs — the parallel batch wrapper is the same code path for both. No special-casing.
DNS Timeout Defaults (Plan 01-03, PERF-02)
- D-16:
reconftw.cfg:387-388defaults change from0to:DNS_BRUTE_TIMEOUT=6h(was0)DNS_RESOLVE_TIMEOUT=4h(was0) Both already pass through_run_dns_with_heartbeat(modules/utils.sh:1434) which respects0(disabled) — non-zero hex/h-suffix values are honored bytimeout/gtimeout. No code change to the helper, just the cfg defaults plus an inline doc comment.
- D-17: When the hard timeout trips, the existing
_run_dns_with_heartbeatalready returns non-zero and emits a clear log line. We add nothing new for surfacing the timeout — the existing badge path (WARNfromend_func) is sufficient. JSONL log entry should carryreason=dns_hard_timeoutso downstream tools (Phase 4 tests, AI report) can distinguish.
Claude's Discretion
- Exact internal helper naming (
_check_disk_mid_run,_abort_disk_full,_timeout_kill_job,_cleanup_inprogress) is a suggestion; planner may refine while keeping the underscore-prefix-for-private convention from CONVENTIONS.md. - The JSONL log key/value spelling (
reason=inprogress_leftover,reason=timeout,reason=dns_hard_timeout) follows the existing pattern atmodules/core.sh:1505-1509. Researcher/planner may align withSTRUCTURED_LOGGINGschema if a more specific convention exists. - How "summary line" (D-04) is printed exactly — most likely via existing
_print_msg WARNor a new_print_resume_bannerhelper — is a planner-level rendering choice. - Test coverage for the new code paths (
.inprogress_*lifecycle,_check_disk_mid_run, timeout kill, DNS hard timeout) is OUT of scope for Phase 1 by design — Phase 4 (TEST-01) explicitly coversparallel_funcstimeout kill path. Planner should NOT add tests in this phase.
<canonical_refs>
Canonical References
Downstream agents MUST read these before planning or implementing.
Phase scope and requirements
.planning/ROADMAP.md§"Phase 1: Resilient Resume & Timeout Safety" — phase goal, success criteria, 3 plans.planning/REQUIREMENTS.md§Resilience (RESIL-01, RESIL-02, RESIL-03) and §Performance (PERF-02) — the four v1 requirements this phase delivers
Codebase intel (driving the changes)
.planning/codebase/CONCERNS.md§"Checkpoint Files Not Created on Interrupted Runs" — drives RESIL-01 / Plan 01-01.planning/codebase/CONCERNS.md§"Disk-Full Detection Is Pre-Flight Only, Not Mid-Run" — drives RESIL-02 / Plan 01-02.planning/codebase/CONCERNS.md§"parallel_funcs Batch Flushing" — drives RESIL-03 / Plan 01-03.planning/codebase/CONCERNS.md§"DNS_BRUTE_TIMEOUT and DNS_RESOLVE_TIMEOUT Default to 0 (Disabled)" — drives PERF-02 / Plan 01-03
Architectural and conventions (must align with)
.planning/codebase/ARCHITECTURE.md§"Key Abstractions → start_func / end_func" and §"Function Execution Path" — lifecycle wrapper contract the sentinel work must preserve.planning/codebase/CONVENTIONS.md§"Function Lifecycle" and §"File Checkpointing" — checkpoint pattern, status badges (OK/WARN/FAIL/SKIP/CACHE),_print_*helpers, JSONL logging.planning/codebase/CONVENTIONS.md§"Path and CWD Conventions" and §"Parallel Execution" — subshells (no pushd/popd),parallel_funcsmachinery
Project constraints
.planning/PROJECT.md§Constraints — single-operator constraint that makes D-02 trap-only staleness detection safe; macOS Bash 4+ re-exec requirement thatwait -nand the timeout kill path depend onCLAUDE.md§Constraints — same single-process / shared-globals constraints applied at file scope
</canonical_refs>
<code_context>
Existing Code Insights
Reusable Assets
check_disk_space()atmodules/utils.sh:421— already returns 0/1 and populatesDISK_SPACE_INFO. The new_check_disk_mid_runwraps it with the new abort path (D-09); no need to re-implementdfparsing.start_func/end_funcatmodules/core.sh:1419and:1437— existing parallel-safe per-function start timestamp (_start_time_${fn}variable) andrecord_func_timingcalls remain; sentinel ops are inserted at the top ofstart_func(after the timestamp init) and insideend_funcBEFORE the existingtouch "$called_fn_dir/.${fn}"at line 1465._run_dns_with_heartbeatatmodules/utils.sh:1434— already respects0=disabledand acceptstimeout/gtimeout-style duration arguments. No code change for DNS hard timeouts — only thereconftw.cfgdefaults.- Heartbeat loop at
lib/parallel.sh:432-465— already iterates alive PIDs everyPARALLEL_HEARTBEAT_SECONDS. Add the timeout kill check inside this loop (D-12). - Status persistence at
modules/core.sh:1505-1509—.status_<fn>and.status_reason_<fn>pattern already exists; timeout reporting (D-14) reuses it forreason=timeout. log_jsonhelper — used throughoutstart_func/end_func; D-09, D-14, D-17 reuse the same call shape (log_json LEVEL func msg key=val ...).
Established Patterns
- Status badge vocabulary is locked:
OK,WARN,FAIL,SKIP,CACHE,INFO,RUN(CONVENTIONS.md). Timeout kill =FAIL(D-14), disk-full abort =FAIL(D-09), resume notice =WARN(D-04). No new badge values introduced. - Verbosity gating —
OUTPUT_VERBOSITY=0/1/2already governs which_print_msg/notificationcalls are visible. Resume summary line isWARN-level so it shows at default verbosity 1; disk-full error uses_print_errorwhich is always visible. - CLI-over-config re-application — any new config knob (
PARALLEL_KILL_GRACE_SECONDS) added in this phase does NOT need a CLI flag for v1 (env-var/cfg override is sufficient). If a flag is added later, follow theCLI_*re-apply pattern atreconftw.sh:513-578per CONVENTIONS.md. - Source guards — no new lib files in this phase; all changes go into existing
lib/parallel.sh,modules/core.sh,modules/utils.sh,modules/modes.sh,reconftw.cfg. Source-guard pattern is preserved by editing existing files.
Integration Points
start()inmodules/modes.sh:13— installs the EXIT/INT/TERM trap for_cleanup_inprogress(D-02), AND emits the resume-summary banner (D-04) before the first module begins. Also where thePRESERVE=falseorphan-cleanup loop (D-05) lives.- Existing ERR trap in
start()atmodules/modes.sh:140— the new EXIT trap must compose with it, not replace. Either chain (trapaccepts multiple handlers per signal via single registered string) or refactor to a single_recon_exit_hookthat calls both. reconftw.cfg— four config additions in this phase:PARALLEL_JOB_TIMEOUT_SECONDS=0,PARALLEL_KILL_GRACE_SECONDS=10, plus two value changes forDNS_BRUTE_TIMEOUT=6handDNS_RESOLVE_TIMEOUT=4h. All grouped with surrounding context — DNS timeouts already at:387-388, parallel knobs should sit nearPARALLEL_HEARTBEAT_SECONDSdocumentation.- No axiom changes — timeout kill happens at the parent shell's
parallel_funcsheartbeat level, before the per-job subshell. Axiom-distributed jobs invoked from inside a parallel batch are killed at the local subshell level (theaxiom-scancommand is terminated, which itself signals remote nodes — this is sufficient).
</code_context>
## Specific Ideas- "Trap-on-exit cleanup" was chosen explicitly over PID-in-sentinel and timestamp-staleness alternatives because the single-operator constraint removes the only failure mode the alternatives addressed (concurrent runs sharing a
called_fn_dir). Planner should NOT reintroduce PID/timestamp metadata "for safety" — the simpler design is the correct one given the constraint. - Resume report format was chosen as a SINGLE banner line (D-04), not per-function
RESUMEbadges. Planner should NOT decorate per-function output with extra resume context — keepOK/WARN/FAIL/SKIPbadges as-is. The summary line is the only resume-specific UI. PARALLEL_JOB_TIMEOUT_SECONDS=0default (D-11) is deliberate. Do NOT propose a non-zero default. The doc comment inreconftw.cfgshould list the recommended values explicitly (3600 for long scans, 600 for CI) but ship disabled.- Boundary-only
dfchecks (D-10) are an intentional simplicity decision. Planner should NOT addrun_commandstderr scanning forNo space left on deviceor per-redirect ENOSPC traps in v1.
- Per-tool timeout overrides (e.g.,
PARALLEL_TIMEOUT_DNS_BRUTE_SECONDS) — discussed and rejected for v1. If users need it, they can tunePARALLEL_JOB_TIMEOUT_SECONDSupward to accommodate the slowest tool. Revisit only if real-world tuning needs surface. - Background heartbeat watcher for mid-function disk checks — would catch a single function burning through disk before the next boundary fires. Rejected as overengineered for v1 given the 5GB pre-flight margin. Consider in a future "observability" milestone if telemetry shows truncated-output incidents.
- Per-redirect ENOSPC trap wrapping every
>/>>— most thorough mid-function detection but intrusive across the entire codebase. Out of scope for v1. MIN_DISK_SPACE_GB2-vs-5 reconciliation — explicitly Phase 5 (DOCS-02). Plan 01-02 deliberately does NOT touchreconftw.cfg:39ormodules/modes.sh:23; we read whichever value is effective at runtime.- Tests for the new code paths — Phase 4 (TEST-01) covers
parallel_funcstimeout kill path. Sentinel-lifecycle and disk-full handling tests can join that same phase if the planner sees fit; Phase 1 ships behavior, Phase 4 ships coverage.
Phase: 1-Resilient Resume & Timeout Safety Context gathered: 2026-05-13