GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(plugin): preserve completed errors on late abort (#66102) · yusha/opencode@71324e2

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages
    • core/test/plugin
      • automation.test.ts
    • plugin/src/promise
      • adapter.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/core/test/plugin/automation.test.ts‎

Copy file name to clipboardExpand all lines: packages/core/test/plugin/automation.test.ts
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,20 @@ it.live("Promise plugin calls aborted mid-call reject with the signal's reason",
341341
expect((reasons[0] as DOMException).name).toBe("AbortError")
342342
}),
343343
)
344+
345+
it.live("a late abort preserves a completed Promise plugin call's error", () =>
346+
Effect.gen(function* () {
347+
const plugins = yield* Plugin.Service
348+
const context = yield* PluginHost.make(plugins, "test")
349+
350+
yield* PluginPromise.fromPromise({
351+
id: "test.late-abort",
352+
async setup(ctx) {
353+
const controller = new AbortController()
354+
const agent = ctx.agent.get({ agentID: "missing" }, { signal: controller.signal })
355+
controller.abort(new Error("late abort"))
356+
await expect(agent).rejects.toThrow("Agent not found: missing")
357+
},
358+
}).effect(context)
359+
}),
360+
)
Collapse file

‎packages/plugin/src/promise/adapter.ts‎

Copy file name to clipboardExpand all lines: packages/plugin/src/promise/adapter.ts
+17-6Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Tool } from "@opencode/schema/tool"
22
import type { Rpc } from "@opencode/schema/rpc"
33
import type { OpenCodeEvent } from "@opencode/client"
44
import type { RpcCallOptions, RpcEventPayload, SelectedEvent, SubscribeOptions } from "@opencode/client/promise/api"
5-
import { Effect, Schema, SchemaAST, Stream } from "effect"
5+
import { Cause, Effect, Exit, Schema, SchemaAST, Stream } from "effect"
66
import type { Scope } from "effect"
77
import { HttpApiEndpoint, HttpApiSchema } from "effect/http-api"
88
import { define } from "../effect/plugin.js"
@@ -302,9 +302,10 @@ export function fromPromise(plugin: Plugin) {
302302
) => {
303303
const compiled = compileEndpoint(endpoint)
304304
return ((input?: unknown, options?: { readonly signal?: AbortSignal }) => {
305+
const signal = options?.signal
305306
// The runner evaluates synchronously before it checks the signal, so an aborted call could start a mutation.
306-
if (options?.signal?.aborted) return Promise.reject(options.signal.reason)
307-
return Effect.runPromiseWith(runtime)(
307+
if (signal?.aborted) return Promise.reject(signal.reason)
308+
return Effect.runPromiseExitWith(runtime)(
308309
Effect.gen(function* () {
309310
// Match the generated Promise client, whose request body crosses JSON before endpoint decoding.
310311
const normalized = yield* Schema.encodeUnknownEffect(JsonInput)(input ?? {}).pipe(
@@ -315,9 +316,19 @@ export function fromPromise(plugin: Plugin) {
315316
if (compiled.noContent) return undefined
316317
return yield* compiled.encode(result)
317318
}),
318-
{ signal: options?.signal },
319-
// An abort mid-call interrupts the fiber; reject with the signal's reason, as fetch does.
320-
).catch((error) => Promise.reject(options?.signal?.aborted ? options.signal.reason : error))
319+
{ signal },
320+
).then((exit) => {
321+
if (Exit.isSuccess(exit)) return exit.value
322+
// Effect records AbortSignal interruptions without an interrupting fiber ID.
323+
if (
324+
signal?.aborted &&
325+
Cause.hasInterruptsOnly(exit.cause) &&
326+
exit.cause.reasons.some((reason) => Cause.isInterruptReason(reason) && reason.fiberId === undefined)
327+
) {
328+
throw signal.reason
329+
}
330+
throw Cause.squash(exit.cause)
331+
})
321332
}) as PromiseMethod
322333
}
323334

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.