Skip to content

copper-cloud 0.13.1: device agent relay fixes - #10

Merged
astherath merged 1 commit into
mainfrom
fix/device-agent-0.13.1
Oct 31, 2026
Merged

astherath merged 1 commit into
mainfrom
fix/device-agent-0.13.1

Conversation

@astherath

Copy link
Copy Markdown
Contributor

Closes the four low-severity issues found in the 0.13.0 device agent relay review. No migrations; 0.13.0 ⇄ 0.13.1 is a binary swap either way.

  1. Lost request on a replaced stream. A request sent down a stream that died before the reply waited out the full 200 s deadline. Now a call stays pending when its stream ends; every stream the device (re)attaches gets each request still pending on its link again (same id, deadline_ms = time left, oldest first), right after hello. The phone already answers a seen request id with its stored reply. Calls with no stream still fail after the 15 s offline grace. — hub.rs (attach re-delivers; Pending keeps the frame + deadline). Test: a_replaced_stream_gets_the_pending_request_again (stream A dropped mid-call → B gets the same id → reply on B → result in < 10 s of a 60 s deadline; then the superseded-while-open case).
  2. Per-link concurrency cap. At most 8 calls in flight per link (DeviceAgentTuning::max_pending_per_link); one more answers at once with isError "Copper on is busy with other calls; try again shortly." (status busy), nothing sent to the device. — hub.rs (begin → Result<Call, Refused>), mcp.rs. Test: calls_past_the_per_link_cap_answer_busy_at_once (JSON + SSE, any token, room again after a reply).
  3. Agents that never read their SSE answer. The relay used to run inside the response body, so an unread answer stalled its deadline and kept the hub entry. Each call now waits in its own task; the agent's response only holds the receiving ends (dropping them still cancels). Hub progress is a bounded try_send (32) and the agent's progress buffer is bounded (32, newest dropped), so a frames POST never waits. — mcp.rs (relay task, relayed, answer_stream). Test: an_agent_that_never_reads_its_answer_still_ends_at_the_deadline (raw TCP agent with a 4 KiB receive buffer never reads; 16 MiB of progress; every POST returns at once; another agent's call goes through; cancel at the deadline and the hub is empty). This test fails on 0.13.0 (no cancel ever reaches the device).
  4. User disable/delete didn't touch the hub. Admin API disable/delete now closes the user's streams with revoked, fails their calls (status user_revoked) and drops their rate-limit buckets (the hub's own per-token GCRA replaces governor there, so buckets can be dropped per user). The CLI (admin disable-user / delete-user) is another process that only touches the database, so a user sweep (every 10 s, a single query, only while the hub holds anything) brings the running server in line. — hub.rs (revoke_user, users), mod.rs (revoke_user, sweep_users, start_user_sweep), app.rs, admin_api.rs. Tests: admin_api_disable_and_delete_close_the_users_streams_and_calls, cli_disable_and_delete_reach_the_running_server_through_the_sweep.

Docs: api.md (re-delivery, busy, slow readers, revoked), admin-api.md, architecture.md, security.md, operations.md (statuses busy, user_revoked; CLI note), CHANGELOG.md, docs/v0.13.1.md; version 0.13.1.

Validation (native PostgreSQL): cargo fmt --all -- --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspace: 259 passed, 0 failed (device_agent 22/22, five runs at --test-threads=4; core device_agent units 19/19).

…cap, non-reading agents, disabled users)

- Re-delivery: a call stays pending when its stream ends without a reply; every stream a
  device (re)attaches gets each request still pending on its link again (same id, deadline_ms =
  time left), oldest first. Pending calls still fail after the 15 s offline grace.
- Per-link cap: at most 8 calls in flight per link (DeviceAgentTuning::max_pending_per_link);
  one more answers at once, isError "Copper on <device> is busy with other calls; try again
  shortly." (status busy).
- Each relayed call waits in its own task: it ends at its deadline / cancel / revoke / shutdown
  whether or not the agent reads its SSE answer; hub progress is a bounded try_send (32) and the
  agent's progress buffer is bounded (32, newest dropped), so a slow reader never holds up a
  frames POST or other calls.
- Disabling or deleting a user (admin API) closes their streams with `revoked`, fails their
  calls (status user_revoked) and drops their rate-limit buckets (the hub's own per-token GCRA
  replaces governor there). `copper-cloud admin disable-user` / `delete-user` work on the
  database; a user sweep (10 s, only while the hub holds anything) reaches the running server.
- Tests: re-delivery after a dropped and a superseded stream, busy cap (JSON + SSE), an agent
  that never reads (16 MiB progress flood, other calls proceed, cancel at the deadline), admin
  API and CLI disable/delete; hub unit tests.
- Docs: api.md (re-delivery, busy, slow readers, revoked), admin-api, architecture, security,
  operations; CHANGELOG + docs/v0.13.1.md; version 0.13.1.
@astherath
astherath merged commit 744a6a3 into main Oct 31, 2026
2 checks passed
@astherath
astherath deleted the fix/device-agent-0.13.1 branch October 31, 2026 22:36
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.

1 participant