Repository navigation
Description
Summary
On 2.3.0, when a server plugin is reloaded in place (for example after a change of its options in opencode.json), the tools that the plugin registers are absent from the tool list for a short time, as a reader inside the server sees it (ctx.tool.list() from another plugin). During the same time ctx.plugin.list() reports the reloading plugin as active. The tools return by themselves. The same test on 2.2.6 does not show the gap.
This is a consistency report, not a report of lost work: in a second measurement, model requests that were sent during the reload were held and arrived after it with the complete tool list.
Environment
- opencode 2.3.0 (release binary), Linux x64, one shared server, three loaded locations.
- Comparison: opencode 2.2.6, same machine, same test.
What was measured
Plugin A registers tools; the test watches one of them. A second plugin registers one test tool. A fixture plugin reads ctx.tool.list() and ctx.plugin.list() for an open session of each location. The test changes one option value of plugin A in the global opencode.json one time and then samples both lists every 20 ms for 15 s.
On 2.3.0, in three runs with two reloads each and three locations (18 location reloads):
| Result | |
|---|---|
| First sample without plugin A's tool | 301 to 366 ms after the configuration write |
| First sample with the tool again | 339 to 454 ms after the write |
| Length of the gap by the samples | 36 to 88 ms, in each of the 18 reloads |
ctx.plugin.list() state of plugin A in the gap |
active in every sample |
| After the return | the tool is present in every sample to the end (more than 14 s) |
The test tool of the second plugin is absent in the same samples and returns in the same sample or one sample later.
On 2.2.6 the same test with the same sampler has no sample without the tool.
A second measurement on a full plugin set read the tool names that a model request carries (arrival times at a stand-in provider). A prompt that was sent during the reload arrived after the reload with the complete tool list. Where the server holds such a prompt was not read.
Expected
A reader of the tool list and the plugin list inside the server sees a consistent pair: either the old registrations until the swap is complete, or a plugin state that says the plugin is not ready. A plugin that checks "is tool X present" after a reload cannot tell this gap from a tool that is truly missing, because the plugin list says active.
Possible cause (read in the source, not proven)
packages/core/src/plugin.ts:137-193 at v2.3.0 (the file is identical on the current dev): the reload runs inside State.batch(...). It first closes the activation scope of every plugin after the unchanged prefix (:141-156), which removes their registrations, and then loads the replacements one after the other (:157-188). The inventory snapshot is taken at the end of the batch (:190) and published after it (:193), so the plugin list keeps the old active rows during the batch. State.batch (packages/core/src/state.ts:87-105) holds back the change notifications until the batch ends, but a direct read of the tool registry during the batch sees the closed registrations.
The order "close, then load" is the same at v2.2.6. Why 2.2.6 does not show the gap to the same reader is not known to me.
Related
- server: location reload invalidates the caller's held layer, so its tool catalog is empty #59993 (a location reload leaves the caller's held layer with an empty tool catalog) is a different path, but the symptom for a reader is similar.
Notes
I can supply a minimal reproduction (two plugins and a sampler) if that helps.
Activity
opencodejr commentedon Nov 17, 2026
Thanks for the detailed report. I reproduced this on the released 2.3.0, and it still happens on the latest
dev(00016308).Setup (the script below does all of this):
opencode servewith three local plugins in the globalopencode.json.ctx.tool.list()andctx.plugin.list()every 20 ms.alphatakes options and registersalpha_probe.betaloads afteralphaand registersbeta_probe.What I saw:
setupruns again about 330 ms after the write.alpha_probe,beta_probeand all thebrowser_*tools of the built-in browser plugin (which loads after alpha) are missing fromctx.tool.list(). The list drops from 68 tools to 21.ctx.plugin.list()keeps reporting alpha asactive.One difference from your report: to see the gap, alpha's
setupwaits 60 ms before registering, like a plugin that loads data first. With an instantsetup, the window was shorter than one 20 ms sample. With that delay, the same script also shows the gap on 2.2.6, so in my setup I could not confirm that it is new in 2.3.0.Your reading of
packages/core/src/plugin.tsfits what I saw. The reload closes the activations after the unchanged prefix, then loads the replacements one by one, and only takes the plugin inventory snapshot at the end.State.batchonly holds back notifications, so reads in between see the closed registrations.Related: #59993, where a location reload leaves an empty tool catalog. It takes a different path but has a similar symptom.
Reproduction script (repro.sh)
Run it:
bash repro.shargszero commentedon Nov 17, 2026
I'd like to work on this.
I read the reload path on
dev(2b5ea4977f) and the gap you measured has a mechanism, not a timing accident:Plugin.listreturns the storedinventorysnapshot (packages/core/src/plugin.ts:51), which is only rebuilt at:132when nothing changed and at:190after the whole swap finishes.:145deletes the slot,:149closes its scope), so its tool registrations are gone the moment that runs.ctx.tool.list()reads a registry the close has already emptied. Both readings are correct about their own source; nothing makes them agree.awaitActivation(packages/core/src/plugin/service.ts:42) gates model requests, which is why your second measurement saw the held requests arrive with the complete tool list — the requests wait for the swap, the two list readers do not.Two directions I can see, and I would rather take the one you prefer:
ctx.tool.list()observes the same latch the requests do.(1) is the stronger guarantee and touches only the swap ordering in
plugin.ts; (2) is smaller but makes one of the two views wait, which changes what a reader can observe rather than removing the inconsistency.I cannot measure your 301–366 ms window here — I have no 2.3.0 build and no multi-location server — so a test I add will assert the invariant ("no sample where a plugin reads as active while its tool is missing") over a reload rather than reproduce your timings. Tell me if you would rather have this as a written analysis on the issue only, with no patch.
argszero commentedon Nov 18, 2026
Follow-up on the direction question from my claim, with measurements rather than a proposal.
I first tried moving the outgoing generation's
Scope.closeto after the new inventory is published, so both views would flip together. That breaks two existing tests —restarts the suffix after an insertionandrestarts the suffix after a revision changesboth assertstop:c → stop:b → start:b → start:c, i.e. the outgoing generation must be fully stopped before the replacement starts. That contract looks deliberate (a plugin may hold a port or a file lock), so I dropped that approach rather than adjusting the tests.What I did instead:
Plugin.listwas the only view returning a cached snapshot (inventory, captured at the last publish) while the others read live state. It now reads the live snapshot at call time like the rest.Measured inside the reload window, sampling both views from the replacement's own setup — after the outgoing scope closed, before the replacement registers:
plugin.list()reports the plugin active,tool.list()no longer holds its tool —true:false, the symptom in the reportfalse:false, and once the reload completes both views agree again (alpha-plugin/alpha)bun test test/plugin.test.ts→ 22 pass, 2 fail; the two failures fail with the same names on a cleanupstream/devworktree here, so they are pre-existing and not from this change.tscreports the three errors already ondevand adds none;oxlintis clean on both files.The change is 6 lines in
packages/core/src/plugin.tsplus one test. It is pushed to my fork asplugin-reload-tool-gap; I am at the 3-open-PR limit, so the pull request goes up as soon as a slot frees.iceteaSA commentedon Nov 26, 2026
Thanks for the analysis and the patch, and sorry for the late answer. A patch is welcome. The invariant test you describe (over a reload, no sample in which a plugin reads as active while its tool is missing) is the right check: the window we measured depends on load and on the number of locations, so a timing assertion would be fragile.
When the pull request is up, we will run it against our reload case on a multi-location server and report the result here.