GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||
GeezerVison is showing github.com — fix(core): make registry reads observe pending reloads by kitlangton · Pull Request #44813 · anomalyco/opencode Conversation
|
| Time | Before this change | Registry contents |
|---|---|---|
| Before | Only review is available. |
["review"] |
| 0 ms | The plugin's loaded source gains deploy and requests reload. |
Still ["review"] |
| 50 ms | The prompt captures the registry's skill list. | Reads ["review"] |
| 500 ms | The debounced reload completes. | ["review", "deploy"] |
At 500 ms the reproducer asserts that the registry contains both skills, while the previously captured prompt still contains only review. The consequence is not merely a briefly stale menu: a model request assembled during the window can proceed without a capability that was already ready to publish.
Intended behavior: the read at 50 ms triggers the pending rebuild and receives both skills, without waiting out the remaining debounce. The original reload waiter completes, and the timer does not rebuild that same generation again.
This guarantee starts when reload is requested. It does not synchronously discover filesystem or configuration changes that their producers have not observed yet, and it does not rewrite an already-sent model request.
sequenceDiagram
participant Plugin as Plugin source
participant Registry
participant Prompt as Model-context assembly
Plugin->>Registry: reload()
Note over Registry: Mark stale; schedule 500 ms debounce
Prompt->>Registry: Read available skills at 50 ms
Registry->>Registry: Rebuild pending generation
Registry-->>Prompt: Current skill list
Registry-->>Plugin: Complete original reload waiter
Note over Registry: Timer skips the already-rebuilt generation
The implementation tracks requested and committed generations and a shared in-flight reload. Consumer paths in Agent, Catalog, Command, Integration, MCP, Reference, Skill, WebSearch, and instruction discovery use State.read(). Internal synchronous get() remains a snapshot read. Batch and finalizer exceptions require the corrections listed below before the broader read contract is safe.
This PR owns reads observing already-requested registry reloads, without adding plugin methods or changing the existing 500 ms background debounce. Separating state commits from synchronous event delivery is the related work in #44843; neither branch should overwrite the other's coordination changes during integration.
The executable example below was run twice against the real pre-fix State implementation, with fixture data and Effect TestClock. No live model call, session, network request, configuration discovery, or plugin activation was involved. The checked-out State file at fa4c5b26dc is identical to this PR's original merge-base file at e28471e0ad.
This models the pre-fix caller wiring, where a consumer reads get(). It is not an unchanged regression test for the PR head, where domain consumers must use read().
From packages/core at the pre-fix revision:
bun -e ' import assert from "node:assert/strict" import { Effect, Fiber } from "effect" import { TestClock } from "effect/testing" import { State } from "./src/state.ts" await Effect.runPromise(Effect.gen(function* () { const source = { skills: ["review"] } const skills = State.create({ initial: () => new Array<string>(), draft: (draft) => draft, }) yield* skills.transform((draft) => draft.push(...source.skills)) source.skills = ["review", "deploy"] const reload = yield* skills.reload().pipe(Effect.forkChild({ startImmediately: true })) console.log("t=0ms Source contains review + deploy; reload requested.") yield* TestClock.adjust("50 millis") const promptSkills = [...skills.get()] assert.deepEqual(promptSkills, ["review"]) assert.equal(reload.pollUnsafe(), undefined) console.log(`t=50ms Prompt captures registry: ${JSON.stringify(promptSkills)}`) yield* TestClock.adjust("450 millis") yield* Fiber.join(reload) assert.deepEqual(skills.get(), ["review", "deploy"]) assert.deepEqual(promptSkills, ["review"]) console.log(`t=500ms Registry is now: ${JSON.stringify(skills.get())}`) console.log(`t=500ms Already-captured prompt still has: ${JSON.stringify(promptSkills)}`) }).pipe(Effect.scoped, Effect.provide(TestClock.layer()))) '
Observed:
t=0ms Source contains review + deploy; reload requested.
t=50ms Prompt captures registry: ["review"]
t=500ms Registry is now: ["review","deploy"]
t=500ms Already-captured prompt still has: ["review"]
Exit code zero means the original stale-read behavior was observed and asserted, not that it is fixed.
Commands previously run from the indicated package directories:
# packages/core bun run test bun typecheck # packages/plugin and packages/www bun typecheck bun run build # packages/www bun run check:generated
7260e8d0e5: 114 targeted tests passed, including State, registry services, and MCP, with isolated HOME/XDG/credentials; Core bun typecheck passed again.Rebased onto v2 at a841d6d046; current head is 0ec8232ac2. Preserved upstream terminal-teardown suppression and its regression tests. The shared Effect platform dependency commit was dropped because it is already upstream. The newer Skill.get() now uses State.read(), with a direct-lookup regression that failed before the adaptation and passed afterward.
# Repository root bun install --frozen-lockfile # packages/core bun typecheck bun run test test/state.test.ts test/skill.test.ts test/agent.test.ts test/catalog.test.ts test/command.test.ts test/integration.test.ts test/reference.test.ts test/websearch.test.ts test/instruction-discovery.test.ts test/mcp.test.ts test/plugin.test.ts test/tool-skill.test.ts
135 passed, 0 failed across 12 files, including the upstream teardown tests. Formatting and diff checks passed, as did all 32 pre-push typecheck tasks. This was a rebase and upstream API integration pass, not a fix for the review findings below.
These findings were reproduced before the rebase at 7260e8d0e5; line references refer to that revision. Their fixes remain outstanding.
reload() inside the same activation batch waits for the batch to finish, while the batch waits for reload (state.ts:158).state.ts:155-174).state.ts:139-140,214-216).integration.ts:391).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
7260e8d to
0ec8232
Compare
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.