Repository navigation
Move Ghostty rendering into a dedicated worker process #8320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3768f2e
feat: harden Ghostty render worker supervision
52dee62
Add remote Ghostty frame presentation layer
673d70a
docs: describe Ghostty render worker boundary
22a16db
test: exercise real Ghostty render worker
209799d
feat: move Ghostty rendering into dedicated worker
1fa047f
test: cover stale render worker recovery config
9a20a04
fix: preserve newest render worker configuration
86e741d
fix: arm late render mirrors for active worker
fcdc3bf
fix: qualify pull request icon color capture
281744b
Merge remote-tracking branch 'origin/main' into feat-ghostty-render-w…
c05c52e
test: cover remote renderer backing layer resize
bd94bf1
fix: keep remote backing layer sized by AppKit
637e1f2
test: expose remote resize frame starvation
fb1f4b3
fix: bound remote terminal resize backlog
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| // swift-tools-version: 6.0 | ||
|
|
||
| import Foundation | ||
| import PackageDescription | ||
|
|
||
| let packageDirectory = URL(fileURLWithPath: #filePath).deletingLastPathComponent() | ||
| let ghosttyArchivePath = packageDirectory | ||
| .appendingPathComponent( | ||
| "../../../GhosttyKit.xcframework/macos-arm64_x86_64/ghostty-internal.a" | ||
| ) | ||
| .standardizedFileURL | ||
| .path | ||
|
|
||
| let package = Package( | ||
| name: "CmuxGhosttyRenderService", | ||
| platforms: [ | ||
| .macOS(.v14), | ||
| ], | ||
| products: [ | ||
| .library( | ||
| name: "CmuxGhosttyRenderClient", | ||
| targets: ["CmuxGhosttyRenderClient"] | ||
| ), | ||
| .library( | ||
| name: "CmuxGhosttyRenderWorker", | ||
| targets: ["CmuxGhosttyRenderWorker"] | ||
| ), | ||
| .executable( | ||
| name: "cmux-ghostty-render-fixture", | ||
| targets: ["cmux-ghostty-render-fixture"] | ||
| ), | ||
| .executable( | ||
| name: "cmux-ghostty-render-worker-test-host", | ||
| targets: ["cmux-ghostty-render-worker-test-host"] | ||
| ), | ||
| ], | ||
| dependencies: [ | ||
| .package(path: "../CmuxTerminalRenderTransport"), | ||
| ], | ||
| targets: [ | ||
| .target( | ||
| name: "CmuxGhosttyRenderClient", | ||
| dependencies: [ | ||
| .product( | ||
| name: "CmuxTerminalRenderTransport", | ||
| package: "CmuxTerminalRenderTransport" | ||
| ), | ||
| ], | ||
| swiftSettings: [ | ||
| .swiftLanguageMode(.v6), | ||
| .enableUpcomingFeature("ExistentialAny"), | ||
| .enableUpcomingFeature("InternalImportsByDefault"), | ||
| ] | ||
| ), | ||
| .systemLibrary( | ||
| name: "CmuxGhosttyRenderWorkerGhosttyKit", | ||
| path: "Sources/GhosttyKit" | ||
| ), | ||
| .target( | ||
| name: "CmuxGhosttyRenderWorker", | ||
| dependencies: [ | ||
| .product( | ||
| name: "CmuxTerminalRenderTransport", | ||
| package: "CmuxTerminalRenderTransport" | ||
| ), | ||
| "CmuxGhosttyRenderWorkerGhosttyKit", | ||
| ], | ||
| swiftSettings: [ | ||
| .swiftLanguageMode(.v6), | ||
| .enableUpcomingFeature("ExistentialAny"), | ||
| .enableUpcomingFeature("InternalImportsByDefault"), | ||
| ], | ||
| linkerSettings: [ | ||
| // The Ghostty XCFramework's macOS archive lacks SwiftPM's | ||
| // required `lib` prefix. Import its headers through the local | ||
| // shim target and link the same archive explicitly. | ||
| .unsafeFlags([ghosttyArchivePath]), | ||
| .linkedLibrary("c++"), | ||
| .linkedFramework("Metal"), | ||
| .linkedFramework("QuartzCore"), | ||
| .linkedFramework("IOSurface"), | ||
| .linkedFramework("UniformTypeIdentifiers"), | ||
| .linkedFramework("Carbon"), | ||
| ] | ||
| ), | ||
| .executableTarget( | ||
| name: "cmux-ghostty-render-fixture", | ||
| dependencies: [ | ||
| .product( | ||
| name: "CmuxTerminalRenderTransport", | ||
| package: "CmuxTerminalRenderTransport" | ||
| ), | ||
| ], | ||
| swiftSettings: [ | ||
| .swiftLanguageMode(.v6), | ||
| ] | ||
| ), | ||
| .executableTarget( | ||
| name: "cmux-ghostty-render-worker-test-host", | ||
| dependencies: ["CmuxGhosttyRenderWorker"], | ||
| swiftSettings: [ | ||
| .swiftLanguageMode(.v6), | ||
| ] | ||
| ), | ||
| .testTarget( | ||
| name: "CmuxGhosttyRenderClientTests", | ||
| dependencies: [ | ||
| "CmuxGhosttyRenderClient", | ||
| "cmux-ghostty-render-fixture", | ||
| "cmux-ghostty-render-worker-test-host", | ||
| ], | ||
| swiftSettings: [ | ||
| .swiftLanguageMode(.v6), | ||
| .enableUpcomingFeature("ExistentialAny"), | ||
| .enableUpcomingFeature("InternalImportsByDefault"), | ||
| ] | ||
| ), | ||
| ] | ||
| ) |
41 changes: 41 additions & 0 deletions
41
...S/CmuxGhosttyRenderService/Sources/CmuxGhosttyRenderClient/GhosttyRenderCommandSink.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| public import CmuxTerminalRenderTransport | ||
| internal import Dispatch | ||
|
|
||
| /// Thread-safe, totally ordered ingress for terminal renderer commands. | ||
| /// | ||
| /// Ghostty PTY output arrives on I/O threads while AppKit mutations arrive on | ||
| /// the main actor. Both enter this one serial queue before the client actor | ||
| /// consumes them, preventing unstructured Tasks from reordering output, | ||
| /// resize, focus, and pointer changes. | ||
| public final class GhosttyRenderCommandSink: @unchecked Sendable { | ||
| private let queue = DispatchQueue( | ||
| label: "dev.cmux.ghostty-render.command-outbox", | ||
| qos: .userInitiated | ||
| ) | ||
| private let continuation: AsyncStream<TerminalRenderWorkerCommand>.Continuation | ||
| let stream: AsyncStream<TerminalRenderWorkerCommand> | ||
|
|
||
| init() { | ||
| let pair = AsyncStream.makeStream( | ||
| of: TerminalRenderWorkerCommand.self, | ||
| bufferingPolicy: .unbounded | ||
| ) | ||
| self.stream = pair.stream | ||
| self.continuation = pair.continuation | ||
| } | ||
|
|
||
| /// Adds one command to the global worker ordering lane without blocking | ||
| /// the caller on process I/O. | ||
| public func enqueue(_ command: TerminalRenderWorkerCommand) { | ||
| queue.async { [continuation] in | ||
| continuation.yield(command) | ||
| } | ||
| } | ||
|
|
||
| /// Ends the ordering lane during client shutdown. | ||
| func finish() { | ||
| queue.async { [continuation] in | ||
| continuation.finish() | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift
The output/recovery path has several independent unbounded buffers, allowing worker stalls to become host OOMs.
Packages/macOS/CmuxGhosttyRenderService/Sources/CmuxGhosttyRenderClient/GhosttyRenderCommandSink.swift#L18-L24: replace the unbounded command stream with a byte-budgeted ingress.Packages/macOS/CmuxGhosttyRenderService/Sources/CmuxGhosttyRenderClient/GhosttyRenderWorkerClient.swift#L40-L45: centralize pending output and subscriber backlog ownership.Packages/macOS/CmuxGhosttyRenderService/Sources/CmuxGhosttyRenderClient/GhosttyRenderWorkerClient.swift#L69-L74: bound or coalesce high-frequency control ingress.Packages/macOS/CmuxGhosttyRenderService/Sources/CmuxGhosttyRenderClient/GhosttyRenderWorkerClient.swift#L126-L133: give event subscribers an explicit bounded/coalesced policy.Packages/macOS/CmuxGhosttyRenderService/Sources/CmuxGhosttyRenderClient/GhosttyRenderWorkerClient.swift#L207-L223: cap pending mutations and request an authoritative snapshot when ordered output exceeds that cap.📍 Affects 2 files
Packages/macOS/CmuxGhosttyRenderService/Sources/CmuxGhosttyRenderClient/GhosttyRenderCommandSink.swift#L18-L24(this comment)Packages/macOS/CmuxGhosttyRenderService/Sources/CmuxGhosttyRenderClient/GhosttyRenderWorkerClient.swift#L40-L45Packages/macOS/CmuxGhosttyRenderService/Sources/CmuxGhosttyRenderClient/GhosttyRenderWorkerClient.swift#L69-L74Packages/macOS/CmuxGhosttyRenderService/Sources/CmuxGhosttyRenderClient/GhosttyRenderWorkerClient.swift#L126-L133Packages/macOS/CmuxGhosttyRenderService/Sources/CmuxGhosttyRenderClient/GhosttyRenderWorkerClient.swift#L207-L223🤖 Prompt for AI Agents
Source: Coding guidelines