Skip to content

fix(feed-sync): real finish times, so Run History duration is not 0 s (SYNC-1) - #190

Merged
satishbagali merged 1 commit into
mainfrom
fix/sync-1-duration
Dec 4, 2026
Merged

satishbagali merged 1 commit into
mainfrom
fix/sync-1-duration

Conversation

@satishbagali

Copy link
Copy Markdown
Collaborator

Problem

Every feed sync and file upload shows "Duration 0 s" in Admin › Feed Library Sync › Run History. The admins' sync e-mail also shows Finished = Started.

  • Cause: finalize_log and touch_last_run wrote func.now().

    • In Postgres, now() is the start of the current transaction.
    • The whole import runs in one transaction.
    • So finished_at, last_run_at and last_success_at recorded the moment the import began, not when it ended.
  • Evidence on Test (read-only, feed_sync_log): 20 of 21 finished runs lasted 0.03–0.25 s.

    • Example: the 235-row upload of 29 Nov recorded 0.083 s.
  • What the shown number really measured:

    Run type Measured
    File upload Excel parse only
    Sync now Celery queue wait only
    Scheduled Download + parse

Change

File Change
backend/repositories/feed_sync_repository.py finished_at, last_run_at, last_success_at use func.clock_timestamp(), the time the statement runs
  • It uses the same database clock as started_at.
  • Not changed:
    • started_at (server default now()).
    • The crash/stale UPDATEs. Each runs in its own short transaction, so its time is already right.
Migration ❌ none
API / e-mail layout unchanged (finished_at keeps its meaning, now correct)
Frontend ❌ none (the PWA computes Duration from the two times)
Old rows keep their old values (the real end time was never stored)

Tests

Test Result
tests/unit 2060 passed; only the 4 known S3-mock failures
Unit tests: finalize_log / touch_last_run assign clock_timestamp() pass; fail on the old code
New real-Postgres test: create_log → commit → 1.2 s of work in the next transaction → finalize_log → commit Duration ≥ 1.2 s with the fix; 0.003 s without it
tests/integration/test_schema_alignment.py pass

After the deploy: upload the Test feed export. Run History should show the real seconds.

🤖 Generated with Claude Code

…ot 0 s

finalize_log and touch_last_run wrote func.now(). In Postgres now() is the
start of the current transaction, and the whole import runs in one
transaction, so finished_at, last_run_at and last_success_at recorded the
moment the import began. Every run on Test showed 0.03-0.25 s ("Duration
0 s"): for a file upload that is only the Excel parse, for Sync now only the
Celery queue wait.

Use func.clock_timestamp() (the time the statement runs, same database clock
as started_at). started_at and the crash/stale UPDATEs keep now(): they run
at the start of their own short transaction. No migration; old rows keep
their old values.

Tested: tests/unit (only the 4 known S3-mock failures); a real-Postgres test
(create_log, commit, 1.2 s of work in the next transaction, finalize_log)
gives >= 1.2 s with the fix and 0.003 s without it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@satishbagali

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@satishbagali
satishbagali merged commit 4fd5620 into main Dec 4, 2026
6 checks passed
@satishbagali
satishbagali deleted the fix/sync-1-duration branch December 4, 2026 06:07
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.

2 participants