Skip to content

Commit 85e1a9b

Browse files
committed
Merge remote-tracking branch 'github/main' into fix/npm-release-age-provider-updates
2 parents 0018adb + cec8d73 commit 85e1a9b

62 files changed

Lines changed: 3139 additions & 371 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/mobile/src/features/usage/UsageRouteScreen.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ function UsageScreen(props: {
249249
onSelect={setView}
250250
size="compact"
251251
role="tab"
252-
className="w-60"
252+
className="flex-1"
253253
/>
254254
</View>
255255
) : (

‎apps/server/src/cloud/ManagedEndpointRuntime.test.ts‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,54 @@ describe("CloudManagedEndpointRuntime", () => {
955955
}),
956956
);
957957

958+
it.effect.each(["SIGINT", "SIGTERM"] as const)(
959+
"does not restart a connector that exits after the server receives %s",
960+
(signal) =>
961+
Effect.gen(function* () {
962+
const spawned: Array<number> = [];
963+
const firstExit = yield* Deferred.make<ChildProcessSpawner.ExitCode>();
964+
const firstKilled = yield* Deferred.make<void>();
965+
const spawner = ChildProcessSpawner.make(() =>
966+
Effect.gen(function* () {
967+
const pid = 400 + spawned.length;
968+
spawned.push(pid);
969+
const handle = makeHandle({
970+
pid,
971+
exitCode:
972+
pid === 400
973+
? Deferred.await(firstExit)
974+
: (Effect.never as Effect.Effect<ChildProcessSpawner.ExitCode>),
975+
onKill: () => {
976+
if (pid === 400) Deferred.doneUnsafe(firstKilled, Exit.void);
977+
},
978+
});
979+
yield* Effect.addFinalizer(() => handle.kill().pipe(Effect.ignore));
980+
return handle;
981+
}),
982+
);
983+
// Invoke only the runtime's own listeners; emitting would reach the test worker's too.
984+
const listenersBefore = new Set(process.listeners(signal));
985+
const runtime = yield* buildCloudManagedEndpointRuntime(spawner);
986+
const runtimeListeners = process
987+
.listeners(signal)
988+
.filter((listener) => !listenersBefore.has(listener));
989+
990+
yield* runtime.applyConfig({
991+
providerKind: "cloudflare_tunnel",
992+
connectorToken: "token",
993+
tunnelId: "tunnel-1",
994+
});
995+
for (const listener of runtimeListeners) listener(signal);
996+
// The process group receives the signal too, so the connector exits cleanly.
997+
yield* Deferred.succeed(firstExit, ChildProcessSpawner.ExitCode(0));
998+
yield* Deferred.await(firstKilled);
999+
// Holding the reconcile lock waits out the supervisor's restart decision.
1000+
yield* runtime.restartConnector(400, Effect.succeed(true));
1001+
1002+
expect(spawned).toEqual([400]);
1003+
}),
1004+
);
1005+
9581006
it.effect("serializes concurrent connector config changes", () =>
9591007
Effect.gen(function* () {
9601008
const spawned: Array<number> = [];

‎apps/server/src/cloud/ManagedEndpointRuntime.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,22 @@ export const make = Effect.gen(function* () {
228228
const prunedRef = yield* Ref.make(false);
229229
const retryLoopRunningRef = yield* Ref.make(false);
230230
const notReadyChecksBeforeRestartRef = yield* Ref.make(CONNECTOR_NOT_READY_CHECKS_BEFORE_RESTART);
231+
// The relay client shares the server's process group, so it exits on these signals before the finalizer runs.
232+
let shutdownSignalReceived = false;
233+
const onShutdownSignal = () => {
234+
shutdownSignalReceived = true;
235+
};
236+
yield* Effect.acquireRelease(
237+
Effect.sync(() => {
238+
process.on("SIGINT", onShutdownSignal);
239+
process.on("SIGTERM", onShutdownSignal);
240+
}),
241+
() =>
242+
Effect.sync(() => {
243+
process.off("SIGINT", onShutdownSignal);
244+
process.off("SIGTERM", onShutdownSignal);
245+
}),
246+
);
231247
// An explicit cloudflared transport in the environment is the user's choice.
232248
const env = yield* HostProcess.Environment;
233249
const transportChosenByUser = Option.isSome(
@@ -363,6 +379,7 @@ export const make = Effect.gen(function* () {
363379

364380
const desiredConfig = yield* Ref.get(desiredConfigRef);
365381
if (
382+
shutdownSignalReceived ||
366383
!desiredConfig ||
367384
desiredConfig.providerKind !== "cloudflare_tunnel" ||
368385
runtimeConfigKey(desiredConfig) !== connector.configKey

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts‎

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { beforeEach, vi } from "vite-plus/test";
99

1010
import type {
1111
ElicitationRequest,
12+
ElicitationResult,
1213
Query as ClaudeQuery,
1314
SDKMessage,
1415
SDKResultMessage,
@@ -5703,6 +5704,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
57035704
options: [
57045705
{ decision: "cancel", label: "Cancel" },
57055706
{ decision: "decline", label: "Decline" },
5707+
{ decision: "acceptForSession", label: "Always allow this session" },
57065708
{ decision: "accept", label: "Approve" },
57075709
],
57085710
});
@@ -5732,16 +5734,41 @@ describe("ClaudeAdapterV2 background wake turns", () => {
57325734
}).pipe(Effect.scoped, Effect.provide(testLayer)),
57335735
);
57345736

5735-
it.effect.each(["acceptForSession", "acceptAlways"] as const)(
5736-
"declines an unsupported %s decision",
5737-
(decision) =>
5738-
Effect.gen(function* () {
5739-
const { harness, elicit, awaitCard } = yield* startElicitationTurn();
5740-
const answer = yield* elicit(approvalOnly);
5741-
const request = yield* awaitCard(1);
5742-
yield* harness.runtime.respondToRuntimeRequest({ requestId: request.id, decision });
5743-
assert.deepEqual(yield* Fiber.join(answer), { action: "decline" });
5744-
}).pipe(Effect.scoped, Effect.provide(testLayer)),
5737+
it.effect("declines an unsupported acceptAlways decision", () =>
5738+
Effect.gen(function* () {
5739+
const { harness, elicit, awaitCard } = yield* startElicitationTurn();
5740+
const answer = yield* elicit(approvalOnly);
5741+
const request = yield* awaitCard(1);
5742+
yield* harness.runtime.respondToRuntimeRequest({
5743+
requestId: request.id,
5744+
decision: "acceptAlways",
5745+
});
5746+
assert.deepEqual(yield* Fiber.join(answer), { action: "decline" });
5747+
}).pipe(Effect.scoped, Effect.provide(testLayer)),
5748+
);
5749+
5750+
it.effect("answers a repeated prompt from a session grant without a card", () =>
5751+
Effect.gen(function* () {
5752+
const { harness, elicit, awaitCard, runtimeRequests } = yield* startElicitationTurn();
5753+
const first = yield* elicit(approvalOnly);
5754+
const request = yield* awaitCard(1);
5755+
yield* harness.runtime.respondToRuntimeRequest({
5756+
requestId: request.id,
5757+
decision: "acceptForSession",
5758+
});
5759+
const granted = { action: "accept", content: {} } satisfies ElicitationResult;
5760+
assert.deepEqual(yield* Fiber.join(first), granted);
5761+
5762+
assert.deepEqual(yield* Fiber.join(yield* elicit(approvalOnly)), granted);
5763+
assert.equal(runtimeRequests().length, 1);
5764+
5765+
const otherMessage = yield* elicit({ ...approvalOnly, message: "Deploy api?" });
5766+
yield* awaitCard(2);
5767+
const otherServer = yield* elicit({ ...approvalOnly, serverName: "builds" });
5768+
yield* awaitCard(3);
5769+
assert.isUndefined(otherMessage.pollUnsafe());
5770+
assert.isUndefined(otherServer.pollUnsafe());
5771+
}).pipe(Effect.scoped, Effect.provide(testLayer)),
57455772
);
57465773

57475774
it.effect("declines URL and value forms without a card", () =>

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3825,11 +3825,12 @@ export const awaitClaudeApprovalDecision = Effect.fn("awaitClaudeApprovalDecisio
38253825
return yield* Effect.raceFirst(Deferred.await(decision), cancellation);
38263826
});
38273827

3828-
// Web and mobile offer a session grant when options are omitted, and this
3829-
// path only ever answers once.
3828+
// MCP servers such as Computer Use ask on every call and expect the client to
3829+
// remember a session grant, as Codex does. The CLI drops a reply's `_meta.persist`.
38303830
const CLAUDE_MCP_ELICITATION_OPTIONS: ReadonlyArray<ProviderApprovalOption> = [
38313831
{ decision: "cancel", label: "Cancel" },
38323832
{ decision: "decline", label: "Decline" },
3833+
{ decision: "acceptForSession", label: "Always allow this session" },
38333834
{ decision: "accept", label: "Approve" },
38343835
];
38353836

@@ -5212,6 +5213,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
52125213
const pendingRuntimeRequests = yield* Ref.make(
52135214
new Map<string, PendingClaudeRuntimeRequest>(),
52145215
);
5216+
const mcpElicitationSessionGrants = yield* Ref.make(new Set<string>());
52155217
// Background local_bash tasks can trigger wake turns on the query stream with no active provider turn.
52165218
const lastTurnRouteByNativeThread = yield* Ref.make(
52175219
new Map<
@@ -10620,6 +10622,10 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
1062010622
);
1062110623
return { action: "decline" } satisfies ElicitationResult;
1062210624
}
10625+
const grantKey = `${request.serverName}\u0000${request.message}`;
10626+
if ((yield* Ref.get(mcpElicitationSessionGrants)).has(grantKey)) {
10627+
return acceptance;
10628+
}
1062310629
// The CLI waits on this answer, so a turn held for its prompt echo
1062410630
// must show its output now, as canUseTool does.
1062510631
if (context.heldRootFrames.length > 0) {
@@ -10706,8 +10712,14 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
1070610712
runtimeRequest: { ...artifacts.request, status: "cancelled", resolvedAt: now },
1070710713
});
1070810714
}
10715+
if (resolved === "acceptForSession") {
10716+
yield* Ref.update(mcpElicitationSessionGrants, (current) =>
10717+
new Set(current).add(grantKey),
10718+
);
10719+
return acceptance;
10720+
}
1070910721
// Never null: the SDK reads null as answered out of band and leaves
10710-
// the server waiting. Every accept is one-time; no grant is offered.
10722+
// the server waiting.
1071110723
return resolved === "accept"
1071210724
? acceptance
1071310725
: ({

‎apps/server/src/orchestration-v2/EventSink.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
type ProjectId,
1313
ThreadId,
1414
} from "@t3tools/contracts";
15-
import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
1615
import * as ProviderCommitBatch from "./ProviderCommitBatch.ts";
1716
import * as Context from "effect/Context";
1817
import * as DateTime from "effect/DateTime";
@@ -79,9 +78,10 @@ const CurrentProviderBatch = Context.Reference<ProviderBatchPublication | undefi
7978
);
8079

8180
export interface EventSinkV2Shape {
82-
readonly consumeProviderEvents: <E, R, E2, R2>(
83-
source: Stream.Stream<ProviderAdapter.ProviderAdapterV2Event, E, R>,
84-
process: (event: ProviderAdapter.ProviderAdapterV2Event) => Effect.Effect<void, E2, R2>,
81+
/** Items that are not provider snapshots, such as a consumer's own control items, never batch. */
82+
readonly consumeProviderEvents: <A extends { readonly type: string }, E, R, E2, R2>(
83+
source: Stream.Stream<A, E, R>,
84+
process: (event: A) => Effect.Effect<void, E2, R2>,
8585
after: Effect.Effect<boolean, E2, R2>,
8686
canBatch: Effect.Effect<boolean, never, R2>,
8787
) => Effect.Effect<

‎apps/server/src/orchestration-v2/NotificationMailbox.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import {
66
} from "@t3tools/contracts";
77

88
export function isBufferedProviderNotification(
9-
message: OrchestrationV2ConversationMessage,
9+
message: Pick<
10+
OrchestrationV2ConversationMessage,
11+
"createdBy" | "creationSource" | "notification" | "delegatedCompletion"
12+
>,
1013
): boolean {
1114
return (
1215
message.createdBy === "agent" &&

0 commit comments

Comments
 (0)