Skip to content

fix: GET /api/campaigns returns incorrect status when deadline is exa… - #751

Merged
ritik4ever merged 1 commit into
ritik4ever:mainfrom
0xElyte:main
Jul 30, 2026
Merged

fix: GET /api/campaigns returns incorrect status when deadline is exa…#751
ritik4ever merged 1 commit into
ritik4ever:mainfrom
0xElyte:main

Conversation

@0xElyte

@0xElyte 0xElyte commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Closes #568
[BUG] GET /api/campaigns returns incorrect status when deadline is exactly now

Description:
When deadline === Date.now() (to the millisecond), campaign status flickers between open and failed on repeated requests depending on server clock drift.

Acceptance Criteria:
Status computed with strict deadline < Date.now() for failed.
Test added for exact boundary (deadline = now ± 1ms).
Status consistent across repeated calls within the same second.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected campaign deadline handling at the exact expiration moment.
    • Campaigns remain open through the deadline and transition to failed immediately afterward.
    • Improved consistency for campaign status, pledge/refund eligibility, remaining hours, and global statistics.
    • Ensured expired campaigns are automatically marked as failed using precise time calculations.

@vercel

vercel Bot commented Jul 29, 2026

Copy link
Copy Markdown

@0xElyte is attempting to deploy a commit to the ritik4ever's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@0xElyte Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 46230c94-c032-44af-aa3c-d6199edfc4d6

📥 Commits

Reviewing files that changed from the base of the PR and between 3e2dd95 and e9f2ed9.

📒 Files selected for processing (3)
  • backend/src/api.test.ts
  • backend/src/services/__tests__/mutation.test.ts
  • backend/src/services/campaignStore.ts

📝 Walkthrough

Walkthrough

Campaign deadline evaluation now uses millisecond precision across progress, filtering, failed timestamp updates, and global statistics. Tests verify campaigns remain open at the exact deadline and become failed one millisecond afterward.

Changes

Campaign deadline precision

Layer / File(s) Summary
Millisecond deadline evaluation
backend/src/services/campaignStore.ts
Converts stored deadlines to milliseconds and applies strict post-deadline comparisons across progress calculation, campaign filtering, automatic failed_at updates, and global statistics.
Deadline boundary validation
backend/src/services/__tests__/mutation.test.ts, backend/src/api.test.ts
Tests exact-deadline and ±1ms behavior, permission flags, hours-left clamping, and API status transitions with controlled time.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: strngecloud

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the deadline-status bug fix in GET /api/campaigns.
Linked Issues check ✅ Passed The code and tests implement strict deadline boundary handling and cover now±1ms plus repeated request consistency.
Out of Scope Changes check ✅ Passed The changes stay focused on campaign deadline status logic and related tests, with no obvious unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Fix failing CI checks
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ritik4ever
ritik4ever merged commit f579f3d into ritik4ever:main Jul 30, 2026
1 of 3 checks passed
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.

[BUG] GET /api/campaigns returns incorrect status when deadline is exactly now

2 participants