mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 13:05:14 +03:00
fix(acp): settle permissions replied elsewhere and type request failures (#52774)
This commit is contained in:
committed by
GitHub
Unverified
parent
2a01ed60b1
commit
ec90ad50d3
@@ -35,7 +35,8 @@ export const connect = Effect.fnUntraced(function* (client: OpenCodeClient, stre
|
||||
Deferred.await(ready).pipe(Effect.flatMap((service) => call(service, ctx))),
|
||||
Effect.catchTags({
|
||||
ACPCatalogLoadError: (error) => ACPClient.classify(error.cause),
|
||||
ACPCatalogNotReadyError: (error) => Effect.die(error),
|
||||
ACPCatalogNotReadyError: (error) =>
|
||||
Effect.fail(new ACPError.ServiceFailureError({ safeMessage: error.message, errorName: "CatalogNotReady" })),
|
||||
}),
|
||||
Effect.mapError((error) => (error instanceof RequestError ? error : ACPError.toRequestError(error))),
|
||||
Effect.tapCauseIf(Cause.hasDies, (cause) => Effect.logError("ACP request failed", cause)),
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { Agent } from "@opencode/schema/agent"
|
||||
import type { Command } from "@opencode/schema/command"
|
||||
import type { Model } from "@opencode/schema/model"
|
||||
import { FSUtil } from "@opencode/util/fs-util"
|
||||
import { Context, Deferred, Effect, Exit, Schedule, Schema, Semaphore, Stream, SubscriptionRef } from "effect"
|
||||
import { Cause, Context, Deferred, Effect, Exit, Schedule, Schema, Semaphore, Stream, SubscriptionRef } from "effect"
|
||||
import type { ConfigOptionProvider } from "./config-option"
|
||||
|
||||
export const builtinCommands = new Map([
|
||||
@@ -90,7 +90,9 @@ export const make = Effect.fnUntraced(function* (client: OpenCodeClient) {
|
||||
{ discard: true },
|
||||
)
|
||||
}),
|
||||
Effect.ignore,
|
||||
Effect.catchCause((cause) =>
|
||||
Cause.hasInterruptsOnly(cause) ? Effect.void : Effect.logWarning("ACP catalog event stream failed", cause),
|
||||
),
|
||||
Effect.ensuring(Deferred.succeed(connected, undefined)),
|
||||
Effect.forkScoped,
|
||||
)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ClientError } from "@opencode/client/effect"
|
||||
import { InvalidRequestError, SessionNotFoundError } from "@opencode/protocol/errors"
|
||||
import { InvalidCursorError, InvalidRequestError, SessionNotFoundError } from "@opencode/protocol/errors"
|
||||
import { Session } from "@opencode/schema/session"
|
||||
import { Effect, Schema } from "effect"
|
||||
import { HttpClientError } from "effect/unstable/http"
|
||||
@@ -16,6 +16,8 @@ export function classify(error: unknown): Effect.Effect<never, ACPError.Error> {
|
||||
return Effect.fail(new ACPError.SessionNotFoundError({ sessionId: error.sessionID }))
|
||||
if (error instanceof InvalidRequestError)
|
||||
return Effect.fail(new ACPError.InvalidRequestError({ message: error.message, field: error.field }))
|
||||
if (error instanceof InvalidCursorError)
|
||||
return Effect.fail(new ACPError.InvalidRequestError({ message: error.message, field: "cursor" }))
|
||||
return Effect.die(error)
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ type Input = {
|
||||
readonly cwd: string
|
||||
readonly tool?: Tool
|
||||
readonly child?: ACPTranslate.ChildSession
|
||||
readonly settled: Effect.Effect<void>
|
||||
}
|
||||
|
||||
const options: PermissionOption[] = [
|
||||
@@ -37,7 +38,13 @@ const decodeFiles = Schema.decodeUnknownOption(Schema.Array(FileDiff.Info))
|
||||
export const reply = Effect.fn("cli.acp.permission.reply")(function* (input: Input, cancelled: Effect.Effect<void>) {
|
||||
yield* Effect.uninterruptibleMask((restore) =>
|
||||
// The race starts racers in order and stops once one is done, so an earlier cancel never starts the ask.
|
||||
restore(cancelled.pipe(Effect.as("reject" as const), Effect.raceFirst(ask(input)))).pipe(
|
||||
restore(
|
||||
cancelled.pipe(
|
||||
Effect.as("reject" as const),
|
||||
Effect.raceFirst(input.settled.pipe(Effect.as("settled" as const))),
|
||||
Effect.raceFirst(ask(input)),
|
||||
),
|
||||
).pipe(
|
||||
Effect.tapCauseIf(Cause.hasDies, (cause) => Effect.logWarning("ACP permission ask failed", cause)),
|
||||
Effect.catchCause(() => Effect.succeed("reject" as const)),
|
||||
Effect.flatMap((decision) => respond(input, decision)),
|
||||
@@ -76,10 +83,12 @@ const ask = Effect.fnUntraced(function* (input: Input) {
|
||||
return selected === "once" || selected === "always" ? selected : "reject"
|
||||
})
|
||||
|
||||
function respond(input: Input, decision: Permission.Reply) {
|
||||
return input.client.permission
|
||||
.reply({ sessionID: input.sessionID, requestID: input.event.data.id, decision })
|
||||
.pipe(Effect.catch(ACPClient.classify))
|
||||
function respond(input: Input, decision: Permission.Reply | "settled") {
|
||||
if (decision === "settled") return Effect.void
|
||||
return input.client.permission.reply({ sessionID: input.sessionID, requestID: input.event.data.id, decision }).pipe(
|
||||
Effect.catchTag("PermissionNotFoundError", () => Effect.void),
|
||||
Effect.catch(ACPClient.classify),
|
||||
)
|
||||
}
|
||||
|
||||
function prefixedTitle(prefix: string | undefined, title: string | undefined) {
|
||||
@@ -104,7 +113,7 @@ const permissionPreviews = Effect.fnUntraced(function* (
|
||||
Effect.gen(function* () {
|
||||
const path = absolutePath(file.file, cwd)
|
||||
const oldText = file.status === "added" ? null : yield* Effect.tryPromise(() => Bun.file(path).text())
|
||||
const newText = applyPatch(oldText ?? "", file.patch)
|
||||
const newText = yield* Effect.try(() => applyPatch(oldText ?? "", file.patch))
|
||||
return newText === false ? [] : [diff(path, oldText, newText)]
|
||||
}),
|
||||
{ concurrency: "unbounded" },
|
||||
|
||||
@@ -22,6 +22,7 @@ import type {
|
||||
ListSessionsResponse,
|
||||
LoadSessionRequest,
|
||||
LoadSessionResponse,
|
||||
McpServer,
|
||||
NewSessionRequest,
|
||||
NewSessionResponse,
|
||||
PromptRequest,
|
||||
@@ -41,7 +42,7 @@ import { configOptions, currentModel, DEFAULT_VARIANT_VALUE, parseModelSelection
|
||||
import type { ACPConnection } from "./connection"
|
||||
import { ACPDirectories } from "./directories"
|
||||
import { ACPError } from "./error"
|
||||
import type { ACPSessions, Attached } from "./sessions"
|
||||
import type { ACPSessions, Attached, SupportedMcpServer } from "./sessions"
|
||||
import { ACPTranslate } from "./translate"
|
||||
import type { ACPTurn } from "./turn"
|
||||
|
||||
@@ -191,23 +192,25 @@ export function make(input: {
|
||||
}),
|
||||
newSession: Effect.fnUntraced(function* (params) {
|
||||
const directories = yield* ACPDirectories.parse(params.cwd, params.additionalDirectories)
|
||||
const mcpServers = yield* supportedMcpServers(params.mcpServers)
|
||||
// Load first so a catalog failure leaves no session.
|
||||
yield* input.catalog.get(params.cwd)
|
||||
const created = yield* input.client.session
|
||||
.create({ location: { directory: AbsolutePath.make(params.cwd) }, ...ACPDirectories.grant(directories) })
|
||||
.pipe(Effect.catch(ACPClient.classify))
|
||||
const attachment = yield* input.sessions.attach(created, params.cwd, params.mcpServers)
|
||||
const attachment = yield* input.sessions.attach(created, params.cwd, mcpServers)
|
||||
return { sessionId: attachment.attached.id, configOptions: attachment.configOptions }
|
||||
}),
|
||||
loadSession: Effect.fnUntraced(function* (params) {
|
||||
const directories = yield* ACPDirectories.parse(params.cwd, params.additionalDirectories)
|
||||
const mcpServers = yield* supportedMcpServers(params.mcpServers)
|
||||
const session = yield* getSession(params.sessionId, params.cwd)
|
||||
yield* ACPDirectories.activate(input.client, session, directories)
|
||||
const attached = (yield* input.sessions.attach(session, session.location.directory, params.mcpServers)).attached
|
||||
const attached = (yield* input.sessions.attach(session, session.location.directory, mcpServers)).attached
|
||||
return yield* replay(attached).pipe(
|
||||
Effect.andThen(currentOptions(attached)),
|
||||
Effect.map((configOptions) => ({ configOptions })),
|
||||
Effect.onError(() => input.sessions.detach(attached.id)),
|
||||
Effect.onError(() => input.sessions.release(attached)),
|
||||
)
|
||||
}),
|
||||
listSessions: Effect.fnUntraced(function* (params) {
|
||||
@@ -247,9 +250,10 @@ export function make(input: {
|
||||
}),
|
||||
resumeSession: Effect.fnUntraced(function* (params) {
|
||||
const directories = yield* ACPDirectories.parse(params.cwd, params.additionalDirectories)
|
||||
const mcpServers = yield* supportedMcpServers(params.mcpServers)
|
||||
const session = yield* getSession(params.sessionId, params.cwd)
|
||||
yield* ACPDirectories.activate(input.client, session, directories)
|
||||
const attachment = yield* input.sessions.attach(session, session.location.directory, params.mcpServers ?? [])
|
||||
const attachment = yield* input.sessions.attach(session, session.location.directory, mcpServers)
|
||||
return { configOptions: attachment.configOptions }
|
||||
}),
|
||||
closeSession: Effect.fnUntraced(function* (params) {
|
||||
@@ -259,11 +263,12 @@ export function make(input: {
|
||||
}),
|
||||
forkSession: Effect.fnUntraced(function* (params) {
|
||||
const directories = yield* ACPDirectories.parse(params.cwd, params.additionalDirectories)
|
||||
const mcpServers = yield* supportedMcpServers(params.mcpServers)
|
||||
const sessionID = yield* ACPClient.decodeSessionID(params.sessionId)
|
||||
const forked = yield* input.client.session.fork({ sessionID }).pipe(Effect.catch(ACPClient.classify))
|
||||
// Forks inherit the source's grants; replace them with this request's.
|
||||
yield* ACPDirectories.activate(input.client, forked, directories)
|
||||
const attachment = yield* input.sessions.attach(forked, forked.location.directory, params.mcpServers ?? [])
|
||||
const attachment = yield* input.sessions.attach(forked, forked.location.directory, mcpServers)
|
||||
return { sessionId: attachment.attached.id, configOptions: attachment.configOptions }
|
||||
}),
|
||||
setSessionConfigOption: Effect.fnUntraced(function* (params) {
|
||||
@@ -283,6 +288,18 @@ export function make(input: {
|
||||
}
|
||||
}
|
||||
|
||||
const supportedMcpServers = Effect.fnUntraced(function* (servers: readonly McpServer[] = []) {
|
||||
const supported = servers.filter(
|
||||
(server): server is SupportedMcpServer => !("type" in server) || server.type === "http",
|
||||
)
|
||||
if (supported.length < servers.length)
|
||||
return yield* new ACPError.InvalidRequestError({
|
||||
message: "Only stdio and HTTP MCP servers are supported",
|
||||
field: "mcpServers",
|
||||
})
|
||||
return supported
|
||||
})
|
||||
|
||||
const requireModel = Effect.fnUntraced(function* (catalog: Catalog, modelID: string, current: Model.Ref) {
|
||||
const selected = parseModelSelection(modelID, catalog.providers)
|
||||
const model = catalog.models.find(
|
||||
|
||||
@@ -3,13 +3,15 @@ import type { McpServer, RequestError, SessionConfigOption } from "@agentclientp
|
||||
import type { OpenCodeClient, OpenCodeEvent } from "@opencode/client/effect"
|
||||
import { Mcp } from "@opencode/schema/mcp"
|
||||
import type { Session } from "@opencode/schema/session"
|
||||
import { Context, Deferred, Effect, Exit, Queue, Ref, Scope, Stream } from "effect"
|
||||
import { Cause, Context, Deferred, Effect, Exit, Queue, Ref, Scope, Stream } from "effect"
|
||||
import type { ACPCatalog, Catalog } from "./catalog"
|
||||
import { ACPClient } from "./client"
|
||||
import { availableCommands, configOptions, type Selection } from "./config-option"
|
||||
import { ACPConnection } from "./connection"
|
||||
import { ACPError } from "./error"
|
||||
|
||||
export type SupportedMcpServer = Exclude<McpServer, { readonly type: "acp" | "sse" }>
|
||||
|
||||
export type Attached = {
|
||||
readonly id: Session.ID
|
||||
readonly cwd: string
|
||||
@@ -20,12 +22,13 @@ export interface Interface {
|
||||
readonly attach: (
|
||||
session: Session.Info,
|
||||
cwd: string,
|
||||
mcpServers: readonly McpServer[],
|
||||
mcpServers: readonly SupportedMcpServer[],
|
||||
) => Effect.Effect<
|
||||
{ readonly attached: Attached; readonly configOptions: SessionConfigOption[] },
|
||||
ACPError.Error | RequestError | ACPCatalog.Error
|
||||
>
|
||||
readonly detach: (sessionID: string) => Effect.Effect<void>
|
||||
readonly release: (attached: Attached) => Effect.Effect<void>
|
||||
readonly require: (sessionID: string) => Effect.Effect<Attached, ACPError.SessionNotFoundError>
|
||||
readonly fork: (attached: Attached, effect: Effect.Effect<void>) => Effect.Effect<void, ACPError.SessionNotFoundError>
|
||||
}
|
||||
@@ -66,7 +69,9 @@ export const make = Effect.fnUntraced(function* (input: {
|
||||
event.type === "session.model.selected" ? { model: event.data.model } : { modeID: event.data.agent },
|
||||
)
|
||||
}),
|
||||
Effect.ignore,
|
||||
Effect.catchCause((cause) =>
|
||||
Cause.hasInterruptsOnly(cause) ? Effect.void : Effect.logWarning("ACP selection event stream failed", cause),
|
||||
),
|
||||
Effect.ensuring(Deferred.succeed(connected, undefined)),
|
||||
Effect.forkScoped,
|
||||
)
|
||||
@@ -89,7 +94,7 @@ export const make = Effect.fnUntraced(function* (input: {
|
||||
if (!isDeepStrictEqual(next.commands, previous.commands)) yield* sendCommands(attached.id, next)
|
||||
})
|
||||
|
||||
const registerMcp = (attached: Attached, servers: readonly McpServer[]) =>
|
||||
const registerMcp = (attached: Attached, servers: readonly SupportedMcpServer[]) =>
|
||||
Effect.suspend(() => {
|
||||
const registered = registeredMcp.get(attached.id) ?? new Set<string>()
|
||||
registeredMcp.set(attached.id, registered)
|
||||
@@ -166,6 +171,10 @@ export const make = Effect.fnUntraced(function* (input: {
|
||||
const entry = sessions.get(sessionID)
|
||||
if (entry) yield* remove(sessionID, entry)
|
||||
}),
|
||||
release: Effect.fn("cli.acp.sessions.release")(function* (attached) {
|
||||
const entry = sessions.get(attached.id)
|
||||
if (entry?.attached === attached) yield* remove(attached.id, entry)
|
||||
}),
|
||||
require: Effect.fn("cli.acp.sessions.require")(function* (sessionID) {
|
||||
const entry = sessions.get(sessionID)
|
||||
if (!entry) return yield* new ACPError.SessionNotFoundError({ sessionId: sessionID })
|
||||
@@ -179,9 +188,8 @@ export const make = Effect.fnUntraced(function* (input: {
|
||||
})
|
||||
})
|
||||
|
||||
function mcpConfig(server: McpServer) {
|
||||
function mcpConfig(server: SupportedMcpServer) {
|
||||
if ("type" in server) {
|
||||
if (server.type === "acp") throw new Error("MCP-over-ACP is not supported")
|
||||
return new Mcp.RemoteConfig({
|
||||
type: "remote",
|
||||
url: server.url,
|
||||
|
||||
@@ -72,7 +72,7 @@ export type TurnState = {
|
||||
readonly compactions: ACPCompaction.Tracked
|
||||
readonly children: ReadonlyMap<string, ChildSession>
|
||||
readonly openChildren: ReadonlySet<string>
|
||||
readonly forms: ReadonlySet<string>
|
||||
readonly asks: ReadonlySet<string>
|
||||
readonly finish?: SessionMessage.Assistant["finish"]
|
||||
readonly usage?: { readonly turn: TokenUsage.Info; readonly last: TokenUsage.Info }
|
||||
readonly stepError?: SessionError.Error
|
||||
@@ -97,7 +97,7 @@ export type Output =
|
||||
readonly child?: ChildSession
|
||||
readonly toolCallSent: boolean
|
||||
}
|
||||
| { readonly _tag: "FormSettled"; readonly formID: string }
|
||||
| { readonly _tag: "AskSettled"; readonly id: string }
|
||||
|
||||
export type Step = {
|
||||
readonly state: TurnState
|
||||
@@ -112,7 +112,7 @@ export const initial: TurnState = {
|
||||
compactions: new Map(),
|
||||
children: new Map(),
|
||||
openChildren: new Set(),
|
||||
forms: new Set(),
|
||||
asks: new Set(),
|
||||
}
|
||||
|
||||
export function step(state: TurnState, event: OpenCodeEvent, ctx: Context): Step {
|
||||
@@ -141,11 +141,14 @@ export function step(state: TurnState, event: OpenCodeEvent, ctx: Context): Step
|
||||
const tool = event.data.source?.id
|
||||
? state.tools.get(toolKey(event.data.sessionID, event.data.source.id))
|
||||
: undefined
|
||||
return { state, outputs: [{ _tag: "PermissionAsk", event, tool, child }] }
|
||||
return {
|
||||
state: { ...state, asks: new Set(state.asks).add(event.data.id) },
|
||||
outputs: [{ _tag: "PermissionAsk", event, tool, child }],
|
||||
}
|
||||
}
|
||||
if (event.type === "form.created" && (event.data.form.sessionID === ctx.sessionID || child)) {
|
||||
return {
|
||||
state: { ...state, forms: new Set(state.forms).add(event.data.form.id) },
|
||||
state: { ...state, asks: new Set(state.asks).add(event.data.form.id) },
|
||||
outputs: [
|
||||
{
|
||||
_tag: "FormAsk",
|
||||
@@ -156,10 +159,16 @@ export function step(state: TurnState, event: OpenCodeEvent, ctx: Context): Step
|
||||
],
|
||||
}
|
||||
}
|
||||
if ((event.type === "form.replied" || event.type === "form.cancelled") && state.forms.has(event.data.id)) {
|
||||
const forms = new Set(state.forms)
|
||||
forms.delete(event.data.id)
|
||||
return { state: { ...state, forms }, outputs: [{ _tag: "FormSettled", formID: event.data.id }] }
|
||||
const settledID =
|
||||
event.type === "permission.replied"
|
||||
? event.data.requestID
|
||||
: event.type === "form.replied" || event.type === "form.cancelled"
|
||||
? event.data.id
|
||||
: undefined
|
||||
if (settledID && state.asks.has(settledID)) {
|
||||
const asks = new Set(state.asks)
|
||||
asks.delete(settledID)
|
||||
return { state: { ...state, asks }, outputs: [{ _tag: "AskSettled", id: settledID }] }
|
||||
}
|
||||
if (!eventSessionID || (eventSessionID !== ctx.sessionID && !child)) return { state, outputs: [] }
|
||||
if (matchesStart(event, ctx.start)) return { state: { ...state, started: true }, outputs: [] }
|
||||
|
||||
@@ -66,7 +66,7 @@ type Subscription = {
|
||||
/** Asks run serially off the event stream. */
|
||||
readonly asks: Queue.Queue<Effect.Effect<void, ACPError.Error | RequestError>>
|
||||
readonly cancelled: Deferred.Deferred<void>
|
||||
readonly forms: Map<string, Deferred.Deferred<void>>
|
||||
readonly settled: Map<string, Deferred.Deferred<void>>
|
||||
}
|
||||
|
||||
export const make = Effect.fnUntraced(function* (input: {
|
||||
@@ -90,7 +90,7 @@ export const make = Effect.fnUntraced(function* (input: {
|
||||
.pipe(Stream.toQueue({ capacity: "unbounded" }), Scope.provide(subscriptionScope)),
|
||||
asks: yield* Queue.unbounded<Effect.Effect<void, ACPError.Error | RequestError>>(),
|
||||
cancelled: yield* Deferred.make<void>(),
|
||||
forms: new Map(),
|
||||
settled: new Map(),
|
||||
}
|
||||
yield* Queue.take(subscription.asks).pipe(
|
||||
Effect.flatten,
|
||||
@@ -116,7 +116,12 @@ export const make = Effect.fnUntraced(function* (input: {
|
||||
yield* Deferred.await(settled)
|
||||
})
|
||||
|
||||
const reply = (subscription: Subscription, ctx: ACPTranslate.Context, ask: PermissionAsk) =>
|
||||
const reply = (
|
||||
subscription: Subscription,
|
||||
ctx: ACPTranslate.Context,
|
||||
ask: PermissionAsk,
|
||||
settled: Deferred.Deferred<void>,
|
||||
) =>
|
||||
ACPPermission.reply(
|
||||
{
|
||||
client: input.client,
|
||||
@@ -127,6 +132,7 @@ export const make = Effect.fnUntraced(function* (input: {
|
||||
cwd: ctx.cwd,
|
||||
tool: ask.tool,
|
||||
child: ask.child,
|
||||
settled: Deferred.await(settled),
|
||||
},
|
||||
Deferred.await(subscription.cancelled),
|
||||
)
|
||||
@@ -138,16 +144,26 @@ export const make = Effect.fnUntraced(function* (input: {
|
||||
case "ChildUpdate":
|
||||
return input.connection
|
||||
.extNotification(ACPTranslate.ChildSessionUpdateMethod, output.update)
|
||||
.pipe(Effect.ignoreCause)
|
||||
.pipe(
|
||||
Effect.catchCause((cause) =>
|
||||
Cause.hasInterruptsOnly(cause)
|
||||
? Effect.void
|
||||
: Effect.logWarning("ACP child session update failed", cause),
|
||||
),
|
||||
)
|
||||
case "PermissionAsk":
|
||||
return Queue.offer(subscription.asks, reply(subscription, ctx, output)).pipe(Effect.asVoid)
|
||||
return Effect.gen(function* () {
|
||||
const settled = yield* Deferred.make<void>()
|
||||
subscription.settled.set(output.event.data.id, settled)
|
||||
yield* Queue.offer(subscription.asks, reply(subscription, ctx, output, settled))
|
||||
})
|
||||
case "FormAsk":
|
||||
return Effect.gen(function* () {
|
||||
const capabilities = yield* Ref.get(input.capabilities)
|
||||
const requestedSchema = ACPElicitation.requestedSchema(output.form, capabilities)
|
||||
if (!requestedSchema) return yield* ACPElicitation.cancelUnshown(input.client, output.form)
|
||||
const settled = yield* Deferred.make<void>()
|
||||
subscription.forms.set(output.form.id, settled)
|
||||
subscription.settled.set(output.form.id, settled)
|
||||
yield* Queue.offer(
|
||||
subscription.asks,
|
||||
ACPElicitation.reply(
|
||||
@@ -165,10 +181,10 @@ export const make = Effect.fnUntraced(function* (input: {
|
||||
),
|
||||
)
|
||||
})
|
||||
case "FormSettled":
|
||||
case "AskSettled":
|
||||
return Effect.suspend(() => {
|
||||
const settled = subscription.forms.get(output.formID)
|
||||
subscription.forms.delete(output.formID)
|
||||
const settled = subscription.settled.get(output.id)
|
||||
subscription.settled.delete(output.id)
|
||||
return settled ? Deferred.succeed(settled, undefined) : Effect.void
|
||||
})
|
||||
}
|
||||
@@ -181,8 +197,10 @@ export const make = Effect.fnUntraced(function* (input: {
|
||||
) {
|
||||
while (true) {
|
||||
const event = yield* take(subscription)
|
||||
const next = ACPTranslate.step(yield* Ref.get(state), event, ctx)
|
||||
yield* Ref.set(state, next.state)
|
||||
const next = yield* Ref.modify(state, (current) => {
|
||||
const step = ACPTranslate.step(current, event, ctx)
|
||||
return [step, step.state]
|
||||
})
|
||||
yield* Effect.forEach(next.outputs, (output) => interpret(subscription, ctx, output), { discard: true })
|
||||
if (next.terminal) {
|
||||
yield* asksSettled(subscription)
|
||||
@@ -227,7 +245,13 @@ export const make = Effect.fnUntraced(function* (input: {
|
||||
})
|
||||
|
||||
const interruptServer = (sessionID: Session.ID) =>
|
||||
input.client.session.interrupt({ sessionID }).pipe(Effect.ignoreCause)
|
||||
input.client.session
|
||||
.interrupt({ sessionID })
|
||||
.pipe(
|
||||
Effect.catchCause((cause) =>
|
||||
Cause.hasInterruptsOnly(cause) ? Effect.void : Effect.logWarning("ACP server interrupt failed", cause),
|
||||
),
|
||||
)
|
||||
|
||||
const windDown = Effect.fnUntraced(function* (
|
||||
subscription: Subscription,
|
||||
@@ -238,7 +262,7 @@ export const make = Effect.fnUntraced(function* (input: {
|
||||
yield* Deferred.succeed(subscription.cancelled, undefined)
|
||||
yield* interruptServer(ctx.sessionID)
|
||||
if (!(yield* Ref.get(state)).started) return
|
||||
if (Option.isSome(yield* Fiber.await(events).pipe(Effect.timeoutOption(drainTimeout)))) return
|
||||
if (Option.exists(yield* Fiber.await(events).pipe(Effect.timeoutOption(drainTimeout)), Exit.isSuccess)) return
|
||||
yield* Fiber.interrupt(events)
|
||||
const abandoned = ACPTranslate.abandon(yield* Ref.get(state), ctx)
|
||||
yield* Ref.set(state, abandoned.state)
|
||||
@@ -323,7 +347,9 @@ export const make = Effect.fnUntraced(function* (input: {
|
||||
},
|
||||
})
|
||||
},
|
||||
(effect) => Effect.ignoreCause(effect),
|
||||
Effect.catchCause((cause) =>
|
||||
Cause.hasInterruptsOnly(cause) ? Effect.void : Effect.logWarning("ACP usage update failed", cause),
|
||||
),
|
||||
)
|
||||
|
||||
// Forked uninterruptible: interruption reaches only `execute`, so the fiber still settles with a response.
|
||||
|
||||
Reference in New Issue
Block a user