Skip to content

fix(opencode-plugin): fetch the provider inventory once per change, not once per workspace - #6391

Merged
reachjalil merged 2 commits into
devfrom
fix/provider-inventory-shared-fetch
Oct 22, 2026
Merged

reachjalil merged 2 commits into
devfrom
fix/provider-inventory-shared-fetch

Conversation

@reachjalil

@reachjalil reachjalil commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

What is this about?

Desktops reload their AI provider list once per change, instead of once per open workspace.

What problem does it solve?

After a Den deploy, every desktop reloads its providers. A desktop with several workspaces open sent the same reload once per workspace: the provider list plus one connect call per provider, each about 36 database queries. During a few back-to-back deploys this came to hundreds of connect calls a minute and about 40% of all Den queries.

What was the situation before?

OpenCode loads one plugin instance per workspace location. The locations already shared one inventory change stream, but each change reached every location and each fetched the full inventory itself.

How is this implemented?

  • packages/opencode-plugin/src/inventory-fetch.ts: one shared fetch per session and credential scope, held behind an immutable globalThis capability like inventory-events.ts.
  • Each location takes a ticket from a strictly increasing counter when it decides to refresh, and joins only a fetch still in flight that started after its ticket, so a change is never answered with older inventory. Aborting one location does not cancel the others; finished or failed fetches are never reused.
  • plugin.ts and desktop.ts call it instead of fetchGatewayInventory.

What else changed?

None.

Release note

None.

Evidence

  • packages/opencode-plugin/src/inventory-fetch.test.ts: five locations asking together went from five inventory fetches → one; a request made after a fetch started still gets its own.

…ot once per workspace

OpenCode loads one plugin instance per workspace location. They already
share one inventory change stream, but each change reached every location
and each one fetched the full gateway inventory itself: the provider list
plus one connect call per provider. A desktop with many locations sent
the same inventory reads to Den many times over for a single change, and
every Den deploy is a change for every desktop.

Locations that ask at the same time now share one fetch per session and
credential scope. A location only takes a fetch that started after it
asked, so a change is never answered with inventory read before it.
Aborting one location's request leaves the shared fetch running for the
others, and a failed fetch is never reused. Like the inventory stream,
only an immutable capability is global; credentials stay in a closure.

Signed-off-by: Jalil <reachjalil@gmail.com>
@vercel

vercel Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

4 Skipped Deployments
Project Deployment Actions Updated
openwork-app Skipped Skipped Oct 22, 2026 10:01pm UTC
openwork-den Skipped Skipped Oct 22, 2026 10:01pm UTC
openwork-diagnostics Skipped Skipped Oct 22, 2026 10:01pm UTC
openwork-landing Skipped Skipped Oct 22, 2026 10:01pm UTC

Request Review

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

OpenWork evidence

Status Commit Preview Updated
🟡 Updating evidence bcec488 View run 2026-10-22 22:03:41 UTC

A preview for this commit is being prepared.

diff-warden[bot]
diff-warden Bot previously approved these changes Oct 22, 2026

@diff-warden diff-warden Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warden clearance. Complete security and confidentiality review of 336e2aa7c2e6a4aee7bfb165a2c0d07b50a24ed6 found no high or medium security findings and no confidentiality findings. Any new push dismisses this approval. Analysis run

@diff-warden

diff-warden Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Warden: approved

No high or medium security findings and no confidentiality findings.

Reviewed bcec488f1f0c · Warden run · Updates after every Warden run.

…y clock

Comparing millisecond timestamps let a Location that asked after a denial
join a fetch that started before it when both landed in the same
millisecond, which the denial-fencing tests caught on Node 24. Each
Location now takes a ticket from a strictly increasing counter when it
decides to refresh and joins only a fetch started after that ticket.
Finished fetches are no longer reused; only a fetch still in flight is
shared, which is all one change fanning out to every Location needs.

Signed-off-by: Jalil <reachjalil@gmail.com>
@vercel
vercel Bot temporarily deployed to Preview – openwork-diagnostics October 22, 2026 22:01 Inactive
@vercel
vercel Bot temporarily deployed to Preview – openwork-app October 22, 2026 22:01 Inactive
@vercel
vercel Bot temporarily deployed to Preview – openwork-landing October 22, 2026 22:01 Inactive
@vercel
vercel Bot temporarily deployed to Preview – openwork-den October 22, 2026 22:01 Inactive
@reachjalil
reachjalil deployed to pr-internal-specs October 22, 2026 22:02 — with GitHub Actions Active

@diff-warden diff-warden Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warden clearance. Complete security and confidentiality review of bcec488f1f0c9a01da51fe2353379b7237247e23 found no high or medium security findings and no confidentiality findings. Any new push dismisses this approval. Analysis run

@reachjalil
reachjalil enabled auto-merge (squash) October 22, 2026 22:04
@reachjalil
reachjalil merged commit 5aab134 into dev Oct 22, 2026
39 of 41 checks passed

This branch was successfully deployed

1 active and 4 inactive deployments
Preview – openwork-diagnostics — bcec488f Deployed Oct 22, 2026 by vercel[bot]
Preview – openwork-app — bcec488f Deployed Oct 22, 2026 by vercel[bot]
Preview – openwork-landing — bcec488f Deployed Oct 22, 2026 by vercel[bot]
Preview – openwork-den — bcec488f Deployed Oct 22, 2026 by vercel[bot]
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