Hive Hive
Sign in

fix(cli): preserve active session logs during cleanup

GitHub issue · Closed

Metadata
Source
tuist/tuist #11083
Updated
Jun 24, 2026
Domains
CLI
Details

Resolves no tracked issue.

Prevents session maintenance from deleting a session directory while the owning CLI process is still running. Each session now writes its owner process identifier to process.pid, and cleanup skips sessions whose owner process is alive before applying age and max-session pruning.

This can happen when multiple tuist invocations share the same $XDG_STATE_HOME/tuist/sessions directory, which is common in CI jobs that run several Tuist commands in the same workspace or user account. Each invocation schedules detached session cleanup after setup. Before this change, cleanup treated every session as removable based only on creation date and the global session limit. A long-running command could be one of the oldest sessions while newer commands were created, so another process could remove that active session directory. When the long-running command later tried to finish rendering Noora output through its logs.txt, the file path was gone and the thrown file error escaped through swift_errorInMain.

The analytics upload path was checked because the crash happens after run metadata is printed. AnalyticsArtifactUploadService zips a copied staging directory and does not remove the live session directory, so the root issue is session cleanup not knowing which sessions are still active. Keeping the logger strict is intentional here: if session setup fails for another reason, that error should still be visible instead of being hidden behind a fallback.

Cleanup itself remains best-effort. If a session disappears while maintenance is scanning, if its attributes cannot be read, or if a removal loses a filesystem race, cleanup skips that entry instead of letting the maintenance task fail.

The inactive-session retention cap remains 50 by default and can be raised with TUIST_SESSION_MAX_SESSIONS. Invalid values, zero, and negative values fall back to the default. The CLI debugging and directories docs now describe the session directory layout and the environment override.

How to test locally

  • mise run cli:lint --fix
  • tuist generate tuist TuistKit TuistKitTests --no-open
  • xcodebuild test -workspace Tuist.xcworkspace -scheme Tuist-Workspace -only-testing TuistKitTests/SessionControllerTests CODE_SIGNING_ALLOWED=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY=""
  • xcodebuild build -workspace Tuist.xcworkspace -scheme tuist CODE_SIGNING_ALLOWED=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY=""
  • git diff --check
Comments
T
tuist[bot] Jun 4, 2026

🛠️ Tuist Run Report 🛠️

Tests 🧪
Scheme Status Cache hit rate Tests Skipped Ran Commit
TuistUnitTests 49 % 2897 5 2892 dd7b476b8
Flaky Tests ⚠️
  • TuistUnitTests: 3 flaky tests (View all)
Test case Module Suite
parseTestStatuses_returnsCorrectStatuses() TuistXCResultServiceTests XCResultServiceTests
parseTestWithCustomLabelXCResult() TuistXCResultServiceTests XCResultServiceTests
parseTestXCResult() TuistXCResultServiceTests XCResultServiceTests
Builds 🔨
Scheme Status Duration Commit
TuistUnitTests 4m 34s dd7b476b8
TA
tuist-atlas[bot] Jun 5, 2026

The fix for preserving active session logs during cleanup is now available in 4.195.17. Update to this version to prevent active sessions from being deleted while the owning CLI process is running.