Repository navigation
Remove runner registry — simplify replay dispatch to plain webhook POST - #166
Conversation
Replace the runner registry (DB table, AES-256-GCM encryption, HMAC auth, token management, runner UI page) with a single `REWIND_REPLAY_WEBHOOK_URL` env var. Replay dispatch becomes a plain unsigned POST; event callbacks require no authentication (trusted sidecar/localhost model). **Deleted:** - `crypto.rs` (AES-256-GCM runner token encryption) - `dispatcher.rs` (HMAC-signed outbound webhook dispatcher) - `runners_tests.rs` (runner endpoint integration tests) - `RunnersPage.tsx` (Runners UI page) - `runners` DB table + indexes - `RunnerConfig`, `auto_register()`, HMAC signing/verification from Python SDK - `aes-gcm`, `base64`, `hmac` Rust dependencies **Simplified:** - `runners.rs` routes → replay-job-only routes (no runner CRUD) - `AppState` → `replay_webhook_url` replaces `crypto`/`dispatcher` - `reaper.rs` → job-timeout-only (no runner references) - `RunReplayButton.tsx` → direct dispatch without runner picker - `runner.py` → `asgi_handler(body_bytes, handler)` with no config - `api.ts` → removed runner CRUD methods and types **Version bumps (breaking):** - Rust workspace: 0.14.10 → 0.15.0 - Python SDK: 0.15.4 → 0.16.0 - Python MCP: 0.13.9 → 0.13.10 - CLI_VERSION: 0.14.10 → 0.15.0 Co-authored-by: Cursor <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
risjai
left a comment
There was a problem hiding this comment.
Review: Remove runner registry — simplify replay dispatch to plain webhook POST
Overview
Massive simplification — net -5,212 lines removing the runner registry, AES-256-GCM token encryption, HMAC-signed dispatch, and the Runners UI page. Replaces all of that with a single REWIND_REPLAY_WEBHOOK_URL env var and unsigned POST. The sidecar/localhost trust model justifies dropping crypto, and the simplification is genuinely clarifying.
That said, this PR moves a meaningful amount of authority from the application layer (token → ownership check) to the network layer ("trust localhost"). Worth being explicit about that tradeoff and hardening the few sharp edges that remain.
Top concerns (see inline)
Security / correctness:
POST /api/replay-jobs/{id}/eventsis now fully unauthenticated. Anyone with network reach to the server can mutate any job's state — mark it errored, completed, push fake progress. Acceptable in single-pod loopback; meaningful risk if the server is ever reachable from neighboring pods (no NetworkPolicy, sidecar shared with untrusted containers, etc.). Document the threat model explicitly or add a lightweight per-job dispatch token (round-trip the value the server sent in the dispatch payload).reqwest::Client::builder().build().unwrap_or_default()silently falls back to a defaultClient(no timeout) ifbuild()fails. Use.expect("…")or build the client once at startup and clone.- No SSRF guard on
REWIND_REPLAY_WEBHOOK_URL. Previous registration path validated webhook URLs viavalidate_export_endpoint. Now the server dispatches to whatever env var an operator sets — including cloud metadata IPs if misconfigured. Operator-controlled, but the prior gate is gone. - No DB migration to drop the now-orphaned
runnerstable. Persistent SQLite DBs upgrading from 0.14.x will keep the table indefinitely, plus the old FK onreplay_jobs.runner_id(SQLite ignoresCREATE TABLE IF NOT EXISTSschema changes on existing tables). WithemptyDirnon-issue; with PVCs, this leaks rows + may surprise on restore.
Quality / coverage:
- The
tokio::spawnblock acquiresstore_arc.lock()three separate times. Functionally fine (no lock held across.await) but fragile and harder to reason about than one consolidated section. - No test asserts the new "events accepted without auth" behavior —
replay_jobs_tests.rswas rewritten but I don't see a positive test forPOST /eventswith no headers, nor a 503 test for the unset-webhook path. - Test plan checkbox for E2E dev1 deploy is unchecked — flagging since this PR also requires a Helm-chart change (
REWIND_REPLAY_WEBHOOK_URL) that isn't in this diff.
UX:
RunReplayButtonwill dispatch even whenREWIND_REPLAY_WEBHOOK_URLis unset → 503. The old flow surfaced "no active runners" with a CLI fallback. Consider checking server config / surfacing a friendly state.
Strengths
- Simplification is real and well-motivated. The crypto / HMAC / token-rotation surface area was load-bearing for a multi-host deployment we never built.
- Version bumps consistent across all 7 files (Rust 0.14.10→0.15.0, MCP 0.13.9→0.13.10, SDK 0.15.4→0.16.0). Major-style bumps appropriate for the breaking SDK change.
- Test fixtures cleanly migrated; old
enable_loopback_webhook_dev_escape_once()plumbing gone. - Python SDK is dramatically cleaner — removing the replay-protection / signature-verification machinery is a real readability win for runner authors.
- Removing
aes-gcm,base64,hmacfrom deps reduces binary size and audit surface.
Ready to merge after the auth comment is resolved (either by documenting the trust model or adding a per-job nonce). Other items can ship as follow-ups.
| Router::new().route( | ||
| "/api/replay-jobs/{id}/events", | ||
| post(post_replay_job_event), | ||
| ) |
There was a problem hiding this comment.
No authentication on event ingestion. Previously this handler required X-Rewind-Runner-Auth, looked up the runner by hash, and verified the runner owned the job (job.runner_id == runner.id). All three checks are gone (see the handler at line ~426).
In a single-pod sidecar where only 127.0.0.1 is reachable, this is fine. But this route is mounted outside bearer auth (here), so any process that can reach the rewind server's port can:
- Mark any job as
completedorerrored - Push fabricated progress
- DoS legitimate replays by racing illegal transitions
Suggested mitigation: include a one-time-use dispatch token in the outbound webhook payload (the server generates it, stores it on the job row, and the runner echoes it back in X-Rewind-Dispatch-Token). That preserves the simplification (no key management, no DB schema for tokens beyond a single column) while restoring "only the runner that received this dispatch can post events for it."
At minimum, document the threat model in the docstring above this route — "server MUST be reachable only from the trusted runner; any reachable principal can mutate any job's state." Future operators reaching for this in a non-sidecar deployment need to know.
| let client = reqwest::Client::builder() | ||
| .timeout(std::time::Duration::from_secs(10)) | ||
| .build() | ||
| .unwrap_or_default(); |
There was a problem hiding this comment.
Silent timeout fallback. reqwest::Client::builder()...build().unwrap_or_default() swallows builder errors and returns a default Client without the 10-second timeout. If TLS init or DNS resolver setup fails, dispatches now hang indefinitely instead of failing fast.
Suggest:
.build()
.expect("reqwest client builder should never fail with these options")or build the client once at AppState init time and clone it into the spawn task — same effect, no per-dispatch construction cost.
| }), | ||
| ) | ||
| })?; | ||
| let webhook_url = state.replay_webhook_url.clone().ok_or_else(|| { |
There was a problem hiding this comment.
No SSRF validation on REWIND_REPLAY_WEBHOOK_URL. The old registration path called validate_export_endpoint(webhook_url) (with the REWIND_ALLOW_LOOPBACK_WEBHOOKS=1 dev escape) before persisting. Now the env var is dispatched to verbatim — including to 169.254.169.254, RFC1918 IPs, or external services if misconfigured.
Operator-controlled config so the practical risk is low, but consider running crate::url_guard::validate_export_endpoint once at startup (in bootstrap_replay_webhook_url) so a misconfig fails the server boot instead of leaking metadata creds on the first replay. Keep the loopback-escape env var so dev still works.
| )?; | ||
| self.conn.execute( | ||
| "CREATE INDEX IF NOT EXISTS idx_replay_jobs_state ON replay_jobs(state)", | ||
| [], |
There was a problem hiding this comment.
Migration concern: runners table is no longer created here, but existing SQLite DBs from 0.14.x will keep:
- The orphaned
runnerstable + indexes - The old
replay_jobs.runner_idFK torunners(id)(SQLite doesn't update column constraints viaCREATE TABLE IF NOT EXISTS— the new table-def above won't replace the existing schema)
With emptyDir (the documented sidecar pattern) this is invisible. With persistent storage (PVC, host volume, restored backup), users carry the dead table forever, and the residual FK can surprise tooling that introspects the schema.
Consider adding an explicit one-time migration: DROP TABLE IF EXISTS runners; (FK is dropped with the table). That way old persistent DBs upgrade cleanly.
| Err(e) => Some(format!("webhook dispatch failed: {e}")), | ||
| }; | ||
| if let Some(err_msg) = &outcome_err { | ||
| if let Ok(store) = store_arc.lock() { |
There was a problem hiding this comment.
Three separate store_arc.lock() acquisitions in this spawn task (one for the error path, one for the success path, one for the WebSocket broadcast read). Functionally correct since no lock is held across .await, but combining the success/error mutation and the post-mutation read into a single locked block would be easier to reason about and shave two lock-acquire/release cycles per dispatch. Minor.
| config: RunnerConfig, | ||
| headers: dict[str, str], | ||
| body_bytes: bytes, | ||
| handler: HandlerFn, |
There was a problem hiding this comment.
Breaking-change surface: removing RunnerConfig (and auto_register, just added in #165) and changing asgi_handler's signature from (config, headers, body_bytes, handler) → (body_bytes, handler, base_url) will break every existing runner integration on upgrade.
The SDK version bump (0.15.4 → 0.16.0) signals breakage, which is correct, but please add a CHANGELOG / migration note to python/CHANGELOG.md (or similar) documenting:
- Drop
from_env(); drop theREWIND_RUNNER_TOKENenv var - Set
REWIND_REPLAY_WEBHOOK_URLon the server instead - New
asgi_handlersignature
Without that, every existing user pip-upgrading will hit a TypeError they have to debug from scratch.
| from ``payload.base_url`` so event callbacks land at the | ||
| dispatcher's server, not the runner's local config. | ||
| ``(202, {"job_id": ...})`` immediately so the Rewind server's | ||
| timeout is satisfied. |
There was a problem hiding this comment.
Docstring says "so the Rewind server's timeout is satisfied" — fine, but consider also stating the new auth posture explicitly: "No signature verification — relies on the runner being reachable only from the dispatching server." Helps the user reading this code in isolation understand the trust boundary that replaced the old HMAC check.
| <div className="flex justify-end gap-2 pt-2"> | ||
| <button | ||
| onClick={submit} | ||
| disabled={isDispatching} |
There was a problem hiding this comment.
If the server boots without REWIND_REPLAY_WEBHOOK_URL, this button will dispatch and the user gets a 503 (replay-job dispatch unavailable). Old flow used a runner list + a CLI fallback for the empty case — that affordance is gone.
Not a blocker, but consider adding a config check (e.g. expose replay_configured: bool on a /api/server-info endpoint) and grey out the button + show "Set REWIND_REPLAY_WEBHOOK_URL on the rewind server to enable" when false. Alternatively keep the CLI fallback string as a help link.
| //! dispatcher's outbound webhook is exercised against a tokio | ||
| //! TcpListener stub spun up per test. | ||
| //! Post runner-registry removal: dispatch goes to a configured webhook URL | ||
| //! (plain POST, no HMAC), events are accepted without runner-auth headers. |
There was a problem hiding this comment.
I don't see a test that verifies POST /api/replay-jobs/{id}/events accepts events with no auth headers at all (the new contract called out here). Worth adding one — both the positive case (no headers, 202 accepted) and a regression guard against accidentally re-introducing the auth requirement (so the test fails the moment someone restores a header check, instead of silently passing because every test happens to set a header).
Also missing: a test for what happens when REWIND_REPLAY_WEBHOOK_URL is unset (setup_no_webhook exists but I don't see it asserting the 503 path on dispatch).
|
|
||
| [workspace.package] | ||
| version = "0.14.10" | ||
| version = "0.15.0" |
There was a problem hiding this comment.
Major-bump-style version (0.14.10 → 0.15.0) is the right call given the SDK + API contract changes are breaking. The post-merge checklist in CLAUDE.md requires a GitHub Release to trigger CI binaries — please create the v0.15.0 tag promptly after merge so the SDK 0.16.0 (CLI_VERSION="0.15.0") doesn't ship pointing at a non-existent release.
1. **Per-job dispatch token** (blocker): Server generates a random `dispatch_token` on job creation, stores it on the row, and sends it in the webhook payload. The events endpoint now requires `X-Rewind-Dispatch-Token` header matching the stored token (403 on mismatch). Python SDK's ProgressReporter passes it automatically. 2. **reqwest .expect()**: Replace `.unwrap_or_default()` with `.expect(...)` so a builder failure panics with a clear message instead of silently dropping the timeout. 3. **SSRF guard on REWIND_REPLAY_WEBHOOK_URL**: New sync `validate_webhook_url_sync()` in url_guard.rs validates the URL at startup — rejects cloud metadata / RFC 1918 / link-local IPs but explicitly allows loopback (sidecar model). Invalid URLs disable replay dispatch with a logged error. 4. **DROP TABLE IF EXISTS runners**: One-time migration in db.rs cleans up the orphaned `runners` table from pre-0.15.0 databases. 5. **Missing tests**: Added `event_endpoint_rejects_missing_dispatch_token` and `event_endpoint_rejects_wrong_dispatch_token`. Existing `create_replay_job_returns_503_when_no_webhook_configured` already covers the 503 path. 6. **Dispatched comment**: Added explanatory comment on the Pending→Dispatched state advance before the network call to document the race prevention invariant. Also consolidated the three `store_arc.lock()` calls in the dispatch spawn block into a single lock acquisition. Co-authored-by: Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]>
Summary
REWIND_REPLAY_WEBHOOK_URLenv var on the rewind sidecar.aes-gcm,base64,hmaccrate dependencies.0.14.10 → 0.15.0, Python SDK0.15.4 → 0.16.0, MCP0.13.9 → 0.13.10.What changed
runnerstable,runners.rsreplay_jobs.rs(extracted replay-job types only)crypto.rs,dispatcher.rs,runners_tests.rsrunners.rs→ replay-job routes only;AppState.replay_webhook_urlreplacescrypto/dispatcher/base_urlRunnerConfig,auto_register(), HMAC signing/verificationasgi_handler(body_bytes, handler, base_url)— no authRunnersPage.tsx, runner nav/routesRunReplayButtondispatches directly without runner pickeraes-gcm,base64,hmacWhy
The runner registry was designed for a multi-runner, multi-host architecture. In practice, rewind runs as a sidecar on the same pod as the agent — all traffic is localhost. The crypto/HMAC/token machinery added complexity, failure modes (registration failures, token rotation), and surface area without security benefit in the sidecar model.
Test plan
cargo check -p rewind-store -p rewind-web— compiles cleancargo test -p rewind-store -p rewind-web— all tests passnpx tsc --noEmitinweb/— no TypeScript errorspython/tests/test_runner.py)REWIND_REPLAY_WEBHOOK_URL) and verify replay dispatch works end-to-endMade with Cursor