Skip to content

fix(agents): PUT /operator-resume is human-only — an agent cannot switch on its own paid wake-ups (0.9.5 M3) - #2860

Merged
vybe merged 1 commit into
devfrom
fix/m3-operator-resume-reject-agent
Sep 17, 2026
Merged

vybe merged 1 commit into
devfrom
fix/m3-operator-resume-reject-agent

Conversation

@dolho

@dolho dolho commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

0.9.5 work order M3. Related to abilityai/trinity-enterprise#329.

Summary

PUT /api/agents/{name}/operator-resume was OwnedAgentByName only. An agent-scoped MCP key resolves to its owner on REST, so the agent's own injected key satisfied the owner check and a (prompt-injected) agent could enable the respond→resume opt-in — whose entire point is "each answer may now spend the owner's money" (ent#329). Add reject_agent_principal(current_user) as the first statement. Grant-vs-use line: the GET stays agent-reachable (an agent may read whether its answers resume it); only the grant is fenced — same shape as the ent#223 consent toggle and the ent#109 bind endpoint.

Test

tests/unit/test_m3_operator_resume_human_only.py:

  • guard present by source;
  • runtime: an agent principal gets 403 + the human-only detail before the DB write or the audit write (both made loud);
  • a JWT owner still flips it (write + audit recorded, response unchanged);
  • the GET carries no reject (guards against an over-eager copy).

Red before the fix (2 failed), green after; test_ent329_operator_resume, test_1310_auth_wiring, test_293_admin_gate_rejects_agent_keys still pass (65 passed). docs/memory/architecture/api-endpoints.md row updated.

🤖 Generated with Claude Code

…tch on its own paid wake-ups (0.9.5 M3, ent#329)

An agent-scoped MCP key resolves to its OWNER on REST, so `OwnedAgentByName` alone was
satisfied by the agent's own injected key: a (prompt-injected) agent could enable the
respond→resume opt-in whose whole point is "each answer may now spend the owner's money".
Add `reject_agent_principal` as the first statement (grant-vs-use line: the GET stays
agent-reachable). Test pins the guard by source and at runtime — 403 with the human-only
detail before the DB write or the audit write — and that a JWT owner still flips it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@dolho

dolho commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

/review Report

Branch: fix/m3-operator-resume-reject-agent → dev (merge-base 3a47f74)
Files Changed: 3 (+102/−3)
Scope: CLEAN — intent (0.9.5 work order M3): reject_agent_principal + a test on PUT /api/agents/{name}/operator-resume. Delivered: the guard as the first statement, a 4-case test, the api-endpoints.md row.
Plan Completion: 2 done / 0 partial — guard: routers/agents.py:1312; test: tests/unit/test_m3_operator_resume_human_only.py.

Critical Findings (block merge)

None.

Informational Findings (review required)

[I1] Auth boundary (4.3) — verified, recorded for the reviewer (Confidence: 9/10)
File: src/backend/routers/agents.py:1312
Evidence: reject_agent_principal(current_user) precedes db.set_operator_resume_enabled(...) and the audit log(...); route is /{agent_name}/operator-resume with OwnedAgentByName — the correct path-param pairing (test_2094_dependency_path_param_pairing.py passes on this branch).
Completeness (4.14): set_operator_resume_enabled has exactly one caller in the tree (routers/agents.py:1314); no MCP tool exposes it (src/mcp-server/src has no operator-resume); the enterprise submodule (checked at its current pin) has no writer either; the only client is ReliabilityPanel.vue on a JWT. So the guard closes every write path. The GET deliberately stays agent-reachable — consistent with the grant-vs-use line and pinned by test_the_read_stays_agent_reachable.
Note the residual the guard does not address, by design: a scope='system' key sets neither agent_name nor connector_agent, so reject_agent_principal is a no-op for trinity-system — architecture.md documents this ("guards over it must be allowlists"). trinity-system switching on another agent's paid wake-ups is a system-agent capability, not the ent#329 hole; if that should be human-only too, reject_non_interactive_principal (#1854) is the allowlist form — a design call for the owner of ent#329, not this fix.

[I2] Test naming (4.7) (Confidence: 6/10)
File: tests/unit/test_m3_operator_resume_human_only.py
Issue: the suite's convention is test_<issue>_<slug>.py; m3 is a work-order row, not a tracker id, so the file won't be found by an issue-number grep later.
Suggestion: test_ent329_operator_resume_human_only.py (the surface it guards) — or file the M3 row as a public type-bug issue and name it for that. Rename-only; no logic change.

[I3] Test gap (4.9) — ordering proof is by loud stubs, not by the audit path (Confidence: 5/10 → appendix)
File: tests/unit/test_m3_operator_resume_human_only.py:52-66
Issue: the runtime test proves the DB write and the audit write are not reached (both _boom), which is the right proof. The happy-path test stubs platform_audit_service.log with a coroutine and asserts the call order — fine, but it asserts event_action only; actor_user (the human) and details={"enabled": …} are not checked. Low value; the audit shape is unchanged by this PR.

Clean Categories

  • 4.1 SQL — no DB code changed; the write goes through the existing db.set_operator_resume_enabled.
  • 4.2 concurrency — no shared state added.
  • 4.4 credentials — nothing logged beyond the existing details={"enabled": …}.
  • 4.5/4.8 — the reject raises before any side effect; no new fire-and-forget.
  • 4.12 enums — no new values.
  • 4.13 docs — docs/memory/architecture/api-endpoints.md:77 updated to "owner-only and human-only"; the ent#329 subsystem section in architecture/ says "PUT owner-only" in its prose too (the "Respond → Resume" block) — one-line staleness, optional.
  • 4.15 product bar — the 403 carries the named human-only detail, same string as the other fenced endpoints.
  • Related guards green on this branch: test_ent329_operator_resume, test_1310_auth_wiring, test_293_admin_gate_rejects_agent_keys, test_2094_dependency_path_param_pairing (65 + 4 passed).

Summary

  • Critical: 0 — none found
  • Informational: 2 (+1 appendix) — I1 is a recorded verification with one design note for ent#329's owner; I2 is a rename
  • Scope: clean

Review complete. Next: /validate-pr 2860; consider the I2 rename before merge (no logic change).

@vybe vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge-train: validated individually against dev (2-PR run, no train branch). Guard is the first statement of the PUT, ahead of both the DB write and the audit write; the runtime tests go red if it is moved after the write. No other writer of operator_resume_enabled; not exposed as an MCP tool. Merged without a closing keyword by decision: ent#329 is already status-in-dev and no public issue tracks this fix.

@vybe
vybe merged commit b272a5f into dev Sep 17, 2026
27 checks passed
@vybe
vybe deleted the fix/m3-operator-resume-reject-agent branch September 17, 2026 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants