Repository navigation
feat(jobs): multi-agent awareness — job owners, presence, concurrency e2e - #76
Conversation
… e2e Several OAuth clients can share one host; prove they run side by side and let them see each other, without adding a tool. - Every /mcp request carries the Agent its bearer was issued to (auth::require_auth -> request extensions -> rmcp Parts -> tools). - Schema v7: jobs.client_id/client_name, clients.client_name/last_used_unix. Last use is rewritten at most once a minute per client. - job(action="list") opens with the agents active in the last 15 min (the caller as `you`) and gives each job `by`; poll/kill of another agent's job still works and says whose it is. - mcp-ssh jobs gains a BY column; mcp-ssh sessions lists each logged-in agent's last activity. - client_name from DCR is untrusted: control/invisible chars stripped, whitespace collapsed, <=32 chars; labels carry a hash tag, never the client_id. - e2e: two_agents_run_commands_and_jobs_concurrently, agents_see_each_other_and_whose_job_is_whose. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🟡 Reviewed5 actionable comment(s) · grounded on your code 🤖 developerz.ai — automated review, running on your model and your box. |
There was a problem hiding this comment.
Review summary — 37 file(s), 5 finding(s).
Critical 0 · Major 1 · Minor 4 · Nit 0
Adds per-job OAuth-client ownership, a presence line in job(action="list") and owner columns in the admin CLI. Low risk: the auth guard and token hashing are unchanged, and the v7 migration only adds nullable columns.
| File | Findings |
|---|---|
docs/architecture.md |
1 minor |
src/oauth/store.rs |
1 minor |
src/oauth/store/presence.rs |
1 major |
src/oauth/store/tests.rs |
2 minor |
- test files were not shown to the reviewer — this diff touched no path recognised as a test, so no assertion was available to read the change against
🤖 developerz.ai review — automated, running on your model and your box. What is this?
| if last_used.is_none_or(|at| now - at >= TOUCH_EVERY) { | ||
| conn.execute( | ||
| "UPDATE clients SET last_used_unix = ?1 WHERE client_id = ?2", | ||
| (now, &client_id), | ||
| )?; | ||
| } |
There was a problem hiding this comment.
major · bug require_auth now goes through authenticate, which writes the client's last-use time.
| if last_used.is_none_or(|at| now - at >= TOUCH_EVERY) { | |
| conn.execute( | |
| "UPDATE clients SET last_used_unix = ?1 WHERE client_id = ?2", | |
| (now, &client_id), | |
| )?; | |
| } | |
| if last_used.is_none_or(|at| now - at >= TOUCH_EVERY) | |
| && let Err(error) = conn.execute( | |
| "UPDATE clients SET last_used_unix = ?1 WHERE client_id = ?2", | |
| (now, &client_id), | |
| ) | |
| { | |
| tracing::warn!(%error, "could not record the client's last use"); | |
| } |
If that UPDATE fails (the disk filled by a runaway job log, or the CLI holding the write lock past the busy timeout), the ? turns it into StoreUnavailable and every /mcp request gets a 503, so agents lose access exactly when they need it to free disk.
| - **Registered clients** — `clients` (`client_id` → redirect URIs, no secrets), capped at 1000; a client at least 7 days old that holds no live token is swept. | ||
| - **Job metadata** — id, title, status (`running`/`exited`/`failed`), exit code or error, start/finish time, process group + boot id, and a saved **output tail** (last 500 lines, ≤256 KiB). This is what makes `job(action="list")` show history across restarts. | ||
| - **Registered clients** — `clients` (`client_id` → redirect URIs, the cleaned `client_name` it registered, when it last used a bearer; no secrets), capped at 1000; a client at least 7 days old that holds no live token is swept. The last-use time is rewritten at most once a minute per client, so a busy agent's requests stay reads; it is what `job(action="list")`'s presence line and `mcp-ssh sessions` read. | ||
| - **Job metadata** — id, title, status (`running`/`exited`/`failed`), exit code or error, start/finish time, process group + boot id, the OAuth client that started it (id + name, so the owner still reads right after the client is swept), and a saved **output tail** (last 500 lines, ≤256 KiB). This is what makes `job(action="list")` show history across restarts. |
There was a problem hiding this comment.
minor · docs docs/architecture.md:64 still says job(action="list") "exposes only the id and state", but ListedJob (src/tools/job_render.rs:46) now adds by, and every list reply opens with a presence line. Update line 64 (and the job row in README.md:74) to mention by and the presence line, while keeping the claim that command text is never exposed.
| None => Ok(false), | ||
| } | ||
| }) | ||
| .call(move |conn| live_token_client(conn, &hash, now).map(|client| client.is_some())) |
There was a problem hiding this comment.
minor · test The design says the stream re-check (validate_hash) never counts as activity, so an idle open SSE stream does not keep an agent active. No test pins that: if a later change routes the re-check through authenticate, nothing fails. Add a store test that calls validate_hash on a live bearer and asserts last_used_unix stays NULL.
| // A second use within a minute is a read: the time doesn't move. | ||
| store | ||
| .authenticate(&hash_token(&bearer)) | ||
| .await | ||
| .unwrap() | ||
| .unwrap(); | ||
| assert_eq!(last_used(&db).await, first); |
There was a problem hiding this comment.
minor · test The throttle test only checks that a second authenticate within a minute leaves last_used_unix alone.
A regression that never refreshes the time after the first write still passes, and that agent would drop out of presence after 15 minutes while busy. Backdate last_used_unix by 61s, call authenticate again, and assert the time moved forward.
| let logged_in = store.logged_in_agents().await.unwrap(); | ||
| let names: Vec<_> = logged_in.iter().map(|a| a.agent.name()).collect(); | ||
| assert_eq!( | ||
| names, | ||
| [Some("beta"), Some("alpha"), Some("idle")], | ||
| "most recent first, never-used last" | ||
| ); | ||
| assert_eq!(logged_in[2].last_used_unix, None); |
There was a problem hiding this comment.
minor · test Every client in active_agents_are_those_seen_in_the_window_newest_first holds a live token.
If the live-token WHERE client_id IN (...) filter in logged_in_agents were dropped, the test would still pass and mcp-ssh sessions would list agents whose logins have expired. Expire one client's access and refresh tokens and assert it is not in logged_in_agents.
Version bump to 2.2.0: Cargo.toml, Cargo.lock, changelog (unreleased → docs/changelog/2.2.0.md, CHANGELOG.md index). Ships #76 (multi-agent awareness, schema v7). No source change. Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
What
Answers "does it support 2 agents on 1 server, and can they see each other?" — yes, and now provably so:
job(action="list")opens with a presence line and gives each job aby; poll/kill of another agent's job says whose it is; the admin CLI shows owners and last activity. Still 3 tools — new behaviour lives onjob(action="list"|"poll"|"kill").(
evil[31m forged-rowis the e2e's hostileclient_name"evil\x1b[31m\nforged-row"after cleaning.)Why
The owner asked whether several agents can share one host and whether they know about each other. Before this PR they already ran concurrently, but no test proved it, and an agent had no way to tell its own jobs from another agent's.
Changes
src/agent.rs(new):Agent(client id + cleaned name) andClientName::parse.client_namefrom DCR is untrusted, so control characters and zero-width/bidi characters are stripped, whitespace is collapsed, and names are capped at 32 chars. The label is<name>#<first 4 hex of SHA-256(client_id)>, which tells two "Claude Code" clients apart without showing any part of theclient_id.Debugshows only the label.src/auth.rs:require_authnow callsStore::authenticate, which returns the bearer'sAgentand inserts it into the request extensions. rmcp passes the HTTPPartsto each tool, so attribution is per request, not per session.src/oauth/store/presence.rs(new):authenticate(records last use at most once a minute per client, so busy agents' requests stay reads),active_agents(15 min window),logged_in_agents. The stream re-check (validate_hash) does not count as activity, so an idle open SSE stream doesn't keep an agent "active".add_agent_identity):jobs.client_id,jobs.client_name(stored on the row, so the owner still shows after the client is swept),clients.client_name,clients.last_used_unix.JobMeta { title, owner }replaces thetitlearg ofJobStore::run/JobRepo::insert_running. This avoids an 8-argument fn and accounts for most of the test churn. AddsJobStore::owner;JobSummary/JobRowcarry the owner.src/tools/caller.rs(new), presence +byrendering injob_render.rs, anagentlabel on every dispatch span, and updatedjobdescription and server instructions.mcp-ssh jobsgets aBYcolumn;mcp-ssh sessionsadds an "agents (logged in, most recently active first)" section with last-active times.Decisions to flag
job(action="list")is no longer bare JSON: the presence line comes first. It already wasn't strict JSON when paged (the[older jobs: …]footer). Called out in the changelog.by: "unknown"(agent) and-(CLI).Concurrency findings
No defect found. Audited the paths:
Db::call: std mutex taken only insidespawn_blocking.jobsmap: tokio mutex, released before every.awaiton I/O.kill_reason: guard dropped before escalation.Tools.create_newreservation, now also covered by e2e.SQLite writes stay serialized by design (one connection) and are low-frequency.
Verification
bin/checkgreen: fmt, clippy-D warnings, 309 unit, 13 e2e, module_map, public_tree.tests/e2e/agents.rs):two_agents_run_commands_and_jobs_concurrently:bgsleep 3job in the same second under the same title, and get distinct ids.agents_see_each_other_and_whose_job_is_whose:byvalues cross-checked from both sides.mcp-ssh jobs --allshows owners inBY;mcp-ssh sessionsshows last-active.authenticatethrottling and expirybyand owner notesAgentsurvives auth → rmcp → tool (you (client#…))Touches
src/auth.rs, so it needs a security-minded review.🤖 Generated with Claude Code