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): reserve the branch-closure provenance key against calle…
…r bytes

A branch-closure record is the durable account of what a cancellation
stopped, and readers trust it: revert refuses it as a boundary, cleanup
preserves it, compaction skips it as a turn, and the UI renders it as a
system notice. Nothing stopped a caller writing that key itself. A
payload carrying it was trusted as a genuine record, so a forged one
could make a message permanently un-revertible and un-prunable.

The key is now reserved wherever caller-owned part bytes enter. The value
is deliberately not inspected: a malformed claim and a well-formed
forgery get the same refusal, which keeps this a provenance gate rather
than a second, divergent copy of the classifier.

Three seams, which is all of them. Part replacement refuses it, ahead of
its reservation, because a payload claiming reserved provenance is
malformed whatever the branch is doing. Prompt checks the resolved parts
once, after the plugin hook has had its opportunity to mutate them and
before the message or any part is persisted, so an offending part cannot
leave a half-written message. Import decodes and checks the whole file
before the first write, so an offending part late in it cannot leave a
partial import.

The guard is on replacePart and not on updatePart. updatePart is the
writer a live execution uses for parts it is producing, called once per
streamed token; a check there would run thousands of times a turn against
a condition only a caller payload can create, and would widen an error
channel across all 38 of its call sites. Splitting replacePart out
earlier is what makes this placement available.

Each seam reports rather than crashes: 400 on the part and prompt routes,
which already declare it, and a CLI failure naming the offending part.

Residual, stated plainly: this is fail-closed by placement, not by
construction. A future internal writer that takes caller bytes and calls
updatePart directly would bypass it. The exposure is narrow because only
a synthetic text part, alone in its message and bound to that message's
own session, can classify at all.
  • Loading branch information

Uh oh!

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

@NamedIdentity
NamedIdentity committed Aug 23, 2026
commit 053d9cd8304876602f300bcec67925ecafdca1d0

There are no files selected for viewing

32 changes: 27 additions & 5 deletions 32 packages/opencode/src/cli/cmd/import.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,17 @@ export const ImportCommand = effectCmd({
handler: Effect.fn("Cli.import")(function* (args) {
const ctx = yield* InstanceRef
if (!ctx) return yield* Effect.die("InstanceRef not provided")
return yield* runImport(args.file, ctx)
// A visible CLI failure naming the offending part, rather than a defect: the file is the
// user's, and this tells them which part to fix.
return yield* runImport(args.file, ctx).pipe(
Effect.catchTag(
"SessionReservedMetadataError",
(error) =>
new CliError({
message: `Cannot import reserved metadata key "${error.key}" on part ${error.partID}`,
}),
),
)
}),
})

Expand Down Expand Up @@ -176,6 +186,19 @@ const runImport = Effect.fn("Cli.import.body")(function* (file: string, ctx: Ins
return
}

// An imported file is caller input, not authenticated replication, so it is decoded and checked
// in full before the first write. Checking as we go would let an offending part late in the file
// leave a partial import behind.
const messages = exportData.messages.map((msg) => ({
info: decodeMessageInfo(msg.info) as SessionV1.Info,
parts: msg.parts.map((part) => decodePart(part) as SessionV1.Part),
}))
yield* Effect.forEach(
messages.flatMap((msg) => msg.parts),
Session.rejectReservedPartMetadata,
{ discard: true },
)

const info = Schema.decodeUnknownSync(Session.Info)({
...exportData.info,
projectID: ctx.project.id,
Expand All @@ -193,8 +216,8 @@ const runImport = Effect.fn("Cli.import.body")(function* (file: string, ctx: Ins
.run()
.pipe(Effect.orDie)

for (const msg of exportData.messages) {
const msgInfo = decodeMessageInfo(msg.info) as SessionV1.Info
for (const msg of messages) {
const msgInfo = msg.info
const { id, sessionID: _, ...msgData } = msgInfo
yield* db
.insert(MessageTable)
Expand All @@ -208,8 +231,7 @@ const runImport = Effect.fn("Cli.import.body")(function* (file: string, ctx: Ins
.run()
.pipe(Effect.orDie)

for (const part of msg.parts) {
const partInfo = decodePart(part) as SessionV1.Part
for (const partInfo of msg.parts) {
const { id: partId, sessionID: _s, messageID, ...partData } = partInfo
yield* db
.insert(PartTable)
Expand Down
7 changes: 6 additions & 1 deletion 7 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 @@ -437,7 +437,12 @@ export const sessionHandlers = HttpApiBuilder.group(InstanceHttpApi, "session",
// The coordinate validation stays ahead of the call: it is a read-only precondition, so
// deciding it first keeps the existing 400 for a malformed request rather than turning it
// into a refusal.
return yield* SessionError.mapAdmission(session.replacePart(payload))
//
// A payload claiming the reserved branch-closure key is malformed in the same way, so it
// answers 400 like the coordinate check above rather than adding an error to this endpoint.
return yield* SessionError.mapAdmission(session.replacePart(payload)).pipe(
Effect.catchTag("SessionReservedMetadataError", () => new HttpApiError.BadRequest({})),
)
})

return handlers
Expand Down
22 changes: 19 additions & 3 deletions 22 packages/opencode/src/session/prompt.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,18 @@ type AdmissionError = SessionClosure.AdmissionRefused | SessionMutation.Mutation

export interface Interface {
readonly cancel: (sessionID: SessionID) => Effect.Effect<void>
readonly prompt: (input: PromptInput) => Effect.Effect<SessionV1.WithParts, Image.Error | AdmissionError>
// `ReservedMetadataError` rides on the two entry points that persist parts someone outside this
// service supplied: `prompt` takes them from its caller, and `command` resolves them from a
// template and then hands them to the `command.execute.before` plugin hook, which can mutate
// them before they are written. `loop` and `shell` build their own and cannot raise it.
readonly prompt: (
input: PromptInput,
) => Effect.Effect<SessionV1.WithParts, Image.Error | AdmissionError | Session.ReservedMetadataError>
readonly loop: (input: LoopInput) => Effect.Effect<SessionV1.WithParts, AdmissionError>
readonly shell: (input: ShellInput) => Effect.Effect<SessionV1.WithParts, Session.BusyError | AdmissionError>
readonly command: (input: CommandInput) => Effect.Effect<SessionV1.WithParts, Image.Error | AdmissionError>
readonly command: (
input: CommandInput,
) => Effect.Effect<SessionV1.WithParts, Image.Error | AdmissionError | Session.ReservedMetadataError>
readonly resolvePromptParts: (template: string) => Effect.Effect<PromptInput["parts"]>
}

Expand Down Expand Up @@ -1111,13 +1119,21 @@ const layer = Layer.effect(
})
}

// The plugin hook above has already had its opportunity to mutate these parts, so one
// preflight here covers both direct prompt input and plugin-supplied metadata. It runs before
// the message or any part is persisted, so a payload claiming reserved closure provenance
// cannot leave a half-written message behind.
yield* Effect.forEach(parts, Session.rejectReservedPartMetadata, { discard: true })

yield* sessions.updateMessage(info)
for (const part of parts) yield* sessions.updatePart(part)

return { info, parts }
}, Effect.scoped)

const prompt: (input: TaskPromptInput) => Effect.Effect<SessionV1.WithParts, Image.Error | AdmissionError> =
const prompt: (
input: TaskPromptInput,
) => Effect.Effect<SessionV1.WithParts, Image.Error | AdmissionError | Session.ReservedMetadataError> =
Effect.fn("SessionPrompt.prompt")(function* (input: TaskPromptInput) {
// An attachment scope is a private capability handed to one delegated call, never resolved
// from a registry here. Generic ingress is unaffected: only a caller that was given a scope
Expand Down
51 changes: 48 additions & 3 deletions 51 packages/opencode/src/session/session.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Database } from "@opencode-ai/core/database/database"
import { EventV2Bridge } from "@/event-v2-bridge"
import { SessionClosure } from "./closure/coordinator"
import { SessionMutation } from "./closure/mutation"
import { CLOSURE_RECORD_METADATA_KEY } from "@opencode-ai/core/session/closure-record"
import { SessionV2 } from "@opencode-ai/core/session"
import * as SessionExecutionLocal from "@opencode-ai/core/session/execution/local"
import { locationServiceMapLayer } from "@opencode-ai/core/location-services"
Expand Down Expand Up @@ -425,6 +426,38 @@ export class BoundaryError extends Schema.TaggedErrorClass<BoundaryError>()("Ses
partID: Schema.optional(PartID),
}) {}

export class ReservedMetadataError extends Schema.TaggedErrorClass<ReservedMetadataError>()(
"SessionReservedMetadataError",
{
key: Schema.Literal(CLOSURE_RECORD_METADATA_KEY),
sessionID: SessionID,
messageID: MessageID,
partID: PartID,
},
) {}

/**
* Reject caller-owned part bytes that claim the branch-closure provenance key.
*
* Closure records are the durable account of what a cancellation stopped, and their meaning depends
* on nobody else being able to write one. The key is reserved rather than the value validated: a
* malformed claim and a well-formed forgery get the same refusal, which keeps this a provenance
* gate and not a second, divergent copy of the classifier.
*/
export function rejectReservedPartMetadata(part: SessionV1.Part): Effect.Effect<void, ReservedMetadataError> {
const metadata = "metadata" in part ? part.metadata : undefined
if (typeof metadata !== "object" || metadata === null || !Object.hasOwn(metadata, CLOSURE_RECORD_METADATA_KEY))
return Effect.void
return Effect.fail(
new ReservedMetadataError({
key: CLOSURE_RECORD_METADATA_KEY,
sessionID: part.sessionID,
messageID: part.messageID,
partID: part.id,
}),
)
}

export type NotFound = NotFoundError

export interface Interface {
Expand Down Expand Up @@ -483,7 +516,7 @@ export interface Interface {
readonly updatePart: <T extends SessionV1.Part>(part: T) => Effect.Effect<T>
readonly replacePart: <T extends SessionV1.Part>(
part: T,
) => Effect.Effect<T, SessionMutation.MutationRefused>
) => Effect.Effect<T, SessionMutation.MutationRefused | ReservedMetadataError>
readonly updatePartDelta: (input: {
sessionID: SessionID
messageID: MessageID
Expand Down Expand Up @@ -725,9 +758,21 @@ const layer: Layer.Layer<
* remember to take one. Now the method that names the operation carries it.
*
* This does not make `updatePart` safe to call blind, and it stays unreserved by design.
*
* It is also where the reserved closure key is refused, for the same reason the reservation is
* here. This is the seam caller-supplied part bytes arrive through; `updatePart` is the writer a
* live execution uses for parts it is producing, called once per streamed token, and a guard
* there would run thousands of times a turn against a condition only a caller payload can
* create. The check runs ahead of the reservation because a payload claiming reserved
* provenance is malformed whatever the branch is doing.
*/
const replacePart = <T extends SessionV1.Part>(part: T): Effect.Effect<T, SessionMutation.MutationRefused> =>
SessionMutation.leased(closure, { sessions: [part.sessionID], kind: "replace_part" }, updatePart(part)).pipe(
const replacePart = <T extends SessionV1.Part>(
part: T,
): Effect.Effect<T, SessionMutation.MutationRefused | ReservedMetadataError> =>
rejectReservedPartMetadata(part).pipe(
Effect.andThen(
SessionMutation.leased(closure, { sessions: [part.sessionID], kind: "replace_part" }, updatePart(part)),
),
Effect.withSpan("Session.replacePart"),
)

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.