Skip to content

AI-3583: swift CI builds swift_demo in its own DerivedData - #2225

Merged
kanat merged 4 commits into
mainfrom
ci/ai-3583-swift-module-cache
Nov 23, 2026
Merged

kanat merged 4 commits into
mainfrom
ci/ai-3583-swift-module-cache

Conversation

@kanat

@kanat kanat commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Why

The swift job of CI (client SDKs) fails at "Build swift_demo" on main and on unrelated PRs since 14:17 today: StreamWebRTC.framework/Headers/RTCPeerConnection.h has been modified since the module file. Runner image and Xcode are the same in the last pass and the failures (xcode-27-arm64 20261104.0337.1, Xcode 27.0). What changed is the SPM cache.

How it works

run 45192193934 (main, 14:15)  cache miss -> fetch -> cancelled mid-fetch
  └─ cache/save (if: always())  saves the half-fetched spm dir, 347 MB
every later run
  ├─ that entry restored (exactly or by restore-key)
  ├─ core build: repos missing, resolves the newest Package.swift allows
  │    StreamWebRTC 156.0.7 -> DerivedData (modules from 156.0.7 headers)
  └─ swift_demo build: its Package.resolved pins StreamWebRTC 145.17.0
       copies 145.17.0 headers into the SAME DerivedData
       -> "has been modified since the module file"

The last pass (run 45164527848) restored a 1.15 GB cache, and the core build reused the checkouts swift_demo had left (StreamWebRTC 145.17.0), so both builds agreed by luck.

Change Result
swift_demo builds into $RUNNER_TEMP/SwiftDemoDerivedData the two builds never share modules, whatever versions each resolves
cache/save: !cancelled(), the core build succeeded and the swift_demo build did not fail, in place of always(); kept with #2235's push-only term (github.event_name == 'push') a cancelled or failed fetch is not saved as a key that is then never saved again
key prefix spm- -> swiftpm- main stops restoring the partial entry

Sharing DerivedData saved no compile work: in the passing run swift_demo recompiled stream-core-swift, swift-protobuf, stream-video-swift and stream-chat-swift anyway, because it pins stream-chat-swift develop (examples/voice_agents/swift_demo/app/SwiftDemo.xcodeproj/project.pbxproj:305-308). Both builds still share the checkout directory. Every build and test step stays.

Validation

Run Commit swift job
45164527848 main 323143f, warm cache pass
45192548920 main 06a1d64, partial cache fail
45198669130 PR #2219, partial cache fail
45204272824 attempt 1, cold cache head 30bb4eb pass: core resolved StreamWebRTC 156.0.7, swift_demo 145.17.0 (the failing mix), 173 tests passed
45204272824 attempt 2, warm cache (1.1 GB exact hit) head 30bb4eb pass: both builds on StreamWebRTC 145.17.0, 173 tests passed

The swift_demo build took 6m14s and 6m07s of its 10-minute limit; it took 5m39s with the shared DerivedData in the last pass. actionlint reports only the existing runs-on: xcode-27 label it does not know.

AI-3583

🤖 Generated with Claude Code

The core build and swift_demo shared one DerivedData. When the SPM cache
lacks the repositories, the core build resolves StreamWebRTC 156.0.7
while swift_demo pins 145.17.0, and swift_demo then fails on modules
built from the other version's headers ("has been modified since the
module file").

The SPM cache is no longer saved from a cancelled run or a failed core
build: run 45192193934 was cancelled mid-fetch and saved a partial cache
that every later main run restored as an exact hit. The key prefix
changes so main stops restoring that entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kanat
kanat marked this pull request as ready for review November 23, 2026 15:21

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reviewed #2225 at 30bb4eb merged onto main 1c87c73 (the base had not moved). CI: all 10 checks pass (swift attempt 1 cold cache, attempt 2 warm).

The cause checks out in the logs. Image and Xcode are the same in every job (xcode-27-arm64 20261104.0337.1). Run 45192193934 got a cache miss and was cancelled while fetching stream-core-swift. Its if: always() save then stored 363578892 B under spm-…2fb668. After that, the core build resolved StreamWebRTC 156.0.7 and swift_demo 145.17.0 into one DerivedData (job 137754895692, lines 432, 9553, 11942). Head attempt 1 passed with that same mix on a cold cache.

Nit R1.2 (PR body, "How it works"): "every later run: exact cache hit on that entry" holds only for runs keyed 2fb668 (45192548920). Runs 45201408392 and 45198669130 had key a531d6 and restored it by restore-key. Run 45201408392 then saved a new full spm-…a531d6 entry from a red run (job 137785661541, line 12031). Suggest "restored (exactly or by restore-key)".

Checked and sound:

  • Separate DerivedData costs no extra compile work. The swift_demo build compiles the same 4158 units with shared and with separate DerivedData (jobs 137657996167 and 137810817020). It took 339 s before and 367-374 s now, against a 600 s limit.
  • The builds run one after another, so nothing races on the shared checkouts folder. swift_demo switches to its pins only after Test core has finished.
  • cache-hit is false on a restore-key hit (actions/cache v4 README), so the new primary key gets saved. That is what we want.
  • The >- scalar parses: the save ran in attempt 1 and was skipped on the exact hit in attempt 2.
  • No swiftpm- restore key can match an spm- entry. The partial 2fb668 entry has already been evicted, and the two spm- entries left are full ones (1.15 GB).
  • actionlint reports only the existing xcode-27 label.
  • Author's Q1 (core resolves whatever Package.swift allows) is not made worse by this PR. It goes to a ticket.

Verdict: request changes, for R1.1.

Comment thread .github/workflows/client-sdks.yml Outdated
- uses: actions/cache/save@v4
if: always() && steps.packages.outcome == 'success' && steps.packages.outputs.cache-hit != 'true'
if: >-
!cancelled() && steps.packages.outcome == 'success' && steps.build-core.outcome == 'success'

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

[Should fix] R1.1 The save still runs after a failed or timed-out Build swift_demo. build-core succeeded and the run was not cancelled, so the condition is true.

That step does network work inside the cached $RUNNER_TEMP/spm on every cold or restore-key run. In job 137795720232 it runs Updating from on all six repos, then checks out 145.17.0 of stream-video-swift-webrtc, develop (2cdca0c) of stream-chat-swift and 1.54.0 of stream-video-swift (lines ~9483-9516). If it stops there (network error or the 10-min timeout), a half-updated tree is saved under the primary key. Later runs get an exact hit on it and never save over it. That is the same class as run 45192193934.

Today this costs a re-fetch on each run, not a red build, now that DerivedData is split. Still, the comment above claims a half-way fetch is never saved.

Fix: add id: build-demo to Build swift_demo and && steps.build-demo.outcome != 'failure' to this if. The save still happens when Test core failed and swift_demo was skipped after a complete core fetch. Extend the comment to match.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 156dd4c: Build swift_demo has id: build-demo, and the save if now requires steps.build-demo.outcome != 'failure' (comment extended). Check: actionlint clean on the changed lines; swift job green on this head. The failing-swift_demo path was not run (unverified).

kanat and others added 2 commits November 23, 2026 17:12
Build swift_demo fetches and checks out its pins in the cached folder, so a
failure there can leave it half updated under the primary key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Delta review of 156dd4c (previous 30bb4eb): GO. No new findings.

  • R1.1 fixed. id: build-demo and && steps.build-demo.outcome != 'failure' in the save if (client-sdks.yml:237, :244-251). A failed swift_demo build gives outcome failure, so no save. A timed-out step is failure too: actions/runner StepsRunner.cs sets TaskResult.Failed when the step's own timeout fires and Canceled only for a job cancel, which !cancelled() already covers. After a Test core failure the demo build is skipped (implicit success()), so the save still runs with a complete core fetch, as the comment says. No step uses continue-on-error, so outcome equals conclusion. Dropping the new term brings back the half-updated cache (checked by reading, not runnable).
  • R1.2 fixed. PR body now reads "restored (exactly or by restore-key)" and "the swift_demo build did not fail".

Unexercised paths: both branch runs (45204272824, 45213885637) were exact cache hits, so the save step was skipped and neither the save-on-miss path nor the failure path ran. The expression parsed, so the step id is wired. I accept this without another run: each term compares documented string values, the worst case is a missed or extra save and never a red job, and a rerun on the PR ref cannot reach a cache miss. The first main run after merge uses the new swiftpm- key prefix, so it is cold and exercises the save.

Checked on 156dd4c merged onto origin/main 108539d: clean merge, only client-sdks.yml differs, actionlint reports only the known xcode-27 label warning. gh pr checks: swift, dart, kotlin, changes, CodeQL and GitGuardian pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

VERDICT: GO (delta round 3, head 5d4f12d, a merge of the previous head 156dd4c with main 284349e, which contains #2235)

R3.1 (conflict with #2235): fixed. The save step in .github/workflows/client-sdks.yml (lines 246-256) now reads:
!cancelled() && github.event_name == 'push' && steps.packages.outcome == 'success' && steps.build-core.outcome == 'success' && steps.build-demo.outcome != 'failure' && steps.packages.outputs.cache-hit != 'true'.

  • #2235's push-only term and its comment lines are kept.
  • This PR's terms are kept: !cancelled(), build-core success, build-demo not failure, id: build-core and id: build-demo, the swiftpm- key and restore-key, and the separate SwiftDemoDerivedData.
  • One comment gives both reasons. I checked the condition with a truth table: each of the six terms alone turns the save off, and a skipped swift_demo after a failed Test core still saves.
  • The PR body names the push-only term. The only difference from main is client-sdks.yml. actionlint reports only the known xcode-27 runner-label warning.

Earlier findings: R1.1 and R1.2 stay fixed. The two PR commits are unchanged in range-diff.

CI on this head (read once, not waited): the swift job passed in 21m12s (run 45222728586). Core build, core tests and swift_demo build succeeded, and the cache save step was skipped. That skip has two reasons: the event was pull_request, and the restore was an exact hit. So this run does not show the push-only term by itself.

First push to main after merge: the swiftpm-...a531d6 entry exists only on refs/pull/2225/merge, which main cannot read. The old spm- entry on main has a different prefix. So the run is cold: no restore, cache-hit is not 'true'. If core builds and swift_demo does not fail, Run actions/cache/save@v4 runs and saves swiftpm-macOS-xcode27-a531d6... on refs/heads/main. Expect a run as long as the PR's cold attempt, with swift_demo about 6 minutes of its 10-minute limit. The next main run should show an exact hit and a skipped save. If the first run fails, nothing is saved and the next run is cold again.

Details: reviewer-3.md in the ledger.

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

[security R1] GO at 5d4f12d, no findings.

Checked for the swift job of client-sdks.yml:

  • Cache scope. A pull_request run, a fork's included, writes only to its own refs/pull/N/merge scope, and a pull_request_target run gets read-only access to the default branch's scope (GitHub docs, "Restrictions for accessing a cache" and "Cache access for low-trust workflow triggers"). So a push to main restores only entries that main-scoped runs saved. The only swiftpm- entry is this PR's own, scoped to its merge ref, so main cannot restore it. Main's first run after the merge starts cold and saves the first main entry.
  • Rename. spm- and swiftpm- are not prefixes of each other, so the new restore-key matches no old entry. No other workflow saves a swiftpm- key, and none sets cache-mode.
  • Push-only save. It limits how much cache storage pull requests use. It is not a trust boundary: a pull request runs the workflow file from its own merge commit, and GitHub's ref scoping is what keeps PR entries away from main. Nothing here depends on it as a guard.
  • Cached folder. It holds public package checkouts only. actions/checkout writes its token into the workspace repo's local git config, outside $RUNNER_TEMP/spm. The job uses no secrets.*, and its permissions are contents: read and pull-requests: read.
  • Expressions. Every ${{ }} in the job is in a with: block, and each value comes from runner.*, hashFiles or a step output. No run: step expands one.

@kanat
kanat merged commit d8bfec0 into main Nov 23, 2026
10 checks passed
@kanat
kanat deleted the ci/ai-3583-swift-module-cache branch November 23, 2026 17:36
kanat added a commit that referenced this pull request Nov 23, 2026
## Why

`client-sdks.yml` cancelled in-progress runs on every ref, main
included. Since #2235 only a push to main saves the Swift package cache,
and since #2225 a cancelled run saves nothing. An empty-cache swift job
takes about 21 minutes, so when main gets a push faster than that, no
run finishes and the cache is never saved. After #2225 merged, main runs
45229507749 (17:36 UTC) and 45232221644 (17:51 UTC) were cancelled by
the next push; run 45233683223 finished and saved `swiftpm-…` on
`refs/heads/main` (`gh api
repos/GetStream/Agents/actions/caches?key=swiftpm-`). AI-3639.

## How it works

`cancel-in-progress` is an expression, which GitHub allows
([docs](https://docs.github.com/en/actions/using-jobs/using-concurrency):
"can specify `cancel-in-progress` as an expression", example `${{
!contains(github.ref, 'release/')}}`). It is now `github.event_name ==
'pull_request'`.

| Event | group | cancel-in-progress | Result |
|---|---|---|---|
| push to main | `…-push-main` | `false` | the running run finishes and
saves the cache; a newer push waits as pending; a still newer push
replaces the pending one (docs: "any existing `pending` job or workflow
in the same concurrency group will be canceled") |
| pull_request from branch X | `…-pull_request-X` | `true` | a new push
cancels the older run of the same PR, as before |
| pull_request from a fork's `main` | `…-pull_request-main` | `true` |
its own group: it never cancels or replaces a run of main's push group
(the event is in the key for this) |

The workflow has only `push` and `pull_request` triggers
(`client-sdks.yml:3-30`), so no other event reaches the expression.

## Validation

- `actionlint .github/workflows/client-sdks.yml`: only the known
`xcode-27` runner-label warning.
- Other workflows: `run_tests.yml:68` saves a mypy cache only on push,
and `ci-go`, `ci-python`, `ci-sdks`, `integration`, `python-versions`,
`run_tests` cancel on main too. Not changed here; a cancelled mypy-cache
run only costs a cold mypy cache, not 21 minutes.
- Unverified until merge: that main runs now queue and the cache is
saved. Watch the first pushes to main that touch the paths of this
workflow: no run of `CI (client SDKs)` on main should end `cancelled`,
and `gh api repos/GetStream/Agents/actions/caches?key=swiftpm-` should
list an entry on `refs/heads/main`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant