Skip to content

Commit df1a7e5

Browse files
t3dotggclaude
andcommitted
fix(opencode): a failed service replacement still reports what is running
A failed hook marked the instance as failed and skipped its probe, so the update ended as unverified. The probe now runs, and it shows the restart hint when the old server is still up. Co-Authored-By: Claude Fable 5.2 <[email protected]>
1 parent f719da1 commit df1a7e5

3 files changed

Lines changed: 34 additions & 5 deletions

File tree

‎apps/server/src/provider/ProviderRegistry.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ import type {
7474
import * as ProviderInstanceRegistry from "./ProviderInstanceRegistry.ts";
7575
import * as ProviderInstanceRegistryMutator from "./ProviderInstanceRegistryMutator.ts";
7676
import * as ProviderRegistry from "./ProviderRegistry.ts";
77+
import { ProviderDriverError } from "@t3tools/provider-core/server/errors";
7778
import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment";
7879
import { makeManualOnlyProviderMaintenanceCapabilities } from "@t3tools/provider-core/server/maintenanceResolver";
7980
vi.mock("@anthropic-ai/claude-agent-sdk", { spy: true });
@@ -1494,6 +1495,7 @@ it.layer(
14941495
const forceRefreshCalls = yield* Ref.make(0);
14951496
const manifest = yield* Ref.make(ModelManifest.BUNDLED_MODEL_MANIFEST);
14961497
const updateEvents = yield* Ref.make<ReadonlyArray<string>>([]);
1498+
const hookFails = yield* Ref.make(false);
14971499
const makeInstance = (name: string) =>
14981500
Effect.gen(function* () {
14991501
const driver = ProviderDriverKind.make("codex");
@@ -1550,6 +1552,12 @@ it.layer(
15501552
Effect.andThen(
15511553
Ref.update(updateEvents, (events) => [...events, `afterUpdate:${name}`]),
15521554
),
1555+
Effect.andThen(Ref.get(hookFails)),
1556+
Effect.flatMap((fails) =>
1557+
fails
1558+
? Effect.fail(new ProviderDriverError({ driver, instanceId, detail: "hook" }))
1559+
: Effect.void,
1560+
),
15531561
),
15541562
orchestrationAdapter: {} as ProviderInstance["orchestrationAdapter"],
15551563
textGeneration: {} as ProviderInstance["textGeneration"],
@@ -1649,6 +1657,19 @@ it.layer(
16491657
assert.notInclude(yield* second.takeMaintenanceReads, "afterUpdate");
16501658
// Instances sharing the replaced service must not cache its old version.
16511659
assert.strictEqual((yield* Ref.get(updateEvents))[0], "afterUpdate:codex_first");
1660+
1661+
// A failed hook leaves the probe to report what is running.
1662+
yield* Ref.set(hookFails, true);
1663+
const probesBeforeFailedHook = yield* Ref.get(first.probes);
1664+
const refreshed = yield* registry.refreshAfterUpdate(
1665+
first.instance.driverKind,
1666+
first.instance.instanceId,
1667+
);
1668+
assert.strictEqual(yield* Ref.get(first.probes), probesBeforeFailedHook + 1);
1669+
assert.include(
1670+
refreshed.map((provider) => provider.instanceId),
1671+
first.instance.instanceId,
1672+
);
16521673
}).pipe(
16531674
Effect.provide(
16541675
ProviderRegistry.layer.pipe(

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,14 +745,22 @@ export const layer = Layer.effect(
745745
(instance) => instance.instanceId === selectedInstanceId,
746746
);
747747
if (selectedInstance?.afterUpdate !== undefined) {
748+
// The probe below reports what is running, so a failed hook needs no status of its own.
748749
yield* selectedInstance.afterUpdate.pipe(
749-
Effect.catchCause((cause) => recoverInstanceFailure(selectedInstance.instanceId, cause)),
750+
Effect.catchCause((cause) =>
751+
Cause.hasInterruptsOnly(cause)
752+
? Effect.interrupt
753+
: Effect.logError("provider post-update hook failed", {
754+
instanceId: selectedInstance.instanceId,
755+
cause: Cause.pretty(cause),
756+
}),
757+
),
750758
);
751759
}
752760
// Accounts can share an installation, but discovery must use each
753761
// instance's own executable, environment, and credentials.
754762
yield* Effect.forEach(
755-
instances.filter((instance) => !failedInstances.has(instance.instanceId)),
763+
instances,
756764
(instance) =>
757765
Effect.gen(function* () {
758766
yield* instance.invalidateCaches ?? Effect.void;

‎docs/user/providers-opencode.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ must use the service's own protocol, host, and port. For a service listening on
5050
Restarting interrupts running turns, and the service then runs with T3 Code's
5151
environment. Set any variables it needs with `opencode service set env <name> <value>`.
5252

53-
T3 Code does not restart any other local server, including the background service
53+
T3 Code does not restart any other server, including the background service
5454
reached through `localhost`. That server can still report the previous version
55-
until you restart it. T3 Code shows that restart requirement instead of treating
56-
the CLI update as a failure.
55+
until you restart it. For a loopback URL, T3 Code shows that restart requirement
56+
instead of treating the CLI update as a failure.
5757

5858
After a lost connection, send another prompt to reconnect to the same OpenCode
5959
session.

0 commit comments

Comments
 (0)