Skip to content

fix(opencode): settle RPCs when Rift exits, not when stderr closes - #46

Merged
nexxeln merged 2 commits into
devfrom
nxl/rpc-settle-on-exit
Oct 5, 2026
Merged

nexxeln merged 2 commits into
devfrom
nxl/rpc-settle-on-exit

Conversation

@nexxeln

@nexxeln nexxeln commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #43 | Stack: #46 ← #47

Why the change

A lifecycle hook that leaves a process running (docker compose up, cmd &) kept the plugin's RPC call open until that process exited, so rift.create hung or timed out after Rift had already created the workspace.

Special things to note

  • A call now settles at most 100 ms after Rift exits and its stdout ends, even if hook processes still hold stderr. Calls without lingering processes still settle on close, and a real-binary create still takes about 20 ms.
  • Stderr keeps draining after the call settles, so hook processes that log to stderr don't get SIGPIPE. An abort after settling no longer kills them either.
  • A Rift process killed by a signal now reports Rift was terminated by SIGKILL instead of Rift exited with status null.

Change outline

Hooks inherit Rift's stderr, so close, which waits for every stdio stream, can wait on the hook's process instead of on Rift. Hooks can't hold stdout (hook.rs points their stdout at stderr), so Rift exiting plus stdout ending is a reliable "done" signal. The short wait gives stderr written before the exit time to arrive in the failure message.

 rpc(executable, request, signal)
-  on close(code)
-    decode response
+  complete(code, signal)
+    if signal → reject "Rift was terminated by <signal>"
+    decode response                       # unchanged
+  on close → complete
+  on exit + stdout end → in 100 ms → complete   # first one wins

Postcreate hook behavior against the real rift binary, before and after:

hook                                      before                       after
sleep 4 &                                 resolves after 4028 ms       resolves after 123 ms
sleep 30 &          (3 s abort signal)    TimeoutError at 3002 ms      resolves after 121 ms
sleep 30 & echo … >&2; exit 2             TimeoutError at 3002 ms      hook_failed with "compose: port 5432 in use" after 122 ms

@nexxeln
nexxeln added this pull request to stack #48 October 5, 2026 07:05
@nexxeln nexxeln changed the title nxl/rpc settle on exit fix(opencode): settle RPCs when Rift exits, not when stderr closes Oct 5, 2026
@nexxeln
nexxeln merged commit 37c225e into dev Oct 5, 2026
9 checks passed
@nexxeln nexxeln mentioned this pull request Oct 5, 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.

1 participant