Skip to content

feat: plan 029 — M6 win-back: Customer inactive trigger, daily sweep, trigger claims, 2 templates - #35

Merged
jack9x merged 15 commits into
developfrom
jack/feature/m6-win-back
Nov 4, 2026
Merged

jack9x merged 15 commits into
developfrom
jack/feature/m6-win-back

Conversation

@jack9x

@jack9x jack9x commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

A customer whose last real order is N days old now starts a workflow once for that order. A daily job finds them in batches. The library grows from 16 to 18 templates, with Win-back + discount and Win-back + free shipping.

Base: develop 8a94a41. Schema change: DB version 7 adds the trigger_claims table. One commit per checkpoint, plus fix: commits from review.

Not verified on the posts order store. check-winback passed on HPOS only: WooCommerce refused the switch because orders are out of sync on the dev site. See "Before merging".

Checkpoints

  • CP0 Docs (854b52e): M3, M4, M5 marked done in ROADMAP-dev.
  • CP1 Trigger claims (57bf1e4, fix 03d60ef)
    • trigger_claims (unique per workflow and subject), TriggerClaimStore, and RunRepository::claim_subject / release_subject.
    • A trigger opts in with Trigger::claims_per_workflow(). The Dispatcher claims before it starts the run.
    • The claim goes back when no run starts or starting throws. The Worker also releases it when a run with no step rows ends because the workflow was turned off.
    • Cleanup deletes the claims of deleted workflows.
  • CP2 Trigger, sweep, health (0a1fcc8, fix d8f02df)
    • CustomerInactive (subject order:<id>) and InactiveSweep: pages of 200, 2 minutes apart, over a 7-day window.
    • An order counts only if it's the person's latest real order, by billing email and by account. Anonymized orders and orders with no billing email are skipped.
    • Health check row inactive_sweep_job, with Schedule again.
  • CP3 Panel (b99718a, fix 4e3bee1): days field (7–730, default 90, whole number) and "Checked once a day". The review fix makes the daily job queue one batch per days value.
  • CP4 Templates (6dfdfae, fix 91b7b14): Condition (not unsubscribed) → Generate coupon → Send email. 15% off or free shipping, 14 days.
  • CP5 Docs and full run (6acf3f3, fixes 0ee0ebf, 38c7f11, ab7bf93, 926b9a9, 07e5a54): check-winback covers batches, templates end to end and preview. Decisions "M6. Win-back"; ROADMAP status and "Today" lines.

Worth a closer look

  • The claim has no end date. It's per workflow and order, not "once per customer per 90 days", so a later order that goes quiet starts a new period by itself. That's why the release paths matter: Dispatcher::dispatch and Worker::release_claim.
  • Real statuses, one set for both sides (InactiveSweep::NOT_REAL). Pending, failed, cancelled and checkout draft don't count. On-hold and refunded do, so a customer with a newer on-hold order gets no "we miss you".
  • Per-batch flush. InactiveSweep::batch calls Runtime::dispatcher()->flush(), because a long Action Scheduler process has one shutdown for many batches.
  • A run doesn't stop when the customer orders during a Wait. The v1.0 templates have no Wait; it's in the v1.1 backlog.
  • Known limits are listed under Cost in docs/workflow-core-decisions.md, section M6. One to weigh: activating a second win-back version emails every customer still in the window again: claims are per workflow. The v1.1 backlog has the fix.

Before merging

  • Manual step (Jack): run ./run.sh check-winback on the posts store: sync orders, switch storage in WooCommerce → Settings → Advanced → Features, run it, switch back.
  • The browser checks below haven't been run. This session had no Chrome.

How to test

  • ./run.sh check-winback (about 2.5 minutes; it creates and removes 500 orders). It stops if the site has an active Customer inactive workflow.
  • Trigger picker → Customers shows Customer inactive. 6 and 731 show the range messages; 90.5 saves as 91.
  • Use Win-back + discount, set an order's date 91 days back, activate. Run yaymatik_inactive_sweep and then the yaymatik_inactive_sweep_batch job it queued from Scheduled Actions. The run shows "Order #N", Completed, 3 steps; the email arrives and the coupon works.
  • Run them again: no new run. An unsubscribed customer's run ends at the Condition's No path, 1 step, no coupon.
  • Settings → Health check: cancel the job, reload, click Schedule again.

jack9x added 15 commits November 3, 2026 14:06
…kflow is off before the run; log failed claim writes
…heck-winback covers batches, templates and preview
@jack9x
jack9x merged commit f747ff8 into develop Nov 4, 2026
1 check passed
@jack9x
jack9x deleted the jack/feature/m6-win-back branch November 17, 2026 02:50
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.

1 participant