Skip to content

Commit 9fe8eae

Browse files
fix(server): tell a plugin when the thread has no room for its status
The status store drops a new status when the thread already shows its most plugin sources or items. status.set still reported success, kept the key against the plugin's 16-status budget, and left the thread's source open with nothing shown. It now checks what the store admitted, frees the slot and returns an error. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 88169d2 commit 9fe8eae

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

‎apps/server/src/plugins/PluginStatus.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,31 @@ it.layer(NodeServices.layer)("PluginStatus", (it) => {
161161
}).pipe(Effect.scoped),
162162
);
163163

164+
it.effect("tells a plugin when the thread has no room for its status", () =>
165+
Effect.gen(function* () {
166+
const { store, set } = yield* start();
167+
// Each plugin runs in its own process, so each gets its own lifetime.
168+
for (const id of ["acme.a", "acme.b", "acme.c"])
169+
yield* set(registrationFor(id), yield* Scope.make(), {
170+
threadId: THREAD_A,
171+
key: "k",
172+
text: id,
173+
});
174+
const lifetime = yield* Scope.make();
175+
const late = registrationFor("acme.d");
176+
const dropped = yield* set(late, lifetime, {
177+
threadId: THREAD_A,
178+
key: "k",
179+
text: "d",
180+
}).pipe(Effect.flip);
181+
assert.include(dropped.message, "was not shown");
182+
assert.lengthOf((yield* store.snapshot).entries, 3);
183+
// The refused status holds no slot: the same plugin can still show one elsewhere.
184+
yield* set(late, lifetime, { threadId: THREAD_B, key: "k", text: "d" });
185+
assert.lengthOf((yield* store.snapshot).entries, 4);
186+
}).pipe(Effect.scoped),
187+
);
188+
164189
it.effect("refuses undeclared capability and malformed input", () =>
165190
Effect.gen(function* () {
166191
const { store, set, clear } = yield* start();

‎apps/server/src/plugins/PluginStatus.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const STOPPED = hostError("The plugin was stopped.");
6363
interface ThreadStatuses {
6464
readonly scope: Scope.Closeable;
6565
readonly handle: ContributionStatusSourceHandle;
66-
/** Keys this process has shown on the thread; the store may still drop one at capacity. */
66+
/** Keys this process has shown on the thread, as the store admitted them. */
6767
readonly keys: Set<string>;
6868
}
6969

@@ -170,6 +170,18 @@ export const make = Effect.fn("PluginStatus.make")(function* () {
170170
...(input.tone === undefined ? {} : { tone: input.tone }),
171171
...(input.tooltip === undefined ? {} : { tooltip: input.tooltip }),
172172
});
173+
// The store drops a new status when the thread already shows its
174+
// most plugin sources or items; tell the plugin instead of claiming it shows.
175+
if (!(yield* thread.handle.items).some((item) => item.key === input.key)) {
176+
thread.keys.delete(input.key);
177+
if (thread.keys.size === 0) {
178+
generation.threads.delete(input.threadId);
179+
yield* Scope.close(thread.scope, Exit.void);
180+
}
181+
return yield* hostError(
182+
"The thread already shows as many plugin statuses as it can; this one was not shown.",
183+
);
184+
}
173185
thread.keys.add(input.key);
174186
return null;
175187
}),

0 commit comments

Comments
 (0)