Skip to content

feat: implement shared ExecutionContext for concurrent sieve checks - #189

Merged
mlieberman85 merged 1 commit into
darnitdevorg:mainfrom
Jaydeep869:feat/execution-context
Apr 15, 2026
Merged

feat: implement shared ExecutionContext for concurrent sieve checks#189
mlieberman85 merged 1 commit into
darnitdevorg:mainfrom
Jaydeep869:feat/execution-context

Conversation

@Jaydeep869

Copy link
Copy Markdown
Contributor

Description

This PR fully implements the shared ExecutionContext system (previously outlined in comments within darnit/core/models.py). This allows large, heavy API toolings (like OpenSSF Scorecard) to cache and share outputs safely across multiple Control evaluations rather than being run redundantly.

Includes thread safe locking mechanisms get_or_run_tool() to anticipate concurrent sieve handler executions. The created execution_context is seamlessly propagated through CheckContext and injected natively downstream onto custom Python Handler's HandlerContext models.

Motivation and Context

Currently, each control runs tools independently, bottlenecking performance. With heavy tools like OpenSSF scorecard running per rule, wait times escalate rapidly. Shared execution contexts securely cache outputs for multi control usage and prevent duplicate networking trips simultaneously.

How Has This Been Tested?

  1. Added unit tests spanning logic within tests/darnit/core/test_models.py verifying cache hits, cache misses, and ThreadPool concurrent access validations limiting tool execution to precisely 1 trigger safely.
  2. Verified property logic dynamically within tests/darnit/sieve/test_orchestrator.py via TestExecutionContextPropagation tests.
  3. Updated /docs/HANDLER_AUTHORING.md demonstrating custom Python handler integrations.
  4. Validated execution using local pytest suite ensuring all core framework / sieve orchestrator paths passed smoothly without regressions.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist:

  • My code follows the code style of this project (ruff check & ruff format).
  • My change requires a change to the documentation.
  • I have updated the documentation (docs/HANDLER_AUTHORING.md).
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

This adds the ExecutionContext class with thread-safe resource locking via get_or_run_tool(), solving the performance issue with executing heavy toolings like OpenSSF Scorecard multiple times. Extends Context models across models, handler_registry, and the sieve orchestrator to map context down. Adds verification tests and handlers logic to HANDLER_AUTHORING.md.

Signed-off-by: jaydeep869 <jaydeeppokhariya2106@gmail.com>
@mlieberman85

Copy link
Copy Markdown
Contributor

LGTM — merging. The double-checked locking design is clean, and the 10-thread concurrency test validates the single-execution guarantee correctly.

Three follow-up issues created:

Thanks for turning the long-standing scaffold in core/models.py into a real implementation with good test coverage.

@mlieberman85
mlieberman85 merged commit 2b84a96 into darnitdevorg:main Apr 15, 2026
8 checks passed
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.

2 participants