Repository navigation
M1 Identity + async proposals (v0.3.0 milestone 1): per-agent tokens and scopes, the agent named in the bar, and no client call ever waits on a human - #4
Conversation
… named in the bar, and no client call ever waits on a human
The hub had ONE bearer token and no identity, so the approval bar could only
say "external agent"; and run_command blocked the client's HTTP call until the
human pressed Enter — Codex and Cursor time out at ~60 s, so two of the three
target agents could not use the hub at all.
REGISTRY. AgentToken { name, token, scopes, worktree } with no Debug derive (a
derived one would put the token into panic messages). Scopes read | journal |
propose | message; journal is deliberately not a default. TOOL_SCOPES is the
authorization table: a tool absent from it is unreachable by anyone. The legacy
single token migrates to an agent named "default" — pure, idempotent, no read
path ever writes; downgrade fails closed (an old binary sees token:"" and
autostart refuses). resolve_bearer folds over every agent with no early exit
and refuses anything that is not 64 lowercase hex. A revoke is visible on the
next request.
IDENTITY. From the bearer only; no tool takes from/as/agent_id. A caller may act
only on its own proposals, and a foreign id answers exactly like an unknown id.
Names are [a-z0-9][a-z0-9_-]{0,31}; reserved words and an adversarial table
(bidi override, ·, whitespace, 33 chars, "run?") are refused by test, because
the name is rendered in the approval bar and must not be able to forge it. The
bar reads "codex · run? ⌘⏎ approve · esc deny"; an external proposal with an
empty agent is not approvable by any key.
ASYNC PROPOSALS. run_command { command, wait_ms } returns within a clamped 25 s
with today's result or a proposal_id; await_decision polls, idempotent, pending
on expiry. There is NO approval timeout: a shown proposal waits as long as the
human takes. The proposal record owns the AgentRunGuard for exactly its
lifetime, released at every terminal state including a panic path; an invariant
test pins PROPOSALS non-terminal <=> AgentState.running. Store bounded at 64.
Abuse limits: 30 s global deny cooldown, 1 pending per agent, 4 total, and a
refusal never emits agent-propose.
Also: a read-only multi-line command block above the bar so a long proposal is
readable in full (closes a documented danger-gate limitation); hub_state, a
read-only IPC command tested to contain no 64-hex substring; protocol hygiene
(2025-11-25, MCP-Protocol-Version, no Mcp-Session-Id); client handshake replays.
Found by the adversarial pass and fixed: initialize disclosed run_command to
every caller regardless of scope; the "chord rule byte-identical" test matched
its own source line and could not fail; a denial cooldown could be outrun by a
caller that read the budget before the Esc landed; the four-surface drift test
ignored descriptions.
agent.rs: zero changed lines. enter_approves, agent_propose, agent_decide,
decision_stands, MIN_REVIEW byte-identical. pty_write_internal: 3 callers, the
write still lexically after the approval check.
183 -> 211 backend tests, 49 -> 55 frontend.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by QodoAdd per-agent MCP identity and asynchronous command proposals
AI Description
Diagram
High-Level Assessment
Files changed (9)
|
Code Review by Qodo
1. Fresh token holders read history
|
| // Minted through the legacy field so `migrate` stays the ONE place that builds the | ||
| // `default` agent, and a fresh install gets exactly what 0.2.9 gave it. | ||
| cfg.token = generate_token()?; | ||
| cfg = migrate(cfg); |
There was a problem hiding this comment.
1. Fresh token holders read history 🐞 Bug ⛨ Security
enable turns an empty registry into a legacy migration, causing migrate to grant the generated default agent every scope instead of DEFAULT_SCOPES. On a fresh install or after the last agent was revoked, /mcp serve on therefore creates a bearer that can call read_journal without the explicit journal grant promised for new agents.
Agent Prompt
## Issue description
Fresh and previously emptied registries create their first agent through the legacy migration path, which grants the sensitive `journal` scope intended only for actual legacy credentials.
## Fix Focus Areas
- src-tauri/src/mcp_server.rs[148-190]
## Recommended Fix
Reserve the all-scope migration for a token loaded from an existing legacy configuration. When `enable` creates a new first agent, construct it with `DEFAULT_SCOPES` directly, while preserving the legacy token byte-for-byte and with its historical scopes only when that token existed on disk.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| // A revoked name can be re-added (the natural thing to do for the same client), and | ||
| // `await_decision` answers by name — so without this the new token could walk the | ||
| // sequential ids and collect the previous holder's exit codes and output. Terminal records | ||
| // only: a live one still owns the approval slot and its bar is still on the user's screen. | ||
| proposals::forget(name); |
There was a problem hiding this comment.
2. Replacement agents receive old results 🐞 Bug ⛨ Security
revoke_agent calls proposals::forget, which deliberately retains non-terminal proposals, while proposal lookup and await_decision authorize access using only the reusable agent name stored on each record. When that name is re-added, its replacement default-scoped token can enumerate sequential process-wide proposal IDs, poll the revoked credential’s live proposal, and retrieve its eventual verdict, command result, or output.
Agent Prompt
## Issue description
Live proposals survive revocation and are owned only by a reusable agent name. Re-adding that name creates a replacement credential that can inherit and retrieve the revoked credential’s pending work, eventual verdict, command result, or output.
## Fix Focus Areas
- src-tauri/src/mcp_server.rs[284-429]
- src-tauri/src/mcp_server.rs[395-400]
- src-tauri/src/mcp_server.rs[451-459]
- src-tauri/src/mcp_server.rs[600-611]
- src-tauri/src/mcp_server.rs[1392-1404]
## Recommended Fix
Give each agent registration an immutable, opaque generation or instance identifier, and propagate it from bearer admission into `Caller` and proposal ownership. Store that identifier on every proposal and require it, together with the proposal ID, for polling and settlement checks. Re-adding the same display name must create a new generation; revoked live proposals may continue holding their execution guard or remain on the bar if required, but they must remain inaccessible to every replacement credential.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| /// The ONE mutator of the registry: file first — it is the source of truth — then the live | ||
| /// roster, so no path can write a revoke and forget the refresh. Callers hold CONFIG_WRITE. | ||
| fn persist(path: &std::path::Path, cfg: &ServeConfig) -> Result<(), String> { | ||
| write_config(path, cfg)?; | ||
| set_agents(&cfg.agents); |
There was a problem hiding this comment.
4. Revoked tokens briefly remain valid 🐞 Bug ⛨ Security
persist writes the changed configuration before replacing the in-memory AGENTS roster used for authentication. A request admitted during that interval still resolves against the pre-revocation roster, so a revoked bearer can start another request despite the promised next-request revocation behavior.
Agent Prompt
### Issue description
A registry change is persisted to disk before the in-memory bearer-authentication roster is updated. Requests arriving between those operations authenticate against stale credentials, including credentials just revoked.
### Fix Focus Areas
- src-tauri/src/mcp_server.rs[931-942]
- src-tauri/src/mcp_server.rs[973-978]
### Recommended Fix
Use one synchronization boundary for roster persistence and admission. Hold the roster lock while writing the configuration and replacing the live roster, with the live roster changed only after a successful write; admission must acquire that same lock while resolving its bearer. This prevents an admission from observing the old roster after a successful revoke write while preserving the prior roster when persistence fails.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| /// Capped because the built-in agent's proposals come from a model and are bounded by | ||
| /// nothing — the MCP path refuses a longer `command` outright. The cut is stated in the | ||
| /// block, since what runs is still the whole thing. | ||
| fn proposal_block(text: &str) -> String { | ||
| match text.char_indices().nth(MAX_COMMAND_CHARS) { | ||
| None => text.to_string(), | ||
| Some((i, _)) => format!("{}\n… cut at {MAX_COMMAND_CHARS} characters — the rest runs unseen", &text[..i]), | ||
| } |
There was a problem hiding this comment.
3. Hidden command tails remain approvable 🐞 Bug ⛨ Security
proposal_block truncates commands after 4096 characters while explicitly retaining an unseen tail, and the approval handler does not reject a truncated proposal. Built-in-agent commands bypass the MCP command-length validation and are passed in full to agent_propose and then the PTY, so an approved visible prefix can conceal destructive shell syntax in its tail.
Agent Prompt
### Issue description
The approval UI renders only the first 4096 characters of a long proposal but still permits approval of the complete command. The built-in agent has no matching command-size limit, so it can submit a command whose unseen suffix reaches the shell.
### Fix Focus Areas
- ui/src/ai_bar.rs[110-124]
- ui/src/ai_bar.rs[411-430]
- src-tauri/src/agent.rs[325-359]
### Recommended Fix
Ensure every approvable proposal is fully reviewable. Prefer rejecting or splitting built-in-agent commands above `MAX_COMMAND_CHARS` before emitting a proposal; alternatively, mark truncated proposals unapprovable and require an explicit paged full-text review that covers the exact command before enabling approval.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Milestone 1 of the v0.3.0 plan. Built one unit at a time, then attacked by four adversaries; all four found something, all fixed with a test.
211 backend tests (was 183) · 55 frontend (was 49) · zero warnings.
agent.rshas zero changed lines vs main;enter_approves,agent_propose,agent_decide,decision_stands,MIN_REVIEWbyte-identical;pty_write_internalstill exactly 3 callers; the PTY write still lexically after the approval check.Why
The hub had one bearer token and no identity, so the bar could only say "external agent"; and
run_commandblocked the client's HTTP call until the human pressed Enter — Codex and Cursor time out at ~60 s, so two of three target agents could not use it.What
/mcp agent add|list|show|revoke). Scopesread | journal | propose | message;journaldeliberately not default. A read-only agent cannot even learnrun_commandexists. Legacy single token migrates to agentdefault; downgrade fails closed.from/as. A foreign proposal id answers exactly like an unknown one. Agent names are[a-z0-9][a-z0-9_-]{0,31}, reserved words refused, and an adversarial table (bidi,·, whitespace, 33 chars,run?) is a test — the name is rendered in the approval bar and must not be able to forge that line.codex · run? ⌘⏎ approve · esc deny. An external proposal with an empty agent is not approvable by any key.run_command { command, wait_ms }returns within 25 s with aproposal_id;await_decisionpolls. There is no approval timeout — the human takes as long as they like. Proposal store bounded at 64.hub_stateread-only IPC (no token ever; tested for 64-hex substrings). Client handshake replays for Claude Code, Codex, Cursor.Found by the adversaries and fixed
initializetold every caller thatrun_commandexists regardless of scope — the propose/poll contract is now shown only topropose-scoped agents./helpabout what a command does — descriptions are compared too.Not verified
Whether a real Codex or Cursor session survives a 3-minute unanswered proposal — needs a real client. Nothing here has run in the app.