Skip to content

feat(cli): preview lifecycle — idle timeout and owner-pid for background servers#2132

Open
WaterrrForever wants to merge 1 commit into
mainfrom
feat/preview-detach
Open

feat(cli): preview lifecycle — idle timeout and owner-pid for background servers#2132
WaterrrForever wants to merge 1 commit into
mainfrom
feat/preview-detach

Conversation

@WaterrrForever

@WaterrrForever WaterrrForever commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • add --idle-timeout <minutes> to hyperframes preview: the server shuts itself down after that long without a request; --background children default to 60 minutes (injected by buildBackgroundPreviewArgs unless the caller pins a value; --idle-timeout 0 opts out), foreground stays disabled by default
  • add --owner-pid <pid>: the server exits when that process does, so an agent session can tie the preview to its own lifetime instead of leaking servers when it is killed
  • an open Studio tab counts as activity (it polls the project signature), so "idle" means nobody — human or agent — is looking
  • document --background/--status/--stop + the new lifecycle flags in the hyperframes-cli skill (they were undocumented there)

History

This PR originally shipped a standalone preview --detach implementation (state files, launch nonces, an internal --detached-child mode). #2384 landed --background/--status/--stop on main in the meantime, which covers the detachment itself — so this was reworked from scratch on top of previewLifecycle: only the two capabilities main lacks remain, as plain preview flags that ride the existing argv forwarding into the background child. The branch was reset; the old implementation is gone.

Design notes

  • The self-shutdown watcher checks both conditions every 30s and SIGTERMs itself, reusing the exact Ctrl+C shutdown path (browser-pool drain, ffmpeg kill, 3s hard deadline) — no second shutdown code path.
  • Lifecycle flags parse and fail loudly in the launching process, not inside a detached child's log file.
  • Vite dev / local-studio modes warn that the flags apply to the embedded server only (matching how --background errors there).

Verification

  • previewLifecycle.test.ts: 18 passed — including default idle-timeout injection, explicit-value preservation (both --idle-timeout 0 and = forms), owner-pid forwarding, and the ported shutdown-reason / processAlive suites
  • cli.commands.test.ts + lifecycle suite: 22 passed
  • oxlint / oxfmt clean; pre-commit hooks passed (typecheck, fallow, commitlint; skills-manifest regenerated by the hook)

Comment thread packages/cli/src/commands/preview.ts Fixed
Comment thread packages/cli/src/commands/preview.ts Fixed
Comment thread packages/cli/src/commands/preview.ts Fixed
…und servers

Rework of the original `preview --detach` PR on top of the
`--background/--status/--stop` lifecycle that landed in #2384: instead
of a parallel detached-server implementation (state files, launch
nonces, a --detached-child internal mode), the two capabilities main
lacks become first-class preview flags that ride the existing argv
forwarding into the background child.

- `--idle-timeout <minutes>`: the server shuts itself down after this
  long with no requests. An open Studio tab counts as activity (it
  polls the project signature), so "idle" means nobody — human or
  agent — is looking. `--background` children default to 60 minutes
  (injected by buildBackgroundPreviewArgs unless the caller pinned a
  value; `--idle-timeout 0` opts out), so background servers no longer
  outlive their usefulness. Foreground default stays disabled.
- `--owner-pid <pid>`: the server exits when that process does — an
  agent session can tie the preview to its own lifetime instead of
  leaking servers when it is killed.

The watcher checks both conditions every 30s and SIGTERMs itself,
reusing the exact Ctrl+C shutdown path (browser-pool drain, ffmpeg
kill, hard deadline). Flags parse and fail loudly in the launching
process, not inside a detached child's log file. Vite dev/local-studio
modes warn that lifecycle flags apply to the embedded server only.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@WaterrrForever WaterrrForever changed the title feat(cli): preview --detach — a background server that manages its own lifecycle feat(cli): preview lifecycle — idle timeout and owner-pid for background servers Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants