Skip to content

Apply cooldown to Swift releases that have publishedAt - #820

Merged
andrew merged 4 commits into
git-pkgs:mainfrom
simonchrz:feat/swift-cooldown
Nov 29, 2026
Merged

andrew merged 4 commits into
git-pkgs:mainfrom
simonchrz:feat/swift-cooldown

Conversation

@simonchrz

@simonchrz simonchrz commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Part of #814. Swift releases are held back by cooldown when the upstream sends publishedAt, as discussed there.

  • The release list has no times, so each release's publishedAt is read from its release document, from the highest version down to the first release that is old enough or has no time, and stored.
  • Releases in cooldown are left out of the list, and a latest-version link to one is dropped. Their release document, Package.swift and source archive get 403.
  • A release without publishedAt is let through. The default upstream (tuist.dev) doesn't send it, so with it nothing changes: I checked apple/swift-nio against tuist.dev with a 3d cooldown and all 197 releases are listed.
  • Cooldown rules name packages as pkg:swift/{scope}/{name}, case-insensitive. packageurl.MakeString returns "" for a registry identity, so the package page now builds the same PURL through handler.CooldownPackagePURL.

Summary by CodeRabbit

  • New Features
    • Swift packages now support release cooldowns. Recently published releases are omitted from version listings and blocked when requested directly; older releases remain available.
    • Cooldowns use Swift’s optional publication timestamp. Releases without a timestamp aren’t filtered by cooldown, and packages with cooldowns disabled remain unaffected.
    • Swift packages can use package-specific cooldown settings and patterns, with unmatched packages using the configured default.
    • When a release is withheld, its latest-version link is removed from the listing.

The release document's optional publishedAt is the only time the Swift
registry API has. Releases in cooldown are left out of the release list,
with a latest-version link to one, and their metadata, manifests and
source archive get 403. A release without publishedAt is let through, so
with the default upstream, which doesn't send it, nothing changes.

Times are read from the highest version down to the first release that is
old enough or has no time, and stored. Cooldown rules name packages as
pkg:swift/{scope}/{name}, which the package page now uses too.
@simonchrz simonchrz added the enhancement New feature or request label Nov 26, 2026
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Adds Swift release cooldown support. The proxy filters release lists using optional publishedAt timestamps, records withheld releases, and blocks requests for those releases.

Changes: Swift release cooldown

Layer / File(s) Summary
Swift policy identity and matching
internal/handler/handler.go, internal/packageurl/*, internal/server/cooldown_view*
Swift is listed as cooldown-supported. Swift package PURLs support policy lookup, and Swift policy matching is case-insensitive.
Swift release filtering
internal/metadata/swift/*
The metadata package parses publishedAt, filters eligible releases from highest version downward, and removes latest-version links for withheld releases. Tests cover filtering, timestamp parsing, and link handling.
Swift request handling and documentation
internal/handler/swift.go, internal/handler/swift_cooldown*, README.md, docs/configuration.md
Swift handlers filter release lists, record withheld releases, and block requests for withheld releases. Tests and documentation cover filtering, blocked responses, lookup failures, and timestamp behavior.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant SwiftClient
  participant SwiftHandler
  participant SwiftCooldown
  participant CooldownDatabase
  participant SwiftRegistry
  SwiftClient->>SwiftHandler: Request package release index
  SwiftHandler->>SwiftCooldown: Filter release metadata
  SwiftCooldown->>CooldownDatabase: Read stored publication time
  SwiftCooldown->>SwiftRegistry: Fetch release document when time is unavailable
  SwiftRegistry-->>SwiftCooldown: Return publishedAt value
  SwiftCooldown->>CooldownDatabase: Store nonzero publication time
  SwiftCooldown->>CooldownDatabase: Record withheld release
  SwiftCooldown-->>SwiftHandler: Return filtered metadata
  SwiftHandler-->>SwiftClient: Return release index
Loading

Possibly related issues

  • git-pkgs/proxy#814: This PR adds Swift cooldown using publishedAt when present and allows releases without it. The issue’s separate Chef request is not addressed.
  • git-pkgs/proxy#132: This PR adds cooldown filtering to Swift release lists. Other ecosystems listed in the issue are outside this change.

Possibly related PRs

  • git-pkgs/proxy#722: This PR uses the shared withheld-version recording path introduced by that PR.

Suggested reviewers: andrew

Merge Risk: Minimal · up to 4260e

Swift packages can now be held back during the cooldown period when the upstream provides publishedAt. Releases in cooldown are left out of the list and their requests get a 403. Releases without timestamps pass through, which the docs state, and one documented limitation remains: a backport published after a newer allowed release stays listed but is refused. No merge-blocking issue was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: cooldown is applied to Swift releases that carry a publishedAt value. The raw summary and objectives confirm that the changeset filters Swift release lists, blocks coo…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: cooldown is applied to Swift releases that carry a publishedAt value. The raw summary and objectives confirm that the changeset filters Swift release lists, blocks cooldown releases with 403, and reads publishedAt from release metadata. The title is specific and concise, and it has no file lists or vague terms.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1598e6f1-1ca4-49b0-aa26-cf5c97219ccd
Commits

Reviewing files that changed from the base of the PR and between 9f333a2 and 4260ec6.

Files selected for processing: 4

  • docs/configuration.md
  • internal/handler/swift_cooldown.go
  • internal/metadata/swift/cooldown.go
  • internal/metadata/swift/cooldown_test.go
Files skipped from review as they are similar to previous changes: 1

  • docs/configuration.md

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Additional comments: 1

internal/metadata/swift/cooldown.go-145-145: 1

145-145: Minor · Functional Correctness · Quick win

Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Compare the link's release identity, not its raw final component.

If a withheld 1.2.0 uses a latest-version target ending in /1.2.0.json, this extracts 1.2.0.json. The lookup misses removed["1.2.0"], so the forbidden release remains linked. Swift permits the .json document URI. (raw.githubusercontent.com)

Parse the target URI and normalize the release-document suffix before comparison. Add a case that removes the .json link and preserves a link to an unremoved version.

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a519652e-1d42-4475-85bb-d7d514342d80
Commits

Reviewing files that changed from the base of the PR and between ef0e860 and 9f333a2.

Files selected for processing: 13

  • README.md
  • docs/configuration.md
  • internal/handler/handler.go
  • internal/handler/swift.go
  • internal/handler/swift_cooldown.go
  • internal/handler/swift_cooldown_test.go
  • internal/metadata/swift/cooldown.go
  • internal/metadata/swift/cooldown_test.go
  • internal/metadata/swift/imports_test.go
  • internal/packageurl/packageurl.go
  • internal/packageurl/packageurl_test.go
  • internal/server/cooldown_view.go
  • internal/server/cooldown_view_test.go

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

A latest-version target can be the release's .json document or carry a
query, so the release is read from the URL's last path segment without
.json.
@simonchrz

Copy link
Copy Markdown
Contributor Author

@coderabbitai Right about the latest-version target: fixed in 366c544. The release is read from the parsed URL's last path segment without .json, so /1.2.0.json and /1.2.0?x=1 are dropped too, and a link to a release left in the list stays.

@coderabbitai

coderabbitai Bot commented Nov 26, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

Analysis chain

Script executed:

#!/bin/bash
printf '%s\n' '--- Current revision ---'
git rev-parse HEAD
printf '%s\n' '--- Reported commit ---'
git show --format=fuller --stat --no-renames 366c544 -- 2>&1 | head -100
printf '%s\n' '--- Implementation outline ---'
ast-grep outline internal/metadata/swift/cooldown.go --items all --match 'WithoutLatestVersion|latest' --view expanded
printf '%s\n' '--- Implementation and tests ---'
rg -n -C 18 'func WithoutLatestVersion|func TestWithoutLatestVersion|1\.2\.0\.json|1\.2\.0\?x=1|latest-version' internal/metadata/swift/cooldown.go internal/metadata/swift/cooldown_test.go internal/handler/swift.go internal/handler/swift_cooldown_test.go

Length of output: 18119


@simonchrz Thanks for the fix. I inspected 366c544: it handles .json and query-string targets and preserves links to releases that remain listed. The tests cover those cases, but I did not run them.

I’ll leave thread resolution to you.


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

You are interacting with an AI system.

@andrew andrew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Two things, neither blocking.

Comment thread internal/metadata/swift/cooldown.go Outdated
return nil, nil, fmt.Errorf("reading time of %s: %w", v, err)
}
}
if published.IsZero() || o.Cooldown.Evaluate(Ecosystem, packagePURL, published, o.EvaluatedAt).Allowed {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The walk ends at the first release that is old enough, in semver order, so an old prerelease above the current stable line ends it straight away. Take a package with a months-old 3.0.0-alpha.1 and an active 2.x line: the alpha is checked first and allowed, the walk stops, and a 2.5.1 published an hour ago stays in the list but gets 403. swift package update picks it and fails instead of resolving to 2.5.0.

The docs describe this for a backport to an older release line, but a lingering prerelease is the more common way to hit it. An allowed prerelease shouldn't end the walk; only an allowed stable release should. That needs a test case alongside TestFilterReleasesWithholdsReleasesInCooldown.

Comment thread internal/handler/swift_cooldown.go Outdated
Comment on lines +14 to +21
// Swift cooldown measures a release by the publishedAt in its release
// document, which the registry specification makes optional. The release
// list has no times, so the proxy reads each release's time once, from the
// newest release down to the first that is old enough, and stores it.
// Releases in cooldown are left out of the list, and their release
// document, manifests and source archive are answered with 403. A release
// without publishedAt is let through, so with an upstream that doesn't
// record the time, such as the default one, cooldown has no effect.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This block repeats the Swift paragraph in docs/configuration.md; delete it. The comment on checkCooldown (lines 81-84) can be cut to its first sentence.

The walk ended at the first release out of cooldown, so a months-old prerelease above the stable line hid a new stable release from it. Only a stable release that is old enough ends it now. Also drop the comment that repeated the docs.
@simonchrz

Copy link
Copy Markdown
Contributor Author

Both done in 4260ec6.

  • An allowed prerelease no longer ends the walk; only an allowed stable release does. TestFilterReleasesLooksPastAnOldPrerelease covers your case: 3.0.0-alpha.1 is months old, 2.5.1 is an hour old and is left out, and the walk stops at 2.5.0. The docs say so too.
  • Removed the header comment and cut the one on checkCooldown to its first sentence.

Main is merged in.

@andrew
andrew merged commit 03f5dbe into git-pkgs:main Nov 29, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants