GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: InstanceState reset-caused deadlock/hang during subagent return by RainbowLazer · Pull Request #50667 · anomalyco/opencode

Conversation

@RainbowLazer

@RainbowLazer RainbowLazer commented Sep 22, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Issue for this PR

Closes #50671

Type of change

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

What does this PR do?

Please provide a description of the issue, the changes you made to fix it, and why they work. It is expected that you understand why your changes work and if you do not understand why at least say as much so a maintainer knows how much to value the PR.

If you paste a large clearly AI generated description here your PR may be IGNORED or CLOSED!

This PR fixes a bug where InstanceState can be reset while a subagent is working, causing it to never return back to the main agent—it checks for the old state instead of the new state and deadlocks with the cleanup logic. New code is Claude-generated and I only vaguely understand it. Adds three levels of defense for the bug: forking of the cleanup fiber so it doesn't cause a deadlock with the cache access otherwise hitting the old state, 10 second timeout to override any deadlocks that occur anyways, and automatic resolution of deferred tasks as cancelled when exiting a scope so they cannot wait forever.

How did you verify your code works?

Added and ran (locally) Claude-generated tests that exercise the bug, e.g., by forcing InstanceState reload with a background task running and ensuring the client does not hang.

Screenshots / recordings

If this is a UI change, please include a screenshot or recording.

Checklist

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

If you do not follow this template your PR will be automatically rejected.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
RainbowLazer added 2 commits September 22, 2026 09:44
@RainbowLazer
Claude-generated fixes to OpenCode hanging bug
5305945
- OpenCode has a bug identified by Claude/Copilot in which instance
  state can reload while a subagent is working, which prevents the
  original agent from ever getting a response—it checks for stale
  state that no longer remains.
- Add Claude-generated defenses and tests for this bug

- Claude summary of changes:

Three-layer defense against the instance lifecycle deadlock:

1. task.ts — Release handler cleanup forked to a daemon fiber,
   breaking the re-entrant ScopedCache deadlock chain. Safe because
   SessionRunState.cancel already calls cancelBackgroundJobs before
   interrupting runners.
2. instance-registry.ts — 10-second disposal timeout added as a safety
   net. Even if an unforeseen deadlock occurs in any disposer, disposal
   completes and the new instance can boot.
3. core/background-job.ts — Scope-close finalizer resolves all pending
   done Deferreds with cancelled status. Prevents zombie waiters from
   blocking forever on a Deferred that will never be resolved.

Tests added:

- test/project/instance-lifecycle.test.ts — 4 tests covering
  disposal/reload with active background jobs, fiber blocked on
  background.wait, and disposal timeout behavior.
- test/background/job.test.ts — 1 new test verifying scope-close
  resolves pending done Deferreds.
@RainbowLazer
Fix typecheck errors and failing tests
f950a3c
Claude summary:
- task.ts: Effect.forkDaemon → Effect.forkDetach
- job.test.ts: Effect.forkDaemon → Effect.forkDetach
- instance-lifecycle.test.ts: Effect.forkDaemon → Effect.forkDetach,
  and rebuilt the layer to use
  Layer.mergeAll(InstanceStore.defaultLayer,
                 BackgroundJob.defaultLayer,
                 CrossSpawnSpawner.defaultLayer
                 ).pipe(Layer.provide(noopBootstrap))
  so InstanceStore.Service is a provider
  (not just a requirement-satisfier)
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:title labels Sep 22, 2026
@github-actions

github-actions Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Hey! Your PR title Patch instancestate reset hang doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search results, the only PR that appears is the current PR #50667 itself. While I found some related PRs in the cleanup fiber and subagent context (#45482 and #45822), they are not duplicates of this PR—they address different aspects of the system.

No duplicate PRs found

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@RainbowLazer RainbowLazer changed the title Patch instancestate reset hang Patch InstanceState reset-caused deadlock/hang during subagent return Sep 22, 2026
@RainbowLazer RainbowLazer changed the title Patch InstanceState reset-caused deadlock/hang during subagent return fix: InstanceState reset-caused deadlock/hang during subagent return Sep 22, 2026
@github-actions github-actions Bot added needs:issue and removed needs:title labels Sep 22, 2026
@github-actions

github-actions Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot removed needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Sep 22, 2026
@github-actions

github-actions Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thdxr

thdxr commented Oct 10, 2026

Copy link
Copy Markdown
Member

This branch has been upgraded to V2. We're no longer taking PRs for V1. If you think this is still relevant, please port it over and open it for V2.

— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thdxr thdxr closed this Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

InstanceState Reload can cause client to hang on subagent return

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@RainbowLazer @thdxr
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.