Guard campaign enrollment against stale state and duplicate writes - #17
Open
TheGuyWithoutH wants to merge 1 commit into
Open
TheGuyWithoutH wants to merge 1 commit into
TheGuyWithoutH wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Makes adding prospects to an existing campaign safer. This is a backend enrollment fix, not a change to the outreach runner.
What it fixes
[Alice, Alice, Bob]now enrolls Alice and Bob only once.expected_status(pending,paused, orrunning). If the run's current status differs at enrollment time, the API returns HTTP 409run_status_changedwithout enrolling targets.For example: a client previews a paused campaign, someone resumes it, then the client submits new prospects with
expected_status: "paused". Enrollment is rejected, allowing the client to refresh before proceeding.How it works
The handler starts an immediate SQLite transaction before checking the expected status and rechecking each eligible target's enrollment in the workflow and active enrollment elsewhere. Profile and track inserts remain in the same transaction, so an insertion failure rolls back the batch.
GET advertises support through
{ expectedStatusGuard: true }. Existing clients can omitexpected_statusand retain their current behavior. Requests with no eligible targets remain successful no-ops.Scope and limits
expected_status. It benefits from duplicate protection, but stale-state protection requires a follow-up to send the previewed status and handle HTTP 409.POST /api/runs) is unchanged. This is not a system-wide enrollment-concurrency fix.Validation
Implementation validation reported:
tsc --noEmit --incremental false.The tests inject competing writes between preview reads and the transaction deterministically; they do not run simultaneous workers or contact LinkedIn.
The subsequent review inspected the diff and surrounding code but could not independently rerun the tests because local dependencies were absent (
typescriptmissing).Run after installing dependencies: