Skip to content

sdk: per-execution result callback for thread-safe engine - #7587

Merged
Mzack9999 merged 1 commit into
devfrom
5651-sdk-result-callback
Jul 25, 2026
Merged

sdk: per-execution result callback for thread-safe engine#7587
Mzack9999 merged 1 commit into
devfrom
5651-sdk-result-callback

Conversation

@Mzack9999

@Mzack9999 Mzack9999 commented Jul 24, 2026

Copy link
Copy Markdown
Member

Summary

  • Add WithResultCallback for per-execution result callbacks on ThreadSafeNucleiEngine.ExecuteNucleiWithOptsCtx (combined with GlobalResultCallback via MultiWriter)
  • Disable template cache on ephemeral executes so concurrent calls do not share/clobber Output
  • Add isolation + regression tests so concurrent callbacks do not overlap

Closes #5651

Summary by CodeRabbit

  • New Features

    • Added support for registering callbacks that receive findings from individual executions.
    • Per-execution callbacks remain isolated during concurrent scans, while global callbacks continue receiving results across executions.
    • Passing an empty callback is safely ignored.
  • Tests

    • Added coverage for concurrent callback isolation, global callback behavior, and empty callback handling.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The SDK adds WithResultCallback for per-execution result handling. Ephemeral executions now use isolated or combined output writers, disable template caching, and preserve global callbacks. Tests validate concurrent isolation, global callback behavior, and nil handling.

Changes

Result callback routing

Layer / File(s) Summary
Callback option contract
lib/config.go
Adds WithResultCallback, which stores non-nil per-execution callbacks and treats nil as a no-op.
Execution-scoped output routing
lib/multi.go
Resolves isolated or combined writers for per-execution callbacks, disables executor caching, and passes the resolved writer into ephemeral execution objects.
Concurrent callback validation
lib/result_callback_test.go
Tests per-execution callback isolation, global callback delivery, nil handling, temporary templates, and result URL extraction.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ExecuteNucleiWithOptsCtx
  participant resolveEphemeralOutput
  participant EphemeralExecutor
  participant ResultCallbacks
  ExecuteNucleiWithOptsCtx->>resolveEphemeralOutput: resolve execution-scoped output
  resolveEphemeralOutput->>EphemeralExecutor: provide isolated or combined writer
  EphemeralExecutor->>ResultCallbacks: emit result events
  ResultCallbacks-->>ExecuteNucleiWithOptsCtx: invoke per-execution and global callbacks
Loading

Suggested reviewers: dwisiswant0, shubhamrasal

Poem

A rabbit hops where callbacks flow,
Each task gets its own result glow.
Global ears hear every cheer,
While private burrows stay crystal clear.
Nil says “nothing”—no need to fear!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 is concise and accurately describes the main change: a per-execution result callback for the thread-safe engine.
Linked Issues check ✅ Passed The PR adds per-execution result callbacks for SDK execution and keeps global callbacks working, matching the linked issue’s callback-processing need.
Out of Scope Changes check ✅ Passed The added routing and tests are all in service of per-execution callback isolation and concurrency safety.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 5651-sdk-result-callback

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/multi.go`:
- Line 8: Replace the testutils.MockOutputWriter dependency in the production
multi execution path with a production runtime writer, and update the
lib/multi.go construction to use it. Ensure the writer synchronizes WriteResult
and all callback state accessed by concurrent template/work goroutines, while
preserving the existing per-call callback behavior through
output.NewMultiWriter.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 608e7db0-3acd-4f7c-aa21-e87ccb313207

📥 Commits

Reviewing files that changed from the base of the PR and between bcf2089 and da2e691.

📒 Files selected for processing (3)
  • lib/config.go
  • lib/multi.go
  • lib/result_callback_test.go

Comment thread lib/multi.go
@Mzack9999
Mzack9999 merged commit 6ecdb94 into dev Jul 25, 2026
19 checks passed
@Mzack9999
Mzack9999 deleted the 5651-sdk-result-callback branch July 25, 2026 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] ... Add execution method for targets, templates, and callback in the SDK module

2 participants