Skip to content

feat(worker): add DB-backed path to ProcessingState#742

Open
thomasrockhu-codecov wants to merge 1 commit intomainfrom
tomhu/processing-state-db-path
Open

feat(worker): add DB-backed path to ProcessingState#742
thomasrockhu-codecov wants to merge 1 commit intomainfrom
tomhu/processing-state-db-path

Conversation

@thomasrockhu-codecov
Copy link
Contributor

@thomasrockhu-codecov thomasrockhu-codecov commented Mar 9, 2026

Summary

  • Adds an optional db_session parameter to ProcessingState. When provided, all methods query/update Upload.state_id in the database instead of using Redis sets.
  • When db_session is omitted, behavior is completely unchanged (Redis path).
  • No callers change in this PR -- purely a capability addition that subsequent PRs will activate.

Stacked on #741.

DB-backed method behavior

Method DB path Redis path (unchanged)
get_upload_numbers COUNT by state_id (UPLOADED=processing, PROCESSED=processed) SCARD on Redis sets
mark_upload_as_processed UPDATE state_id to PROCESSED SMOVE between sets
mark_uploads_as_merged UPDATE state_id to MERGED SREM from processed set
get_uploads_for_merging SELECT WHERE state_id=PROCESSED LIMIT 10 SRANDMEMBER
mark_uploads_as_processing No-op (DB state is set at upload creation) SADD to processing set
clear_in_progress_uploads No-op SREM from processing set

Test plan

  • CI passes
  • New TestProcessingStateDBPath test class covers all DB-backed methods
  • Existing Redis-path tests are unchanged and still pass
  • Full lifecycle test: UPLOADED -> PROCESSED -> MERGED via DB state

Made with Cursor


Note

Low Risk
Default behavior remains Redis-backed and no callers were changed; the main risk is correctness/performance of the newly added SQLAlchemy code path when it’s enabled later (upload state transitions and merge selection).

Overview
Adds an optional db_session to ProcessingState so upload processing/processed/merged tracking can be derived from and persisted to the DB (Upload.state_id) rather than Redis sets.

When db_session is provided, get_upload_numbers counts UPLOADED/PROCESSED uploads for the commit, mark_upload_as_processed and mark_uploads_as_merged update state in-place, get_uploads_for_merging selects PROCESSED uploads (bounded by MERGE_BATCH_SIZE), and clear_in_progress_uploads marks still-UPLOADED uploads as ERROR; the Redis path remains unchanged. Tests add a new DB-backed lifecycle suite using factories to validate counts, transitions, batch sizing, and no-op behavior.

Written by Cursor Bugbot for commit 3b30446. This will update automatically on new commits. Configure here.

@thomasrockhu-codecov thomasrockhu-codecov force-pushed the tomhu/processing-state-db-path branch from 3f76621 to 0fadde0 Compare March 9, 2026 19:51
@thomasrockhu-codecov thomasrockhu-codecov force-pushed the tomhu/upload-state-merged-enum branch from c5551ca to 1f86365 Compare March 9, 2026 20:35
@thomasrockhu-codecov thomasrockhu-codecov force-pushed the tomhu/processing-state-db-path branch from 0fadde0 to 668d5ed Compare March 9, 2026 20:35
@sentry
Copy link

sentry bot commented Mar 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.25%. Comparing base (cb5abf0) to head (3b30446).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #742      +/-   ##
==========================================
- Coverage   92.25%   92.25%   -0.01%     
==========================================
  Files        1304     1304              
  Lines       47923    47949      +26     
  Branches     1628     1628              
==========================================
+ Hits        44210    44233      +23     
- Misses       3404     3407       +3     
  Partials      309      309              
Flag Coverage Δ
workerintegration 58.52% <46.42%> (-0.03%) ⬇️
workerunit 90.34% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@codecov-notifications
Copy link

codecov-notifications bot commented Mar 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@thomasrockhu-codecov thomasrockhu-codecov force-pushed the tomhu/processing-state-db-path branch from 668d5ed to d514a42 Compare March 10, 2026 12:06
@thomasrockhu-codecov thomasrockhu-codecov marked this pull request as ready for review March 10, 2026 12:09
Base automatically changed from tomhu/upload-state-merged-enum to main March 10, 2026 14:08
@thomasrockhu-codecov thomasrockhu-codecov requested a review from a team as a code owner March 10, 2026 14:08
@thomasrockhu-codecov thomasrockhu-codecov force-pushed the tomhu/processing-state-db-path branch 2 times, most recently from 6ce1a54 to 9c656c6 Compare March 10, 2026 14:19
@thomasrockhu-codecov thomasrockhu-codecov force-pushed the tomhu/processing-state-db-path branch 2 times, most recently from e0b3bdf to 696d952 Compare March 10, 2026 15:10
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Add an optional db_session parameter to ProcessingState. When provided,
all methods use DB queries (Upload.state_id) instead of Redis sets.
When omitted, behavior is unchanged (Redis path).

DB-backed methods:
- get_upload_numbers: COUNT by state_id (UPLOADED=processing, PROCESSED=processed)
- mark_upload_as_processed: UPDATE state_id to PROCESSED
- mark_uploads_as_merged: UPDATE state_id to MERGED
- get_uploads_for_merging: SELECT WHERE state_id=PROCESSED LIMIT batch_size
- mark_uploads_as_processing / clear_in_progress_uploads: no-op (DB path)

No callers change in this PR -- this is a pure capability addition.

Made-with: Cursor
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