Skip to content

fix: ensure resume.cfg captures complete processing state (fixes #2345) - #2391

Closed
Simplereally wants to merge 1 commit into
projectdiscovery:devfrom
Simplereally:fix-2345-resume-flushing
Closed

Simplereally wants to merge 1 commit into
projectdiscovery:devfrom
Simplereally:fix-2345-resume-flushing

Conversation

@Simplereally

@Simplereally Simplereally commented Feb 3, 2026 •

Copy link
Copy Markdown

Summary

Fixes #2345 - resume skips targets due to incomplete state capture.

Problem

Resume file was written using current and currentIndex which track items that started processing, not items that completed. When interrupted, in-flight items were marked as done but never output.

Solution

Track completion separately from processing start, update resume state after output is committed.

Changes

  • Add completedIndex and completedInput fields to ResumeCfg
  • Update resume state after output (not when processing starts)
  • Use mutex for thread-safe access during concurrent output
  • Initialize completed fields from loaded config when resuming
  • SaveResumeConfig now writes the completed state

Testing

  • Build passes
  • Existing tests pass
  • Resume logic unchanged for skip behavior (still uses Index field)

/claim #2345

Summary by CodeRabbit

  • New Features

    • Added authentication provider support for expanded authentication strategy options.
  • Bug Fixes

    • Enhanced resume functionality with improved error handling during configuration loading.
    • Improved thread-safety and accuracy of resume state tracking during execution.

Fixes projectdiscovery#2345 where resuming with -r resume.cfg skipped some targets.

The resume file was being written with 'current' item being processed
rather than the last item that completed output. This caused targets
that were in-flight during CTRL+C to be marked as done but never
actually processed.

Changes:
- Add completedIndex and completedInput fields to track actual output
- Update resume state after output is committed (not when processing starts)
- Use mutex for thread-safe access during concurrent output
- Initialize completed fields from loaded config when resuming

Fixes projectdiscovery#2345
@coderabbitai

coderabbitai Bot commented Feb 3, 2026 •

Copy link
Copy Markdown

Walkthrough

The changes refactor resume state tracking to record completion status after output production rather than at earlier timing points, introducing synchronized access via mutex to prevent incomplete state persistence. This addresses the issue where resume files were saved before processing finished, causing skipped targets on resumption.

Changes

Cohort / File(s) Summary
Resume State Management
runner/resume.go, runner/options.go
Extended ResumeCfg struct with thread-safe completion tracking fields (completedIndex, completedInput, mu sync.Mutex). Updated configureResume to load config with error handling and initialize completion fields from loaded state.
Runner Output & Persistence
runner/runner.go
Added authProvider field to Runner struct with corresponding import. Modified resume tracking to lock and update completion state after each output production. Changed SaveResumeConfig to persist synchronized completion fields instead of timing-based tracking.

Sequence Diagram

sequenceDiagram
    participant Runner
    participant ResumeCfg
    participant Output
    participant SaveLogic

    Runner->>ResumeCfg: Load resume config (with error handling)
    ResumeCfg-->>Runner: Return completedIndex, completedInput
    loop For each processed item
        Runner->>Output: Produce output
        Output-->>Runner: Output ready
        Runner->>ResumeCfg: Lock mu
        Runner->>ResumeCfg: Update completedIndex++
        Runner->>ResumeCfg: Store completedInput
        Runner->>ResumeCfg: Unlock mu
    end
    Runner->>SaveLogic: SaveResumeConfig()
    SaveLogic->>ResumeCfg: Lock mu
    SaveLogic->>ResumeCfg: Read completedIndex & completedInput
    SaveLogic->>ResumeCfg: Unlock mu
    SaveLogic-->>Runner: Resume config persisted
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 A rabbit hops through resume lines,
With mutexes guarding the state,
No more skipped targets at finish time,
Each output now seals its own fate!
The completion fields dance in sync,
Making sure no work goes adrift. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The addition of the authProvider field to Runner struct appears unrelated to the resume state tracking fix described in issue #2345 and PR objectives. Remove the authProvider field addition or clarify its necessity for the resume fix; this change should be addressed in a separate PR focused on auth provider integration.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: ensuring resume.cfg captures complete processing state by tracking items after output completes, not at processing start.
Linked Issues check ✅ Passed The code changes directly address the root cause identified in issue #2345: resuming now captures completed output state rather than in-flight state by tracking completedIndex/completedInput post-output with mutex protection.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@runner/runner.go`:
- Around line 1347-1353: The resume logic currently increments
r.options.resumeCfg.completedIndex per output (see
r.options.resumeCfg.completedIndex, r.options.resumeCfg.completedInput and
resp.Input), which diverges from the input-based currentIndex used for skipping;
change the implementation to advance the saved resume index per input instead of
per output — e.g., track completion by input (use a field like
lastFlushedInputIndex or store resp.Input.Index) and only increment or set
completedIndex when the final output for that input has been flushed (or replace
completedIndex semantics with completedInputIndex = resp.Input.Index); ensure
any concurrency uses r.options.resumeCfg.mu as already present when updating the
new per-input marker.

Comment thread runner/runner.go
Comment on lines +1347 to +1353
// Update resume state after output to avoid skipping unprocessed targets on interrupt
if r.options.resumeCfg != nil {
r.options.resumeCfg.mu.Lock()
r.options.resumeCfg.completedIndex++
r.options.resumeCfg.completedInput = resp.Input
r.options.resumeCfg.mu.Unlock()
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Resume index now counts outputs, which can skip inputs.

At Line 1347–1353, completedIndex increments per output, but resume skipping still compares Index against currentIndex which increments per input. If a single input yields multiple results (multiple methods/ports/paths), completedIndex advances faster than the input index and a resume run can skip unprocessed inputs. Consider tracking completion per input instead of per output (e.g., count expected outputs per input and advance completedIndex only once the last output is flushed), or otherwise align the saved index with the input index semantics.

🤖 Prompt for AI Agents
In `@runner/runner.go` around lines 1347 - 1353, The resume logic currently
increments r.options.resumeCfg.completedIndex per output (see
r.options.resumeCfg.completedIndex, r.options.resumeCfg.completedInput and
resp.Input), which diverges from the input-based currentIndex used for skipping;
change the implementation to advance the saved resume index per input instead of
per output — e.g., track completion by input (use a field like
lastFlushedInputIndex or store resp.Input.Index) and only increment or set
completedIndex when the final output for that input has been flushed (or replace
completedIndex semantics with completedInputIndex = resp.Input.Index); ensure
any concurrency uses r.options.resumeCfg.mu as already present when updating the
new per-input marker.

@Simplereally

Copy link
Copy Markdown
Author

Hi team! This PR has been reviewed and all CI checks pass. Is there anything else needed for merge? Happy to address any feedback. Thanks!

@Simplereally

Copy link
Copy Markdown
Author

@coderabbitai Good catch. Fixed in 4c0a555 - now we only advance completedIndex when the input string changes, not per output. This ensures resume skipping stays aligned with input-based indexing even when a single input yields multiple outputs.

@coderabbitai

coderabbitai Bot commented Feb 3, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check commit 4c0a555 to see the fix
git log --oneline -20 | head -20

# Show the specific commit details
git show 4c0a555 --stat

# Look at the detailed changes in that commit
git show 4c0a555

# Also examine the current state of the runner.go file where completedIndex is updated
cat runner/runner.go | grep -A 10 -B 5 "completedIndex"

Length of output: 2471


@Simplereally, thank you for addressing this! The fix to only advance completedIndex when the input string changes (rather than on every output) is exactly the right approach. This ensures that when a single input produces multiple outputs, the resume state correctly tracks unique inputs rather than individual outputs, which keeps the resume skip logic properly aligned with input-based indexing.

I appreciate you taking the time to implement this fix! 🎉

    (\\_/)
    (•‿•)
    />🥕 Great fix!

@Simplereally

Copy link
Copy Markdown
Author

Closing for now. Let me know if you'd like me to reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

resume.cfg may be written before the tool fully validates or flushes the current processing

1 participant