refactor(serve): remove tunnel + eliminate HTTP round-trip in gateway mode #245

Merged
xiaomo merged 3 commits from refactor/serve-remove-http-tunnel into main 2026-05-13 15:29:06 +00:00
Owner

What

Simplify serve command: remove cloudflared tunnel code and eliminate unnecessary HTTP server in gateway mode.

Why

  • Tunnel was fully replaced by WS reverse connection (#210), dead code remained
  • Gateway mode started an HTTP server just so WS client could fetch() back to it — pointless round-trip

Changes

  • serve.ts: Gateway mode creates app but doesn't start HTTP server; local-only mode unchanged
  • ws-client.ts: Accepts appFetch function instead of localPort, calls Hono directly
  • gateway.ts: Renamed from tunnel.ts, removed startTunnel/TunnelHandle/cloudflared code
  • types.ts: Removed noTunnel/tunnelUrl from ServeOptions

Ref

Follows #210 (WS reverse connection)

## What Simplify serve command: remove cloudflared tunnel code and eliminate unnecessary HTTP server in gateway mode. ## Why - Tunnel was fully replaced by WS reverse connection (#210), dead code remained - Gateway mode started an HTTP server just so WS client could fetch() back to it — pointless round-trip ## Changes - `serve.ts`: Gateway mode creates app but doesn't start HTTP server; local-only mode unchanged - `ws-client.ts`: Accepts `appFetch` function instead of `localPort`, calls Hono directly - `gateway.ts`: Renamed from `tunnel.ts`, removed `startTunnel`/`TunnelHandle`/cloudflared code - `types.ts`: Removed `noTunnel`/`tunnelUrl` from `ServeOptions` ## Ref Follows #210 (WS reverse connection)
xingyue added 1 commit 2026-05-13 14:59:58 +00:00
- WS client receives app.fetch function instead of localPort
- Gateway mode no longer starts a local HTTP server
- Local-only mode (no secret) still starts HTTP server as before
- Removes unnecessary HTTP round-trip for gateway requests
xingyue added 1 commit 2026-05-13 15:17:16 +00:00
- CLI: 'serve' command → 'connect', remove local-only HTTP mode
  (no WORKFLOW_GATEWAY_SECRET now errors instead of falling back)
- CLI: agentToken → clientToken, X-Agent-Token → X-Client-Token
- Gateway: AgentSocket DO → ClientSocket, AGENT_SOCKET → CLIENT_SOCKET
- Gateway: /api/agents/:agent/* → /api/clients/:client/*
- Gateway: agentToken → clientToken in EndpointRecord and register API
- Dashboard: all agent references → client throughout UI and API layer
- Added Durable Object migration for the class rename
xiaomo requested changes 2026-05-13 15:24:51 +00:00
Dismissed
xiaomo left a comment
Owner

Migration Bug in wrangler.toml

The first migration (tag add-agent-socket) was already deployed with new_sqlite_classes = ["AgentSocket"]. This PR changes it to new_sqlite_classes = ["ClientSocket"], which breaks the migration chain — Wrangler compares applied migrations by tag, and modifying an already-applied migration is invalid.

Fix: Restore the first migration to its original form:

[[migrations]]
tag = "add-agent-socket"
new_sqlite_classes = ["AgentSocket"]

[[migrations]]
tag = "rename-agent-to-client"
renamed_classes = [{ from = "AgentSocket", to = "ClientSocket" }]

The second migration correctly handles the rename — just leave the first one untouched.


Everything else looks good: serve→connect rename is clean, HTTP server removal with direct appFetch is a nice simplification, agent→client rename is thorough across CLI/gateway/dashboard, token header rename is consistent, and the requireNextArg using inline { ok: false, error } instead of the err() helper is a minor inconsistency but not blocking.

Minor nit: pathAfterAgent variable in index.ts still says "Agent" — consider renaming to pathAfterClient for consistency.

## Migration Bug in `wrangler.toml` The first migration (tag `add-agent-socket`) was already deployed with `new_sqlite_classes = ["AgentSocket"]`. This PR changes it to `new_sqlite_classes = ["ClientSocket"]`, which **breaks the migration chain** — Wrangler compares applied migrations by tag, and modifying an already-applied migration is invalid. **Fix:** Restore the first migration to its original form: ```toml [[migrations]] tag = "add-agent-socket" new_sqlite_classes = ["AgentSocket"] [[migrations]] tag = "rename-agent-to-client" renamed_classes = [{ from = "AgentSocket", to = "ClientSocket" }] ``` The second migration correctly handles the rename — just leave the first one untouched. --- Everything else looks good: serve→connect rename is clean, HTTP server removal with direct `appFetch` is a nice simplification, agent→client rename is thorough across CLI/gateway/dashboard, token header rename is consistent, and the `requireNextArg` using inline `{ ok: false, error }` instead of the `err()` helper is a minor inconsistency but not blocking. Minor nit: `pathAfterAgent` variable in `index.ts` still says "Agent" — consider renaming to `pathAfterClient` for consistency.
xingyue added 1 commit 2026-05-13 15:26:25 +00:00
- wrangler.toml: keep first migration as AgentSocket (already applied),
  second migration handles the rename
- index.ts: pathAfterAgent → pathAfterClient
xiaomo approved these changes 2026-05-13 15:27:27 +00:00
xiaomo left a comment
Owner

两个问题都修好了,LGTM

两个问题都修好了,LGTM ✅
xingyue force-pushed refactor/serve-remove-http-tunnel from e0b280d5e1 to 238a94f7a6 2026-05-13 15:28:40 +00:00 Compare
xiaomo merged commit 9b23e6f85a into main 2026-05-13 15:29:06 +00:00
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/workflow#245