Skip to content

[codex] Fix bundle size metadata queue#2476

Open
riderx wants to merge 1 commit into
mainfrom
codex/fix-version-size-queue
Open

[codex] Fix bundle size metadata queue#2476
riderx wants to merge 1 commit into
mainfrom
codex/fix-version-size-queue

Conversation

@riderx

@riderx riderx commented Jun 9, 2026

Copy link
Copy Markdown
Member

Summary

Fixes on_version_update so app version size metadata is only written from a completed R2 bundle state.

  • Skip zero-size metadata writes for intermediate r2-direct upload snapshots that already have an r2_path.
  • Retry R2 bundle size lookup before writing metadata.
  • Return a retryable 503 when a completed r2 bundle still has no readable object size, so the queue keeps the message and applies its retry budget instead of deleting it as successful.
  • Add unit coverage for pending r2-direct, successful completed r2, and retryable missing-size cases.

Motivation

The exact production failure path was: CLI creates the version as r2-direct, upload-link updates r2_path while the row is still r2-direct, then the final upload update flips the row to r2. The old trigger treated the intermediate snapshot as no v2 path and upserted app_versions_meta.size = 0. If the final size lookup later returned 0, it logged and returned success, so the queue deleted the message and the zero remained.

Business Impact

Bundle storage accounting becomes consistent again for new uploads. Failed or delayed R2 metadata reads are observable and retryable instead of silently creating wrong zero-byte metadata, which reduces undercounted storage and bad admin/debug data.

Test Plan

  • bunx vitest run tests/on-version-update-cleanup.unit.test.ts
  • bun run lint:backend
  • bun run typecheck:backend
  • bun run test:backend
  • bun run typecheck
  • bun run lint (passes with one existing frontend JSDoc warning in src/services/compatibilityEvents.ts)

AI-Generated Content

This PR was generated by Codex.

Summary by CodeRabbit

  • New Features

    • Added automatic retry for bundle-size retrieval from cloud object storage to improve reliability.
  • Bug Fixes

    • Improved handling when bundle size or path is missing: retryable errors are returned so processing can be retried; manifest-only updates persist zero-size metadata; manifest-cleanup updates are not retried.
  • Tests

    • Expanded tests for bundle size metadata, retry behavior, manifest cleanup, and updated test setup cleanup for impersonation scenarios.

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@riderx, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 38 minutes and 17 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 70a5ff07-6efd-4191-a627-9cedf1a4a0d9

📥 Commits

Reviewing files that changed from the base of the PR and between 045a2a3 and 9a7a369.

📒 Files selected for processing (3)
  • supabase/functions/_backend/triggers/on_version_update.ts
  • tests/log-as.test.ts
  • tests/on-version-update-cleanup.unit.test.ts
📝 Walkthrough

Walkthrough

Adds retry-backed bundle-size retrieval for R2 uploads, enforces R2 path validation in version updates, centralizes zero-size metadata upserts, exposes test utilities, adds manifest-cleanup early-return, and extends unit tests and mocks to validate bundle-size metadata and retry behavior.

Changes

Bundle Size Retry and Metadata Handling

Layer / File(s) Summary
Bundle size retry mechanism
supabase/functions/_backend/triggers/on_version_update.ts
Imports retry utilities and defines retry constants for bundle-size lookups.
V2 path size with retry and error handling
supabase/functions/_backend/triggers/on_version_update.ts
Adds getBundleSizeWithRetry, integrates it into v2PathSize, and throws a 503 quickError when size remains unavailable after retries.
Storage provider validation and routing
supabase/functions/_backend/triggers/on_version_update.ts
Introduces upsertZeroVersionMetadata, refactors updateIt to enforce r2_path for storage_provider==='r2', route R2 updates through size checks, and log/skip metadata for non-R2 paths.
Test utilities export and manifest detection
supabase/functions/_backend/triggers/on_version_update.ts
Exports onVersionUpdateTestUtils (getBundleSizeWithRetry, updateIt) and adds isManifestCleanupUpdate detection used by the handler.
Handler early-return and skip adjustment
supabase/functions/_backend/triggers/on_version_update.ts
Adds manifest-cleanup early-return to skip bundle metadata retry and tightens the early-skip condition to respect R2 storage.
Test mocks and bundle size metadata tests
tests/on-version-update-cleanup.unit.test.ts
Extends hoisted mocks with appVersionsMetaUpsert, appVersionsMetaUpsertEq, and getSize; updates s3 mock wiring; imports onVersionUpdateTestUtils; and adds tests covering R2 metadata write, zero-size upserts, positive-size upserts, retryable missing sizes, and manifest-cleanup behavior.

Test Seed Cleanup

Layer / File(s) Summary
Seed: clean stripe_info for stale org
tests/log-as.test.ts
seedStaleCreatedByOrg() now deletes stripe_info rows for the stale org's customer_id during setup.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title '[codex] Fix bundle size metadata queue' directly addresses the main objective of fixing the on_version_update trigger to correctly handle R2 bundle size metadata writes.
Description check ✅ Passed The PR description includes a comprehensive Summary, clear Motivation explaining the production failure path, Business Impact, and detailed Test Plan with checkmarks. It covers the required template sections and provides sufficient detail about changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

@codspeed-hq

codspeed-hq Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by 81.51%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 42 untouched benchmarks
⏩ 2 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
/updates manifest response with metadata 208.7 µs 115 µs +81.51%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing codex/fix-version-size-queue (9a7a369) with main (5969436)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@coderabbitai coderabbitai Bot added the codex label Jun 9, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 98fcf3d0bf

ℹ️ 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".

Comment thread supabase/functions/_backend/triggers/on_version_update.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@supabase/functions/_backend/triggers/on_version_update.ts`:
- Around line 177-180: The exported HTTP handler currently always returns 200
and thus never honors the retryable 503 thrown by updateIt(); modify the
exported app route handler to call and await updateIt() (the same updateIt used
by onVersionUpdateTestUtils) and propagate its thrown quickError/HTTP status up
to the HTTP response so a record with storage_provider === 'r2' and missing
r2_path/manifest results in a 503 retryable response instead of being
acknowledged with 200. Ensure the handler does not swallow exceptions from
updateIt() and maps quickError status and payload into the HTTP response.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 9f1fe932-46af-4d31-9627-75df40614d7e

📥 Commits

Reviewing files that changed from the base of the PR and between 5969436 and 98fcf3d.

📒 Files selected for processing (2)
  • supabase/functions/_backend/triggers/on_version_update.ts
  • tests/on-version-update-cleanup.unit.test.ts
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • Cap-go/capacitor-updater (manual)

Comment thread supabase/functions/_backend/triggers/on_version_update.ts
@riderx riderx force-pushed the codex/fix-version-size-queue branch from 98fcf3d to b24f2d9 Compare June 9, 2026 22:04

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b24f2d955c

ℹ️ 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".

Comment thread supabase/functions/_backend/triggers/on_version_update.ts
@riderx riderx force-pushed the codex/fix-version-size-queue branch from b24f2d9 to 045a2a3 Compare June 9, 2026 22:21

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 045a2a3b72

ℹ️ 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".

Comment thread supabase/functions/_backend/triggers/on_version_update.ts
@riderx riderx force-pushed the codex/fix-version-size-queue branch from 045a2a3 to 9a7a369 Compare June 9, 2026 22:34
@sonarqubecloud

sonarqubecloud Bot commented Jun 9, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant