Skip to content

ocr: hand the caller credential to the worker before the card commits - #4

Merged
reoring merged 1 commit into
mainfrom
fix/ocr-bearer-before-commit
Nov 10, 2026
Merged

reoring merged 1 commit into
mainfrom
fix/ocr-bearer-before-commit

Conversation

@reoring

@reoring reoring commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Problem

On Craftsman (Contacts 0.3.1, CPU-only llm), an uploaded card became ocrState: unavailable within 4 s, twice out of two uploads; pressing retry then started a real read.

Writes take pg_advisory_xact_lock. A worker poll that fires while the upload transaction is open (it contains the sheet-split call, up to 15 s) queues behind it and claims the card the instant the upload commits, before the handler reaches Enqueue. processCard finds no bearer and marks the card unavailable.

Change

Enqueue inside the transaction (credential present whenever the card is claimable), Forget on failure, Kick after commit. The two tests that pinned enqueue-after-commit now assert the credential is handed over before the card is visible and that the wake-up follows the commit.

Checks

go vet ./cmd/server/..., go test -p 1 -count=1 ./cmd/server/... against PostgreSQL 16: pass.

Every upload whose transaction outlasted a worker poll (the sheet-split call
alone can take 15 s) ended 'unavailable' within seconds. Writes are serialized
by an advisory lock, so the worker's claim queued behind the upload and ran the
instant it committed - before the handler enqueued the bearer afterwards. The
worker then found the card with no credential and recorded it unavailable.

The credential is now enqueued inside the transaction, forgotten if it fails,
and the worker is woken after the commit.
@reoring
reoring merged commit d786ed3 into main Nov 10, 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.

1 participant