Skip to content

fix(pty): own daemon lifetime and hand off restarts - #45551

Merged
jlongster merged 6 commits into
v2from
pty-daemon-lifetime
Aug 27, 2026
Merged

jlongster merged 6 commits into
v2from
pty-daemon-lifetime

Conversation

@jlongster

@jlongster jlongster commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Issue for this PR

No linked issue. Companion daemon change: anomalyco/opencode-pty#6 (merged).

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Give each server its own PTY daemon, using a UUID runtime directory rather than a database-path hash. A scoped ownership connection makes the daemon stop when its server exits or dies.

Automatic version replacement prepares an authenticated, bounded handoff before stopping the old server. A private sidecar shares the handoff with concurrent startup contenders, and the replacement claims ownership before becoming ready. Explicit stop/restart remains destructive to terminals.

Also allow local CLI builds to embed a locally built daemon through OPENCODE_PTY_BIN.

Core and CLI now pin the published @opencode-ai/[email protected], which provides protocol 7. The lockfile includes the updated platform packages, and the lifecycle tests pass against the released binary rather than a local daemon build.

The remote-shell/default-directory fix is now on v2 and is preserved by this rebase. This PR remains focused on daemon lifecycle changes.

How did you verify your code works?

  • Regenerated clients with bun run generate in packages/client.
  • bun test in packages/client.
  • bun test test/persistent-pty-daemon.test.ts in packages/core.
  • bun test test/persistent-pty.test.ts in packages/server, with OPENCODE_PTY_BIN pointing to the installed @opencode-ai/[email protected] binary.
  • bun test --timeout 30000 test/standalone.test.ts in packages/cli.
  • bun typecheck in Core, Server, Client, and CLI.
  • Prettier and git diff --check.

Screenshots / recordings

Not applicable; no TUI changes are included.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@jlongster
jlongster marked this pull request as ready for review August 27, 2026 12:59
@jlongster
jlongster force-pushed the pty-daemon-lifetime branch from 3dc6d4d to 4be3978 Compare August 27, 2026 15:05
@jlongster
jlongster merged commit 2b8a3e7 into v2 Aug 27, 2026
9 of 10 checks passed
@jlongster
jlongster deleted the pty-daemon-lifetime branch August 27, 2026 15:52
jinhuang712 pushed a commit to jinhuang712/opencode that referenced this pull request Sep 26, 2026
jlongster added a commit that referenced this pull request Nov 10, 2026
… owner loss

`opencode service restart` and `stop` asked the server to shut its process
daemon down before stopping it. That call predates handoff (#45551): a stop
without a handoff now drops the daemon's owner, which stops the daemon and
its processes anyway, and the next server resumes the sessions and settles
their calls. `uninstall` still shuts the daemon down explicitly.

User decisions:
- Remove the up-front daemon shutdown from service restart and stop; keep it in uninstall
jlongster added a commit that referenced this pull request Nov 10, 2026
… owner loss

`opencode service restart` and `stop` asked the server to shut its process
daemon down before stopping it. That call predates handoff (#45551): a stop
without a handoff now drops the daemon's owner, which stops the daemon and
its processes anyway, and the next server resumes the sessions and settles
their calls. `uninstall` still shuts the daemon down explicitly.

User decisions:
- Remove the up-front daemon shutdown from service restart and stop; keep it in uninstall
jlongster added a commit that referenced this pull request Nov 10, 2026
… owner loss

`opencode service restart` and `stop` asked the server to shut its process
daemon down before stopping it. That call predates handoff (#45551): a stop
without a handoff now drops the daemon's owner, which stops the daemon and
its processes anyway, and the next server resumes the sessions and settles
their calls. `uninstall` still shuts the daemon down explicitly.

User decisions:
- Remove the up-front daemon shutdown from service restart and stop; keep it in uninstall
jlongster added a commit that referenced this pull request Nov 10, 2026
… owner loss

`opencode service restart` and `stop` asked the server to shut its process
daemon down before stopping it. That call predates handoff (#45551): a stop
without a handoff now drops the daemon's owner, which stops the daemon and
its processes anyway, and the next server resumes the sessions and settles
their calls. `uninstall` still shuts the daemon down explicitly.

User decisions:
- Remove the up-front daemon shutdown from service restart and stop; keep it in uninstall
jlongster added a commit that referenced this pull request Nov 10, 2026
… owner loss

`opencode service restart` and `stop` asked the server to shut its process
daemon down before stopping it. That call predates handoff (#45551): a stop
without a handoff now drops the daemon's owner, which stops the daemon and
its processes anyway, and the next server resumes the sessions and settles
their calls. `uninstall` still shuts the daemon down explicitly.

User decisions:
- Remove the up-front daemon shutdown from service restart and stop; keep it in uninstall
jlongster added a commit that referenced this pull request Nov 10, 2026
… owner loss

`opencode service restart` and `stop` asked the server to shut its process
daemon down before stopping it. That call predates handoff (#45551): a stop
without a handoff now drops the daemon's owner, which stops the daemon and
its processes anyway, and the next server resumes the sessions and settles
their calls. `uninstall` still shuts the daemon down explicitly.

User decisions:
- Remove the up-front daemon shutdown from service restart and stop; keep it in uninstall
jlongster added a commit that referenced this pull request Nov 10, 2026
… owner loss

`opencode service restart` and `stop` asked the server to shut its process
daemon down before stopping it. That call predates handoff (#45551): a stop
without a handoff now drops the daemon's owner, which stops the daemon and
its processes anyway, and the next server resumes the sessions and settles
their calls. `uninstall` still shuts the daemon down explicitly.

User decisions:
- Remove the up-front daemon shutdown from service restart and stop; keep it in uninstall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant