Skip to content

Studio Code: detach remote-session by default and add attach subcommand - #3347

Merged
gcsecsey merged 3 commits into
trunkfrom
stu-1681-use-detatch-mode-by-default-and-allow-to-attach-to-an
May 6, 2026
Merged

Studio Code: detach remote-session by default and add attach subcommand#3347
gcsecsey merged 3 commits into
trunkfrom
stu-1681-use-detatch-mode-by-default-and-allow-to-attach-to-an

Conversation

@epeicher

@epeicher epeicher commented May 5, 2026

Copy link
Copy Markdown
Contributor

Related issues

How AI was used in this PR

Implementation written by Claude under direction. I reviewed the diff and verified behavior end-to-end against a live daemon (attach connects, formats logs, detaches on Ctrl-C without killing the daemon). Test design and edge cases (rotation, dead-PID, daemon-exit detection) were iterated on with the assistant.

Proposed Changes

  • Flip studio code remote-session start default from foreground to detached. The new behavior is "background daemon" by default; pass --no-detach to keep running attached in the foreground (same code path as before).
  • Add studio code remote-session attach: connects to a running daemon, replays a 16 KB tail of ~/.studio/remote-session.log, then streams new entries in the same human-readable format used when running foreground. Errors with exit 1 if no daemon is running. Ctrl-C / SIGTERM detach the terminal without stopping the daemon. Recovers from log rotation (size shrinks → reset offset) and reports daemon exit when the PID stops being live.
  • Export formatLogLineForStdout() from remote-session/logger.ts so attach can reuse the existing JSON-to-human formatter and stay consistent with foreground output.

Testing Instructions

CLI:

  1. npm run cli:build
  2. STUDIO_REMOTE_SESSION_ENABLED=1 node apps/cli/dist/cli/main.mjs code remote-session start — should print Remote-session daemon started (PID …) and return immediately.
  3. studio code remote-session status — confirms the daemon is running.
  4. studio code remote-session attach — should print the attach banner, replay the last bit of log, and stream new entries live. Press Ctrl-C: should print Detached. Daemon is still running.
  5. studio code remote-session status — daemon should still be running after detaching.
  6. studio code remote-session stop — terminates the daemon. Re-running attach should now error with Remote-session daemon is not running.
  7. Foreground path: studio code remote-session start --no-detach — should still run attached and print activity to stdout as before.

Tests:

  • npm test -- apps/cli/remote-session/tests apps/cli/commands/ai/tests (150 passing)
  • npm run typecheck

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
…mand

`studio code remote-session start` now daemonizes by default — pass
`--no-detach` to keep running attached in the foreground. The new
`attach` subcommand connects to a running daemon and streams its log
file to stdout in the same human-readable format used by foreground
mode; Ctrl-C detaches the terminal without stopping the daemon.
The child spawned by startDaemon parses its own argv. With `--detach`
defaulting to true, the child was re-entering the daemon-spawn branch
instead of running the bridge, so the PID file was never written and
startup timed out. Append `--no-detach` to the spawn args so the child
always runs in foreground mode.
@epeicher
epeicher marked this pull request as ready for review May 5, 2026 17:11

@gcsecsey gcsecsey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @epeicher for tackling this! 🙌 In my testing the updated commands are working well, and I could attach-detach to the same session multiple times as described. 👍

command output
start Image
status Image
attach Image
detaching Image
status (after detaching) image
stop CleanShot 2026-05-05 at 23 06 33@2x
start --no-detach CleanShot 2026-05-05 at 23 07 43@2x
@gcsecsey
gcsecsey enabled auto-merge (squash) May 5, 2026 22:09
…e-detatch-mode-by-default-and-allow-to-attach-to-an
@wpmobilebot

Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing 20fd75c vs trunk

app-size

Metric trunk 20fd75c Diff Change
App Size (Mac) 1454.06 MB 1454.06 MB +0.01 MB ⚪ 0.0%

site-editor

Metric trunk 20fd75c Diff Change
load 1523 ms 1537 ms +14 ms ⚪ 0.0%

site-startup

Metric trunk 20fd75c Diff Change
siteCreation 8091 ms 8078 ms 13 ms ⚪ 0.0%
siteStartup 4933 ms 4922 ms 11 ms ⚪ 0.0%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff)

@gcsecsey
gcsecsey merged commit 66e1fc0 into trunk May 6, 2026
10 checks passed
@gcsecsey
gcsecsey deleted the stu-1681-use-detatch-mode-by-default-and-allow-to-attach-to-an branch May 6, 2026 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants