Skip to content

Inbox: resume an ended OpenCode session from the reply box - #3937

Merged
backnotprop merged 4 commits into
backnotprop:mainfrom
oorestisime:feat/inbox-resume-ended-opencode
Nov 29, 2026
Merged

backnotprop merged 4 commits into
backnotprop:mainfrom
oorestisime:feat/inbox-resume-ended-opencode

Conversation

@oorestisime

@oorestisime oorestisime commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A reply to an OpenCode session that has ended can now resume that same session from the Inbox, history and all, instead of waiting for the person to reopen it in a terminal or handing the thread to a brand-new session.

The Inbox already restarts sessions it launched itself ("Your reply continues it"). A session the person started in a terminal had no launch record, so nothing ever restarted it, and a reply sat in the Inbox until the person went and resumed it by hand. Picked from the reply's recipient list, the new "Resume this OpenCode session" row (between the ended session and "New OpenCode session", added in 47b10b7) goes through the existing reply-launch path. The reply's launch records adopted_session, and its start runs the host's resume on that session instead of start. For OpenCode that is opencode2 serve with PLANNOTATOR_INBOX_LAUNCHED_SESSION, which works on any ses_ id. From then on it behaves like any launched session (Stop, Open in Terminal, respawn on the next reply). The ended session stays the default, and nothing resumes unpicked.

Checked by hand against real OpenCode 2.4.0: a scratch Inbox from this branch, a terminal-started opencode2 run session that posted and exited, a reply with Resume picked. The same ses_ id was resumed under the Inbox, took the reply, and answered in the thread.

Where review is worth the time:

  • run() in inbox-launch.ts. The adopted branch passes { ...launch, session_ref: adopted_session } to host.resume (or to Rex's resume command) and settles the reply on that same session. Settling on the same session is why the wake is a plain reply (no redirected_from) and the session keeps the thread.
  • The two-writer guard (adoptHeld). It refuses to start while any process's argv names the session, and also when ps can't be read, following the Rex resume rule. It can't see a TUI the person opened with plain opencode and then picked the session in its picker. Such a session would be polling, though, and so wouldn't read as ended.
  • Which hosts can adopt. It is opt-in per host through LaunchHost.adopts; only OpenCode implements it. I didn't check whether Claude Code's claude respawn or Pi's resume work on a session the Inbox didn't start, so those can follow separately.
  • Linked machines. The row is offered only when the machine's launch block marks the agent adopts: true. An older machine never shows it, so its reply-launch never sees a resume it would drop.
  • Wording. I chose "Resume this OpenCode session" in the list and "You resumed OpenCode in " in the header. Once picked, the pill and reply box name the agent ("OpenCode"). Happy to change any of it.

Also fixed here, since it showed up on the first try of this: the status line under a reply that started a session stayed on "Starting …" until a reload. openThreadReads.ts and panes/shownReads.ts treated a thread as launched only when its first message carried the launch, so a reply-launch's line was never read again. This affected the existing "New … session" row the same way. Now any message with a launch counts (separate commit).

e2e: inbox-ended-session.spec.ts

A reply to an OpenCode session that ended could only wait for the
person to reopen it in a terminal, or go to a brand-new session. The
Inbox already resumes sessions it launched itself; one the person
started in a terminal had no launch record, so nothing resumed it.

When the session asked has ended and its agent on the thread's machine
can resume a session the Inbox never started (LaunchHost.adopts; OpenCode,
whose `opencode2 serve` takes any ses_ id), the recipient list offers
"Resume this OpenCode session" above the start row. Picked, Send posts
`to: { launch: { agent, project_id, resume } }` through the existing
reply-launch path. The reply's launch records `adopted_session`, and its
start resumes that session (host.resume, or Rex's resume command) instead
of making one, then settles the reply on the same session: a plain wake,
the session keeps the thread, and later replies respawn it like any
launch. It never starts while a process still runs that session.

The ended session stays the default; nothing resumes unpicked. An older
machine sends no `adopts`, so it offers no Resume row.
The Resume row keeps its words in the list ("Resume this OpenCode
session"), but once picked the pill, the reply box and the sent line say
the agent's name instead of the row's words. The thread header reads
"You resumed OpenCode in <project>" for a resumed session.
The window read an open thread's run line again ("Starting <agent>…",
"Working") only when the thread's root carried the launch. A reply that
starts a session (the New session row) or resumes one carries the launch
itself, so its line stayed on "Starting…" until a reload. Any message
with a launch now counts.
The reply list's start and Resume rows come from one call in
thread/replyStart.ts (replyStartsOf), so Thread.tsx stays at the line
ceiling tests/inbox-structure.test.ts holds it to.
@backnotprop
backnotprop merged commit f8debfc into backnotprop:main Nov 29, 2026
44 checks passed
@backnotprop

Copy link
Copy Markdown
Owner

Your four commits went in with #4186, with your authorship kept: the resume itself, the two-writer guard and the run-line fix. The one change from this PR is where the person finds it: a "Resume OpenCode" button under the saved answer, in place of a row in the reply list. Thank you; it goes out in 0.29.8.

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