Skip to content

Remove runner registry — simplify replay dispatch to plain webhook POST - #166

Merged
risjai merged 3 commits into
masterfrom
rjain/remove-runner-registry
May 10, 2026
Merged

risjai merged 3 commits into
masterfrom
rjain/remove-runner-registry

Conversation

@risjai

@risjai risjai commented May 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Removes the entire runner registry (DB table, AES-256-GCM encryption, HMAC-signed dispatch, token management, Runners UI page) and replaces it with a single REWIND_REPLAY_WEBHOOK_URL env var on the rewind sidecar.
  • Replay dispatch is now a plain unsigned POST to the configured URL — the sidecar/localhost trust model makes cryptographic authentication unnecessary.
  • Net -5,212 lines across Rust backend, Python SDK, Web UI, and tests. Removes aes-gcm, base64, hmac crate dependencies.
  • Breaking change — version bumps: Rust 0.14.10 → 0.15.0, Python SDK 0.15.4 → 0.16.0, MCP 0.13.9 → 0.13.10.

What changed

Layer Deleted Simplified
Rust store runners table, runners.rs replay_jobs.rs (extracted replay-job types only)
Rust web crypto.rs, dispatcher.rs, runners_tests.rs runners.rs → replay-job routes only; AppState.replay_webhook_url replaces crypto/dispatcher/base_url
Python SDK RunnerConfig, auto_register(), HMAC signing/verification asgi_handler(body_bytes, handler, base_url) — no auth
Web UI RunnersPage.tsx, runner nav/routes RunReplayButton dispatches directly without runner picker
Cargo deps aes-gcm, base64, hmac —

Why

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 clean
  • cargo test -p rewind-store -p rewind-web — all tests pass
  • npx tsc --noEmit in web/ — no TypeScript errors
  • Python SDK tests pass (python/tests/test_runner.py)
  • Deploy to dev1 with updated Helm chart (REWIND_REPLAY_WEBHOOK_URL) and verify replay dispatch works end-to-end

Made with Cursor

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]>
@vercel

vercel Bot commented May 10, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
rewind Ready Ready Preview, Comment May 10, 2026 2:11pm

@risjai risjai left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}/events is 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 default Client (no timeout) if build() 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 via validate_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 runners table. Persistent SQLite DBs upgrading from 0.14.x will keep the table indefinitely, plus the old FK on replay_jobs.runner_id (SQLite ignores CREATE TABLE IF NOT EXISTS schema changes on existing tables). With emptyDir non-issue; with PVCs, this leaks rows + may surprise on restore.

Quality / coverage:

  • The tokio::spawn block acquires store_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.rs was rewritten but I don't see a positive test for POST /events with 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:

  • RunReplayButton will dispatch even when REWIND_REPLAY_WEBHOOK_URL is 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, hmac from 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),
)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 completed or errored
  • 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.

Comment thread crates/rewind-web/src/runners.rs Outdated
let client = reqwest::Client::builder()
.timeout(std::time::Duration::from_secs(10))
.build()
.unwrap_or_default();

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(|| {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)",
[],

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Migration concern: runners table is no longer created here, but existing SQLite DBs from 0.14.x will keep:

  1. The orphaned runners table + indexes
  2. The old replay_jobs.runner_id FK to runners(id) (SQLite doesn't update column constraints via CREATE 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.

Comment thread crates/rewind-web/src/runners.rs Outdated
Err(e) => Some(format!("webhook dispatch failed: {e}")),
};
if let Some(err_msg) = &outcome_err {
if let Ok(store) = store_arc.lock() {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Drop from_env(); drop the REWIND_RUNNER_TOKEN env var
  2. Set REWIND_REPLAY_WEBHOOK_URL on the server instead
  3. New asgi_handler signature

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment thread Cargo.toml

[workspace.package]
version = "0.14.10"
version = "0.15.0"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
@risjai
risjai merged commit bd1eeef into master May 10, 2026
6 checks passed
@risjai
risjai deleted the rjain/remove-runner-registry branch May 10, 2026 14:17

This branch was successfully deployed

1 active deployment
Preview — 200f9680 Deployed May 10, 2026 by vercel[bot]
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