Skip to content

fix(ci): never pick a build number lower than what Apple has already seen - #659

Merged
libravault-xyz merged 2 commits into
devfrom
fix/ios-testflight-build-number-ordering
Aug 26, 2026
Merged

libravault-xyz merged 2 commits into
devfrom
fix/ios-testflight-build-number-ordering

Conversation

@libravault-xyz

Copy link
Copy Markdown
Collaborator

Root cause of builds 40/41 never notifying testers, found by the user
(not something the API diagnostics in #643/#652/#654 could surface, since
build-number ordering is a cross-build comparison, not a property of any
single build's own state).

ios-testflight.yml's default build number is github.run_number — this
workflow's own run counter. Build 148 was uploaded via a completely
separate path (the CircleCI fallback pipeline's own TestFlight
verification test — see its own "What to Test" text and
docs/circleci-agent-pipeline-design.md) with a build number far above
where run_number was at the time. Apple's upload uniqueness check is per
exact build number, not strictly-increasing, so every run_number-based
build since (40, 41) uploaded and validated cleanly, reached
externalState=IN_BETA_TESTING, autoNotifyEnabled=true, correct group
assignment — every field checkable via the API was clean. But TestFlight
never treats a numerically lower build as newer than one it's already
seen, so neither was ever offered to testers or triggered a notification.

Currently testing live: build 149 (build_number=149, manually
dispatched, higher than 148) is uploading now to confirm.

Fix: when build_number isn't explicitly provided, query the App Store
Connect API for the highest build number seen for this app across any
upload path, and use max(that, run_number) + 1 instead of trusting
run_number blindly.

🤖 Generated with Claude Code

…seen

Root cause of builds 40/41 never notifying testers, found by the user:
this workflow's default build number (github.run_number) only tracks
this workflow's own run count. Build 148 -- an out-of-band CircleCI
fallback-pipeline test upload, a completely separate path -- landed with
a build number far above where run_number was at the time. Apple's
uniqueness check is per exact build number, not strictly-increasing, so
every run_number-based build after that (40, 41) uploaded and validated
fine, reached externalState=IN_BETA_TESTING, autoNotifyEnabled=true,
group-assigned correctly -- every field an exhaustive API diagnostic
sweep could check was clean. But TestFlight never treats a numerically
lower build as newer than one it's already seen, so neither build was
ever offered to testers or triggered a notification. Currently testing
this theory live: build 149 (manually dispatched with build_number=149,
higher than 148) is uploading now; if it's the first build since 148 to
actually reach a device, this is confirmed.

Fix: when build_number isn't explicitly provided, query the App Store
Connect API for the highest build number seen for this app on any
upload path, and use max(that, run_number) + 1 instead of trusting
run_number blindly.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@github-actions github-actions Bot added the risk:high Touches a sensitive path or exceeds diff-size threshold — always human merge label Aug 26, 2026
@libravault-pipeline-bot libravault-pipeline-bot Bot added the status:needs-review QA passed, awaiting principal-review-agent label Aug 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR was opened outside the automated pipeline (author isn't libravault-pipeline-bot[bot]) and doesn't link an issue (no Closes #N-style line in its body), so there's no acceptance criteria for qa-agent.yml to verify against — it would otherwise sit with no risk/status label and nothing downstream would pick it up (see issue #223's actual history, and issue #343 for this issue-less case specifically). This deterministic backstop (pr-intake.yml) classified its risk and applied status:needs-review to route it straight to principal review.

@github-actions

Copy link
Copy Markdown
Contributor

Principal review — verdict: human-merge

Risk label: risk:high is correct and current — re-ran classify_pr_risk.py origin/dev origin/fix/ios-testflight-build-number-ordering myself, it independently reproduces risk:high (touches .github/workflows/**, a sensitive_paths match). Single commit (fc36bde), so the label isn't stale. This alone routes to status:needs-human-merge regardless of what follows — but there's also a CONFIRMED finding below, which would force human-merge either way.

CONFIRMED: off-by-one lets the new auto-increment logic re-create the exact bug it's fixing

.github/workflows/ios-testflight.yml's new auto-increment branch:

RUN_NUMBER=${{ github.run_number }}
BUILD_NUMBER=$(( HIGHEST > RUN_NUMBER ? HIGHEST + 1 : RUN_NUMBER ))

When HIGHEST == RUN_NUMBER (Apple has already seen a build numbered exactly this run's run_number, via an explicit build_number dispatch or the CircleCI fallback path — both of which this repo uses routinely, including in this very PR's own live test with build_number=149), the > is false and BUILD_NUMBER resolves to RUN_NUMBER, which equals HIGHEST. That's a build number Apple has already seen — the exact failure class this PR sets out to fix, just reached via == instead of <. Verified the arithmetic directly (HIGHEST=150 RUN_NUMBER=150 → 150, not 151). The PR description says the fix computes max(that, run_number) + 1; the actual code only adds 1 in the strictly-greater branch, so it doesn't match its own stated intent.

Should be >=, or unconditionally $(( (HIGHEST > RUN_NUMBER ? HIGHEST : RUN_NUMBER) + 1 )).

Filed as #660 per the permanent-record policy for CONFIRMED findings, with repro steps and a concrete reachability scenario for this repo.

PLAUSIBLE, non-blocking: unpaginated Build.all(..., limit: 200) could silently truncate later

The highest-build-number query (Spaceship::ConnectAPI::Build.all(app_id: app.id, platform: "IOS", limit: 200)) uses .all (not .all_pages, which other steps in this same file and list-testflight-groups.yml use for exhaustive listing), with no sort:. Once this app has uploaded more than 200 IOS builds total, this call returns some undefined 200-build subset — not necessarily the 200 most recent — so HIGHEST could silently come back lower than the true highest, reintroducing the same silent-invisibility failure mode this PR exists to close. Not an active bug today (the app is only around build ~150 per the PR body), and I'm not filing an issue for it since it isn't concretely reachable yet — flagging for whoever revisits this file next. A sort: "-uploadedDate" would make the truncation direction safe even after 200 builds.

Everything else checked out

  • Build#version is genuinely the build number field, not app version — confirmed against three other existing usages in this repo (list-testflight-groups.yml:83, :88, :106; ios-testflight.yml:321 later in this same file), so .to_i on it is correct and consistent with established convention.
  • No new networking dependency: the new App Store Connect API call reuses the same spaceship gem, the same four secrets (APP_STORE_CONNECT_ISSUER_ID/KEY_ID/PRIVATE_KEY, APPLE_BUNDLE_ID), and the same auth pattern already used by later steps in this exact workflow file (upload, verify-distribution). It's a new call site within an already-established, human-approved integration, not a new external service — I don't think this trips the "no new networking call without human sign-off" rule, which (per AGENTS.md and CONTRIBUTING.md) is aimed at the shipped app's F-Droid/Play networking surface, not this CI pipeline's pre-existing Apple API integration.
  • Failure handling is correct: if the Ruby/Spaceship call raises (bad creds, app not found, etc.), HIGHEST=$(ruby ...) propagates a non-zero exit under the Actions-default bash -e, verified directly (set -e; x=$(false) exits with status 1) — so an API failure hard-fails the step loudly rather than silently falling back to run_number with stale data.
  • No injection risk: RUN_NUMBER=${{ github.run_number }} interpolates a GitHub-controlled integer (same pattern the pre-existing code already used for the same context), and all Ruby-side values come through ENV[...] rather than string-interpolated into the script text.
  • Sensitive-path disclosure: the PR doesn't call out touching .github/workflows/** in its description, but this is self-evident from the diff (it's the only file changed) and correctly caught by the deterministic classifier regardless — not treating this as a missed-disclosure finding.
  • Testing claim, verified against ground truth: the PR body's "currently testing live: build 149... to confirm" run (workflow run 32946742863) is real and I checked it, but it ran at head 49b4aee (the pre-fix commit, on dev) with an explicit build_number=149 input — meaning it exercises the pre-existing explicit-input branch, not the new auto-increment/API-query code this PR actually adds. The new logic in this PR has not been exercised by any real run yet (expected, since this workflow is workflow_dispatch-only and can't run as a normal PR check) — worth the human merger knowing this is going out effectively untested beyond the arithmetic itself, especially given the bug above.
  • No unit tests added — reasonable given there's no existing harness in this repo for testing embedded workflow-YAML bash/ruby (every prior fix to this same file, e.g. fix(ci): verify + retry external TestFlight group distribution #624, fix(ci): wire real, per-build tester notes into iOS TestFlight uploads #139, fix(ci): actually wait for TestFlight processing so group distribution runs #97, fix(ci): auto-assign TestFlight uploads to the external testers group #83, followed the same live-dispatch-verification pattern instead of unit tests), so not treating this as an AGENTS.md violation.
  • status:blocked is not present on this PR or a linked issue — proceeding was appropriate.

@github-actions github-actions Bot added status:needs-human-merge Principal review done, requires human merge decision and removed status:needs-review QA passed, awaiting principal-review-agent labels Aug 26, 2026
…uild number

Principal review on this PR (#659) caught it: the previous ternary only
added 1 in the strictly-greater branch, so when Apple has already seen a
build numbered exactly this run's run_number (a routine case here --
explicit build_number dispatches and the CircleCI fallback path both do
this), BUILD_NUMBER resolved to a number Apple had already seen -- the
exact failure class this fix exists to close, just reached via == instead
of <. Verified: HIGHEST=150 RUN_NUMBER=150 now yields 151, not 150.
Filed as #660 by the reviewer; fixed here rather than as a follow-up.

Also added an explicit sort: "-uploadedDate" to the highest-build-number
query per the reviewer's non-blocking note, even though Build.all already
paginates exhaustively internally (confirmed against fastlane source --
it calls .all_pages itself) so it wasn't an active truncation risk.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@libravault-xyz
libravault-xyz merged commit 08e93f8 into dev Aug 26, 2026
8 checks passed
@libravault-xyz
libravault-xyz deleted the fix/ios-testflight-build-number-ordering branch August 26, 2026 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:high Touches a sensitive path or exceeds diff-size threshold — always human merge status:needs-human-merge Principal review done, requires human merge decision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants