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): notify registries after state commits by kitlangton · Pull Request #44843 · anomalyco/opencode Conversation
|
| Step | Outer registration | Synchronous listener |
|---|---|---|
| 1 | Acquires the registry lock. | |
| 2 | Commits deploy. |
|
| 3 | Announces the update and waits for listeners. | Starts running. |
| 4 | Still holds the lock. | Tries to register deploy-preview; waits for the lock. |
| 5 | Waits for the listener to return. | Cannot proceed until the outer update releases the lock. |
The wait cycle is outer update -> listener -> registry lock -> outer update. Advancing the reproducer by one virtual hour does not resolve it: registration remains pending and deploy-preview is absent. If plugin activation awaits that registration, activation remains stuck too.
Intended behavior: release the lock before invoking the listener. Its nested registration can then acquire the lock and finish. This specific failure requires a synchronous listener that mutates the same registry; ordinary asynchronous stream subscribers do not automatically share the deadlock.
Fixture scenario: one update selects experimental-model for an agent and adds that model to the catalog.
| Moment | Selected model | Catalog contains it? |
|---|---|---|
| Before the batch | stable-model |
Yes |
| Agent selection commits and announces | experimental-model |
No |
| Catalog commits and announces | experimental-model |
Yes |
The first listener sees a new selection and the old catalog. A listener validating or using that combination could report "model unavailable" or choose a fallback, even though the completed configuration is valid. The reproducer asserts the mixed snapshot; it does not claim an actual model request or UI action was executed.
Intended behavior: commit both registries before delivering either event, so each listener can refetch the completed batch.
sequenceDiagram
participant Batch
participant Agent as Agent registry
participant Catalog
participant Listener
Batch->>Agent: Commit selection and finalize
Batch->>Catalog: Commit model and finalize
Note over Batch,Catalog: Mutation coordination released
Batch->>Listener: Announce agent update
Listener->>Catalog: Refetch committed models
Catalog-->>Listener: Includes selected model
Batch->>Listener: Announce catalog update
State gains a post-commit notify phase while retaining coordinated finalize. Registry Bus publications move to notify; reference materialization remains in finalize. Reload scheduling releases ownership before notification delivery so listeners can request another reload, while each reload waiter remains associated with its generation's notification result.
This PR owns the commit/notification boundary, not the read-side debounce behavior in #44813. Durable Bus publication and MCP lifecycle reconciliation are unchanged. The rebase preserves current v2 teardown suppression; failure delivery and watcher-policy reentrancy still need the corrections below.
Both examples below ran twice against the real pre-fix State implementation with fixture data and Effect TestClock. No live session, network request, configuration discovery, or real plugin activation was involved. The fixture invokes its listener directly from finalize, reproducing the synchronous boundary used by pre-fix Bus publication.
These are baseline caller-wiring reproductions, not unchanged tests for the PR head: publishers covered by this PR must move their callbacks from finalize to notify.
From packages/core at the pre-fix revision fa4c5b26dc:
bun -e ' import assert from "node:assert/strict" import { Effect, Scope } from "effect" import { TestClock } from "effect/testing" import { State } from "./src/state.ts" const batch = Effect.gen(function* () { const observed: { event: string; model: string; models: string[]; available: boolean }[] = [] const selection = State.create({ initial: () => ({ model: "stable-model" }), draft: (draft) => draft, finalize: () => observe("agent.updated"), }) const catalog = State.create({ initial: () => ["stable-model"], draft: (draft) => draft, finalize: () => observe("catalog.updated"), }) const observe = (event: string) => Effect.sync(() => { observed.push({ event, model: selection.get().model, models: [...catalog.get()], available: catalog.get().includes(selection.get().model), }) }) yield* State.batch(Effect.gen(function* () { yield* selection.transform((draft) => { draft.model = "experimental-model" }) yield* catalog.transform((draft) => draft.push("experimental-model")) })) assert.deepEqual(observed, [ { event: "agent.updated", model: "experimental-model", models: ["stable-model"], available: false }, { event: "catalog.updated", model: "experimental-model", models: ["stable-model", "experimental-model"], available: true }, ]) observed.forEach((entry, index) => console.log(`event ${index + 1}: ${JSON.stringify(entry)}`)) assert.equal(catalog.get().includes(selection.get().model), true) }) await Effect.runPromise(batch.pipe(Effect.scoped, Effect.provide(TestClock.layer()))) const listener = Effect.gen(function* () { const scope = yield* Scope.make() const trace: string[] = [] let reentered = false const commands = State.create({ initial: () => new Array<string>(), draft: (draft) => draft, finalize: () => Effect.gen(function* () { if (reentered) return reentered = true trace.push("Registry committed deploy; synchronous update listener entered.") trace.push("Listener awaits registration of its deploy-preview command.") yield* commands.transform((draft) => draft.push("deploy-preview")).pipe(Scope.provide(scope)) trace.push("Listener returned.") }), }) const update = yield* commands.transform((draft) => draft.push("deploy")) .pipe(Scope.provide(scope), Effect.forkDetach({ startImmediately: true })) yield* TestClock.adjust("1 hour") assert.equal(update.pollUnsafe(), undefined) assert.deepEqual(commands.get(), ["deploy"]) assert.equal(trace.length, 2) trace.forEach((line, index) => console.log(`step ${index + 1}: ${line}`)) console.log("After one virtual hour: outer update still pending; deploy-preview still missing.") console.log("Wait cycle: outer update -> listener -> registry lock -> outer update.") }) await Effect.runPromise(listener.pipe(Effect.provide(TestClock.layer()))) // The intentional deadlock cannot unwind its scope. Process exit cleans up this fixture. process.exit(0) '
Observed:
event 1: {"event":"agent.updated","model":"experimental-model","models":["stable-model"],"available":false}
event 2: {"event":"catalog.updated","model":"experimental-model","models":["stable-model","experimental-model"],"available":true}
step 1: Registry committed deploy; synchronous update listener entered.
step 2: Listener awaits registration of its deploy-preview command.
After one virtual hour: outer update still pending; deploy-preview still missing.
Wait cycle: outer update -> listener -> registry lock -> outer update.
Exit code zero means both original failure modes were observed and asserted, not that they are fixed. The intentionally deadlocked fixture has no external resources and is isolated to this short-lived process.
Commands previously run from packages/core:
bun typecheck bun run test test/state.test.ts test/agent.test.ts test/command.test.ts test/catalog.test.ts test/skill.test.ts test/websearch.test.ts test/reference.test.ts test/integration.test.ts test/instruction-discovery.test.ts bun run test
c990acf3eb: 88 targeted tests passed, including registry services and filesystem watchers, with isolated HOME/XDG/credentials; Core bun typecheck passed again.v2 base.Rebased onto v2 at a841d6d046; current head is b5cca1a60f. Preserved State.batch(..., { flush: false }), closed-state guards, and both sets of tests. Suppressed materialization and disposal paths return no-op notification effects instead of undefined.
bun install --frozen-lockfile: passed; lockfile unchanged.bun typecheck from packages/core: passed.This was a rebase and upstream integration pass, not a fix for the review findings below.
These findings were reproduced before the rebase at c990acf3eb; line references refer to that revision. Their fixes remain outstanding.
state.ts:52-53).".git" during notification causes another listener to receive ["dist", ".git"], followed by the outer notification's older ["dist"]. The later stale callback can restore a watcher that the current policy says to ignore (filesystem/location-watcher-policy.ts:41-43).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
c990acf to
b5cca1a
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.