Repository navigation
chore(monthly): #290 P3 follow-ups — batch payment_account lookup, doc comment, expiry isolation, cron failure alerts (Refs #308) - #309
Conversation
… and alert on cron failures (Refs #308) Addresses all 4 app-only P3 follow-ups from #290 (zero DB migrations): - Add deduped, bounded-concurrency paymentAccounts() helper (max 5 in flight, per-campaign error isolation) and skip payment_account RPCs on /me/contributions for plans without a payable current-month donation; run usable-account and pledge-balance lookups in parallel with one consistent clock. - Move misplaced ContributionList doc comment above ContributionList in apps/web/src/app/me/contributions/page.tsx. - Isolate cron steps in issue-plan-donations and plan-notices within the shared deadline; drain multi-batch expire_plan_donations (500/batch), isolate batch errors without losing earlier counts, and detect/alert stalled bad batches without breaching the maxDuration budget. - Emit structured zero-PII JSON error logs (plan_cron.failed_outcomes, plan_job.plan_failed, plan_job.expire_batch_stalled/failed) whenever monthly plan cron jobs record 'failed' outcomes or errors.
There was a problem hiding this comment.
If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.
Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
|
PO acceptance: merge at a80257d Verified on GitHub:
|
Refs #308
App-only (
apps/web, zero DB migrations) cleanup batching all 4 non-blocking P3 follow-ups from #290 (#276Monthly donations A):What changes
payment_accountlookup batching & pruning (apps/web/src/server/contributions/index.ts,apps/web/src/app/me/contributions/page.tsx,apps/web/src/app/me/contributions/PlanList.tsx,apps/web/src/lib/plans.ts):paymentAccounts()helper with campaign ID deduplication, bounded parallel concurrency (PAYMENT_ACCOUNT_BATCH_CONCURRENCY = 5, defensive finite-number guard), and per-campaign error isolation (failed lookups stay unknown instead of blocking or hiding other campaigns).give.payment_accountRPCs on/me/contributionsfor ended plans or plans without a potentially payable current-month donation (already received/expired, not yet issued, non-live, or pastends_at), sharingcurrentPlanDonation()withPlanListand running usable-account and pledge-balance lookups in parallel with one consistent clock.apps/web/src/app/me/contributions/page.tsx):ContributionList's JSDoc block from abovewithUsableAccountsback directly aboveContributionList.apps/web/src/server/plans/jobs.ts,apps/web/src/app/api/cron/issue-plan-donations/route.ts,apps/web/src/app/api/cron/plan-notices/route.ts):issue-plan-donations(issue_plan_donations/expire_plan_donations) andplan-notices(plan_end_notices/plan_followups) within the shared 45 s budget so a failure in one step never stalls the other (while still returning HTTP 500 on step failure).expirePlanDonations()to drain multiple 500-row batches within budget, isolate batch errors/throws/malformed responses without losing earlier batch counts, and probegive.contributions(select("id")) whenexpire_plan_donationsreturns0(only while budget remains somaxDuration = 60is preserved) to detect and flag stalled bad batches (expire_stalled: true,done: false).'failed'outcomes (apps/web/src/server/plans/jobs.ts, both monthly cron routes,/me/contributions/page.tsx):logPlanCronFailures()andlogPlanStepFailure()emitting structured JSON error logs (plan_cron.failed_outcomes,plan_job.plan_failed,plan_job.expire_batch_stalled,plan_job.expire_batch_failed,plan_cron.step_failed) with strictly zero PII (never logging donor name, email, phone, IP, user ID, account number, reference code, or rawerror.message).Verification
pnpm format:check: cleanpnpm lint: cleanpnpm typecheck: cleanpnpm --filter @give/web exec vitest run --maxWorkers=2: 180 files / 2,650 tests pass (79 tests across the 6 touched suites)pnpm build: cleane3e3788f-ca56-4a90-a6bd-b26c0af5b1bf): PASS (1 P2 budget guard on overdue probe + 4 P3 nits caught and fixed; re-verified 0 P0–P3 remaining)📌 TL;DR
This PR hardens the monthly plan cron jobs by isolating step failures, implementing batched expiry with stall detection, and introducing structured zero-PII logging for observability. It also refactors the contributions page to deduplicate and bound payment account lookups, improving reliability and performance.
🎯 Type of Change
🔍 Changes Walkthrough
apps/web/src/app/api/cron/issue-plan-donations/route.tssweepPlansandexpirePlanDonationsfailures. Added structured logging for step failures and cron outcomes. Updated response to includeexpire_stalledand detailed expiry status.apps/web/src/app/api/cron/issue-plan-donations/route.test.tsapps/web/src/app/api/cron/plan-notices/route.tsplan_end_noticesandplan_followupssweeps. Added structured logging for failures and outcomes.apps/web/src/app/api/cron/plan-notices/route.test.tsapps/web/src/server/plans/jobs.ts1. Replaced raw
console.errorwith structured JSON logging (logPlanError,logPlanWarn) to prevent PII leakage.2. Added
logPlanCronFailuresandlogPlanStepFailurehelpers.3. Rewrote
expirePlanDonationsto support batched processing (EXPIRE_BATCH_SIZE), budget-aware stopping, and stall detection viahasOverduePlanDonations.4. Added
ExpirePlansResultinterface for detailed status reporting.apps/web/src/server/plans/jobs.test.tsapps/web/src/server/contributions/index.tspaymentAccountsfunction for batched, deduplicated, and concurrency-bounded payment account lookups. AddedPAYMENT_ACCOUNT_BATCH_CONCURRENCYconstant.apps/web/src/server/contributions/contributions.test.tspaymentAccountsdeduplication, error isolation, and concurrency limits.apps/web/src/app/me/contributions/page.tsxwithUsableAccountsto use the newpaymentAccountsbatch function. Optimized to only look up accounts for plans with payable current-month donations. Parallelized plan and pledge balance fetching.apps/web/src/app/me/contributions/page.test.tsapps/web/src/app/me/contributions/PlanList.tsxcurrentPlanDonationhelper for reusability. Re-exportedvnMonthStart.apps/web/src/lib/plans.tsvnMonthStartutility here for shared access between client and server components.apps/web/src/lib/plans.test.tsvnMonthStarttimezone boundary conditions.📊 Architectural Flow
sequenceDiagram participant Cron as Cron Trigger participant Route as Cron Route Handler participant Jobs as Plan Jobs Service participant DB as Database (Supabase) participant Logs as Structured Logs (Zero-PII) Cron->>Route: GET /api/cron/issue-plan-donations Route->>Jobs: sweepPlans(db, "issue_plan_donations") loop Sweep Plans Jobs->>DB: rpc:issue_plan_donations alt Success DB-->>Jobs: { plan_id, outcome } else Failure DB-->>Jobs: { error } Jobs->>Logs: logPlanError (structured JSON) Jobs-->>Route: PlanJobError end end Jobs-->>Route: PlanSweep Result Route->>Logs: logPlanCronFailures (if failed > 0) Route->>Jobs: expirePlanDonations(db, now, budget) loop Batch Expiry (within budget) Jobs->>DB: rpc:expire_plan_donations alt Success DB-->>Jobs: count alt Count == 0 Jobs->>DB: hasOverduePlanDonations (probe) DB-->>Jobs: boolean alt Overdue exists Jobs->>Logs: logPlanError (stalled) end end else Failure DB-->>Jobs: { error } Jobs->>Logs: logPlanError (structured JSON) Jobs-->>Route: ExpirePlansResult (failed: true) end end Jobs-->>Route: ExpirePlansResult Route-->>Cron: JSON Response (status, done, expired, stalled)