Skip to content

fix: stop noisy false-error logs during full sync - #56

Merged
Majorfi merged 2 commits into
mainfrom
fix/sync-log-hygiene
Jul 13, 2026
Merged

fix: stop noisy false-error logs during full sync#56
Majorfi merged 2 commits into
mainfrom
fix/sync-log-hygiene

Conversation

@Majorfi

@Majorfi Majorfi commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Why

Full syncs emit two alarming log lines that are actually harmless, which keeps confusing users running a non-admin Immich API key (a supported config). This is the "ambiguous messages" complaint from #45.

Changes

1. deleteAssetsNotIn — drop the temp table inside the transaction

The DROP TABLE IF EXISTS tmpKeepAssets was deferred, so it ran after tx.Commit() — always against an already-closed transaction. Every successful full sync logged:

[DB] Failed to drop temp table: sql: transaction has already been committed or rolled back

Moved the DROP inside the transaction, right before Commit. Error paths still unwind everything via defer tx.Rollback() (the CREATE TEMP TABLE is transactional), so no cleanup leaks.

2. doUserFullSync — don't re-log the expected non-admin 401/403

For a non-admin key, GET /api/libraries is admin-only and returns 403. syncLibraries already logs that accurately (Failed to fetch libraries ... (may require admin key)), but the full-sync caller logged a second, failure-sounding line:

[Sync] Library sync failed during full sync for user ...: immich getLibraries returned HTTP 403

Now suppressed when the error is an ImmichHTTPError with status 401/403. Genuine failures (network, 5xx, …) still log. deleteSyncState("libraryIDBackfillDone") behavior is unchanged.

Result

For a non-admin key, a full sync no longer prints the temp-table error nor the duplicate "Library sync failed" line — only the accurate informational may require admin key warning remains.

Testing

  • go build ./..., go vet ./..., go test ./... — all green.
  • Existing coverage exercises both paths (the 403 via the full-sync-forbidden test asserting libraryIDBackfillDone stays unset; the temp table via the full-sync tests). No behavior change, so no new tests.

Refs #45

deleteAssetsNotIn deferred its temp-table DROP until after tx.Commit(), so
the drop always ran on an already-closed transaction and logged
"[DB] Failed to drop temp table: sql: transaction has already been committed
or rolled back" on every successful full sync. Move the DROP inside the
transaction, before Commit; error paths still roll back via defer.

doUserFullSync logged "Library sync failed during full sync" for the expected
401/403 a non-admin key gets on /api/libraries, duplicating the accurate
warning syncLibraries already emits. Suppress that extra line for the expected
auth case; genuine (non-HTTP) failures still log.

Copilot AI 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.

Pull request overview

This PR reduces misleading/noisy log output during full syncs by (1) ensuring temp-table cleanup happens while the SQL transaction is still valid, and (2) avoiding a duplicate “library sync failed” log line for expected 401/403 outcomes when using a non-admin Immich API key.

Changes:

  • Suppress the full-sync “Library sync failed…” log when syncLibraries returns an ImmichHTTPError with 401/403 (since syncLibraries already logs the expected condition).
  • Move DROP TABLE tmpKeepAssets into the transaction in deleteAssetsNotIn to prevent running it after Commit() on a closed transaction.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
backend/syncService.go Avoid duplicate failure-sounding logs for expected non-admin library-access responses during full sync.
backend/database.go Execute temp-table drop before committing the transaction to prevent post-commit “tx already committed/rolled back” errors.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread backend/database.go Outdated
deleteAssetsNotIn returned an error on DROP failure, diverging from
deleteAlbumsNotIn/deleteTagsNotIn which drop inline before Commit and
ignore the result. Aborting the tx there could turn a successful asset
cleanup into a caller error. Match the established best-effort pattern;
the drop still runs inside the transaction, so the original
post-Commit failure is still fixed.
@Majorfi
Majorfi merged commit a1df8ad into main Jul 13, 2026
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.

2 participants