Skip to content
Merged
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
81c6d8c
test: require isolated app-host user state
lawrencecchen Aug 6, 2026
56aa78d
ci: isolate app-host user configuration
lawrencecchen Aug 6, 2026
5beeaa3
test(ci): scope app-host isolation guard to jobs
lawrencecchen Aug 6, 2026
945f370
test(ci): reject malformed isolation workflow
lawrencecchen Aug 6, 2026
2ef782f
test: require app-host launch home isolation
lawrencecchen Aug 6, 2026
8b8856f
test: reject app-host config path leaks
lawrencecchen Aug 6, 2026
c42f766
fix: isolate launched app-host user state
lawrencecchen Aug 6, 2026
047ad6c
test: require nonempty app-host XDG default
lawrencecchen Aug 6, 2026
1ba2484
fix: default app-host XDG path safely
lawrencecchen Aug 6, 2026
14d0359
test: keep app-host redirects off xcodebuild
lawrencecchen Aug 6, 2026
468bf90
fix: scope redirects to launched app host
lawrencecchen Aug 6, 2026
695659d
test: require XCTest runner home isolation
lawrencecchen Aug 6, 2026
552ae7b
fix: isolate XCTest app host through runner environment
lawrencecchen Aug 6, 2026
3f2d757
test: close app-host isolation validation gaps
lawrencecchen Aug 6, 2026
ba91848
fix: harden app-host isolation validation
lawrencecchen Aug 6, 2026
8250217
test: cover optional app-host isolation validation
lawrencecchen Aug 6, 2026
883f2b9
fix: keep app-host isolation assertions opt in
lawrencecchen Aug 6, 2026
56ea1f4
test: reject app-host XDG and scheme overrides
lawrencecchen Aug 6, 2026
2ae885e
fix: bind app-host XDG to isolated home
lawrencecchen Aug 6, 2026
fad91f4
test: cover non-isolated macOS Bash wrapper
lawrencecchen Aug 6, 2026
600a406
fix: support optional isolation on macOS Bash
lawrencecchen Aug 6, 2026
234e73b
test: cover app-host child isolation boundaries
lawrencecchen Aug 6, 2026
592a76a
fix: isolate app-host child process state
lawrencecchen Aug 6, 2026
5022f30
test: require fail-closed app-host cleanup
lawrencecchen Aug 6, 2026
b1491f4
fix: fail closed and clean app-host homes
lawrencecchen Aug 6, 2026
0a9de06
test: require cleanup after XDG removal
lawrencecchen Aug 6, 2026
42e5fd2
fix: clean homes after XDG removal
lawrencecchen Aug 6, 2026
a164928
Merge remote-tracking branch 'origin/main' into fix-app-host-user-con…
lawrencecchen Aug 6, 2026
50beb70
style: restore process helper indentation
lawrencecchen Aug 6, 2026
bbb381a
test: require robust app-host teardown discovery
lawrencecchen Aug 6, 2026
879598a
fix: make app-host teardown robust
lawrencecchen Aug 6, 2026
33e9656
test: preserve long-path app-host fixture
lawrencecchen Aug 6, 2026
e095c75
test: keep app-host isolation out of driver environment
lawrencecchen Aug 6, 2026
991d9ec
fix: isolate app-host redirects at launch boundary
lawrencecchen Aug 6, 2026
b17616b
Merge remote-tracking branch 'origin/main' into fix-app-host-user-con…
lawrencecchen Aug 6, 2026
8718178
test: reject ambient Ghostty configuration reads
lawrencecchen Aug 6, 2026
6a882f9
fix: validate every Ghostty config path
lawrencecchen Aug 6, 2026
4dd956f
test: clean mutated app-host XDG entries
lawrencecchen Aug 6, 2026
9684a02
fix: clean mutated app-host XDG entries
lawrencecchen Aug 6, 2026
c414754
Merge remote-tracking branch 'origin/main' into fix-app-host-user-con…
lawrencecchen Aug 6, 2026
9999aa7
test: require durable app-host isolation evidence
lawrencecchen Aug 6, 2026
d6efb15
fix: require durable app-host isolation evidence
lawrencecchen Aug 6, 2026
b8ab901
test: enforce short symlink-safe app-host homes
lawrencecchen Aug 6, 2026
df068f0
fix: use short symlink-safe app-host homes
lawrencecchen Aug 6, 2026
024c139
Merge remote-tracking branch 'origin/main' into fix-app-host-user-con…
lawrencecchen Aug 6, 2026
6faea3b
test: exercise app-host home symlink guard
lawrencecchen Aug 7, 2026
158a1b5
test: require app-host identity receipts
lawrencecchen Aug 7, 2026
471ce8a
fix: bind app-host cleanup to run identity
lawrencecchen Aug 7, 2026
82125af
Merge remote-tracking branch 'origin/main' into fix-app-host-user-con…
lawrencecchen Aug 7, 2026
8e830f7
Merge remote-tracking branch 'origin/main' into fix-app-host-user-con…
lawrencecchen Aug 7, 2026
d605f32
test: keep app-host receipts across CI jobs
lawrencecchen Aug 7, 2026
5a59e8c
fix: persist app-host process authority
lawrencecchen Aug 7, 2026
ca1ac9e
Merge remote-tracking branch 'origin/main' into fix-app-host-user-con…
lawrencecchen Aug 7, 2026
687f65a
test: inject lsof into app-host retry guard
lawrencecchen Aug 7, 2026
c221490
test: preserve existing app-host authority scope
lawrencecchen Aug 7, 2026
e083962
fix: preserve existing app-host authority scope
lawrencecchen Aug 7, 2026
226ef0e
test: model dead-pid lsof diagnostics
lawrencecchen Aug 7, 2026
accca0a
fix: classify dead-pid lsof diagnostics as stale
lawrencecchen Aug 7, 2026
248c855
test: authenticate cleanup before ownership transfer
lawrencecchen Aug 7, 2026
f15dcb8
fix: authenticate app-host scope before ownership transfer
lawrencecchen Aug 7, 2026
a89bcc2
test: bind app-host receipts to process incarnation
lawrencecchen Aug 7, 2026
ef40365
fix: bind app-host receipts to process incarnation
lawrencecchen Aug 7, 2026
2ca686f
test: make app-host owner fixture portable
lawrencecchen Aug 7, 2026
4f94aad
test: require atomic app-host receipt publication
lawrencecchen Aug 7, 2026
465d819
fix: publish app-host receipts atomically
lawrencecchen Aug 7, 2026
9791ac1
test: cover app-host recovery review gaps
lawrencecchen Aug 7, 2026
b9be11c
fix: harden app-host recovery
lawrencecchen Aug 7, 2026
d29d25d
test: cover app-host ownership lifecycle gaps
lawrencecchen Aug 7, 2026
74b7718
fix: scope app-host recovery to one run
lawrencecchen Aug 7, 2026
406ed58
test: recover authenticated prior-run app hosts
lawrencecchen Aug 7, 2026
3f7e9c5
test: cover multiple current app-host owners
lawrencecchen Aug 7, 2026
aced3f7
test: bound prior app-host recovery eligibility
lawrencecchen Aug 7, 2026
d7d98a9
test: model lsof machine descriptor fields
lawrencecchen Aug 7, 2026
6609970
test: recover deleted prior app-host owners
lawrencecchen Aug 7, 2026
8a97cb8
fix: recover authenticated prior app hosts
lawrencecchen Aug 7, 2026
cb159ca
test: model lsof access mode fields
lawrencecchen Aug 7, 2026
c978816
fix: verify lsof receipt access mode
lawrencecchen Aug 7, 2026
c6f1906
test: include lsof access mode in cleanup fixture
lawrencecchen Aug 7, 2026
82b5c67
test: reject untrusted newest confirmations
lawrencecchen Aug 7, 2026
e2522e4
fix: authenticate newest app-host confirmations
lawrencecchen Aug 7, 2026
4a290ce
test: cover app-host machine ownership boundaries
lawrencecchen Aug 7, 2026
276101a
fix: bind app-host recovery to machine ownership
lawrencecchen Aug 7, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ jobs:
- name: Validate app-host xcodebuild attempt budget
run: ./tests/test_ci_app_host_xcodebuild_attempts.sh

- name: Validate app-host user configuration isolation
run: python3 tests/test_ci_app_host_home_isolation.py

- name: Validate app-host identity and cleanup confirmation
run: bash tests/test_ci_app_host_identity.sh

- name: Validate app-host process receipts
run: bash tests/test_ci_app_host_processes.sh

- name: Validate isolated app-host home cleanup
run: bash tests/test_ci_app_host_home_cleanup.sh

- name: Validate cmux profiling support scripts
run: ./tests/test_start_cmux_profiling.sh

Expand Down Expand Up @@ -475,6 +487,10 @@ jobs:
matrix:
shard: [1, 2, 3, 4]
env:
# This independent job-level marker makes every app-host wrapper fail
# closed if a setup step or environment handoff loses either redirect.
CMUX_CI_APP_HOST_ISOLATION_REQUIRED: "1"
CMUX_APP_HOST_SHARD: ${{ matrix.shard }}
CMUX_CI_XCODE_APP: ${{ vars.CMUX_CI_XCODE_APP_MACOS_15 }}
CMUX_CI_REQUIRED_MACOS_SDK_MAJOR: "26"
CMUX_SKIP_ZIG_BUILD: "1"
Expand Down Expand Up @@ -548,6 +564,9 @@ jobs:
mkdir -p "$DERIVED_DATA_PATH"
echo "CMUX_DERIVED_DATA_PATH=$DERIVED_DATA_PATH" >> "$GITHUB_ENV"

- name: Prepare isolated app-host home
run: scripts/ci/prepare-app-host-home.sh

- name: Resolve Swift packages
run: |
set -euo pipefail
Expand Down Expand Up @@ -1093,6 +1112,10 @@ jobs:
CMUX_CLI_BIN="$CLI_BIN" python3 tests/test_omp_extension_install.py
CMUX_CLI_BIN="$CLI_BIN" python3 tests/test_campfire_extension_install.py

- name: Clean up isolated app-host home
if: ${{ always() }}
run: scripts/ci/run-in-console-session.sh scripts/ci/cleanup-app-host-home.sh

tests:
name: tests
# Aggregate gate for the test/build suites in this workflow. Required by
Expand Down
129 changes: 129 additions & 0 deletions Sources/AppHostProcessReceipt.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import Darwin
import Foundation

enum AppHostProcessReceipt {
static func writeIfRequired() {
_ = retainedReceiptDescriptor
}

/// The open descriptor is the process-incarnation proof. Keeping it alive
/// until process exit prevents a reused PID at the same executable path
/// from inheriting authority from a durable receipt.
private static let retainedReceiptDescriptor: Int32 = createIfRequired()

private static func createIfRequired() -> Int32 {
let environment = ProcessInfo.processInfo.environment
guard environment["CMUX_APP_HOST_ISOLATION_REQUIRED"] == "1" else { return -1 }
guard
let receiptDirectory = environment["CMUX_APP_HOST_RECEIPT_DIR"],
!receiptDirectory.isEmpty,
!receiptDirectory.contains(where: { $0.isNewline }),
let key = environment["CMUX_APP_HOST_KEY"],
key.utf8.count == 12,
key.utf8.allSatisfy({ (48 ... 57).contains($0) || (97 ... 102).contains($0) }),
let executablePath = Bundle.main.executableURL?.resolvingSymlinksInPath().path,
!executablePath.contains(where: { $0.isNewline })
else {
fail("required identity is incomplete")
}

let fileManager = FileManager.default
let directoryURL = URL(fileURLWithPath: receiptDirectory, isDirectory: true)
var isDirectory: ObjCBool = false
guard fileManager.fileExists(atPath: directoryURL.path, isDirectory: &isDirectory),
isDirectory.boolValue
else {
fail("receipt directory is unavailable")
}
do {
let values = try directoryURL.resourceValues(forKeys: [.isSymbolicLinkKey])
guard values.isSymbolicLink != true,
directoryURL.standardizedFileURL.path == directoryURL.resolvingSymlinksInPath().path
else {
fail("receipt directory changed identity")
}

let pid = getpid()
let receiptURL = directoryURL.appendingPathComponent("app-host-\(pid).receipt", isDirectory: false)
var descriptor: Int32 = -1
var temporaryURL: URL?
for _ in 0 ..< 8 {
let candidateURL = directoryURL.appendingPathComponent(
".app-host-\(pid)-\(UUID().uuidString.lowercased()).receipt.tmp",
isDirectory: false
)
descriptor = candidateURL.path.withCString {
Darwin.open(
$0,
O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC | O_NOFOLLOW,
mode_t(S_IRUSR | S_IWUSR)
)
}
if descriptor >= 0 {
temporaryURL = candidateURL
break
}
guard errno == EEXIST else {
fail("temporary receipt file could not be opened safely")
}
}
guard descriptor >= 0, let temporaryURL else {
fail("a unique temporary receipt file could not be created")
}
guard Darwin.fchmod(descriptor, mode_t(S_IRUSR | S_IWUSR)) == 0 else {
discardTemporaryReceipt(descriptor, at: temporaryURL)
fail("receipt permissions could not be restricted")
}
let receipt = "version=2\nkey=\(key)\npid=\(pid)\nexecutable=\(executablePath)\nreceipt_fd=\(descriptor)\n"
let receiptData = Data(receipt.utf8)
let wroteReceipt = receiptData.withUnsafeBytes { bytes -> Bool in
guard let baseAddress = bytes.baseAddress else { return true }
var offset = 0
while offset < bytes.count {
let written = Darwin.write(
descriptor,
baseAddress.advanced(by: offset),
bytes.count - offset
)
if written > 0 {
offset += written
} else if written < 0, errno == EINTR {
continue
} else {
return false
}
}
return true
}
guard wroteReceipt, Darwin.fsync(descriptor) == 0 else {
discardTemporaryReceipt(descriptor, at: temporaryURL)
fail("receipt contents could not be persisted")
}
let published = temporaryURL.path.withCString { temporaryPath in
receiptURL.path.withCString { receiptPath in
Darwin.rename(temporaryPath, receiptPath) == 0
}
}
guard published else {
discardTemporaryReceipt(descriptor, at: temporaryURL)
fail("receipt file could not be published atomically")
}
return descriptor
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
} catch {
fail(error.localizedDescription)
}
}

private static func discardTemporaryReceipt(_ descriptor: Int32, at url: URL) {
let savedErrno = errno
Darwin.close(descriptor)
url.path.withCString { _ = Darwin.unlink($0) }
errno = savedErrno
}

private static func fail(_ reason: String) -> Never {
fputs("FAIL: app-host process receipt: \(reason)\n", stderr)
fflush(stderr)
Darwin.exit(70)
}
}
1 change: 1 addition & 0 deletions Sources/cmuxApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import CmuxTerminal
@main
enum CmuxMain {
static func main() {
AppHostProcessReceipt.writeIfRequired()
#if DEBUG
// Bonsplit's `dlog` and the app's `cmuxDebugLog` resolve the same
// debug log file. Route bonsplit through the shared writer so the
Expand Down
4 changes: 4 additions & 0 deletions cmux.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ C0DE71B10000000000000001 /* AppDelegate+AgentChatNotifications.swift in Sources
F47126CFDAE244988A92E2D0 /* AppDelegateWindowFrameReconcileTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD21AD844E5D4D50A6DFC442 /* AppDelegateWindowFrameReconcileTests.swift */; };
A11EAB000000000000000000 /* AppearanceSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = A11EAB000000000000000001 /* AppearanceSettings.swift */; };
A11EAA000000000000000000 /* AppearanceSettingsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A11EAA000000000000000001 /* AppearanceSettingsTests.swift */; };
C97160000000000000000001 /* AppHostProcessReceipt.swift in Sources */ = {isa = PBXBuildFile; fileRef = C97160000000000000000002 /* AppHostProcessReceipt.swift */; };
C8046FF15781CC7E4F8EAEA6 /* AppHostWindowReleaseGuardTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3FAA194471B7BA157FB4660 /* AppHostWindowReleaseGuardTests.swift */; };
A7206E010000000000000001 /* AppIconAppearanceObserverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7206E020000000000000001 /* AppIconAppearanceObserverTests.swift */; };
D1320AA0D1320AA0D1320AA1 /* AppIconDockTilePlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1320AA0D1320AA0D1320AA4 /* AppIconDockTilePlugin.swift */; };
Expand Down Expand Up @@ -2940,6 +2941,7 @@ C0DE71B10000000000000002 /* AppDelegate+AgentChatNotifications.swift */ = {isa =
FD21AD844E5D4D50A6DFC442 /* AppDelegateWindowFrameReconcileTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegateWindowFrameReconcileTests.swift; sourceTree = "<group>"; };
A11EAB000000000000000001 /* AppearanceSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppearanceSettings.swift; sourceTree = "<group>"; };
A11EAA000000000000000001 /* AppearanceSettingsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppearanceSettingsTests.swift; sourceTree = "<group>"; };
C97160000000000000000002 /* AppHostProcessReceipt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppHostProcessReceipt.swift; sourceTree = "<group>"; };
B3FAA194471B7BA157FB4660 /* AppHostWindowReleaseGuardTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppHostWindowReleaseGuardTests.swift; sourceTree = "<group>"; };
IC000002 /* AppIcon.icon */ = {isa = PBXFileReference; lastKnownFileType = folder; path = AppIcon.icon; sourceTree = "<group>"; };
A7206E020000000000000001 /* AppIconAppearanceObserverTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppIconAppearanceObserverTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -5660,6 +5662,7 @@ C0DE71B10000000000000002 /* AppDelegate+AgentChatNotifications.swift */ = {isa =
46814000000000000000000C /* GhosttyTitleUpdateSurfaceState.swift */,
D7C6F5010000000000000001 /* GhosttyTitleChangeSubscription.swift */,
A11EAD000000000000000001 /* WorkspaceAppearanceResolution.swift */,
C97160000000000000000002 /* AppHostProcessReceipt.swift */,
A5001011 /* cmuxApp.swift */,
875200000000000000000002 /* cmuxApp+SurfaceNavigationMenu.swift */,
C51A73000000000000000014 /* CmuxWorkerEntrypoint.swift */,
Expand Down Expand Up @@ -8657,6 +8660,7 @@ C0DE71B10000000000000002 /* AppDelegate+AgentChatNotifications.swift */ = {isa =
B1F0C0080000000000000001 /* AppDelegateDetachedInspectorClose.swift in Sources */,
D37777040000000000000001 /* AppDelegateSettingsPresentation.swift in Sources */,
A11EAB000000000000000000 /* AppearanceSettings.swift in Sources */,
C97160000000000000000001 /* AppHostProcessReceipt.swift in Sources */,
A5001621 /* AppleScriptSupport.swift in Sources */,
A5001A02A1B2C3D4E5F60718 /* AppWindowBackdropControllerDependencies.swift in Sources */,
A5001A00A1B2C3D4E5F60718 /* AppWindowChromeComposition.swift in Sources */,
Expand Down
29 changes: 23 additions & 6 deletions cmuxTests/CLIGenericHookPersistenceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3059,15 +3059,32 @@ extension CLINotifyProcessIntegrationRegressionTests {
try JSONSerialization.data(withJSONObject: legacyHookJSON, options: [.prettyPrinted, .sortedKeys])
.write(to: codexHome.appendingPathComponent("hooks.json", isDirectory: false), options: .atomic)

let inheritedEnvironment = [
"HOME": root.path,
"CFFIXED_USER_HOME": root
.appendingPathComponent("inherited-app-host", isDirectory: true).path,
"XDG_CONFIG_HOME": root
.appendingPathComponent("inherited-app-host/.config", isDirectory: true).path,
"CMUX_APP_HOST_ISOLATION_REQUIRED": "1",
"CODEX_HOME": codexHome.path,
"PATH": "/usr/bin:/bin:/usr/sbin:/sbin",
"CMUX_CLI_SENTRY_DISABLED": "1",
]
let environmentResult = runProcess(
executablePath: "/usr/bin/env",
arguments: [],
environment: inheritedEnvironment,
timeout: 5
)
XCTAssertEqual(environmentResult.status, 0, environmentResult.stderr)
let childEnvironment = Set(environmentResult.stdout.split(separator: "\n").map(String.init))
XCTAssertTrue(childEnvironment.contains("CFFIXED_USER_HOME=\(root.path)"))
XCTAssertTrue(childEnvironment.contains("XDG_CONFIG_HOME=\(root.path)/.config"))

let result = runProcess(
executablePath: cliPath,
arguments: ["hooks", "codex", "install", "--yes"],
environment: [
"HOME": root.path,
"CODEX_HOME": codexHome.path,
"PATH": "/usr/bin:/bin:/usr/sbin:/sbin",
"CMUX_CLI_SENTRY_DISABLED": "1",
],
environment: inheritedEnvironment,
timeout: 5
)

Expand Down
25 changes: 24 additions & 1 deletion cmuxTests/CLINotifyProcessTestSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ extension CLINotifyProcessIntegrationRegressionTests {
let stdinPipe = standardInput == nil ? nil : Pipe()
process.executableURL = URL(fileURLWithPath: executablePath)
process.arguments = arguments
process.environment = environment
process.environment = isolatedCLIChildEnvironment(environment)
process.standardInput = stdinPipe ?? FileHandle.nullDevice
process.standardOutput = stdoutPipe
process.standardError = stderrPipe
Expand Down Expand Up @@ -433,6 +433,7 @@ extension CLINotifyProcessIntegrationRegressionTests {
_ = exitSignal.wait(timeout: .now() + 1)
}
}

_ = outputGroup.wait(timeout: .now() + 2)

outputLock.lock()
Expand All @@ -448,4 +449,26 @@ extension CLINotifyProcessIntegrationRegressionTests {
timedOut: timedOut
)
}

/// App-host CI gives XCTest an isolated Core Foundation home. CLI tests
/// then supply a narrower HOME for each subprocess. Keep all three user
/// configuration roots on that per-test home so the inherited app-host
/// redirects cannot make sibling CLI tests share state.
private func isolatedCLIChildEnvironment(
_ environment: [String: String]
) -> [String: String] {
guard environment["CMUX_APP_HOST_ISOLATION_REQUIRED"] == "1",
let rawHome = environment["HOME"]?.trimmingCharacters(in: .whitespacesAndNewlines),
!rawHome.isEmpty else {
return environment
}

var resolved = environment
resolved["CFFIXED_USER_HOME"] = rawHome
resolved["XDG_CONFIG_HOME"] = URL(
fileURLWithPath: rawHome,
isDirectory: true
).appendingPathComponent(".config", isDirectory: true).path
return resolved
}
}
Loading
Loading