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: reliability improvements for async operations by adolago · Pull Request #9047 · anomalyco/opencode

Conversation

@adolago

@adolago adolago commented Jan 17, 2026

Copy link
Copy Markdown

Summary

This PR adds several reliability improvements for async operations in the codebase.

Changes

MCP State Synchronization (mcp/index.ts)

  • Added per-server mutex (serverMutexes Map + withServerMutex) to prevent concurrent state mutations for the same server
  • Wrapped add, connect, disconnect, and reconnect operations with mutex
  • Added transport cleanup on connection failure and for unused pending OAuth transports

LSP Client Cleanup (lsp/client.ts)

  • Added connection disposal and server process cleanup on initialization failure
  • Prevents resource leaks when LSP server fails to initialize

PTY Subscriber Management (pty/index.ts)

  • Added proactive cleanup of stale subscribers (those not in readyState 1) when new client connects
  • Added onError handler alongside onClose for WebSocket error handling

Improved Error Logging

  • Replaced silent .catch(() => {}) blocks with debug logging in:
    • config/config.ts - Plugin installation errors
    • file/watcher.ts - Subscription cleanup failures
    • project/instance.ts - Instance disposal errors

Testing

These changes have been tested on the agent-core fork and all 721 tests pass.

Motivation

These fixes address:

  1. Race conditions - Concurrent MCP server operations could corrupt state
  2. Resource leaks - Failed LSP/transport connections weren't being cleaned up
  3. Debuggability - Silent catches made it difficult to diagnose issues

Sorry, something went wrong.

Uh oh!

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

All reactions
@adolago
fix: reliability improvements for async operations
3a163a2
- Add per-server mutex to MCP to prevent concurrent state mutations
- Clean up transports on connection failure and for unused connections
- Add connection/process cleanup on LSP client init failure
- Add proactive stale subscriber cleanup and onError handler in PTY
- Replace silent catches with debug logging in config, watcher, instance

These fixes address potential race conditions, resource leaks, and
improve debuggability by logging previously swallowed errors.
@github-actions github-actions Bot added the needs:issue label Jan 17, 2026
@github-actions

github-actions Bot commented Jan 17, 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 commented Jan 17, 2026

Copy link
Copy Markdown
Contributor

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

The search results show the current PR (#9047) and two other PRs related to memory leak prevention:

Potential Related PRs:

  1. fix(core): add dispose functions to prevent subscription memory leaks #7032 - fix(core): add dispose functions to prevent subscription memory leaks

    • Related to resource cleanup and memory leak prevention similar to the current PR's focus on cleaning up failed connections and resources
  2. fix(core): add dispose functions to prevent subscription memory leaks #7914 - fix(core): add dispose functions to prevent subscription memory leaks

    • Same title as fix(core): add dispose functions to prevent subscription memory leaks #7032, potentially a duplicate or related to the same issue

These PRs address similar concerns around cleanup and disposal of resources, which aligns with the current PR's work on LSP client cleanup and transport cleanup. However, they appear to be older PRs focused on subscription memory leaks rather than the comprehensive async operation reliability improvements in PR #9047.

The current PR #9047 appears to be a newer, more comprehensive fix that builds on or complements these earlier cleanup efforts.

All reactions

Sorry, something went wrong.

Uh oh!

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

@adolago adolago closed this Jan 17, 2026
@adolago
adolago deleted the upstream-reliability-fixes branch January 17, 2026 08:00
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

needs:issue

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

1 participant

@adolago
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.