Repository navigation
fix(operator-queue): an approval's decision must be one the agent offered (#2376) - #2414
Conversation
…ered (#2376) `OperatorResponse.response` is a bare `str`, and the router, the DB write and the write-back into the agent's own queue file all passed it through verbatim. No layer checked that an **approval** item's recorded decision was one of the options the agent authored — so #2370 shipped `response: "approved"` against `options: ["Approve", "Deny"]` for five months without a single 4xx, and the agent read back a decision string it never offered. ## At the sink, not in a router This is the approval channel for irreversible actions (#1402 poison-park, ent#329 respond -> resume, the TARGET_ARCHITECTURE v2 human gate), and it has four producers today. A rule that lives in whichever router is next re-ships the class the first time someone adds a channel button or an ops agent, so `services/operator_queue_choices.py` owns it and both writers call it. A leaf module rather than `operator_queue_service`: that module instantiates its sync-service singleton and imports `AgentClient` at module scope, and the Workspace asks path must not drag either in to answer a question about a list of strings. ## The rule, and what it deliberately does not do Exact string match. The options are AGENT-authored, so only the agent knows whether `approve` and `Approve` mean the same thing to it — normalising here would silently answer that on its behalf, when the whole point is that the recorded decision is one the agent can compare against its own list. The 422 carries the offered options. A refusal that says only "invalid" leaves the operator guessing at strings they never wrote. Exempt, and all spelled as the same absence rather than as special cases at the call site: questions, alerts, approvals that offered nothing, a non-list or non-string blob, and — the case worth naming — one whose options are the #1632 size-cap marker. That placeholder RECORDS that the choices were dropped, so treating it as offered would let it be recorded as a decision, and treating the item as constrained would make it unanswerable. An empty `response` is not rejected. Both entry points allow an answer carried entirely by `response_text`, and the asks path has its own `empty_answer` refusal for a truly empty one; a 422 there would break a working path to validate a field nobody filled in. `acknowledged` never reaches the rule because both writers refuse a non-pending item first — structural, and pinned by assertion on the ordering rather than by comment. ## One marker, one definition `_OPTIONS_DROPPED_MARKER` now imports from the leaf. Two literals drift the day either side is reworded, and the sink would then accept the placeholder as a decision. ## Verification 18 tests: the exact #2370 case, near-miss casing, every exempt shape, the marker alone and the marker beside a real option, and that both entry points emit the named 422 with the list. AC #3 is enforced rather than asserted — an AST caller-parity guard pins the writer set to exactly the two known callers and requires each to validate; removing the asks-side call turns it red (verified: 2 failed). 244 pass across the operator-queue, asks, #1632, #1677 and ent#329 suites. MCP needs no change: `ApiError` embeds the raw body in `.message`, so the structured detail already reaches `respond_to_operator_queue`'s `{error: msg}` — pinned by test rather than assumed. Closes #2376 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
obasilakis
left a comment
There was a problem hiding this comment.
/validate-pr — approving.
The placement is the whole value here, and it is right. This is the approval channel for irreversible actions with four producers today, so a check in whichever router happened to be next would have been the fifth place to forget it. Putting it at the sink and pinning that with an AST caller-parity guard is the #1677 shape applied correctly.
Things I checked and agree with:
- Exact match, deliberately. The options are agent-authored, so normalising
approvetoApprovewould answer on the agent's behalf a question only the agent can answer. The docstring says this rather than leaving it to be rediscovered. - The dropped-options marker is now one definition, imported.
operator_queue_serviceholding its own literal while the validator held a second copy is exactly how the sink would have ended up accepting a size-cap placeholder as a decision. Good catch to fold it. - The exemptions are spelled as one absence. Questions, alerts, an approval that offered nothing, a non-list blob, and a marker-only list all return
Nonefromusable_optionsrather than becoming five special cases at two call sites. - An empty
responseis not rejected. Turning a text-only answer into a 422 would have broken a working path in the name of validating a field that was never filled in; the Workspace path keeps its ownempty_answerrefusal for a genuinely empty one. - The 422 carries
offered_options. A refusal that does not name agent-authored strings leaves the operator guessing, and re-deriving them by parsing the message is what breaks the day the wording changes. ThreadingAskError.datathrough_raiserather than stuffing it into prose is the right plumbing.
That #2370 recorded "approved" against ["Approve", "Deny"] for five months without a single 4xx is a good piece of evidence to have put in the PR body.
Checklist: base dev, Closes #2376, feature flow updated with the rule and its exemptions, security scan clean, no packaging or schema surface, both writers reach the validator, CI green.
One non-blocking note: src/mcp-server/src/tools/operator_queue.ts is the fourth producer and routes through this endpoint, so it is covered — but its inline comment still says only "Backend 400s on a non-pending item" and the tool description does not mention that an approval's response must be one of the offered options. An agent will now hit a 422 the tool never told it about. Worth a sentence there when convenient.
Summary
OperatorResponse.responseis a barestr, and the router, the DB write and the write-back into the agent's own queue file all passed it through verbatim. No layer checked that an approval item's recorded decision was one of the options the agent authored — so #2370 shippedresponse: "approved"againstoptions: ["Approve", "Deny"]for five months without a single 4xx, and the agent read back a decision string it never offered.At the sink, not in a router
This is the approval channel for irreversible actions (#1402 poison-park, ent#329 respond→resume, the TARGET_ARCHITECTURE v2 human gate), with four producers today. A rule living in whichever router is next re-ships the class the first time someone adds a channel button or an ops agent — so
services/operator_queue_choices.pyowns it and both writers call it.A leaf module rather than
operator_queue_service: that module instantiates its sync-service singleton and importsAgentClientat module scope, and the Workspace asks path must not drag either in to answer a question about a list of strings.The rule, and what it deliberately does not do
approveandApprovemean the same thing to it. Normalising would answer that on its behalf, when the point is that the recorded decision is one the agent can compare against its own list.responseis not rejected. Both entry points allow an answer carried entirely byresponse_text; a 422 there would break a working path to validate a field nobody filled in.acknowledgednever reaches the rule because both writers refuse a non-pending item first — structural, and pinned by asserting the ordering rather than by comment.Exempt cases are all spelled as the same absence rather than as special cases at the call site: questions, alerts, approvals offering nothing, a non-list or non-string blob, and — worth naming — one whose options are the #1632 size-cap marker. That placeholder records that the choices were dropped, so treating it as offered would let it be recorded as a decision, and treating the item as constrained would make it unanswerable.
_OPTIONS_DROPPED_MARKERnow imports from the leaf: two literals drift the day either side is reworded, and the sink would then accept the placeholder as a decision.Acceptance criteria
acknowledgedunaffectedVerification
AC #3 is the one worth calling out: rather than asserting "both call it", an AST caller-parity guard (the #1677 shape) pins the writer set of
db.respond_to_operator_queue_itemto exactly the two known callers and requires each to validate. A third writer fails CI.244 pass across the operator-queue, asks, #1632, #1677 and ent#329 suites.
MCP needed no change —
ApiErrorembeds the raw body in.message, so the structured detail already reachesrespond_to_operator_queue's{error: msg}. Pinned by test rather than assumed.Closes #2376
🤖 Generated with Claude Code