Repository navigation
feat(campaign): background reconciliation of scheduled, sending, and unknown campaigns - #180
Merged
Merged
Conversation
…unknown campaigns
Campaigns that are scheduled, sending, or unconfirmed now settle on their
own, and those that cannot are flagged for an operator.
- Campaign_Reconciler::reconcile_in_background() reconciles acting for no
user: the same lock, rules, and provider reads as an operator's
reconcile, audited with no actor and automatic: true. It is the only
entry point without a user, so the system can reconcile but never send
or schedule.
- Campaign_Reconcile_Job watches one campaign on Reconcile_Cadence: a
scheduled campaign two minutes after its send time, a sending one every
five minutes while fresh and up to hourly as it ages, an unknown outcome
soon and then on the reconciler's settle window or the provider's
retry_after. Busy or changed campaigns are looked at again shortly; a
transient provider error retries; missing, untracked, inconclusive,
contradiction, duplicate drafts, or a refused credential stops the watch.
- Job_Outcome::again() reschedules a job that did its work with its
attempts reset, so a long watch never uses them up.
- Reconciliation_Sweep, a recurring job queued each tick, starts a watch
for every watched campaign without one and skips campaigns whose watch
stopped since they last changed. Schema 9 indexes campaigns by state.
- GET /campaigns/{id}/remote reports the watch; the campaign page says
when the next automatic check runs or why checks stopped, the timeline
marks automatic checks, and Status counts campaigns needing operator
action.
Closes #171
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Closes #171. Part of #66 (M5). Based on
master.What this adds
Campaign_Reconciler::reconcile_in_background()reconciles acting for no user. It uses the same campaign lock, rules, and provider reads as an operator's reconcile. Its audit events have no actor and carryautomatic: true. It's the reconciler's only entry point without a user, so the system can reconcile but never send or schedule. No system user with delivery authority was introduced.Campaign_Reconcile_Jobwatches one campaign onReconcile_Cadence:retry_after).Each outcome maps to a next step:
retry_aftermissing,untracked,inconclusive,contradiction,duplicate_drafts, or a refused credentialJob_Outcome::again()puts a job that did its work back in the queue with its attempts reset, so a long-running watch never uses them up.Reconciliation_Sweepis a recurring job. The dispatcher queues it on each tick, with dedupe, and it runs every five minutes. It queues one watch per scheduled, sending, or unknown campaign without one, skipping campaigns whose watch stopped since they last changed. Schema 9 addscampaigns.state_updatedfor its query.Operator surfaces:
GET /campaigns/{id}/remotereturnswatch(watching,stopped, oridle; schema added);Evidence (#171)
Background_Reconciliation_Testuses the real reconciler, real HTTP client, and scripted Mailchimp:sent, the audit event has no actor and is markedautomatic, and no send action is made.unknownand reschedules the check. After the window it settles asprovider_draft, and there is still only one send.missing: the watch stops and nothing changes locally. The sweep doesn't restart it, and a day later there are still no reads./remotereportsstopped/missing(validated against the schema), and Status counts the campaign.Verification
pnpm qa:fastpasses.Note for Studio
After this merges, Studio's WP-Cron reconciles any campaign left scheduled, sending, or unknown against the real Mailchimp account, using read-only requests. Leftovers from browser tests that have simulated Mailchimp IDs will come back
missing, stop, and show as needing operator action. That's the intended behaviour; archive them to clear the warning.🤖 Generated with Claude Code