Skip to content

fix(backend): read the preview pointer before writing the manifest - #17844

Merged
aryanorastar merged 1 commit into
BasedHardware:mainfrom
singhharsh1708:fix/backend-desktop-preview-publish-reads-first
Sep 29, 2026
Merged

aryanorastar merged 1 commit into
BasedHardware:mainfrom
singhharsh1708:fix/backend-desktop-preview-publish-reads-first

Conversation

@singhharsh1708

@singhharsh1708 singhharsh1708 commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #17845.

_publish_preview_transaction reads the manifest, stages transaction.create for a new build, and only then reads the slug pointer. Firestore does not allow a transactional read after a write, and google-cloud-firestore raises ReadAfterWriteError before sending it. So publishing any new build fails, the manifest is never created, and a retry fails the same way. The route only catches ValueError, so POST /v2/desktop/previews/publish answers 500, and the Codemagic preview step that calls it with curl --fail fails.

#10145 found the preview lane had never completed end to end and #10223 unblocked its Codemagic signing stage; this registry call is the step a build reaches after that.

The pointer read now sits next to the manifest read, before any write. This is the same fix #9783 made for the memory ledger (#9780).

With the real google-cloud-firestore 2.20.0 client and @transactional decorator, only the gRPC API stubbed:

publish a new build main this branch
POST /v2/desktop/previews/publish 500 201
Firestore ReadAfterWriteError, rolled back committed, pointer at generation 1

TestPreviewPublish in test_desktop_previews.py runs publish_preview against the repo's StrictFirestore, which enforces the same rule. The first-publish test fails on main with its ReadAfterWriteError; the second pins that republishing the same build writes nothing.

$ cd backend && BACKEND_UNIT_TEST_FILE_LIST=<test_desktop_previews.py, test_desktop_updates.py> bash test.sh
155 passed, 0 failed
$ cd backend && MEMORY_MODE=read python -m pytest testing/e2e/
120 passed, 3 skipped, 2 xfailed

Failure-Class: none

@Git-on-my-level

Copy link
Copy Markdown
Member

Verified against the head: this is a correct, minimal repair of a real failure.

backend/database/desktop_previews.py — _publish_preview_transaction staged transaction.create(manifest_ref, ...) before reading pointer_ref.get(transaction=...). google-cloud-firestore rejects a transactional read after a staged write, so the first publish of any new build raised ReadAfterWriteError and rolled back with nothing created. Moving the pointer read up next to the manifest read puts both reads before the first write — the only ordering Firestore accepts. The rest of the transaction is unchanged (same reads, same writes, same compare-and-set via _build_preview_pointer), so concurrency semantics are preserved.

backend/tests/unit/test_desktop_previews.py — the new TestPreviewPublish runs publish_preview against StrictFirestore (backend/tests/unit/fixtures/strict_firestore_transaction.py), whose _assert_read_allowed enforces exactly this read-before-write rule: the first-publish test fails on main with the same ReadAfterWriteError and passes here, and the republish test pins the idempotent no-write path (no creates, no sets). Solid regression coverage for a one-line production change.

I also checked the 500 claim statically in backend/routers/updates.py: /v2/desktop/previews/publish catches only ValueError (409), and ReadAfterWriteError is a RuntimeError, so main surfaces 500 and the Codemagic curl --fail step fails as described. Issue #17845 matches.

Excellent diagnosis and write-up — every particular of the failure-mode analysis checked out. Leaving the merge call to a maintainer since this sits on the preview publish path; from the code side I have no concerns.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added positive-signal Automation verified a genuine fix/quality contribution backend Backend Task (python) labels Sep 23, 2026
@aryanorastar

Copy link
Copy Markdown
Collaborator

Keeping this open. Not approving b3cc8dd5023d. origin/main ca828a8c617d _publish_preview_transaction still transaction.creates the manifest before pointer_ref.get. This SHA reads the pointer first and test_desktop_previews.py uses a strict Firestore transaction. Hygiene SKIPPED. Do not approve this sha.

— Astar, on behalf of @aryanorastar

@aryanorastar aryanorastar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

origin/main 7b90e34 backend/database/desktop_previews.py still calls pointer_ref.get after transaction.create of the manifest inside _publish_preview_transaction. Tests pin that hole. Required checks are green.

@aryanorastar
aryanorastar merged commit 461f50f into BasedHardware:main Sep 29, 2026
55 of 57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend Task (python) positive-signal Automation verified a genuine fix/quality contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Publishing a new desktop preview build fails with a Firestore read-after-write error

3 participants