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(task): make async subagent tasks answer honestly, once, in order, and stop by NamedIdentity · Pull Request #45482 · anomalyco/opencode

fix(task): make async subagent tasks answer honestly, once, in order, and stop #45482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
NamedIdentity wants to merge 89 commits into anomalyco:dev from NamedIdentity:task-lifecycle

Uh oh!

There was an error while loading. Please reload this page.

Closed

fix(task): make async subagent tasks answer honestly, once, in order, and stop #45482

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
0b85718
fix: cancel the background job that was observed, not whatever holds …
NamedIdentity Aug 19, 2026
e2ef533
feat(session): add branch closure and task attachment modules
NamedIdentity Aug 20, 2026
7b234b3
feat(session): wire branch closure into the session HTTP surface
NamedIdentity Aug 20, 2026
4bf5e5f
fix(background): grant jobs that supply no admission
NamedIdentity Aug 20, 2026
40627ff
feat(opencode): give task one explicit input for async execution
NamedIdentity Aug 20, 2026
29c3a53
feat(opencode): hold a subagent's answer until its async children settle
NamedIdentity Aug 20, 2026
b40e7ed
fix(opencode): target one exact run for task wait, promote and cancel
NamedIdentity Aug 20, 2026
8be4e8b
fix(opencode): interrupt a task exactly, without re-entering branch c…
NamedIdentity Aug 20, 2026
0c7a7d0
fix(opencode): report what a task child actually finished with
NamedIdentity Aug 20, 2026
d5b4e38
refactor(session): use a descriptive id for the task attachment parti…
NamedIdentity Aug 20, 2026
cf5d97d
feat(tui): say async where a task stops blocking its caller
NamedIdentity Aug 20, 2026
dd30ebb
feat(ui): render a branch closure record where work was stopped
NamedIdentity Aug 20, 2026
af846fd
feat(tui): settle stopped task branches and order undo behind a real …
NamedIdentity Aug 20, 2026
39cbbc6
fix(session): order undo and redo against branch cancellation
NamedIdentity Aug 20, 2026
2a156b0
fix(session): order destructive session changes against cancellation
NamedIdentity Aug 20, 2026
88ad6e3
fix(workspace): close a local prior owner before warping a session away
NamedIdentity Aug 20, 2026
efd3b87
fix(session): keep closure records intact through compaction and sett…
NamedIdentity Aug 20, 2026
d4eb702
fix(run): derive direct-run's Task body from the structured outcome
NamedIdentity Aug 20, 2026
b54ba7b
fix(session): require a reservation for event replay reaching the pro…
NamedIdentity Aug 20, 2026
998c36c
fix(session): stop permission and question replies from resuming a cl…
NamedIdentity Aug 20, 2026
0d847fb
fix(acp): abort a backing session before removing it, and skip closur…
NamedIdentity Aug 20, 2026
053d9cd
fix(session): reserve the branch-closure provenance key against calle…
NamedIdentity Aug 20, 2026
24ce5ed
test(session): cover task return classification, selection and rendering
NamedIdentity Aug 20, 2026
5d63182
test(lib): add closure, attachment and physical fixtures for the bran…
NamedIdentity Aug 20, 2026
f678987
test(session): cover attachment claim ownership and the task return gate
NamedIdentity Aug 20, 2026
80e5e91
test(session): cover exact job lifetimes and the bind-before-arm prot…
NamedIdentity Aug 20, 2026
460a970
test(run): cover task envelopes and closure records on the direct-run…
NamedIdentity Aug 20, 2026
1245422
fix(session): record the task edge coordinates a branch walk needs
NamedIdentity Aug 20, 2026
e788b88
test(session): cover the task edge coordinates end to end
NamedIdentity Aug 20, 2026
04135ba
test(session): state two bind-suite constraints directly
NamedIdentity Aug 20, 2026
766533e
test(session): cover branch-membership proof, discovery and the locat…
NamedIdentity Aug 20, 2026
e5a806a
test(session): cover mutation ordering, closure records, high-water a…
NamedIdentity Aug 20, 2026
c65251c
test(session): cover the attached async status observation
NamedIdentity Aug 20, 2026
b3cb808
test(session): cover abort completion and incomplete-stop repair
NamedIdentity Aug 20, 2026
e8da823
test(session): cover the fence-and-quiesce loop
NamedIdentity Aug 20, 2026
0fdbf21
chore: regenerate SDK and OpenAPI for the new session error types
NamedIdentity Aug 20, 2026
7f6f77f
feat(core): deliver background job answers per position, in conversat…
NamedIdentity Aug 23, 2026
1bf959f
feat(task): send a prompt to a running task, and deliver every answer
NamedIdentity Aug 23, 2026
f86ef18
chore(run): drop stale task_prior_output references
NamedIdentity Aug 23, 2026
a735f4b
test(task): drop absence guards naming a mechanism upstream never had
NamedIdentity Aug 23, 2026
c4d6c33
fix(tui): reach branch closure from Double-Escape, and report a faile…
NamedIdentity Aug 23, 2026
77e915e
fix(task): stop the async protocol promising a status line nothing emits
NamedIdentity Aug 24, 2026
60eb3e2
fix(provider): append message suffix after cache selection
NamedIdentity Aug 19, 2026
d8e944c
feat(session): split appended messages during conversion
NamedIdentity Aug 19, 2026
8e88905
fix(session): carry appended messages outside cache selection
NamedIdentity Aug 19, 2026
c709afb
test(session): cover appended-message cache boundaries
NamedIdentity Aug 19, 2026
d2da3a8
test(session): verify appended-message routing
NamedIdentity Aug 19, 2026
d5bb79d
fix(session): preserve max-step suffix shape
NamedIdentity Aug 19, 2026
95e096e
fix(session): preserve structured plugin messages
NamedIdentity Aug 19, 2026
daa3260
feat(session): emit the attached-async status line the protocol names
NamedIdentity Aug 24, 2026
9ee5a66
fix(task): release child attachment scope on lifetime end, not delivery
NamedIdentity Aug 24, 2026
aeb6699
refactor(core): remove the detection-time announce/floor mechanism
NamedIdentity Aug 24, 2026
ce8b3d3
fix(core): disposition a lifetime whose last reserved extension is re…
NamedIdentity Aug 24, 2026
148ba8e
task: restore async protocol text verbatim
NamedIdentity Aug 25, 2026
a78a57a
fix: restore lifecycle safety guards
NamedIdentity Aug 25, 2026
eb6d61b
test(session): restore closure model and wiring suites
NamedIdentity Aug 25, 2026
6bd3cc5
test(session): restore closure HTTP and task boundary suites
NamedIdentity Aug 25, 2026
e98556a
test(session): restore closure mutation authority corpus
NamedIdentity Aug 25, 2026
4df77b1
fix(server): restore substitutable HTTP session graph
NamedIdentity Aug 25, 2026
f17558e
fix(session): restore closure admission and metadata guards
NamedIdentity Aug 25, 2026
b86608c
fix(ui): restore closure-aware turn selection and timeline
NamedIdentity Aug 25, 2026
bc064e4
fix(tui): restore descendant attention and prompt sequencing
NamedIdentity Aug 25, 2026
c9d9f5d
test(tool): align the task wire-schema snapshot with the restored des…
NamedIdentity Aug 25, 2026
f8131f6
test: restore lifecycle acceptance coverage
NamedIdentity Aug 25, 2026
dfca98b
fix(provider): preserve cache breakpoint inputs
NamedIdentity Aug 25, 2026
a71434a
fix(ui): restore closure-aware selection guards
NamedIdentity Aug 25, 2026
cecbaac
docs(api): describe recursive session abort
NamedIdentity Aug 25, 2026
8094d33
fix(session): restore attachment scope boundaries
NamedIdentity Aug 27, 2026
d4dbd0e
session/attachment: gate supplemental borrow on scope resolution (CP-…
NamedIdentity Aug 31, 2026
1b03a15
session/attachment: refuse ownership only on a published resolution
NamedIdentity Aug 31, 2026
f3775e2
fix(core): preserve nonaccepted extension cause at the shared finalizer
NamedIdentity Aug 31, 2026
1815393
session/attachment: prove the scope-join refusal boundary end to end
NamedIdentity Aug 31, 2026
1cc44fa
feat(core): restore the answer-log delivery floor, keyed on sequence
NamedIdentity Aug 31, 2026
7d89206
test(session): layer the background flag on the R-08 supplement oracle
NamedIdentity Aug 31, 2026
109e77b
fix(task): gate answer filing on return eligibility and project termi…
NamedIdentity Aug 31, 2026
c36dd72
refactor(session): move return-eligibility off the public attachment …
NamedIdentity Aug 31, 2026
7ec8a78
fix(task): degrade the faulting attachment generation on scope mismatch
NamedIdentity Aug 31, 2026
2a0357c
feat(session): gate attachment results on Admission Freshness membership
NamedIdentity Sep 1, 2026
5a8dc67
session/attachment: freeze admission members at publication
NamedIdentity Sep 1, 2026
d9f700c
fix(task): preserve cancelled owner-scope terminal
NamedIdentity Sep 2, 2026
82597a4
test(task): prove selected evidence parity
NamedIdentity Sep 2, 2026
68b8091
fix(task): deliver truthful cancellation envelopes
NamedIdentity Sep 2, 2026
bac04f7
test(task): prove live sequence-floor ordering
NamedIdentity Sep 2, 2026
36a3a24
test(session): prove B-2 terminal winner composition
NamedIdentity Sep 2, 2026
ed2cf5e
test(task): close R-08 and wake evidence
NamedIdentity Sep 2, 2026
731c26b
session: add FIFO reply-required Runner generations
NamedIdentity Sep 4, 2026
b2f1ee1
session: route reply-required prompts through FIFO Runner
NamedIdentity Sep 4, 2026
26847ff
test(session): prove FIFO release-gate scheduling
NamedIdentity Sep 4, 2026
ca47439
test(session): verify dev prompt FIFO wiring
NamedIdentity Sep 4, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Prev Previous commit
Next Next commit
fix(session): stop permission and question replies from resuming a cl…
…osed branch

Replying to a permission prompt or answering a question resolves the
deferred that a blocked tool is waiting on. Nothing stopped that
happening after the tool's branch had been cancelled, so a reply arriving
just after a stop restarted the work the stop had ended.

Both now pass through admission, checked before the deferred resolves.
Permission takes one admission for the whole resolved set: its two
cascade loops filter on the replying session, so a single reply can never
resolve another session's deferred, and per-continuation admissions would
let a partial settle strand a resumed tool unaccounted for. Question
resolves exactly one deferred, so one admission covers it by
construction.

Both polarities are admitted, on evidence rather than symmetry. A
rejection reaches the processor's tool-call failure path, which writes
the part to error - a durable transcript mutation - and only then breaks
conditionally, so it is a continuation rather than a proven termination.

None of them retries after release. Waiting for closure and then running
the body is precisely resuming a blocked tool inside a branch that has
just closed, which is what the guard exists to prevent. The joined
admission is still settled.

Unknown-request replies are unchanged and answer NotFound as before,
deliberately ahead of admission.

A refusal is reported as a conflict rather than raised as a defect. These
are interactive routes, so the refusal is the expected result of the
user's own concurrent stop; a 500 would report a server fault that did
not occur.
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@NamedIdentity
NamedIdentity committed Aug 23, 2026
commit 998c36c233d6b2dfbd386aaeeddf6120f1ae10f4

There are no files selected for viewing

43 changes: 41 additions & 2 deletions 43 packages/opencode/src/permission/index.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ import { Deferred, Effect, Layer, Context } from "effect"
import os from "os"
import { PermissionV1 } from "@opencode-ai/core/v1/permission"
import { EventV2Bridge } from "@/event-v2-bridge"
import { SessionClosure } from "@/session/closure/coordinator"
import { SessionAdmission } from "@/session/closure/admission"

export const Event = PermissionV1.Event

export interface Interface {
readonly ask: (input: PermissionV1.AskInput) => Effect.Effect<void, PermissionV1.Error>
readonly reply: (input: PermissionV1.ReplyInput) => Effect.Effect<void, PermissionV1.NotFoundError>
readonly reply: (
input: PermissionV1.ReplyInput,
) => Effect.Effect<void, PermissionV1.NotFoundError | SessionClosure.AdmissionRefused>
readonly list: () => Effect.Effect<ReadonlyArray<PermissionV1.Request>>
}

Expand Down Expand Up @@ -43,6 +47,7 @@ const layer = Layer.effect(
Service,
Effect.gen(function* () {
const events = yield* EventV2Bridge.Service
const closure = yield* SessionClosure.Service
const state = yield* InstanceState.make<State>(
Effect.fn("Permission.state")(function* (ctx) {
void ctx
Expand Down Expand Up @@ -109,8 +114,38 @@ const layer = Layer.effect(
const reply = Effect.fn("Permission.reply")(function* (input: PermissionV1.ReplyInput) {
const { approved, pending } = yield* InstanceState.get(state)
const existing = pending.get(input.requestID)
// Unknown-request behaviour is unchanged and deliberately sits ahead of admission, so a reply
// naming an unknown request on a closing session still answers NotFound rather than a refusal.
if (!existing) return yield* new PermissionV1.NotFoundError({ requestID: input.requestID })

// A reply resolves deferreds that resume blocked tools, so it is admission-controlled: once a
// branch has closed, resuming its tools would restart the work that was just stopped.
//
// One admission covers the whole resolved set. Both cascade loops below filter on this
// session, so a single reply can never resolve a deferred belonging to another one; per-
// continuation admissions would let a partial settle strand a resumed tool unaccounted for.
//
// Both polarities are admitted, because neither is proven terminal. A rejection reaches the
// processor's tool-call failure path, which writes the part to error — a durable mutation —
// and then breaks only conditionally; a correction carries model-visible feedback and does
// not take that branch at all.
//
// `retryable: false` is the point rather than an omission. Waiting for closure and then
// retrying is exactly resuming a blocked tool inside a branch that has just closed. Refusing
// is the answer; the joined admission is still settled.
return yield* SessionAdmission.admitted(
closure,
{ session: existing.info.sessionID, origin: "external", source: "Permission.reply", retryable: false },
() => replyAdmitted(input, existing, approved, pending),
)
})

const replyAdmitted = Effect.fn("Permission.replyAdmitted")(function* (
input: PermissionV1.ReplyInput,
existing: PendingEntry,
approved: PermissionV1.Rule[],
pending: Map<PermissionV1.ID, PendingEntry>,
) {
pending.delete(input.requestID)
yield* events.publish(Event.Replied, {
sessionID: existing.info.sessionID,
Expand Down Expand Up @@ -218,6 +253,10 @@ export function visibleTools<T>(tools: Record<string, T>, ruleset: PermissionV1.
return Object.fromEntries(Object.entries(tools).filter(([name]) => !hidden.has(name)))
}

export const node = LayerNode.make({ service: Service, layer: layer, deps: [EventV2Bridge.node] })
export const node = LayerNode.make({
service: Service,
layer: layer,
deps: [EventV2Bridge.node, SessionClosure.node],
})

export * as Permission from "."
70 changes: 52 additions & 18 deletions 70 packages/opencode/src/question/index.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { SessionID } from "@/session/schema"
import { QuestionID } from "./schema"
import { EventV2Bridge } from "@/event-v2-bridge"
import { QuestionV1 } from "@opencode-ai/schema/question-v1"
import { SessionClosure } from "@/session/closure/coordinator"
import { SessionAdmission } from "@/session/closure/admission"

export const Option = QuestionV1.Option
export type Option = typeof Option.Type
Expand Down Expand Up @@ -54,8 +56,8 @@ export interface Interface {
readonly reply: (input: {
requestID: QuestionID
answers: ReadonlyArray<Answer>
}) => Effect.Effect<void, NotFoundError>
readonly reject: (requestID: QuestionID) => Effect.Effect<void, NotFoundError>
}) => Effect.Effect<void, NotFoundError | SessionClosure.AdmissionRefused>
readonly reject: (requestID: QuestionID) => Effect.Effect<void, NotFoundError | SessionClosure.AdmissionRefused>
readonly list: () => Effect.Effect<ReadonlyArray<Request>>
}

Expand All @@ -65,6 +67,7 @@ const layer = Layer.effect(
Service,
Effect.gen(function* () {
const events = yield* EventV2Bridge.Service
const closure = yield* SessionClosure.Service
const state = yield* InstanceState.make<State>(
Effect.fn("Question.state")(function* () {
const state = {
Expand Down Expand Up @@ -121,14 +124,29 @@ const layer = Layer.effect(
yield* Effect.logWarning("reply for unknown request", { requestID: input.requestID })
return yield* new NotFoundError({ requestID: input.requestID })
}
pending.delete(input.requestID)
yield* Effect.logInfo("replied", { requestID: input.requestID, answers: input.answers })
yield* events.publish(Event.Replied, {
sessionID: existing.info.sessionID,
requestID: existing.info.id,
answers: input.answers.map((a) => [...a]),
})
yield* Deferred.succeed(existing.deferred, input.answers)
// An answer resumes the suspended tool that asked, so the guard has to run before the
// deferred resolves: after a branch closes, resuming its tool restarts the work that was
// just stopped. There is no cascade here — exactly one deferred is resolved — so one
// admission covers the whole resolved set by construction.
//
// `retryable: false` is what keeps that decided. Waiting for release and then running this
// body is precisely resuming the suspended tool after the branch closed. The joined
// admission is still settled.
return yield* SessionAdmission.admitted(
closure,
{ session: existing.info.sessionID, origin: "external", source: "Question.reply", retryable: false },
() =>
Effect.gen(function* () {
pending.delete(input.requestID)
yield* Effect.logInfo("replied", { requestID: input.requestID, answers: input.answers })
yield* events.publish(Event.Replied, {
sessionID: existing.info.sessionID,
requestID: existing.info.id,
answers: input.answers.map((a) => [...a]),
})
yield* Deferred.succeed(existing.deferred, input.answers)
}),
)
})

const reject = Effect.fn("Question.reject")(function* (requestID: QuestionID) {
Expand All @@ -138,13 +156,25 @@ const layer = Layer.effect(
yield* Effect.logWarning("reject for unknown request", { requestID })
return yield* new NotFoundError({ requestID })
}
pending.delete(requestID)
yield* Effect.logInfo("rejected", { requestID })
yield* events.publish(Event.Rejected, {
sessionID: existing.info.sessionID,
requestID: existing.info.id,
})
yield* Deferred.fail(existing.deferred, new RejectedError())
// Admitted for the same reason the answer is, and the reason is evidence rather than
// symmetry: a rejection reaches the processor's tool-call failure path, which writes the
// part to error — a durable transcript mutation — and only then breaks conditionally. So
// this is a continuation, not a proven termination, and retrying it after release would
// drive that mutation into a branch that has just closed.
return yield* SessionAdmission.admitted(
closure,
{ session: existing.info.sessionID, origin: "external", source: "Question.reject", retryable: false },
() =>
Effect.gen(function* () {
pending.delete(requestID)
yield* Effect.logInfo("rejected", { requestID })
yield* events.publish(Event.Rejected, {
sessionID: existing.info.sessionID,
requestID: existing.info.id,
})
yield* Deferred.fail(existing.deferred, new RejectedError())
}),
)
})

const list = Effect.fn("Question.list")(function* () {
Expand All @@ -156,6 +186,10 @@ const layer = Layer.effect(
}),
)

export const node = LayerNode.make({ service: Service, layer: layer, deps: [EventV2Bridge.node] })
export const node = LayerNode.make({
service: Service,
layer: layer,
deps: [EventV2Bridge.node, SessionClosure.node],
})

export * as Question from "."
4 changes: 2 additions & 2 deletions 4 packages/opencode/src/server/routes/instance/httpapi/groups/permission.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { PermissionV1 } from "@opencode-ai/core/v1/permission"
import { Permission } from "@/permission"
import { Schema } from "effect"
import { HttpApi, HttpApiEndpoint, HttpApiError, HttpApiGroup, OpenApi } from "effect/unstable/httpapi"
import { PermissionNotFoundError } from "../errors"
import { PermissionNotFoundError, SessionBusyError } from "../errors"
import { Authorization } from "../middleware/authorization"
import { InstanceContextMiddleware } from "../middleware/instance-context"
import { WorkspaceRoutingMiddleware, WorkspaceRoutingQuery } from "../middleware/workspace-routing"
Expand Down Expand Up @@ -33,7 +33,7 @@ export const PermissionApi = HttpApi.make("permission")
query: WorkspaceRoutingQuery,
payload: ReplyPayload,
success: described(Schema.Boolean, "Permission processed successfully"),
error: [HttpApiError.BadRequest, PermissionNotFoundError],
error: [HttpApiError.BadRequest, PermissionNotFoundError, SessionBusyError],
}).annotateMerge(
OpenApi.annotations({
identifier: "permission.reply",
Expand Down
6 changes: 3 additions & 3 deletions 6 packages/opencode/src/server/routes/instance/httpapi/groups/question.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Question } from "@/question"
import { QuestionID } from "@/question/schema"
import { Schema } from "effect"
import { HttpApi, HttpApiEndpoint, HttpApiError, HttpApiGroup, OpenApi } from "effect/unstable/httpapi"
import { QuestionNotFoundError } from "../errors"
import { QuestionNotFoundError, SessionBusyError } from "../errors"
import { Authorization } from "../middleware/authorization"
import { InstanceContextMiddleware } from "../middleware/instance-context"
import { WorkspaceRoutingMiddleware, WorkspaceRoutingQuery } from "../middleware/workspace-routing"
Expand Down Expand Up @@ -34,7 +34,7 @@ export const QuestionApi = HttpApi.make("question")
query: WorkspaceRoutingQuery,
payload: ReplyPayload,
success: described(Schema.Boolean, "Question answered successfully"),
error: [HttpApiError.BadRequest, QuestionNotFoundError],
error: [HttpApiError.BadRequest, QuestionNotFoundError, SessionBusyError],
}).annotateMerge(
OpenApi.annotations({
identifier: "question.reply",
Expand All @@ -46,7 +46,7 @@ export const QuestionApi = HttpApi.make("question")
params: { requestID: QuestionID },
query: WorkspaceRoutingQuery,
success: described(Schema.Boolean, "Question rejected successfully"),
error: [HttpApiError.BadRequest, QuestionNotFoundError],
error: [HttpApiError.BadRequest, QuestionNotFoundError, SessionBusyError],
}).annotateMerge(
OpenApi.annotations({
identifier: "question.reject",
Expand Down
2 changes: 1 addition & 1 deletion 2 packages/opencode/src/server/routes/instance/httpapi/groups/session.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ export const SessionApi = HttpApi.make("session")
query: WorkspaceRoutingQuery,
payload: PermissionResponsePayload,
success: described(Schema.Boolean, "Permission processed successfully"),
error: [HttpApiError.BadRequest, ApiNotFoundError, PermissionNotFoundError],
error: [HttpApiError.BadRequest, ApiNotFoundError, PermissionNotFoundError, SessionBusyError],
}).annotateMerge(
OpenApi.annotations({
identifier: "permission.respond",
Expand Down
34 changes: 20 additions & 14 deletions 34 packages/opencode/src/server/routes/instance/httpapi/handlers/permission.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Effect } from "effect"
import { HttpApiBuilder } from "effect/unstable/httpapi"
import { InstanceHttpApi } from "../api"
import { PermissionNotFoundError } from "../errors"
import * as SessionError from "./session-errors"

export const permissionHandlers = HttpApiBuilder.group(InstanceHttpApi, "permission", (handlers) =>
Effect.gen(function* () {
Expand All @@ -17,22 +18,27 @@ export const permissionHandlers = HttpApiBuilder.group(InstanceHttpApi, "permiss
params: { requestID: PermissionV1.ID }
payload: PermissionV1.ReplyBody
}) {
yield* svc
.reply({
requestID: ctx.params.requestID,
reply: ctx.payload.reply,
message: ctx.payload.message,
})
.pipe(
Effect.catchTag("Permission.NotFoundError", (error) =>
Effect.fail(
new PermissionNotFoundError({
requestID: String(error.requestID),
message: `Permission request not found: ${error.requestID}`,
}),
// A reply arriving while the session's branch is being cancelled is refused. That is an
// expected, recoverable outcome of the user's own concurrent stop, so it is reported as a
// conflict rather than raised as a server defect.
yield* SessionError.mapAdmission(
svc
.reply({
requestID: ctx.params.requestID,
reply: ctx.payload.reply,
message: ctx.payload.message,
})
.pipe(
Effect.catchTag("Permission.NotFoundError", (error) =>
Effect.fail(
new PermissionNotFoundError({
requestID: String(error.requestID),
message: `Permission request not found: ${error.requestID}`,
}),
),
),
),
)
)
return true
})

Expand Down
45 changes: 26 additions & 19 deletions 45 packages/opencode/src/server/routes/instance/httpapi/handlers/question.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Effect } from "effect"
import { HttpApiBuilder } from "effect/unstable/httpapi"
import { InstanceHttpApi } from "../api"
import { QuestionNotFoundError } from "../errors"
import * as SessionError from "./session-errors"

export const questionHandlers = HttpApiBuilder.group(InstanceHttpApi, "question", (handlers) =>
Effect.gen(function* () {
Expand All @@ -17,12 +18,31 @@ export const questionHandlers = HttpApiBuilder.group(InstanceHttpApi, "question"
params: { requestID: QuestionID }
payload: Question.Reply
}) {
yield* svc
.reply({
requestID: ctx.params.requestID,
answers: ctx.payload.answers,
})
.pipe(
// Refused while the session's branch is being cancelled — an expected outcome of the user's
// own concurrent stop, reported as a conflict rather than a server defect.
yield* SessionError.mapAdmission(
svc
.reply({
requestID: ctx.params.requestID,
answers: ctx.payload.answers,
})
.pipe(
Effect.catchTag("Question.NotFoundError", (error) =>
Effect.fail(
new QuestionNotFoundError({
requestID: String(error.requestID),
message: `Question request not found: ${error.requestID}`,
}),
),
),
),
)
return true
})

const reject = Effect.fn("QuestionHttpApi.reject")(function* (ctx: { params: { requestID: QuestionID } }) {
yield* SessionError.mapAdmission(
svc.reject(ctx.params.requestID).pipe(
Effect.catchTag("Question.NotFoundError", (error) =>
Effect.fail(
new QuestionNotFoundError({
Expand All @@ -31,19 +51,6 @@ export const questionHandlers = HttpApiBuilder.group(InstanceHttpApi, "question"
}),
),
),
)
return true
})

const reject = Effect.fn("QuestionHttpApi.reject")(function* (ctx: { params: { requestID: QuestionID } }) {
yield* svc.reject(ctx.params.requestID).pipe(
Effect.catchTag("Question.NotFoundError", (error) =>
Effect.fail(
new QuestionNotFoundError({
requestID: String(error.requestID),
message: `Question request not found: ${error.requestID}`,
}),
),
),
)
return true
Expand Down
18 changes: 11 additions & 7 deletions 18 packages/opencode/src/server/routes/instance/httpapi/handlers/session.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -387,13 +387,17 @@ export const sessionHandlers = HttpApiBuilder.group(InstanceHttpApi, "session",
payload: typeof PermissionResponsePayload.Type
}) {
yield* requireSession(ctx.params.sessionID)
yield* permissionSvc.reply({ requestID: ctx.params.permissionID, reply: ctx.payload.response }).pipe(
Effect.catchTag("Permission.NotFoundError", (error) =>
Effect.fail(
new PermissionNotFoundError({
requestID: String(error.requestID),
message: `Permission request not found: ${error.requestID}`,
}),
// The session-scoped compatibility route converges on the same `Permission.reply` as the
// root one, so the guard inside the service covers both and no second authority exists here.
yield* SessionError.mapAdmission(
permissionSvc.reply({ requestID: ctx.params.permissionID, reply: ctx.payload.response }).pipe(
Effect.catchTag("Permission.NotFoundError", (error) =>
Effect.fail(
new PermissionNotFoundError({
requestID: String(error.requestID),
message: `Permission request not found: ${error.requestID}`,
}),
),
),
),
)
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
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.