feat: advertise session capabilities, implement cancel and set_mode #11
No reviewers
Labels
No labels
code-review
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
sam/brainless!11
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/acp-session-capabilities"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Fixes Paseo's ACP import listing and completes the session command surface.
1. Advertise
session/list,session/close,session/resume(fixes import listing)Initializepreviously advertised onlyloadSession: true. Paseo (and any spec-compliant ACP client) gates itssession/list,session/close, andsession/resumecalls on thesessionCapabilitiesflags, so brainless's handlers for those commands were dead code in the Paseo flow:session/list— Paseo returns[]without calling it (acp-agent.ts:1161), so the session-import listing showed nothing.session/close— Paseo skips the close-cleanup call (acp-agent.ts:1275).session/resume— Paseo preferssession/loadwhenloadSessionis advertised, but other clients gate onsessionCapabilities.resume; advertising it makes the implemented handler reachable.Initializenow advertisessessionCapabilities: {list, close, resume}alongsideloadSession: true. The handlers were already correct — this is purely advertisement.2. Implement
session/cancelThe acp-go-sdk transport already cancels the in-flight prompt's context when
session/cancelarrives, then dispatches toAgent.Cancel.Promptnow observes the canceled context and settles the turn withstopReason: "cancelled"instead of returning a JSON-RPC error — Paseo renders that as "turn canceled" (Interrupted) rather than "turn failed".Cancelremains a no-op by design; the cancellation is transport-handled.Note: the ADK runner stops waiting on cancellation but does not abort the underlying in-flight model HTTP call (ADK v2.4.0 behavior). It is bounded by process lifetime — Paseo tree-kills the agent on close. Documented in
Prompt.3. Implement
session/set_modeThe harness now advertises three modes —
fast,normal,deep— in themodesfield ofsession/new,session/load, andsession/resumeresponses (Paseo'sderiveModesFromACPreads this and shows a mode switcher). A mode is a preset over the thinking selector, applied to the active model:fast→ reasoning offnormal→ the model's default effortdeep→ the model's maximum declared effortSetSessionModevalidates the mode id (unknown modes are rejected), applies it, and persists it in the selection so it survives load/resume. Switching models falls back tonormalmode when the new model cannot honor the current level, so the advertisedcurrentModeIdnever lies.Tests
TestACPInitializeAdvertisesSessionCapabilities— initialize advertisesloadSession+list/close/resume.TestACPCancelStopsInflightPrompt—session/cancelsettles an in-flight prompt (against a blocking model server) withstopReason: cancelledand no error.TestACPSetModeChangesThinking— modes are advertised in lifecycle responses;deep/fast/normalchange the reasoning effort on the wire (high/none/lowfor a[low, high]model); unknown modes are rejected.TestACPSessionListReturnsPersistedSessions—session/listreturns persisted sessions andsession/closeaccepts the listed id.Verification
go build ./...,go vet ./...,gofmt,golangci-lint run(0 issues),go test ./...andracedetector test ./...all pass.Deployment note
This changes brainless itself. The paseo image bakes a compiled brainless binary (pi-deploy PR #37), so after merge the binary must be rebuilt and the paseo image refreshed (
docker compose build paseo && docker compose up -d paseo) to pick this up.High-signal review of the session-capabilities + cancel + set_mode PR. The advertisement fix (sessionCapabilities list/close/resume + loadSession), the cancel handling, and the test suite are solid — cancellation correctness is verified end-to-end against a blocking server, and the new mode tests cover the wire effect. Two IMPORTANT correctness gaps remain in the new mode state machine (the advertised currentModeId can diverge from the actual wire effort), plus one test-robustness suggestion. See inline comments.
@ -153,0 +174,4 @@})srv = httptest.NewServer(mux)t.Cleanup(srv.Close)🟡 SUGGESTION — If any assertion in TestACPCancelStopsInflightPrompt fails before the trailing
close(release)(e.g. the prompt does not settle within 10s), the handler stays blocked onreleaseChandt.Cleanup(srv.Close)(httptest.Server.Close blocks until outstanding requests finish) hangs the whole test run instead of reporting the failure — and since the ADK runner does not cancel the in-flight HTTP request context,req.Context().Done()will not unblock it. Fix: also register a cleanup that closesrelease, guarded bysync.Onceso the trailing explicit close stays safe.@ -45,1 +118,4 @@// Drop the thinking level when the new model does not declare it, and// fall back to the normal mode so the advertised mode never lies about// a level the model cannot honor.if !h.reg.Reasoning(ref) || !slices.Contains(h.reg.ThinkingModes(ref), config.ReasoningEffort(thinking)) {🟠 IMPORTANT — When a mode is kept across a model switch, the code reuses the stale
thinkingfrom the old model instead of recomputing it for the new model. Concretely: with mode=deep and p/m1 (efforts [low, high]) the stored thinking becomes "high"; switching to a model whose declared max is higher (e.g. [low, high, max]) keeps thinking="high" (it is still in the new model's set, so the fallback does not trigger), sodeepadvertises "maximum declared effort" but sends "high" on the wire — the mode under-delivers relative to its contract. Condition: new model's max effort exceeds the previous model's max. Fix: when keeping the mode, recompute the level for the new model, e.g. in the else branch setthinking = modeThinking(mode, h.reg.ThinkingModes(ref))before theset/setModewrites.🟠 IMPORTANT — The
configIDThinkingbranch writes the manual thinking level without reconcilingmode, so the advertisedcurrentModeIdcan lie (contradicting the PR's stated invariant). Example:set_mode deepon p/m2 sets mode=deep, thinking=high; the client then moves the thinking selector to "low" via this branch, which callsh.sel.set(ref, value)and leaves mode=deep untouched. The next NewSession/LoadSession/ResumeSession advertises currentModeId=deep while the wire sends effort=low, and a later model switch keeps the stale mode too. Fix: when a manual thinking override no longer equals the active mode's preset level, fall back to normal, e.g. after validation:mode := h.sel.modeSnap(); if modeThinking(mode, h.reg.ThinkingModes(ref)) != string(effort) { mode = modeNormal }; h.sel.set(ref, value); h.sel.setMode(mode, value).Reviewed. The session-capabilities advertisement, cancel handling, and test coverage are strong, but two IMPORTANT mode-state consistency issues should be fixed before merge: (1) a kept mode reuses the stale thinking level on model switch, so
deepcan under-deliver on a model with a higher max effort; (2) a manual thinking-selector override leavesmodeuntouched, so the advertisedcurrentModeIdcan lie about the actual wire effort. Both are small reconciliations of the mode state. One SUGGESTION on test-hang robustness in the blocking-server helper. (Note: REQUEST_CHANGES was rejected by Forgejo because this review runs as the PR author pi-agent; posted as COMMENT with the same findings.)@ -153,0 +174,4 @@})srv = httptest.NewServer(mux)t.Cleanup(srv.Close)🟡 SUGGESTION — If any assertion in TestACPCancelStopsInflightPrompt fails before the trailing
close(release)(e.g. the prompt does not settle within 10s), the handler stays blocked onreleaseChandt.Cleanup(srv.Close)(httptest.Server.Close blocks until outstanding requests finish) hangs the whole test run instead of reporting the failure — and since the ADK runner does not cancel the in-flight HTTP request context,req.Context().Done()will not unblock it. Fix: also register a cleanup that closesrelease, guarded bysync.Onceso the trailing explicit close stays safe.@ -45,1 +118,4 @@// Drop the thinking level when the new model does not declare it, and// fall back to the normal mode so the advertised mode never lies about// a level the model cannot honor.if !h.reg.Reasoning(ref) || !slices.Contains(h.reg.ThinkingModes(ref), config.ReasoningEffort(thinking)) {🟠 IMPORTANT — When a mode is kept across a model switch, the code reuses the stale
thinkingfrom the old model instead of recomputing it for the new model. Concretely: with mode=deep and p/m1 (efforts [low, high]) the stored thinking becomes "high"; switching to a model whose declared max is higher (e.g. [low, high, max]) keeps thinking="high" (it is still in the new model's set, so the fallback does not trigger), sodeepadvertises "maximum declared effort" but sends "high" on the wire — the mode under-delivers relative to its contract. Condition: new model's max effort exceeds the previous model's max. Fix: when keeping the mode, recompute the level for the new model, e.g. in the else branch setthinking = modeThinking(mode, h.reg.ThinkingModes(ref))before theset/setModewrites.🟠 IMPORTANT — The
configIDThinkingbranch writes the manual thinking level without reconcilingmode, so the advertisedcurrentModeIdcan lie (contradicting the PR's stated invariant). Example:set_mode deepon p/m2 sets mode=deep, thinking=high; the client then moves the thinking selector to "low" via this branch, which callsh.sel.set(ref, value)and leaves mode=deep untouched. The next NewSession/LoadSession/ResumeSession advertises currentModeId=deep while the wire sends effort=low, and a later model switch keeps the stale mode too. Fix: when a manual thinking override no longer equals the active mode's preset level, fall back to normal, e.g. after validation:mode := h.sel.modeSnap(); if modeThinking(mode, h.reg.ThinkingModes(ref)) != string(effort) { mode = modeNormal }; h.sel.set(ref, value); h.sel.setMode(mode, value).All three review findings are addressed in commit
757345f(pushed to the branch):if mode != modeNormal { thinking = modeThinking(mode, h.reg.ThinkingModes(ref)) }), sodeepon a model with a higher declared max sends that max instead of the stale level from the old model.thinkingconfig-option branch now reconciles the mode — if the manual override diverges from the active mode's preset level, it falls back tonormal, so the advertisedcurrentModeIdnever claims an effort that isn't sent on the wire.newBlockingResponsesServernow returns async.Once-guardedrelease func()and registers it as cleanup (LIFO, beforesrv.Close), so a test that fails before releasing can't hanghttptest.Server.Closeon the blocked handler.Added
TestModeReconcilesOnModelSwitchAndOverride, which inspects the selection directly —maxandhighclamp to the same genai thinking level, so the wire can't distinguish them.go test ./...,racedetector test ./..., andgolangci-lint run(0 issues) all pass.Additional fix in commit
e836c80: thethinkingConfigclamping quirk I flagged is now resolved.What changed: declared reasoning efforts
xhigh/maxcouldn't reach the wire — the ADK openaimodel bridge maps genai thinking levels onto Responsesreasoning.effortand itsreasoningEffortsmap tops out athigh(genai has no xhigh/max level, and the bridge errors on unknown ones). So a model declaring[low, high, max]advertised amaxoption and adeepmode that silently senthigh.normalizeEffortsnow collapsesxhigh/maxtohigh(deduped) at registry load, so the thinking option and mode presets only ever offer levels the bridge can send: a[low, high, max]model offers[low, high], anddeepresolves to its highest expressible effort.thinkingConfigkeeps the clamp as a safety net for hand-built entries. README updated.Tests: the mode-reconcile test now uses expressible-different models (
[low, medium]vs[low, medium, high]); a newTestReasoningEffortNormalizationassertsxhigh/maxcollapse tohighanddeepresolves there.go test ./...,racedetector test ./..., andgolangci-lint run(0 issues) all pass.Note: if you ever want true
xhigh/maxon the wire, that requires bypassing or vendoring the ADK openaimodel bridge (itsreasoningEffortsmap), which is out of scope for this PR.