#22059: [Bug]: allow CONTROL_UI sessions.patch/delete
gateway
size: S
Cluster:
Network Error Handling Improvements
## Summary
Fixes #22051 by allowing CONTROL_UI clients to patch/delete sessions via gateway RPC while keeping the webchat restriction for other UI clients.
## Changes
- Allowlist exception added in `sessions.ts` by checking `client.connect.client.id` against `GATEWAY_CLIENT_IDS.CONTROL_UI` in the shared webchat mutation guard.
- Added regression coverage in `server.sessions.gateway-server-sessions-a.e2e.test.ts`:
- Existing webchat rejection behavior remains covered.
- New test confirms CONTROL_UI with `mode: ui` can successfully `sessions.patch` and `sessions.delete`.
## Validation
- `pnpm test:e2e src/gateway/server.sessions.gateway-server-sessions-a.e2e.test.ts`
## Confidence Score
- 10/10 confidence.
- Fix is scoped to a single guard path and does not alter validation schema, auth model, or session persistence behavior.
- Behavior is directly aligned with the intended client matrix: webchat UI remains blocked, control UI is allowed.
- Regression coverage confirms both allowed and rejected paths in the same suite, minimizing risk of future regression.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR adds an allowlist exception for `CONTROL_UI` clients to bypass the webchat session mutation restriction, enabling them to patch and delete sessions via gateway RPC. The fix is implemented by adding an early return in the `rejectWebchatSessionMutation` guard that checks if the client ID is `CONTROL_UI` before applying the webchat check.
**Key changes:**
- Added client ID check in `rejectWebchatSessionMutation()` to allow `CONTROL_UI` clients
- New e2e test validates that `CONTROL_UI` with `mode: ui` can successfully patch and delete sessions
- Existing webchat rejection test remains in place to ensure the restriction still applies to `WEBCHAT_UI` clients
**Note:** While the implementation is functionally sound, the fix may be more defensive than strictly necessary. The `isWebchatClient()` function identifies webchat clients by checking if `mode === "webchat"` OR `id === "webchat-ui"`. Since `CONTROL_UI` uses `id: "openclaw-control-ui"` and `mode: "ui"`, it wouldn't match the webchat pattern anyway. However, the explicit allowlist provides clearer intent and future-proofs against potential changes to the webchat detection logic.
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge with minor style improvement recommended
- The implementation correctly adds the CONTROL_UI allowlist exception and includes comprehensive test coverage. The logic is sound and scoped to a single guard function. One minor style inconsistency was identified regarding client ID normalization, but it doesn't affect functionality in practice since client IDs are typically provided using constants. The fix is conservative and maintains backward compatibility while achieving the stated goal.
- No files require special attention
<sub>Last reviewed commit: 9cfa4ed</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#22109: fix(gateway): allow Control UI session patch/delete
by lc708 · 2026-02-20
89.2%
#17527: fix(gateway): allow WebChat to attach to main session regardless of...
by Glucksberg · 2026-02-15
75.5%
#21186: fix(gateway): strict loopback guard for Control UI (v2)
by dinakars777 · 2026-02-19
75.5%
#18694: fix(ui): reset session key to main after /new in webchat
by Phineas1500 · 2026-02-17
75.5%
#20089: fix(gateway): preserve control-ui scopes when dangerouslyDisableDev...
by vashkartik · 2026-02-18
75.2%
#17753: fix: Control UI unusable over HTTP - missing scopes
by MisterGuy420 · 2026-02-16
74.5%
#21642: fix(ui): disable dashboard session delete for webchat clients
by graysurf · 2026-02-20
74.3%
#9218: Fix Control UI chat resync on gaps and terminal events
by figitaki · 2026-02-05
74.1%
#13960: fix(ui): preserve structured config validation error details
by constansino · 2026-02-11
73.8%
#22808: test(ui): split baseline browser-test fixes from webchat feature
by opnsec · 2026-02-21
73.7%