Skip to content

Commit c0045af

Browse files
committed
fix(providers): address PR review on command catalog loading
Drop the GrokAcpSupport re-export shim, load OpenCode catalogs from command/skill endpoints only, and keep ACP available-commands scoped to the root session without leaking across failed startups.
1 parent be53874 commit c0045af

5 files changed

Lines changed: 35 additions & 99 deletions

File tree

‎apps/server/src/provider/Layers/GrokProvider.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,8 @@ import {
3131
enrichProviderSnapshotWithVersionAdvisory,
3232
type ProviderMaintenanceCapabilities,
3333
} from "../providerMaintenance.ts";
34-
import {
35-
makeGrokAcpRuntime,
36-
mapAcpAvailableCommandsToProviderCatalog,
37-
resolveGrokAcpBaseModelId,
38-
} from "../acp/GrokAcpSupport.ts";
34+
import { makeGrokAcpRuntime, resolveGrokAcpBaseModelId } from "../acp/GrokAcpSupport.ts";
35+
import { mapAcpAvailableCommandsToProviderCatalog } from "../providerCommandCatalog.ts";
3936

4037
const GROK_PRESENTATION = {
4138
displayName: "Grok",

‎apps/server/src/provider/acp/AcpSessionRuntime.ts‎

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,9 @@ export interface AcpSessionRuntimeStartResult {
143143
| EffectAcpSchema.ResumeSessionResponse;
144144
readonly modelConfigId: string | undefined;
145145
/**
146-
* Latest `session/update` `available_commands_update` payload captured during
147-
* (or after) start. Grok advertises slash commands and skills this way; the
148-
* update often arrives before `session/new` resolves, so the runtime must
149-
* record it even while start is still in flight.
146+
* Latest root-session `available_commands_update` catalog. Captured during
147+
* start (Grok often emits it before `session/new` resolves) and refreshed on
148+
* subsequent `start()` reads from the live ref so late updates are not lost.
150149
*/
151150
readonly availableCommands: ReadonlyArray<EffectAcpSchema.AvailableCommand>;
152151
}
@@ -427,11 +426,17 @@ export const make = (
427426

428427
yield* acp.handleSessionUpdate((notification) =>
429428
Effect.gen(function* () {
430-
// Capture skill/slash catalogs even while start is in flight. Grok emits
431-
// `available_commands_update` before `session/new` resolves; dropping it
432-
// here is what left provider status with empty skills (issue #4109).
429+
const startState = yield* Ref.get(startStateRef);
430+
431+
// Capture skill/slash catalogs during start (Grok emits
432+
// `available_commands_update` before `session/new` resolves). After the
433+
// root session is known, ignore child/foreign session catalogs.
433434
if (notification.update.sessionUpdate === "available_commands_update") {
434-
yield* Ref.set(availableCommandsRef, notification.update.availableCommands);
435+
const acceptCatalog =
436+
startState._tag !== "Started" || notification.sessionId === startState.result.sessionId;
437+
if (acceptCatalog) {
438+
yield* Ref.set(availableCommandsRef, notification.update.availableCommands);
439+
}
435440
}
436441

437442
const gate = yield* Ref.get(sessionLoadGateRef);
@@ -449,7 +454,6 @@ export const make = (
449454
if (sessionUpdateIsReplay(notification)) {
450455
return;
451456
}
452-
const startState = yield* Ref.get(startStateRef);
453457
// One runtime projects one root ACP session. Child-session updates need
454458
// explicit lineage routing and must never be flattened into this stream.
455459
if (
@@ -594,6 +598,10 @@ export const make = (
594598
);
595599

596600
const startOnce = Effect.gen(function* () {
601+
// Each attempt starts with a clean catalog so a failed startup cannot
602+
// leak stale available_commands into a later retry.
603+
yield* Ref.set(availableCommandsRef, []);
604+
597605
const initializePayload = {
598606
protocolVersion: 1,
599607
clientCapabilities: initializeClientCapabilities,
@@ -743,7 +751,17 @@ export const make = (
743751
const effect = yield* Ref.modify(startStateRef, (state) => {
744752
switch (state._tag) {
745753
case "Started":
746-
return [Effect.succeed(state.result), state] as const;
754+
// Re-read the live ref so post-start available_commands_update is
755+
// visible on subsequent start() calls (not only the one-shot snapshot).
756+
return [
757+
Ref.get(availableCommandsRef).pipe(
758+
Effect.map((availableCommands) => ({
759+
...state.result,
760+
availableCommands,
761+
})),
762+
),
763+
state,
764+
] as const;
747765
case "Starting":
748766
return [Deferred.await(state.deferred), state] as const;
749767
case "NotStarted":
@@ -757,6 +775,7 @@ export const make = (
757775
Effect.onError((cause) =>
758776
Deferred.failCause(deferred, cause).pipe(
759777
Effect.andThen(Ref.set(startStateRef, { _tag: "NotStarted" })),
778+
Effect.andThen(Ref.set(availableCommandsRef, [])),
760779
),
761780
),
762781
),

‎apps/server/src/provider/acp/GrokAcpSupport.test.ts‎

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import * as EffectAcpErrors from "effect-acp/errors";
55
import {
66
applyGrokAcpModelSelection,
77
buildGrokAcpSpawnInput,
8-
mapAcpAvailableCommandsToProviderCatalog,
98
resolveGrokAcpBaseModelId,
109
} from "./GrokAcpSupport.ts";
1110

@@ -17,82 +16,6 @@ describe("resolveGrokAcpBaseModelId", () => {
1716
});
1817
});
1918

20-
describe("mapAcpAvailableCommandsToProviderCatalog", () => {
21-
it("maps path-backed commands to skills and every command to slash entries", () => {
22-
const catalog = mapAcpAvailableCommandsToProviderCatalog([
23-
{
24-
name: "compact",
25-
description: "Compress history",
26-
input: { hint: "optional context" },
27-
},
28-
{
29-
name: "diagnosing-bugs",
30-
description: "Hard bug loop",
31-
_meta: {
32-
scope: "user",
33-
path: "/Users/me/.grok/skills/diagnosing-bugs/SKILL.md",
34-
},
35-
},
36-
{
37-
name: " ",
38-
description: "ignored empty name",
39-
},
40-
]);
41-
42-
expect(catalog.slashCommands).toEqual([
43-
{
44-
name: "compact",
45-
description: "Compress history",
46-
input: { hint: "optional context" },
47-
},
48-
{
49-
name: "diagnosing-bugs",
50-
description: "Hard bug loop",
51-
},
52-
]);
53-
expect(catalog.skills).toEqual([
54-
{
55-
name: "diagnosing-bugs",
56-
description: "Hard bug loop",
57-
path: "/Users/me/.grok/skills/diagnosing-bugs/SKILL.md",
58-
scope: "user",
59-
enabled: true,
60-
},
61-
]);
62-
});
63-
64-
it("dedupes by name case-insensitively and ignores blank paths", () => {
65-
const catalog = mapAcpAvailableCommandsToProviderCatalog([
66-
{
67-
name: "Review",
68-
description: "First",
69-
_meta: { path: "/tmp/a/SKILL.md", scope: "project" },
70-
},
71-
{
72-
name: "review",
73-
description: "Second",
74-
_meta: { path: "/tmp/b/SKILL.md", scope: "user" },
75-
},
76-
{
77-
name: "no-path",
78-
description: "Slash only",
79-
_meta: { path: " " },
80-
},
81-
]);
82-
83-
expect(catalog.slashCommands.map((command) => command.name)).toEqual(["no-path", "Review"]);
84-
expect(catalog.skills).toEqual([
85-
{
86-
name: "Review",
87-
description: "First",
88-
path: "/tmp/a/SKILL.md",
89-
scope: "project",
90-
enabled: true,
91-
},
92-
]);
93-
});
94-
});
95-
9619
describe("buildGrokAcpSpawnInput", () => {
9720
it("passes the T3 Code referrer through Grok OAuth env", () => {
9821
const spawn = buildGrokAcpSpawnInput({ binaryPath: "/usr/local/bin/grok" }, "/tmp/project", {

‎apps/server/src/provider/acp/GrokAcpSupport.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@ import * as EffectAcpErrors from "effect-acp/errors";
88
import type * as EffectAcpSchema from "effect-acp/schema";
99
import { normalizeModelSlug } from "@t3tools/shared/model";
1010

11-
import { mapAcpAvailableCommandsToProviderCatalog } from "../providerCommandCatalog.ts";
1211
import * as AcpSessionRuntime from "./AcpSessionRuntime.ts";
1312
import { makeXAiPromptCompletionRuntime } from "./XAiAcpExtension.ts";
1413

15-
export { mapAcpAvailableCommandsToProviderCatalog };
16-
1714
const GROK_API_KEY_ENV = "XAI_API_KEY";
1815
const GROK_OAUTH2_REFERRER_ENV = "GROK_OAUTH2_REFERRER";
1916
const T3_CODE_OAUTH_REFERRER = "t3code";

‎apps/server/src/provider/opencodeRuntime.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -818,11 +818,11 @@ const makeOpenCodeRuntime = Effect.gen(function* () {
818818
directory: input.directory,
819819
...(input.serverPassword ? { serverPassword: input.serverPassword } : {}),
820820
});
821-
const inventory = yield* loadOpenCodeInventory(client);
822-
return mapOpenCodeSdkCatalogToProviderCatalog({
823-
commands: inventory.commands,
824-
skills: inventory.skills,
821+
// Only the catalog endpoints — do not couple to provider.list / app.agents.
822+
const [commands, skills] = yield* Effect.all([loadCommands(client), loadSkills(client)], {
823+
concurrency: "unbounded",
825824
});
825+
return mapOpenCodeSdkCatalogToProviderCatalog({ commands, skills });
826826
}),
827827
).pipe(Effect.orElseSucceed(() => EMPTY_PROVIDER_COMMAND_CATALOG));
828828

0 commit comments

Comments
 (0)