Skip to content

feat(gate): minimal asynchronous polling for the Muse route - #45

Merged
chaodu-agent merged 2 commits into
mainfrom
muse-async-poll-impl
Nov 22, 2026
Merged

chaodu-agent merged 2 commits into
mainfrom
muse-async-poll-impl

Conversation

@chaodu-agent

Copy link
Copy Markdown
Contributor

Draft. Not for merge until reviewed.

Implemented

  • Async admission: with hold_mode = "async", a held grant is answered at once with 202 and a body holding only status, request_id and poll_token (128-bit random; only its sha256 is stored, compared in constant time).
  • Polling: GET /poll/<token>?wait=N. wait is validated before the token lookup (missing = 0, cap 25; non-numeric, negative, empty or repeated gives 400). Statuses: pending, approved/forwarded outcomes, denied, expired, send_failed, send_unknown, dropped (the design's final statuses). The poll store is read-only and has no approve path.
  • Final-status window: a final status stays readable for 60 s. After that, and for an unknown token or a wrong method, the answer is the same uniform 404.
  • Config switch: [passthrough] hold_mode = "blocking" | "async", default blocking. The blocking route is unchanged; /poll/ is only intercepted in async mode.
  • async_hold_secs: hold lifetime in async mode, 5..=600, default 120.
  • Held record is written first under the table lock; a write failure returns audit_unavailable before any token or notification. Approve versus expiry is decided on the table mutex, first wins.
  • Per-token poll limit (implementer choice, the design gives no numbers): 10 polls per second, 429 rate_limited with Retry-After: 1.

Changed files

  • crates/ap-core/src/config.rs
  • crates/ap-proxy/src/lib.rs
  • crates/ap-proxy/src/async_poll.rs, async_poll/tests.rs
  • crates/ap-proxy/src/hold/mod.rs
  • crates/ap-proxy/src/passthrough.rs
  • crates/ap-proxy/src/passthrough/hold_path.rs, hold_path/async_mode.rs
  • crates/ap-proxy/src/passthrough/hold_tests.rs, async_tests.rs

Test results (macmini arm64, umask 022)

  • cargo fmt --check: exit 0
  • cargo clippy --workspace --all-targets -- -D warnings: exit 0
  • cargo test --workspace: exit 0, 0 failed
  • 33 new tests matching "async" (10 store/poll unit, 1 error-class, 21 end to end, 1 config). Matrix tests need feature matrix-upstream and were not run.

Known pre-existing reds (fail on base, not caused by this PR)

  • Three netguard tests under umask 0002 (pass under umask 022).
  • Matrix PT-09 and P1-09.

Review

One round, HIGH/MEDIUM only: APPROVED, no HIGH or MEDIUM findings. LOW notes: config keys sit under [passthrough] and apply to every held grant (there is no muse. section); poll rate limit numbers are an implementer choice.

Not as designed

  • Config is under [passthrough], not a muse. section.
  • Evidence line is written once at the 202; the task writes none.
  • View-page remaining time (limits.hold) is fixed at startup from async_hold_secs.

Implements docs/design/muse-async-poll.md: [passthrough] hold_mode = async answers
202 with request_id and a 128-bit poll token (sha256 stored, constant-time compare);
GET /poll/<token>?wait=N returns pending or a final status (approved_and_sent, denied,
expired, dropped, send_failed, send_unknown) for 60 s, then a uniform 404. Reuses the
hold table, start claim, audit writer and Telegram notification; blocking stays default.

Checks (macmini arm64, umask 022, ~/tmp/auth-proxy-muse-async-poll-impl-20261122105632):
- cargo fmt --check: exit 0
- cargo clippy --workspace --all-targets -- -D warnings: exit 0
- cargo test --workspace: exit 0, no failures (known reds: netguard x3 under umask 0002,
  matrix PT-09/P1-09; not triggered)
…t refusals, drop poll rate limit

- hold_mode and async_hold_secs move from [passthrough] to the route; load requires a
  passthrough route with a hold grant. Other held routes keep blocking, dedupe and supersede.
- Detached async forwards are tracked (AsyncTasks) and included in the shutdown wait
  (request_deadline_secs + 2). A cut after forward_started ends as send_unknown (completed,
  code upstream_reset); before it, dropped.
- Admission refused after the held record (cooldown, identity_cap, table_full) writes a terminal
  hold record for that request_id with the refusal code and status 503.
- Remove the per-token poll rate limit and the 429 rate_limited response.

Checks on macmini (arm64, umask 022): see PR comment / follow-up commit trailer.
@chaodu-agent
chaodu-agent marked this pull request as ready for review November 22, 2026 16:18
@chaodu-agent
chaodu-agent merged commit 25d4c6d into main Nov 22, 2026
1 check passed
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