Skip to content

AI-3610: save the Swift package cache only from main - #2235

Merged
dangusev merged 1 commit into
mainfrom
worktree-swift-cache-main-only
Nov 23, 2026
Merged

dangusev merged 1 commit into
mainfrom
worktree-swift-cache-main-only

Conversation

@dangusev

Copy link
Copy Markdown
Contributor

Why

The repo cache holds 11.77 GB in 34 entries. The default limit is 10 GB. Above the limit, GitHub deletes the entries used least recently, from all workflows. The Swift job saves its package cache (about 1.1 GB) from pull requests too, and a pull request's copy is readable only by that pull request. On 2026-11-23 the same Swift cache was in the repo cache three times: on main, on #2224 and on #2225.

From 2026-10-24 to 2026-11-23:

Swift job ran Exact key missed, 1.1 GB saved again
Pull request runs 577 163 of 456 (36%)
Pushes to main 188 60 of 157 (38%)

The key inputs changed on main once in that period (#1880), so the misses come from deletions. AI-3610 has the full cache breakdown.

How it works

Swift job
├─ restore: exact key, else the newest spm-<os>-xcode27-* entry
├─ build and test
└─ save, when the exact key missed
   ├─ push to main  -> saves, and every later run reads it
   └─ pull request  -> no save (before: a 1.1 GB copy for that PR only)
Run Before After
PR, key same as main restores main's entry; on a miss saves its own copy restores main's entry; no save
PR that changes Package.swift, Package.resolved or the key first run saves, later runs hit its copy each run restores main's nearest entry and fetches the changed packages
Push to main saves on a miss same

The mypy cache already saves only on push (.github/workflows/run_tests.yml:67). The change is the save condition at .github/workflows/client-sdks.yml:243.

In the 30 days above, one pull request changed the key inputs (#1880, 1 Swift run). #2225 changes the key prefix and edits the same if:, so the second of the two to merge needs a rebase. After #2225 merges, the old spm- entries on main (about 1.45 GB) can be deleted with gh cache delete.

Validation

  • The workflow parses as YAML and the save condition reads as intended. actionlint is not installed here, so it did not run.
  • Not run in CI yet. The effect on the hit rates of the other caches (Go, uv, Gradle) is not measured.

🤖 Generated with Claude Code

A pull request's copy of the Swift package cache (about 1.1 GB) is
readable only by that pull request. These copies push the repo cache
over its limit, and GitHub then deletes entries of all workflows,
main's Swift entry included. Pull requests now restore main's entry.
@dangusev
dangusev marked this pull request as ready for review November 23, 2026 16:30
@dangusev
dangusev merged commit eaaf409 into main Nov 23, 2026
14 checks passed
@dangusev
dangusev deleted the worktree-swift-cache-main-only branch November 23, 2026 16:47
kanat added a commit that referenced this pull request Nov 23, 2026
## 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](https://github.com/GetStream/Agents/actions/runs/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](https://github.com/GetStream/Agents/actions/runs/45164527848)
| main 323143f, warm cache | pass |
|
[45192548920](https://github.com/GetStream/Agents/actions/runs/45192548920)
| main 06a1d64, partial cache | fail |
|
[45198669130](https://github.com/GetStream/Agents/actions/runs/45198669130)
| PR #2219, partial cache | fail |
|
[45204272824](https://github.com/GetStream/Agents/actions/runs/45204272824/job/137795720232)
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](https://github.com/GetStream/Agents/actions/runs/45204272824/job/137810817020)
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](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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