Skip to content
Source
Sign inSign up
pingdotgg/t3code

[Bug]: generated macOS LaunchAgent can hit EMFILE under the default maxfiles limit #11055

Closedszyprzy(GitHub profile, opens in a new tab) opened this issue 1 comment

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

  1. On macOS, check the default per-process open-file limit available to a user LaunchAgent:

    launchctl limit maxfiles

    On my host the soft limit is 256:

    maxfiles    256    unlimited
  2. Install or update the T3 background service:

    npx t3@nightly service update
  3. Confirm that the generated plist has no per-job open-file override:

    plutil -extract SoftResourceLimits.NumberOfFiles raw \
      "$HOME/Library/LaunchAgents/com.t3tools.t3code.service.plist"

    This fails because SoftResourceLimits.NumberOfFiles is absent.

  4. Start T3 through the LaunchAgent and use it with the normal T3 data directory and project set. On this host, startup hit EMFILE in the T3 user-data watcher on two consecutive nightly versions.

This last step depends on the number of descriptors/watchers needed by a particular T3 installation, so it may not fail on every fresh profile. The service-definition check is deterministic; the runtime failure was observed twice, on 0.0.36-nightly.20260827.1206 and 0.0.36-nightly.20260828.1208.

Expected behavior

The macOS background service should be able to start its required file watchers under the resource limits established by its generated LaunchAgent. If the required resources cannot be obtained, the service should fail in a clear and actionable way rather than losing a watcher during startup.

Actual behavior

The generated LaunchAgent inherits the host's soft maxfiles limit of 256. T3 then logged EMFILE: too many open files, watch while creating a FileSystem.watch on its user-data directory.

The server continued startup afterward in the captured runs, but the watcher failure makes the resulting state unclear and can leave settings or user-data changes unwatched.

Running service update recreates the plist without a locally added resource limit, so the exposure returns after an otherwise normal service repair/update.

Impact

Minor bug or occasional failure

Version or commit

Runtime failure observed in 0.0.36-nightly.20260827.1206 and 0.0.36-nightly.20260828.1208. The current plist renderer still emits no SoftResourceLimits on main at d29c56a5c404cb0f58d3b2ac41762fa0d0ac28d4.

Environment

macOS 26.6.2 (Apple Silicon), launchd user agent, Homebrew Node; current host soft maxfiles limit: 256

Logs or stack traces

PlatformError: Unknown: FileSystem.watch (<HOME>/.t3/userdata)
    at systemError (file://<HOME>/.t3/runtime/versions/0.0.36-nightly.20260827.1206/node_modules/t3/dist/Path-DtM9tupg.mjs:142:34)
    at FSWatcher.<anonymous> (file://<HOME>/.t3/runtime/versions/0.0.36-nightly.20260827.1206/node_modules/t3/dist/NodeServices-BkTDLo1l.mjs:1546:33)
    at FSWatcher.emit (node:events:514:20)
    at FSWatcher._handle.onchange (node:internal/fs/watchers:275:12)
    at server.startup.settings.start (file://<HOME>/.t3/runtime/versions/0.0.36-nightly.20260827.1206/node_modules/t3/dist/bin.mjs:67632:99) {
  [cause]: Error: EMFILE: too many open files, watch
      at FSWatcher._handle.onchange (node:internal/fs/watchers:269:21)
}

The same failure appeared again with 0.0.36-nightly.20260828.1208 at the same FileSystem.watch boundary.

Investigation notes

I inspected the generated plist, the loaded launchd environment, the historical boot-service log, and the current renderer.

I cannot tell from outside the project whether the preferred approach is to change the LaunchAgent resources, reduce descriptor pressure, change watcher behavior, or surface a clearer startup failure. A locally higher per-job limit stopped the errors in my observations, but that correlation is not intended as a prescribed upstream value or implementation.

Workaround

I currently maintain a local per-job open-file limit in the LaunchAgent and verify it after service updates. The exact value is local policy, not a proposed T3 default.

  1. juliusmarminge added labelsneeds more info

  2. juliusmarminge removed labelsneeds more info

  3. tanstack-source added labelsbug

  4. I tried to reproduce this on the current build and could not.

    Commit 1d4d9be3ff (origin/main), pooled Mac on macOS 26.6.2, Apple silicon. 1) Rendered the LaunchAgent with main's renderBootServicePlist (apps/server/src/cloud/bootService.ts), changing only the Label to a throwaway one: plutil -extract SoftResourceLimits.NumberOfFiles raw fails with 'No value at that key path'. The plist sets no open-file limit, as reported. 2) That Mac's launchctl limit maxfiles is 65536/524288, not 256, and system settings are off-limits. To match the reporter's limit, ProgramArguments ran /bin/sh -c 'ulimit -n 256; exec node apps/server/src/bin.ts serve --port 47555 --base-dir <scratch>'. The job was started with launchctl bootstrap gui/$UID. 3) Fresh home: running, 58 fds, no EMFILE. 4) Added 10, then 80, small git repos as projects with t3 project add and restarted with launchctl kickstart -k: 57 fds, no EMFILE. 5) Built apps/web and paired a real browser client through an SSH tunnel; it opened project p80 with VCS status: 64 fds, no EMFILE in boot-service.log. 6) Mechanism check: a bare Node script under ulimit -n 256. It opened files until EMFILE, then freed one fd: fs.watch on the userdata directory still started and reported no error. With no fd free, Node failed with (libuv) kqueue(): Too many open files before the watch call, not with the reporter's FileSystem.watch error. Conclusion: the plist gap is real on main, but the runtime EMFILE needs the server to actually exhaust 256 descriptors. A fresh profile with 80 projects and a connected client uses about a quarter of that, so the reporter's workload (provider sessions, terminals, etc.) could not be recreated.

    Closing as not planned. If it still happens for you, reply with the exact steps and the version you are on and it will be looked at again.

  5. juliusmarminge closed this

Sign in to join this conversation.