Skip to content

fix(ci): admit desktop-backend traffic on lineage, not branch recency - #11768

Merged
Git-on-my-level merged 1 commit into
mainfrom
fix/desktop-backend-traffic-lineage-guard
Aug 18, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
fix/desktop-backend-traffic-lineage-guard

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Aug 17, 2026 •

Copy link
Copy Markdown
Member

Problem

The dev desktop-backend deploy refuses to route traffic whenever origin/main advances during the build:

ERROR: candidate is stale because origin/main advanced to
015172400b775fe897f2ea9158bfbeb59907372d; traffic remains unchanged.

A desktop-backend deploy takes ~5 minutes. When commits land faster than that, every run is pre-empted at the last step — after Cloud Build and the acceptance probes have already run. The check cannot prevent a build; by the time it fires, the build is finished. All it can do is discard it.

Three consecutive runs failed this way on 2026-08-17:

Run main@ Outcome
32059345833 4f8da45f failed (project/URL resolution — different cause)
32074024600 fc458ef3 stale: main advanced to a7ff90a4
32074869094 03f50eb1 stale: main advanced to 01517240

The failure mode is worse than a stuck pipeline. Prod promotes the last dev-accepted candidate, so with dev unable to accept anything since 19:06, the prod run at 22:11 reported success while re-shipping the 34bd15da image. #11764 is merged, built, and sitting in an unrouted revision — while the dashboard reads green.

It is also self-reinforcing: the more the team merges, the less likely any deploy ever lands.

Why the check was redundant

The two protections it appeared to provide are both already in place elsewhere, and they fight each other:

  • Ordering is guaranteed by the desktop-backend-auto-dev concurrency group with cancel-in-progress: false. A newer run cannot route while an older one holds the lock. But holding that lock for the full build is exactly what guarantees main has moved by the time the older run reaches the traffic step — a queued run behind it has its commit on main by definition.
  • Debounce against stacked Cloud Builds is the entry guard in Resolve immutable candidate identity (:68), which exits before Google Auth and before any build is spent. This PR does not touch it. Superseded commits still bail out early; a burst of three merges still builds only the newest.

Re-asking the same question after the build could only throw away finished work.

Change

Gate the promotion on lineage rather than recency: refuse only when the candidate does not descend from the release SHA recorded on the revision currently serving 100% traffic. That preserves the real safety property — never move desktop-backend backwards — without requiring that nobody merged during the build.

Unknown lineage (a legacy revision with no recorded SHA, or a commit unreachable in the checkout) warns and admits. Dev is currently serving desktop-backend-00461-qiy, a pre-SHA revision, so refusing on unknown lineage would deadlock the pipeline on the very next run.

Scoped to the dev workflow. desktop_backend_prod.yml admits via admitted-source and never carried this guard.

Verification

python3 -m pytest .github/scripts/test_check_desktop_backend_traffic_regression.py -q   # 11 passed
python3 .github/scripts/check-desktop-backend-release-policy.py                          # OK
python3 .github/scripts/check-deployment-concurrency.py                                  # OK
python3 -m pytest .github/scripts/test_check_desktop_backend_release_policy.py -q         # 27 passed
make preflight

Replayed the three real failures against the SHA prod actually serves (34bd15da):

Candidate Old guard New guard
03f50eb1 (#11764) refused admitted — descends from serving
fc458ef3 refused admitted
a7ff90a4 (#11760) refused admitted
34bd15da vs serving 03f50eb1 admitted refused — would move backwards
serving SHA empty (dev today) n/a admitted with ::warning

Exercised the live discovery path against the prod service: extract_single_cloud_run_traffic_revision.py resolved desktop-backend-34bd15da499c-32074856543-1, and the jq expression read OMI_DESKTOP_BACKEND_RELEASE_SHA=34bd15da499cbfe314f1b5d9014b79611f91736c off it. The dev project was not reachable from the read-only bot (run.services.get denied), so that half runs first in CI.

The unit tests cover the decision function through an injected ancestry oracle, and the git seam itself against a real temporary repository — including the unreachable-commit path — rather than stubbing it.

Risk

Traffic shifts become more frequent, because builds that pass acceptance now actually ship instead of being discarded. That is the intent. If churn needs bounding, the correct lever is the entry-side debounce, not discarding completed work at the exit.

Failure-Class: new

Adds FC-promotion-gate-admits-on-recency-not-lineage — a gate between an accepted candidate and its traffic promotion may refuse only backwards promotions, never merely because the branch advanced during the build. Guard artifact is the checked-in decision function and its fixtures.

Review in cubic

The dev deploy refused to route traffic whenever `origin/main` advanced
during the build, so under sustained merge pressure every candidate was
discarded after its Cloud Build and acceptance probes had already run.
Three consecutive runs failed this way on 2026-08-17 (19:15, 22:01,
22:11), stranding #11764 in a built-but-unrouted revision while the
prod job green-checked and re-shipped the last accepted image.

The check was also redundant with the protection it appeared to provide.
Run ordering is already guaranteed by the `desktop-backend-auto-dev`
concurrency group with `cancel-in-progress: false`, and the debounce that
prevents stacked Cloud Builds is the entry guard in `Resolve immutable
candidate identity`, which exits before any build is spent. Re-asking the
same question after the build could only throw finished work away.

Gate the promotion on lineage instead: refuse only when the candidate
does not descend from the release SHA recorded on the revision serving
100% traffic. That keeps the real property — never move desktop-backend
backwards — without requiring that nobody merged. Unknown lineage
(legacy revisions with no recorded SHA, unreachable commits) warns and
admits, so a service already serving a pre-SHA revision cannot deadlock.

Scoped to the dev workflow; `desktop_backend_prod.yml` admits via
`admitted-source` and never carried this guard.

Verification:
  python3 -m pytest .github/scripts/test_check_desktop_backend_traffic_regression.py -q
    -> 11 passed
  python3 .github/scripts/check-desktop-backend-release-policy.py -> OK
  python3 .github/scripts/check-deployment-concurrency.py -> OK
  python3 -m pytest .github/scripts/test_check_desktop_backend_release_policy.py -q
    -> 27 passed

  Replayed the three real failures against the SHA prod serves
  (34bd15d) — 03f50eb, fc458ef and a7ff90a all now ADMITTED.
  Reverse direction (candidate 34bd15d vs serving 03f50eb) REFUSED.
  Empty serving SHA (dev's current pre-SHA revision) ADMITTED with a
  warning.

  Exercised the live discovery path against the prod service:
  extract_single_cloud_run_traffic_revision.py resolved
  desktop-backend-34bd15da499c-32074856543-1 and the jq expression read
  OMI_DESKTOP_BACKEND_RELEASE_SHA=34bd15da499cbfe314f1b5d9014b79611f91736c.
  The dev project was not reachable from the read-only bot
  (run.services.get denied), so that half runs first in CI.

Failure-Class: new
@Git-on-my-level
Git-on-my-level force-pushed the fix/desktop-backend-traffic-lineage-guard branch from 1c6db2b to 5664818 Compare August 17, 2026 23:16
@Git-on-my-level
Git-on-my-level merged commit ec1b272 into main Aug 18, 2026
38 checks passed
@Git-on-my-level
Git-on-my-level deleted the fix/desktop-backend-traffic-lineage-guard branch August 18, 2026 00:00
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