opencode icon indicating copy to clipboard operation
opencode copied to clipboard

server: add option to disable session auto-resume on service start

Open NikonP opened this issue 1 month ago • 7 comments

Summary

The background service unconditionally resumes every suspended session when it starts, so a turn that was in flight during an unclean stop/restart continues on its own and spends tokens without any user input. There is no config, CLI flag, or service setting to disable this.

Environment

  • opencode version: 2.0.19
  • OS: Linux 6.12.104-1-MANJARO (x86_64)
  • Terminal: ghostty (TERM=xterm-256color, TERM_PROGRAM=ghostty, COLORTERM=truecolor)
  • Shell: fish
  • Install/channel: release
  • Active plugins: none

Reproduction

  1. Start a session and let it get into an active turn (assistant streaming / tool running).
  2. Stop the background service uncleanly, e.g. opencode service restart while the turn is still running (or let the process crash / reboot).
  3. On restart, observe that the session's turn resumes by itself with no new user input.

You can confirm the state in the DB before restart:

sqlite3 ~/.local/share/opencode/opencode.db \
  "select id,title,time_suspended from session_v2 where time_suspended is not null and parent_id is null;"

Expected Behavior

There should be a way to keep sessions parked after a service restart, i.e. an opt-in/opt-out for automatically continuing in-flight turns. At minimum a config option (e.g. under session) or an environment variable. Desired default for this user: do not auto-resume; wait for explicit user input.

Actual Behavior

ServerProcess.start calls resumeSuspendedSessions() whenever it runs in service mode, and that routine resumes every suspended session it finds. In 2.0.19 (binary /usr/bin/opencode) the relevant code is:

// ServerProcess.start (service mode); `a` is the service flag
var UW = j(function*(e){ yield*Ht(e.resumeSuspendedSessions) });
// ...
if (a) yield* UW(AH(O, Ms)).pipe(...);

resumeSuspendedSessions gathers suspended sessions and background jobs that are not currently active and resumes them:

// subagent/job service
resumeSuspendedSessions: A(function*(){
  let f = yield* i.active,
      q = yield* s.pendingBackground,
      S = q.flatMap(I => I.status === "running" && I.recovery.kind === "subagent" ? [I.recovery.childSessionID] : []),
      T = new Set([...yield* a.listSuspended(), ...S].filter(I => !f.has(I)));
  yield* a.releaseChildClaims(S);
  // ... resume pending background jobs ...
  let O = yield* i.active;
  yield* _((yield* a.listSuspended()).filter(I => !O.has(I)), (I) => i.resume(I));
})

Supporting store logic:

listSuspended: select { sessionID } from session_v2
               where time_suspended is not null and parent_id is null
claim:   update session_v2 set time_suspended = <now> where id = ? and time_suspended is null   // on execution start
release: update session_v2 set time_suspended = null, resume_attempts = 0 where id = ?           // on execution end

So any session whose execution did not finish cleanly keeps time_suspended set and is auto-continued on the next service start.

Additional Context

  • No documented or schema option exists in 2.0.19:
    • V2 Config schema fields (shell, model, default_agent, update, share, enterprise, username, permissions, agents, snapshots, watcher, formatter, lsp, media, tool_output, mcp, compaction, skills, commands, instructions, references, websearch, plugins, worktree, warming, providers, experimental) contain no session/resume/recovery toggle.
    • experimental exposes only shell_scanner, subagent_depth, policies.
    • cli.json session.* has no such key.
    • opencode service set accepts only hostname, port, password, env, cors.
    • No matching OPENCODE_* environment variable.
  • resume_attempts on session_v2 also exists; release resets it to 0.
  • The only workarounds found are unsupported: a SQLite trigger on session_v2 that nulls time_suspended on update, or a wrapper that clears it before launching opencode. Both are fragile (DB edits / launch-path dependent), so a first-class option would be much better.
  • Frequency: deterministic - happens on every service start while a session is suspended.
  • Related: session.interrupt already exposes a resume query param, and session.prompt/session.synthetic accept resume in the payload, but there is no server-level control over startup recovery.

NikonP avatar Oct 16 '26 10:10 NikonP

Thanks for the detailed write-up! To restate the request: you'd like a setting (a config key under something like session, or an environment variable) that stops the background service from automatically resuming suspended or in-flight sessions when it starts, so they wait for your next input instead of spending tokens on their own.

I checked current dev. Startup recovery still runs unconditionally in service mode, and there is no option to turn it off. The plugin API also has no hook into startup recovery, so for now this can't be done as a plugin either. Maintainers will consider it.

Related issues:

  • #55076: the service resumes killed opencode run --standalone sessions, which led to a costly unattended runaway
  • #51213: the service resumes sessions that another live server is still running
  • #54180: declining a tool call is recorded as a shutdown, so that turn resumes after a restart
  • #35646: the original issue that added auto-resume after a restart

opencode-agent[bot] avatar Oct 16 '26 10:10 opencode-agent[bot]

Also see my comment here: https://github.com/anomalyco/opencode/issues/59635#issuecomment-6859509869

I declined a tool call and closed the TUI tab. I very much did not expect it to continue on a restart after I had explicitly stopped it.

neonphog avatar Nov 13 '26 17:11 neonphog

The resume function is a horror when switching local llm. Please add an option to turn it off completely! I need to switch ti PI otherwise which I want to avoid. Please.

Sly12346 avatar Nov 14 '26 09:11 Sly12346

Also see my comment here: #59635 (comment)

I declined a tool call and closed the TUI tab. I very much did not expect it to continue on a restart after I had explicitly stopped it.

This is exactly my use case. And it so frustrating...

NikonP avatar Nov 14 '26 11:11 NikonP

this is extremely frustraing feature when using local llm.... it switches model automatically. please make it possible to disable. thank you

lukaskrasa avatar Nov 19 '26 20:11 lukaskrasa

image

this is so annoying... 2 days old session restart just on vibes.

opencode is a total shitshow now.

NikonP avatar Nov 26 '26 09:11 NikonP

Adding a real-data point for the stale-claim case (IDs, paths, host and message content redacted).

Environment: OpenCode 2.0.25, opencode serve --service (V2), Linux x86_64, single shared service on one machine.

Timeline (local time):

When Event
2026-11-17 11:08 and 2026-11-23 15:31 last activity in two unrelated sessions; both last turns ended finish: "error", error.type: "aborted"
2026-11-26 19:33 machine rebooted
2026-11-26 19:34:17 background service started
2026-11-26 19:34:19 both sessions received a synthetic message: type: "synthetic", description: "Continuing after restart", metadata: {"notice": "restart"}
19:34:20 → 19:35:21 / 19:36:05 both sessions generated continuously until the user interrupted each one; the resulting assistant messages end with {"type":"aborted","message":"Step interrupted"}
after the interrupt session_v2.time_suspended is NULL for both

So the sweep was not recovering a turn that had been in flight "just now": the durable claim had been sitting on two sessions idle for 9 and 3 days, and the first service start after that replayed them. I don't see an age bound or a provenance check — a claim left by a shutdown days ago is indistinguishable from one left a second ago.

This is the same shape as the OP's report, but the age makes the consent problem sharper: nothing in the UI tells the user that a week-old turn is about to restart, and the synthetic notice only appears once the resumed turn is already running.

Two suggestions in the meantime, alongside the opt-out request:

  1. Bound recovery by claim age, or only recover claims whose owning generation ended within a short window (e.g. the previous service generation's shutdown/exit was observed at startup).
  2. Mark a recovered turn as "needs confirmation" instead of resuming it automatically.

Happy to test a build if either is implemented.

Sanitized: no session or message IDs, chat IDs, paths, hostnames, or message content are included.

SXongin avatar Nov 26 '26 11:11 SXongin