Skip to content

[Fix] Tasks hang forever when OpenCode session creation never returns#383

Merged
mrubens merged 7 commits into
developfrom
fix/opencode-session-create-timeout-02ud5dh2okb4k
Jul 15, 2026
Merged

[Fix] Tasks hang forever when OpenCode session creation never returns#383
mrubens merged 7 commits into
developfrom
fix/opencode-session-create-timeout-02ud5dh2okb4k

Conversation

@roomote-roomote

@roomote-roomote roomote-roomote Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Opened on behalf of Matt Rubens. Follow up by mentioning @roomote-roomote, in the web UI, or in Slack.

Related issue

Related to #379 (mitigation / fail-closed diagnostics; does not claim to fix the underlying OpenCode instance bootstrap hang).

Why this PR exists

  • A maintainer explicitly invited this PR in the linked issue or discussion
  • I am a maintainer / this is internal Roomote work

What changed

Self-hosted tasks that hang forever on OpenCode's first session/create bootstrap now fail closed with diagnostics instead of staying running with zero further logs.

  • Unary OpenCode HTTP requests now have hard timeouts (POST /session defaults to 90s; other unary calls 60s; health 15s), overridable via env
  • Request start/success/timeout/failure is logged with method, path, label, directory, timeout, and elapsed time
  • Session-create failures emit a durable opencode_session_create_failed diagnostic (workspace, MCP names, HOME, model, elapsed/timeout, error)
  • Initial StartNewTask failures leave a transcript-visible error and shut down as a terminal Failed run — not a resumable TaskAborted/Canceled
  • Cancel while session create is pending still forces settle/shutdown on failure; a late successful create after cancel aborts that orphan session instead of starting the turn under a stopped manager

How it was tested

  • Unit coverage for createSession timeout + logging
  • Harness coverage for terminal failure, cancel/create success race, and diagnostics
  • HarnessManager coverage for StartNewTask commandError terminal shutdown and cancel-before-session failure race
  • Pre-push gates passed

Checklist

  • The PR title follows the repo convention
  • This PR is small and scoped to one change
  • pnpm lint and pnpm check-types pass locally
  • I added tests or included a clear manual validation note above
  • I removed secrets, tokens, private keys, and customer data from code, logs, and screenshots
  • If this change should appear in the changelog, I ran pnpm changeset

mrubens added 2 commits July 15, 2026 11:23
…osed

Add request timeouts and session-create diagnostics so tasks no longer sit
running forever when OpenCode never returns from the first POST /session.
@roomote-roomote

roomote-roomote Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

No new code issues found. See task

  • Session-create failures used resumable TaskAborted → fixed as terminal Failed
  • Cancel + later create failure discarded → fixed force shutdown after cancel
  • Cancel + later create success left live orphan session → fixed abort late session / no prompt

Reviewed 3d85cca

@roomote-roomote

roomote-roomote Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

Fixed the successful-create cancel race too.

If CancelTask arrives before any session id exists, we still mark the cancel. A later-successful ensureSession aborts that late session and emits taskAborted — it no longer starts the initial prompt while the manager is already stopped.

Latest: cc06e11b

mrubens added 5 commits July 15, 2026 11:35
Stop mapping OpenCode session-create failures through TaskAborted (Canceled);
emit a transcript error and shut down via commandError so resolveStatus
returns Failed.
If the user cancels before OpenCode invents a session, CancelTask is a no-op
and a later StartNewTask timeout must still force sandbox shutdown.
If CancelTask arrives before ensureSession finishes, mark the race and abort
any session that still gets created so a stopped manager cannot keep an
orphan live turn.
Make the OpenCode session-create timeout copy tell users to open the Logs
sidebar and inspect harness.log instead of a vague worker logs reference.
@mrubens mrubens marked this pull request as ready for review July 15, 2026 15:00
@mrubens mrubens merged commit 7f729c9 into develop Jul 15, 2026
17 checks passed
@mrubens mrubens deleted the fix/opencode-session-create-timeout-02ud5dh2okb4k branch July 15, 2026 15:00
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