Skip to content

Support backtraces for crashing Swift binaries#290

Merged
Joannis merged 15 commits intomainfrom
jo/swift-backtrace
Feb 19, 2026
Merged

Support backtraces for crashing Swift binaries#290
Joannis merged 15 commits intomainfrom
jo/swift-backtrace

Conversation

@Joannis
Copy link
Copy Markdown
Member

@Joannis Joannis commented Jan 31, 2026

Depends on a PR for swift-container-plugin.

image

@Joannis Joannis force-pushed the jo/swift-backtrace branch from 3d6178b to 68e0e09 Compare January 31, 2026 19:56
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 31, 2026

Codecov Report

❌ Patch coverage is 0% with 149 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
Sources/Wendy/cli/commands/BuildCommand.swift 0.00% 66 Missing ⚠️
Sources/Wendy/SwiftPM.swift 0.00% 57 Missing ⚠️
...es/WendyAgent/Services/WendyContainerService.swift 0.00% 17 Missing ⚠️
Sources/Wendy/cli/commands/PackageCache.swift 0.00% 6 Missing ⚠️
Sources/Imager/DownloadSupport.swift 0.00% 3 Missing ⚠️

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #290      +/-   ##
==========================================
- Coverage   13.11%   13.04%   -0.07%     
==========================================
  Files         137      137              
  Lines       25461    25603     +142     
==========================================
+ Hits         3338     3340       +2     
- Misses      22123    22263     +140     
Flag Coverage Δ
Linux 11.23% <0.00%> (-0.06%) ⬇️
macOS 13.67% <0.00%> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
Sources/Imager/DownloadSupport.swift 0.00% <0.00%> (ø)
Sources/Wendy/cli/commands/PackageCache.swift 0.00% <0.00%> (ø)
...es/WendyAgent/Services/WendyContainerService.swift 0.00% <0.00%> (ø)
Sources/Wendy/SwiftPM.swift 0.00% <0.00%> (ø)
Sources/Wendy/cli/commands/BuildCommand.swift 0.00% <0.00%> (ø)

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

euanh pushed a commit to apple/swift-container-plugin that referenced this pull request Feb 2, 2026
…171)

This is needed for swift-backtrace #154 . Following PR should be able to
address that once we figure out
https://forums.swift.org/t/where-to-source-swift-backtrace-binaries/84499

Motivation
----------

#154 ability to see backtraces for swift binaries. But generally it's
also useful to set environment variables in containers for certain use
cases.

Modifications
-------------

Allow passing in `--env`, so you can direct `SWIFT_BACKTRACE`.

Result
------

Swift backtrace is possible on the end-user side. Example:
wendylabsinc/wendy-agent#290

Test Plan
---------

I did manual testing already in wendy-agent. You can trivially test this
by passing `--env` and reading it out in a swift app with the following
code:

```swift
import Foundation

print(ProcessInfo.processInfo.environment)
```
@Joannis Joannis marked this pull request as ready for review February 2, 2026 11:56
@Joannis Joannis requested a review from a team as a code owner February 2, 2026 11:56
@Joannis
Copy link
Copy Markdown
Member Author

Joannis commented Feb 2, 2026

PR upstream is merged

@Joannis Joannis enabled auto-merge February 2, 2026 13:43
zamderax
zamderax previously approved these changes Feb 3, 2026
@Joannis
Copy link
Copy Markdown
Member Author

Joannis commented Feb 3, 2026

Just recalled something, we'll want to add a check for the adopted swift-container-plugin version. Needs to be 1.3.0 or higher

Add warning if too low, and omit swift-backtrace
Copilot AI review requested due to automatic review settings February 8, 2026 21:54
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds support for Swift crash backtraces when running/building Swift apps in Wendy-built containers, gated behind a newer swift-container-plugin version, and adds a small example app to validate crash behavior.

Changes:

  • Preserve image-provided environment variables in the agent by merging image config env with Wendy’s base env.
  • Detect swift-container-plugin version (cache it) and pass extra --env / --resources to swift package build-container-image to enable swift-backtrace.
  • Bump example dependency version and add a new “HelloCrash” example package for validating backtraces.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
Sources/WendyAgent/Services/WendyContainerService.swift Merge image config env with Wendy base env when generating OCI spec.
Sources/Wendy/cli/commands/RunCommand.swift Detect plugin version (cached) and attempt to include swift-backtrace + env during wendy run.
Sources/Wendy/cli/commands/PackageCache.swift Cache container plugin version alongside previous package analysis results.
Sources/Wendy/cli/commands/BuildCommand.swift Enforce/upgrade plugin version and attempt to include swift-backtrace + env during wendy build.
Sources/Wendy/SwiftPM.swift Add --env passthrough to container build; add dependency search + semver compare helper; add updateDependencies().
Examples/HelloHTTP/Package.swift Bump swift-container-plugin minimum version to 1.3.0.
Examples/HelloCrash/Sources/main.swift New crash-on-launch sample to validate backtrace behavior.
Examples/HelloCrash/Package.swift New minimal Swift package for the crash example.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Sources/Wendy/cli/commands/BuildCommand.swift
Comment thread Sources/Wendy/cli/commands/RunCommand.swift Outdated
Comment thread Sources/Wendy/SwiftPM.swift Outdated
Comment thread Sources/Wendy/SwiftPM.swift
Comment thread Sources/Wendy/SwiftPM.swift Outdated
Copilot AI review requested due to automatic review settings February 9, 2026 07:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 11 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Sources/Wendy/cli/commands/RunCommand.swift Outdated
Comment thread Sources/Imager/DownloadSupport.swift
Comment thread Sources/Wendy/SwiftPM.swift Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 9, 2026 20:41
Joannis and others added 2 commits February 9, 2026 21:42
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 12 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Sources/Wendy/SwiftPM.swift
Comment thread Sources/Wendy/cli/commands/RunCommand.swift Outdated
Comment thread Sources/Wendy/cli/commands/RunCommand.swift Outdated
# Conflicts:
#	Sources/Wendy/cli/commands/BuildCommand.swift
#	Sources/Wendy/cli/commands/RunCommand.swift
Copilot AI review requested due to automatic review settings February 11, 2026 08:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 11 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Sources/Wendy/SwiftPM.swift
Comment on lines +451 to +484
// Add swift-backtrace binaries for crash reporting
findBacktrace: for binaryName in [
"swift-backtrace-static-linux-arm64",
"swift-backtrace-linux-arm64",
] where backtraceAvailable {
let destination = "/swift-backtrace"
if let backtraceUrl = Bundle.module.url(
forResource: binaryName,
withExtension: nil
) {
resources.append((source: backtraceUrl.path(), destination: destination))
additionalEnv.append(
"SWIFT_BACKTRACE=enable=yes,sanitize=yes,threads=all,images=all,interactive=no,swift-backtrace=/swift-backtrace"
)
break findBacktrace
}
let backtraceUrl = URL(fileURLWithPath: CommandLine.arguments[0])
.deletingLastPathComponent()
.appending(path: "wendy-agent_wendy.bundle")
.appending(path: "Contents")
.appending(path: "Resources")
.appending(path: "Resources")
.appending(component: binaryName)

if FileManager.default.fileExists(atPath: backtraceUrl.path()) {
resources.append(
(source: backtraceUrl.path(), destination: destination)
)
additionalEnv.append(
"SWIFT_BACKTRACE=enable=yes,sanitize=yes,threads=all,images=all,interactive=no,swift-backtrace=/swift-backtrace"
)
break findBacktrace
}
}
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

When backtraceAvailable is true but neither backtrace binary is found, the build proceeds silently without backtraces. Consider emitting a warning in that case (similar to the ds2 handling below) to make missing resources diagnosable.

Copilot uses AI. Check for mistakes.
Comment thread Sources/WendyAgent/Services/WendyContainerService.swift Outdated
Comment thread Sources/Wendy/cli/commands/BuildCommand.swift
Copilot AI review requested due to automatic review settings February 15, 2026 14:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 11 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

entry[entry.index(after: separatorIndex)...]
)
}
let env = envDict.map { "\($0.key)=\($0.value)" }
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

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

The environment variable dictionary is converted to an array using .map, which does not guarantee a stable ordering. This could lead to non-deterministic behavior when comparing environment variables or debugging. Consider sorting the output for deterministic results: let env = envDict.map { "\($0.key)=\($0.value)" }.sorted()

Suggested change
let env = envDict.map { "\($0.key)=\($0.value)" }
let env = envDict.map { "\($0.key)=\($0.value)" }.sorted()

Copilot uses AI. Check for mistakes.
Comment thread Sources/Wendy/cli/commands/BuildCommand.swift Outdated
Comment thread Sources/WendyAgent/Services/WendyContainerService.swift
Comment thread Sources/Wendy/cli/commands/BuildCommand.swift Outdated
Comment thread Sources/Wendy/SwiftPM.swift
Comment thread Sources/Wendy/Resources/swift-backtrace-linux-arm64
Comment thread Sources/WendyAgent/Services/WendyContainerService.swift
@Joannis Joannis disabled auto-merge February 19, 2026 14:11
@Joannis Joannis merged commit 7dce643 into main Feb 19, 2026
8 of 9 checks passed
@Joannis Joannis deleted the jo/swift-backtrace branch February 19, 2026 14:11
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.

4 participants