fix(backend): harden cron stat app follow-up#1931
Conversation
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThe changes introduce a retry-with-backoff wrapper for org plan refresh queueing in a cron job trigger. A new function encapsulates the existing RPC call, automatically retrying on failures with configurable delays. Error and success states are logged with attempt information, and corresponding tests validate both failure recovery and multi-attempt retry behavior. Changes
Sequence DiagramsequenceDiagram
participant Handler as Request Handler
participant Wrapper as queueOrgPlanRefreshWithRetry
participant Retry as retryWithBackoff
participant Queue as queueOrgPlanRefresh RPC
participant Log as Logger (cloudlog/cloudlogErr)
Handler->>Wrapper: Call with orgStatsRefreshTarget
activate Wrapper
Wrapper->>Retry: Execute with shouldRetry condition
activate Retry
loop Retry Loop (up to N attempts)
Retry->>Queue: Attempt RPC call
activate Queue
Queue-->>Retry: Result (ok or error)
deactivate Queue
alt Success
Retry-->>Wrapper: Return successful result
else Failure & shouldRetry
Note over Retry: Wait (backoff delay)
Note over Retry: Increment attempt counter
end
end
deactivate Retry
alt Final Success
Wrapper->>Log: cloudlog (success message with retry info)
else Final Failure
Wrapper->>Log: cloudlogErr (error with attempt count)
end
deactivate Wrapper
Wrapper-->>Handler: Return result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 32cb99cc8a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| attempts, | ||
| error: result?.error, | ||
| }) | ||
| return |
There was a problem hiding this comment.
Fail cron_stat_app when follow-up queueing exhausts retries
If all retries to queue_cron_stat_org_for_org fail, this branch only logs and returns, so the handler still sends a 200 response. In the current queue flow, queue_consumer deletes messages on any 2xx, which means persistent follow-up failures (for example an RPC permission/function regression, not just a transient 502) will silently drop org plan refresh work instead of being retried from the queue. Please propagate failure after retry exhaustion for non-transient errors (or otherwise preserve retryable queue semantics).
Useful? React with 👍 / 👎.



Summary (AI generated)
cron_stat_appplan-refresh queueing when the downstream RPC returns transient failurescron_stat_appfollow-up unit testsMotivation (AI generated)
cron_stat_appalready saves the daily stats before it queues the downstream org-plan refresh. When that follow-up RPC returned a transient502, the trigger still ended as a500, which caused noisy Discord alerts and unnecessary queue retries even though the primary work had succeeded.Business Impact (AI generated)
This reduces false-positive backend alert noise and avoids reprocessing already-saved stats for transient downstream failures. The result is cleaner operations around billing/statistics jobs without changing customer-visible stats behavior.
Test Plan (AI generated)
bunx vitest run tests/cron_stat_app_followup.unit.test.tsbunx eslint supabase/functions/_backend/triggers/cron_stat_app.ts tests/cron_stat_app_followup.unit.test.tsbun typecheckbunx vitest run tests/cron_stat_app.test.ts(blocked locally: Supabase on127.0.0.1:54321was not running)Generated with AI
Summary by CodeRabbit
Bug Fixes
Tests