Skip to content

Commit d69236d

Browse files
feat(core): add V2-native unqueue/edit of pending session inputs
New SessionV2.pending/withdraw/revise methods let a caller remove or edit a message that's been durably admitted but not yet promoted into a visible turn -- plus three new HTTP routes and a TUI /queue dialog. Ported from upstream anomalyco#4821 (126 reactions): PR anomalyco#6415 "Easy Message Unqueue with /unqueue" (closed by a 60-day-stale bot, never reviewed) and PR anomalyco#6271 "add edit and discard actions for queued messages" (more thorough, self-closed after apparent lack of maintainer response). Both PRs remove a queued message from an in-memory callback list and delete the V1 message -- a backend model with no equivalent in this repo's V2 session core, where a queued message is a durable row that stays pending until a safe promotion point. So the backend here is a fresh, V2-native design, not a port: a durable event (session.next.prompt.withdrawn / .revised) is published and projected the same way SessionInput.Prompted already works, guarded to only affect rows that are neither promoted nor withdrawn, with a withdraw winning any race against an in-flight promotion. What was reused: the remove/edit concepts themselves, /unqueue kept as a command alias (anomalyco#6415), and the general shape of a queued-message picker UI (anomalyco#6271) -- reworked as a /queue list dialog rather than anomalyco#6271's inline "EDITING" mode in the main prompt box. New requireInput flag threads through the turn loop in packages/core/src/session/runner/llm.ts so a turn whose only justification was a withdrawn input is skipped rather than run with nothing to answer -- merged by hand against this fork's own model-fallback feature, which had already added a different parameter (tried) to the exact same functions. KNOWN, SIGNIFICANT GAP: the TUI still sends every prompt through the legacy V1 SessionPrompt path, which never creates the V2 session_input rows this feature acts on. /queue will show an empty list for anything typed in the actual running TUI today. Switching the TUI to send V2 prompts is a materially bigger decision than this feature's own scope and was deliberately left for a separate follow-up rather than silently expanded into. The backend is fully real, tested, and reachable via the HTTP API directly today. New tests: packages/core/test/session-prompt.test.ts (+10 cases), session-runner.test.ts (+4), packages/tui/test/cli/tui/data.test.tsx (+2), three new httpapi-exercise scenarios, event-manifest count updated (88 -> 90 for the two new durable events). Client and legacy JS SDKs regenerated. Verified against this fork's current dev, including the manual merge against model-fallback: bun typecheck clean across all 30 packages; packages/core 1178 pass (only the pre-existing pty flake); packages/opencode 3613 pass, only the 4 pre-existing cf-ai-gateway failures; packages/tui 230 pass; httpapi-exercise coverage mode 214 pass. Co-Authored-By: Claude Sonnet 5 <[email protected]>
1 parent 990038a commit d69236d

30 files changed

Lines changed: 1798 additions & 78 deletions

File tree

‎FORK_CHANGES.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ Each entry names the upstream gap it addresses, whether it originated as our own
66

77
## Implemented
88

9+
### Unqueue / edit queued messages (V2 backend)
10+
11+
A durable, V2-native way to remove or edit a message that's been admitted but not yet promoted into a visible turn — new `SessionV2.pending`/`withdraw`/`revise` methods, three new HTTP routes, and a TUI `/queue` dialog. **Not yet reachable from the real TUI** — see known gaps.
12+
13+
- **Upstream gap:** [anomalyco/opencode#4821](https://github.com/anomalyco/opencode/issues/4821) — 126 reactions. [PR #6415](https://github.com/anomalyco/opencode/pull/6415) "Easy Message Unqueue with /unqueue" (9 files) was closed by a 60-day-stale bot, never reviewed. [PR #6271](https://github.com/anomalyco/opencode/pull/6271) "add edit and discard actions for queued messages" (11 files, more thorough — both edit and discard) was self-closed by the author after apparent lack of maintainer response, not a merit rejection.
14+
- **Origin:** implemented by an Opus 5 agent, with an unusually important caveat flagged up front in its own research: both upstream PRs remove a queued message from an *in-memory callback list* and delete the V1 message — a backend model with no equivalent in this repo's V2 session core, where a queued message is a *durable row* that stays pending until a safe promotion point (see this repo's own `AGENTS.md`: "An explicit `queue` input remains pending until the Session would otherwise become idle; promote one queued input at that boundary..."). So the backend here is a fresh, V2-native design — not a port — built the same way `SessionInput.Prompted`/`projectPrompted` already work: a durable event (`session.next.prompt.withdrawn` / `.revised`) is published and then projected into a `withdrawn_seq` column (new, migration `20260923161657_session_input_withdrawn`) or a replaced `prompt` value, with the update guarded to only affect rows that are neither promoted nor withdrawn (racing a withdraw against an in-flight promotion resolves in the withdraw's favor — the runner skips answering a turn that no longer has anything pending for it). What *was* reused from the PRs: the "remove" and "edit" concepts themselves, `/unqueue` kept as a command alias (from #6415), and the general shape of a queued-message picker UI (from #6271) — reworked as a `/queue` list dialog (select a message to edit its text, or press ctrl+d twice to remove it) rather than #6271's inline "EDITING" mode in the main prompt box.
15+
- **Where:** `packages/core/src/session/input.ts` (`listPending`/`withdraw`/`revise`/the new `NotPending` error), `packages/core/src/session.ts` (`SessionV2.pending`/`withdraw`/`revise`), `packages/core/src/session/runner/llm.ts` (a `requireInput` flag threading through the turn loop so a turn whose only justification was a withdrawn input is skipped rather than run with nothing to answer — merged by hand against this fork's own model-fallback feature, which had already added a different parameter to the exact same functions), three new routes (`GET /api/session/:id/input`, `PATCH .../input/:messageID`, `DELETE .../input/:messageID`) in `packages/protocol/src/groups/session.ts` + `packages/server/src/handlers/session.ts`, and a new `packages/tui/src/component/dialog-queued-input.tsx` + `/queue` command.
16+
- **Known, significant gap — read before relying on this:** the TUI still sends every prompt through the legacy V1 `SessionPrompt` path, which never creates the V2 `session_input` rows this feature acts on. **`/queue` will show an empty list for anything typed in the actual running TUI today.** Switching the TUI to send V2 prompts (`delivery: "queue"`) would make this feature real end-to-end, but is a materially bigger decision (it changes how every prompt in the TUI is sent) than this feature's own scope, and was deliberately left for a separate follow-up rather than silently expanded into. The backend is fully real, tested, and reachable via the HTTP API directly today. Also: the web app's own queue UI keeps its queue in the browser and doesn't call these routes; there's no "QUEUED"/"EDITING" badge on messages in the transcript; editing changes text only, not attachments or agent mentions; withdrawal also applies to a not-yet-promoted default-"steer" message, not just explicitly-queued ones (the dialog labels those "next turn"); the TUI dialog itself has no render test (only its data layer and API calls are tested).
17+
- **Verified:** `bun typecheck` clean across all 30 packages. New tests: `packages/core/test/session-prompt.test.ts` (+10 cases — a withdrawn message never reaches the model and the next queued one still runs; withdrawing the only queued message adds no extra model call; withdrawing an already-promoted message is rejected; an edited message runs with the edited text; a promotion that loses the race to a withdraw is refused; double-withdraw/unknown-id/wrong-session/retry-after-withdraw are all rejected), `packages/core/test/session-runner.test.ts` (+4), `packages/tui/test/cli/tui/data.test.tsx` (+2), three new `httpapi-exercise` scenarios, and an updated `event-manifest.test.ts` event count (88 → 90 for the two new durable events). Client and legacy JS SDKs regenerated. Full suites (re-verified against this fork's current `dev`, including the manual merge against model-fallback's own changes to the same runner functions): `packages/core` 1178 pass (only the pre-existing `pty` flake); `packages/opencode` 3613 pass, only the 4 pre-existing, confirmed-unrelated `cf-ai-gateway` failures; `packages/tui` 230 pass; `httpapi-exercise` coverage mode 214 pass (only the pre-existing, unrelated missing `/api/session/{sessionID}/cost` scenario).
18+
- **Where:** [`dev` branch history](https://github.com/chipp-ai/opencode/commits/dev).
19+
920
### Find-in-session (TUI)
1021

1122
Search within the current session's message history in the TUI — open with `<leader>f` or `/find` (alias `/search`), type a query, step between matches with Enter/Shift+Enter, Esc to close.

‎packages/client/src/contract.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ export const groupNames = {
4040

4141
export const endpointNames = {
4242
"session.messages": "list",
43+
"session.input.list": "listInputs",
44+
"session.input.revise": "reviseInput",
45+
"session.input.withdraw": "withdrawInput",
4346
"integration.connect.key": "connectKey",
4447
"integration.connect.oauth": "connectOauth",
4548
"integration.attempt.status": "attemptStatus",

‎packages/client/src/generated-effect/client.ts‎

Lines changed: 82 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -131,23 +131,56 @@ const Endpoint3_7 = (raw: RawClient["server.session"]) => (input: Endpoint3_7Inp
131131
Effect.map((value) => value.data),
132132
)
133133

134-
type Endpoint3_8Request = Parameters<RawClient["server.session"]["session.compact"]>[0]
134+
type Endpoint3_8Request = Parameters<RawClient["server.session"]["session.input.list"]>[0]
135135
type Endpoint3_8Input = { readonly sessionID: Endpoint3_8Request["params"]["sessionID"] }
136136
const Endpoint3_8 = (raw: RawClient["server.session"]) => (input: Endpoint3_8Input) =>
137-
raw["session.compact"]({ params: { sessionID: input["sessionID"] } }).pipe(Effect.mapError(mapClientError))
137+
raw["session.input.list"]({ params: { sessionID: input["sessionID"] } }).pipe(
138+
Effect.mapError(mapClientError),
139+
Effect.map((value) => value.data),
140+
)
138141

139-
type Endpoint3_9Request = Parameters<RawClient["server.session"]["session.wait"]>[0]
140-
type Endpoint3_9Input = { readonly sessionID: Endpoint3_9Request["params"]["sessionID"] }
142+
type Endpoint3_9Request = Parameters<RawClient["server.session"]["session.input.revise"]>[0]
143+
type Endpoint3_9Input = {
144+
readonly sessionID: Endpoint3_9Request["params"]["sessionID"]
145+
readonly messageID: Endpoint3_9Request["params"]["messageID"]
146+
readonly prompt: Endpoint3_9Request["payload"]["prompt"]
147+
}
141148
const Endpoint3_9 = (raw: RawClient["server.session"]) => (input: Endpoint3_9Input) =>
142-
raw["session.wait"]({ params: { sessionID: input["sessionID"] } }).pipe(Effect.mapError(mapClientError))
149+
raw["session.input.revise"]({
150+
params: { sessionID: input["sessionID"], messageID: input["messageID"] },
151+
payload: { prompt: input["prompt"] },
152+
}).pipe(
153+
Effect.mapError(mapClientError),
154+
Effect.map((value) => value.data),
155+
)
143156

144-
type Endpoint3_10Request = Parameters<RawClient["server.session"]["session.revert.stage"]>[0]
157+
type Endpoint3_10Request = Parameters<RawClient["server.session"]["session.input.withdraw"]>[0]
145158
type Endpoint3_10Input = {
146159
readonly sessionID: Endpoint3_10Request["params"]["sessionID"]
147-
readonly messageID: Endpoint3_10Request["payload"]["messageID"]
148-
readonly files?: Endpoint3_10Request["payload"]["files"]
160+
readonly messageID: Endpoint3_10Request["params"]["messageID"]
149161
}
150162
const Endpoint3_10 = (raw: RawClient["server.session"]) => (input: Endpoint3_10Input) =>
163+
raw["session.input.withdraw"]({ params: { sessionID: input["sessionID"], messageID: input["messageID"] } }).pipe(
164+
Effect.mapError(mapClientError),
165+
)
166+
167+
type Endpoint3_11Request = Parameters<RawClient["server.session"]["session.compact"]>[0]
168+
type Endpoint3_11Input = { readonly sessionID: Endpoint3_11Request["params"]["sessionID"] }
169+
const Endpoint3_11 = (raw: RawClient["server.session"]) => (input: Endpoint3_11Input) =>
170+
raw["session.compact"]({ params: { sessionID: input["sessionID"] } }).pipe(Effect.mapError(mapClientError))
171+
172+
type Endpoint3_12Request = Parameters<RawClient["server.session"]["session.wait"]>[0]
173+
type Endpoint3_12Input = { readonly sessionID: Endpoint3_12Request["params"]["sessionID"] }
174+
const Endpoint3_12 = (raw: RawClient["server.session"]) => (input: Endpoint3_12Input) =>
175+
raw["session.wait"]({ params: { sessionID: input["sessionID"] } }).pipe(Effect.mapError(mapClientError))
176+
177+
type Endpoint3_13Request = Parameters<RawClient["server.session"]["session.revert.stage"]>[0]
178+
type Endpoint3_13Input = {
179+
readonly sessionID: Endpoint3_13Request["params"]["sessionID"]
180+
readonly messageID: Endpoint3_13Request["payload"]["messageID"]
181+
readonly files?: Endpoint3_13Request["payload"]["files"]
182+
}
183+
const Endpoint3_13 = (raw: RawClient["server.session"]) => (input: Endpoint3_13Input) =>
151184
raw["session.revert.stage"]({
152185
params: { sessionID: input["sessionID"] },
153186
payload: { messageID: input["messageID"], files: input["files"] },
@@ -156,60 +189,60 @@ const Endpoint3_10 = (raw: RawClient["server.session"]) => (input: Endpoint3_10I
156189
Effect.map((value) => value.data),
157190
)
158191

159-
type Endpoint3_11Request = Parameters<RawClient["server.session"]["session.revert.clear"]>[0]
160-
type Endpoint3_11Input = { readonly sessionID: Endpoint3_11Request["params"]["sessionID"] }
161-
const Endpoint3_11 = (raw: RawClient["server.session"]) => (input: Endpoint3_11Input) =>
192+
type Endpoint3_14Request = Parameters<RawClient["server.session"]["session.revert.clear"]>[0]
193+
type Endpoint3_14Input = { readonly sessionID: Endpoint3_14Request["params"]["sessionID"] }
194+
const Endpoint3_14 = (raw: RawClient["server.session"]) => (input: Endpoint3_14Input) =>
162195
raw["session.revert.clear"]({ params: { sessionID: input["sessionID"] } }).pipe(Effect.mapError(mapClientError))
163196

164-
type Endpoint3_12Request = Parameters<RawClient["server.session"]["session.revert.commit"]>[0]
165-
type Endpoint3_12Input = { readonly sessionID: Endpoint3_12Request["params"]["sessionID"] }
166-
const Endpoint3_12 = (raw: RawClient["server.session"]) => (input: Endpoint3_12Input) =>
197+
type Endpoint3_15Request = Parameters<RawClient["server.session"]["session.revert.commit"]>[0]
198+
type Endpoint3_15Input = { readonly sessionID: Endpoint3_15Request["params"]["sessionID"] }
199+
const Endpoint3_15 = (raw: RawClient["server.session"]) => (input: Endpoint3_15Input) =>
167200
raw["session.revert.commit"]({ params: { sessionID: input["sessionID"] } }).pipe(Effect.mapError(mapClientError))
168201

169-
type Endpoint3_13Request = Parameters<RawClient["server.session"]["session.context"]>[0]
170-
type Endpoint3_13Input = { readonly sessionID: Endpoint3_13Request["params"]["sessionID"] }
171-
const Endpoint3_13 = (raw: RawClient["server.session"]) => (input: Endpoint3_13Input) =>
202+
type Endpoint3_16Request = Parameters<RawClient["server.session"]["session.context"]>[0]
203+
type Endpoint3_16Input = { readonly sessionID: Endpoint3_16Request["params"]["sessionID"] }
204+
const Endpoint3_16 = (raw: RawClient["server.session"]) => (input: Endpoint3_16Input) =>
172205
raw["session.context"]({ params: { sessionID: input["sessionID"] } }).pipe(
173206
Effect.mapError(mapClientError),
174207
Effect.map((value) => value.data),
175208
)
176209

177-
type Endpoint3_14Request = Parameters<RawClient["server.session"]["session.history"]>[0]
178-
type Endpoint3_14Input = {
179-
readonly sessionID: Endpoint3_14Request["params"]["sessionID"]
180-
readonly limit?: Endpoint3_14Request["query"]["limit"]
181-
readonly after?: Endpoint3_14Request["query"]["after"]
210+
type Endpoint3_17Request = Parameters<RawClient["server.session"]["session.history"]>[0]
211+
type Endpoint3_17Input = {
212+
readonly sessionID: Endpoint3_17Request["params"]["sessionID"]
213+
readonly limit?: Endpoint3_17Request["query"]["limit"]
214+
readonly after?: Endpoint3_17Request["query"]["after"]
182215
}
183-
const Endpoint3_14 = (raw: RawClient["server.session"]) => (input: Endpoint3_14Input) =>
216+
const Endpoint3_17 = (raw: RawClient["server.session"]) => (input: Endpoint3_17Input) =>
184217
raw["session.history"]({
185218
params: { sessionID: input["sessionID"] },
186219
query: { limit: input["limit"], after: input["after"] },
187220
}).pipe(Effect.mapError(mapClientError))
188221

189-
type Endpoint3_15Request = Parameters<RawClient["server.session"]["session.events"]>[0]
190-
type Endpoint3_15Input = {
191-
readonly sessionID: Endpoint3_15Request["params"]["sessionID"]
192-
readonly after?: Endpoint3_15Request["query"]["after"]
222+
type Endpoint3_18Request = Parameters<RawClient["server.session"]["session.events"]>[0]
223+
type Endpoint3_18Input = {
224+
readonly sessionID: Endpoint3_18Request["params"]["sessionID"]
225+
readonly after?: Endpoint3_18Request["query"]["after"]
193226
}
194-
const Endpoint3_15 = (raw: RawClient["server.session"]) => (input: Endpoint3_15Input) =>
227+
const Endpoint3_18 = (raw: RawClient["server.session"]) => (input: Endpoint3_18Input) =>
195228
Stream.unwrap(
196229
raw["session.events"]({ params: { sessionID: input["sessionID"] }, query: { after: input["after"] } }).pipe(
197230
Effect.mapError(mapClientError),
198231
Effect.map((stream) => stream.pipe(Stream.mapError(mapClientError))),
199232
),
200233
)
201234

202-
type Endpoint3_16Request = Parameters<RawClient["server.session"]["session.interrupt"]>[0]
203-
type Endpoint3_16Input = { readonly sessionID: Endpoint3_16Request["params"]["sessionID"] }
204-
const Endpoint3_16 = (raw: RawClient["server.session"]) => (input: Endpoint3_16Input) =>
235+
type Endpoint3_19Request = Parameters<RawClient["server.session"]["session.interrupt"]>[0]
236+
type Endpoint3_19Input = { readonly sessionID: Endpoint3_19Request["params"]["sessionID"] }
237+
const Endpoint3_19 = (raw: RawClient["server.session"]) => (input: Endpoint3_19Input) =>
205238
raw["session.interrupt"]({ params: { sessionID: input["sessionID"] } }).pipe(Effect.mapError(mapClientError))
206239

207-
type Endpoint3_17Request = Parameters<RawClient["server.session"]["session.message"]>[0]
208-
type Endpoint3_17Input = {
209-
readonly sessionID: Endpoint3_17Request["params"]["sessionID"]
210-
readonly messageID: Endpoint3_17Request["params"]["messageID"]
240+
type Endpoint3_20Request = Parameters<RawClient["server.session"]["session.message"]>[0]
241+
type Endpoint3_20Input = {
242+
readonly sessionID: Endpoint3_20Request["params"]["sessionID"]
243+
readonly messageID: Endpoint3_20Request["params"]["messageID"]
211244
}
212-
const Endpoint3_17 = (raw: RawClient["server.session"]) => (input: Endpoint3_17Input) =>
245+
const Endpoint3_20 = (raw: RawClient["server.session"]) => (input: Endpoint3_20Input) =>
213246
raw["session.message"]({ params: { sessionID: input["sessionID"], messageID: input["messageID"] } }).pipe(
214247
Effect.mapError(mapClientError),
215248
Effect.map((value) => value.data),
@@ -224,16 +257,19 @@ const adaptGroup3 = (raw: RawClient["server.session"]) => ({
224257
switchAgent: Endpoint3_5(raw),
225258
switchModel: Endpoint3_6(raw),
226259
prompt: Endpoint3_7(raw),
227-
compact: Endpoint3_8(raw),
228-
wait: Endpoint3_9(raw),
229-
stage: Endpoint3_10(raw),
230-
clear: Endpoint3_11(raw),
231-
commit: Endpoint3_12(raw),
232-
context: Endpoint3_13(raw),
233-
history: Endpoint3_14(raw),
234-
events: Endpoint3_15(raw),
235-
interrupt: Endpoint3_16(raw),
236-
message: Endpoint3_17(raw),
260+
listInputs: Endpoint3_8(raw),
261+
reviseInput: Endpoint3_9(raw),
262+
withdrawInput: Endpoint3_10(raw),
263+
compact: Endpoint3_11(raw),
264+
wait: Endpoint3_12(raw),
265+
stage: Endpoint3_13(raw),
266+
clear: Endpoint3_14(raw),
267+
commit: Endpoint3_15(raw),
268+
context: Endpoint3_16(raw),
269+
history: Endpoint3_17(raw),
270+
events: Endpoint3_18(raw),
271+
interrupt: Endpoint3_19(raw),
272+
message: Endpoint3_20(raw),
237273
})
238274

239275
type Endpoint4_0Request = Parameters<RawClient["server.message"]["session.messages"]>[0]

‎packages/client/src/generated/client.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ import type {
1919
SessionsSwitchModelOutput,
2020
SessionsPromptInput,
2121
SessionsPromptOutput,
22+
SessionsListInputsInput,
23+
SessionsListInputsOutput,
24+
SessionsReviseInputInput,
25+
SessionsReviseInputOutput,
26+
SessionsWithdrawInputInput,
27+
SessionsWithdrawInputOutput,
2228
SessionsCompactInput,
2329
SessionsCompactOutput,
2430
SessionsWaitInput,
@@ -398,6 +404,40 @@ export function make(options: ClientOptions) {
398404
},
399405
requestOptions,
400406
).then((value) => value.data),
407+
listInputs: (input: SessionsListInputsInput, requestOptions?: RequestOptions) =>
408+
request<{ readonly data: SessionsListInputsOutput }>(
409+
{
410+
method: "GET",
411+
path: `/api/session/${encodeURIComponent(input.sessionID)}/input`,
412+
successStatus: 200,
413+
declaredStatuses: [404, 400, 401],
414+
empty: false,
415+
},
416+
requestOptions,
417+
).then((value) => value.data),
418+
reviseInput: (input: SessionsReviseInputInput, requestOptions?: RequestOptions) =>
419+
request<{ readonly data: SessionsReviseInputOutput }>(
420+
{
421+
method: "PATCH",
422+
path: `/api/session/${encodeURIComponent(input.sessionID)}/input/${encodeURIComponent(input.messageID)}`,
423+
body: { prompt: input["prompt"] },
424+
successStatus: 200,
425+
declaredStatuses: [409, 404, 400, 401],
426+
empty: false,
427+
},
428+
requestOptions,
429+
).then((value) => value.data),
430+
withdrawInput: (input: SessionsWithdrawInputInput, requestOptions?: RequestOptions) =>
431+
request<SessionsWithdrawInputOutput>(
432+
{
433+
method: "DELETE",
434+
path: `/api/session/${encodeURIComponent(input.sessionID)}/input/${encodeURIComponent(input.messageID)}`,
435+
successStatus: 204,
436+
declaredStatuses: [409, 404, 400, 401],
437+
empty: true,
438+
},
439+
requestOptions,
440+
),
401441
compact: (input: SessionsCompactInput, requestOptions?: RequestOptions) =>
402442
request<SessionsCompactOutput>(
403443
{

0 commit comments

Comments
 (0)