xworkmate-bridge/internal
Haitao Pan 2333c3e5fd feat(acp): durable per-session run registry — survive gateway WS loss (T7/T8/T9)
OpenClaw gateway turns are async: chat.send returns a runId fast, the app then
polls tasks.get. Previously every tasks.get re-asked the gateway, so a WS blip /
reconnect that lost the gateway's in-memory run state turned into not_found /
socket_closed — the already-finished result was lost and the client either
hard-failed or polled forever.

Make tasks.get resilient by leaning on the per-session store (s.sessions),
whose lifetime is independent of the bridge<->gateway WebSocket:

- T8: cache a gateway-confirmed terminal result (final client-facing shape, after
  download-URL decoration + inline-content stripping) into sess.lastResult and
  serve it on subsequent polls, so a later gateway not_found cannot lose it.
- T7: when the gateway can't confirm (unavailable / socket closed / not_found) but
  the run is still within budget, synthesize a running handle so the client keeps
  polling across a transient blip — run tracking decoupled from WS lifetime.
- T9: when the run is past its DeadlineAt and the gateway still can't confirm,
  return a deterministic `interrupted` terminal (OPENCLAW_RUN_DEADLINE_EXCEEDED).

Correctness guards:
- startOpenClawGatewayTask resets State/ProgressTerminal when a session is reused
  for a new turn, so a prior turn's terminal can't be mis-served for a new runId.
- cache lookups verify the cached runId matches the requested runId (defense in depth).

Design note: T7 is handled at the tasks.get layer (re-correlate by runId via the
durable session store) rather than rewiring gatewayruntime's pending map — lower
risk, equivalent effect. A killed in-flight request surfaces as a gateway error
that the new fallback absorbs. T9 only force-terminates when the gateway is
unconfirmed, never when it explicitly reports running (avoids killing legit long
runs; the client-side deadline T3 covers that case).

Tests: internal/acp/openclaw_run_registry_test.go (terminal detection, within-budget
keep-polling, past-deadline interrupt, cache hit/replay, cross-runId isolation,
no-session not_found). go vet + full acp package green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 18:52:41 +08:00
..
acp feat(acp): durable per-session run registry — survive gateway WS loss (T7/T8/T9) 2026-06-26 18:52:41 +08:00
desktop fix(desktop): time out ICE gathering 2026-06-13 07:10:28 +08:00
gatewayruntime fix: stabilize gateway device token reissue 2026-06-18 14:48:03 +08:00
geminiadapter fix: remove unused functions and dead code to pass staticcheck 2026-06-05 18:43:15 +08:00
hermesadapter fix: structure hermes empty response failures 2026-04-29 19:26:58 +08:00
memory Initial standalone ACP bridge repository 2026-04-09 09:49:48 +08:00
opencodeadapter perf: optimize webrtc mouse input throttle, ffmpeg encoding and http connection pooling 2026-06-04 11:28:00 +08:00
router fix: remove unused functions and dead code to pass staticcheck 2026-06-05 18:43:15 +08:00
service Support review bridge auth token 2026-05-30 10:34:51 +08:00
shared chore: remove unused legacy bridge helpers 2026-06-12 14:49:51 +08:00
skills fix: remove unused functions and dead code to pass staticcheck 2026-06-05 18:43:15 +08:00