openclaw/src/gateway
Dave Lauer d03c404cb4
feat(compaction): add adaptive chunk sizing, progressive fallback, and UI indicator (#1466)
* fix(ui): allow relative URLs in avatar validation

The isAvatarUrl check only accepted http://, https://, or data: URLs,
but the /avatar/{agentId} endpoint returns relative paths like /avatar/main.
This caused local file avatars to display as text instead of images.

Fixes avatar display for locally configured avatar files.

* fix(gateway): resolve local avatars to URL in HTML injection and RPC

The frontend fix alone wasn't enough because:
1. serveIndexHtml() was injecting the raw avatar filename into HTML
2. agent.identity.get RPC was returning raw filename, overwriting the
   HTML-injected value

Now both paths resolve local file avatars (*.png, *.jpg, etc.) to the
/avatar/{agentId} endpoint URL.

* feat(compaction): add adaptive chunk sizing and progressive fallback

- Add computeAdaptiveChunkRatio() to reduce chunk size for large messages
- Add isOversizedForSummary() to detect messages too large to summarize
- Add summarizeWithFallback() with progressive fallback:
  - Tries full summarization first
  - Falls back to partial summarization excluding oversized messages
  - Notes oversized messages in the summary output
- Add SAFETY_MARGIN (1.2x) buffer for token estimation inaccuracy
- Reduce MIN_CHUNK_RATIO to 0.15 for very large messages

This prevents compaction failures when conversations contain
unusually large tool outputs or responses that exceed the
summarization model's context window.

* feat(ui): add compaction indicator and improve event error handling

Compaction indicator:
- Add CompactionStatus type and handleCompactionEvent() in app-tool-stream.ts
- Show '🧹 Compacting context...' toast while active (with pulse animation)
- Show '🧹 Context compacted' briefly after completion
- Auto-clear toast after 5 seconds
- Add CSS styles for .callout.info, .callout.success, .compaction-indicator

Error handling improvements:
- Wrap onEvent callback in try/catch in gateway.ts to prevent errors
  from breaking the WebSocket message handler
- Wrap handleGatewayEvent in try/catch with console.error logging
  to isolate errors and make them visible in devtools

These changes address UI freezes during heavy agent activity by:
1. Showing users when compaction is happening
2. Preventing uncaught errors from silently breaking the event loop

* fix(control-ui): add agentId to DEFAULT_ASSISTANT_IDENTITY

TypeScript inferred the union type without agentId when falling back to
DEFAULT_ASSISTANT_IDENTITY, causing build errors at control-ui.ts:222-223.
2026-01-23 06:32:30 +00:00
..
protocol feat: add sessions preview rpc and menu prewarm 2026-01-22 10:21:50 +00:00
server fix: enforce secure control ui auth 2026-01-21 23:58:42 +00:00
server-methods refactor: centralize control ui avatar helpers 2026-01-22 23:41:36 +00:00
assistant-identity.test.ts fix: surface concrete ai error details 2026-01-22 22:24:25 +00:00
assistant-identity.ts feat(compaction): add adaptive chunk sizing, progressive fallback, and UI indicator (#1466) 2026-01-23 06:32:30 +00:00
auth.test.ts Gateway auth: accept local Tailscale Serve hostnames and tailnet IPs (#885) 2026-01-16 07:51:25 +00:00
auth.ts feat: add device token auth and devices cli 2026-01-20 10:30:53 +00:00
boot.test.ts fix: stabilize tests and logging 2026-01-18 18:43:31 +00:00
boot.ts refactor(logging): split config + subsystem imports 2026-01-19 00:15:44 +00:00
call.test.ts fix: add explicit tailnet gateway bind 2026-01-21 20:36:09 +00:00
call.ts fix: add explicit tailnet gateway bind 2026-01-21 20:36:09 +00:00
chat-abort.ts refactor: remove bridge protocol 2026-01-19 10:08:29 +00:00
chat-attachments.test.ts chore: migrate to oxlint and oxfmt 2026-01-14 15:02:19 +00:00
chat-attachments.ts chore: migrate to oxlint and oxfmt 2026-01-14 15:02:19 +00:00
chat-sanitize.ts fix: strip envelopes in chat history 2026-01-19 22:52:00 +00:00
client.maxpayload.test.ts Gateway: enable canvas host + inject action bridge 2025-12-18 23:32:22 +01:00
client.test.ts fix: validate ws tls fingerprint 2026-01-20 13:04:20 +00:00
client.ts feat: show node PATH and bootstrap node host env 2026-01-21 11:06:56 +00:00
config-reload.test.ts refactor: migrate messaging plugins to sdk 2026-01-18 08:54:00 +00:00
config-reload.ts refactor: remove bridge protocol 2026-01-19 10:08:29 +00:00
control-ui-shared.ts refactor: centralize control ui avatar helpers 2026-01-22 23:41:36 +00:00
control-ui.test.ts refactor: centralize control ui avatar helpers 2026-01-22 23:41:36 +00:00
control-ui.ts refactor: centralize control ui avatar helpers 2026-01-22 23:41:36 +00:00
device-auth.ts feat: enforce device-bound connect challenge 2026-01-20 13:04:19 +00:00
exec-approval-manager.ts fix: unify exec approval ids 2026-01-22 00:59:29 +00:00
gateway-cli-backend.live.test.ts fix: stabilize ci checks 2026-01-19 00:34:26 +00:00
gateway-models.profiles.live.test.ts feat: preflight update runner before rebase 2026-01-22 04:19:33 +00:00
gateway.e2e.test.ts test: speed up test suite 2026-01-23 02:55:38 +00:00
hooks-mapping.test.ts feat: allow hook model overrides 2026-01-08 09:33:42 +00:00
hooks-mapping.ts chore: migrate to oxlint and oxfmt 2026-01-14 15:02:19 +00:00
hooks.test.ts refactor: migrate messaging plugins to sdk 2026-01-18 08:54:00 +00:00
hooks.ts style: oxfmt fixes (#925) (thanks @grp06) 2026-01-15 03:22:54 +00:00
http-common.ts refactor: share responses input handling 2026-01-20 08:21:57 +00:00
http-utils.ts fix: expand /v1/responses inputs (#1229) (thanks @RyanLisse) 2026-01-20 07:37:30 +00:00
live-image-probe.ts chore: migrate to oxlint and oxfmt 2026-01-14 15:02:19 +00:00
net.test.ts fix: treat tailnet host as local for pairing 2026-01-21 00:14:15 +00:00
net.ts fix: add explicit tailnet gateway bind 2026-01-21 20:36:09 +00:00
node-command-policy.ts fix: enforce ws3 roles + node allowlist 2026-01-20 09:24:01 +00:00
node-registry.ts feat: show node PATH and bootstrap node host env 2026-01-21 11:06:56 +00:00
open-responses.schema.ts feat(gateway): implement OpenResponses /v1/responses endpoint phase 2 2026-01-20 07:37:01 +00:00
openai-http.e2e.test.ts test(gateway): consolidate server suites for speed 2026-01-23 06:22:09 +00:00
openai-http.ts refactor: share responses input handling 2026-01-20 08:21:57 +00:00
openresponses-http.e2e.test.ts test(gateway): consolidate server suites for speed 2026-01-23 06:22:09 +00:00
openresponses-http.ts refactor: share responses input handling 2026-01-20 08:21:57 +00:00
openresponses-parity.e2e.test.ts test(gateway): add OpenResponses parity E2E tests 2026-01-20 07:37:01 +00:00
probe.ts chore: migrate to oxlint and oxfmt 2026-01-14 15:02:19 +00:00
server-broadcast.test.ts fix: tighten tls fingerprints and approval events 2026-01-20 13:04:20 +00:00
server-broadcast.ts fix: tighten tls fingerprints and approval events 2026-01-20 13:04:20 +00:00
server-browser.ts CLI: streamline startup paths and env parsing 2026-01-18 23:10:39 +00:00
server-channels.ts refactor(logging): split config + subsystem imports 2026-01-19 00:15:44 +00:00
server-chat-registry.test.ts test(gateway): cover helper registries 2026-01-03 19:37:09 +01:00
server-chat.ts fix: resolve format/build failures 2026-01-19 11:32:15 +00:00
server-close.ts fix: reschedule heartbeat on hot reload 2026-01-21 00:53:54 +00:00
server-constants.ts fix: stabilize ci 2026-01-21 22:59:11 +00:00
server-cron.ts chore: migrate to oxlint and oxfmt 2026-01-14 15:02:19 +00:00
server-discovery-runtime.ts refactor: remove bridge protocol 2026-01-19 10:08:29 +00:00
server-discovery.ts chore: migrate to oxlint and oxfmt 2026-01-14 15:02:19 +00:00
server-http.ts fix: remove duplicate loadConfig import 2026-01-22 07:08:13 +00:00
server-lanes.ts refactor: use command lane enum 2026-01-20 10:51:25 +00:00
server-maintenance.ts refactor: remove bridge protocol 2026-01-19 10:08:29 +00:00
server-methods-list.ts feat: add sessions preview rpc and menu prewarm 2026-01-22 10:21:50 +00:00
server-methods.ts feat: add sessions preview rpc and menu prewarm 2026-01-22 10:21:50 +00:00
server-mobile-nodes.ts refactor: remove bridge protocol 2026-01-19 10:08:29 +00:00
server-model-catalog.ts refactor(gateway): split server runtime 2026-01-14 09:11:21 +00:00
server-node-events-types.ts refactor: remove bridge protocol 2026-01-19 10:08:29 +00:00
server-node-events.test.ts refactor: remove bridge protocol 2026-01-19 10:08:29 +00:00
server-node-events.ts fix: resolve format/build failures 2026-01-19 11:32:15 +00:00
server-node-subscriptions.test.ts refactor: remove bridge protocol 2026-01-19 10:08:29 +00:00
server-node-subscriptions.ts refactor: remove bridge protocol 2026-01-19 10:08:29 +00:00
server-plugins.test.ts fix: log plugin load errors in gateway 2026-01-19 00:15:24 +00:00
server-plugins.ts fix: log plugin load errors in gateway 2026-01-19 00:15:24 +00:00
server-reload-handlers.ts fix: reschedule heartbeat on hot reload 2026-01-21 00:53:54 +00:00
server-restart-sentinel.ts fix: pass threadId in restart sentinel 2026-01-21 01:26:15 +00:00
server-runtime-config.ts refactor: centralize control ui avatar helpers 2026-01-22 23:41:36 +00:00
server-runtime-state.ts fix: expand /v1/responses inputs (#1229) (thanks @RyanLisse) 2026-01-20 07:37:30 +00:00
server-session-key.ts refactor: canonicalize gateway session store keys 2026-01-17 07:41:24 +00:00
server-shared.ts refactor(gateway): split server helpers 2026-01-03 19:37:09 +01:00
server-startup-log.ts fix: resolve format/build failures 2026-01-19 11:32:15 +00:00
server-startup.ts CLI: streamline startup paths and env parsing 2026-01-18 23:10:39 +00:00
server-tailscale.ts chore: migrate to oxlint and oxfmt 2026-01-14 15:02:19 +00:00
server-utils.test.ts chore: migrate to oxlint and oxfmt 2026-01-14 15:02:19 +00:00
server-utils.ts fix(gateway): format status/code errors 2026-01-03 19:37:09 +01:00
server-wizard-sessions.ts refactor(gateway): split server runtime 2026-01-14 09:11:21 +00:00
server-ws-runtime.ts refactor: remove bridge protocol 2026-01-19 10:08:29 +00:00
server.agent.gateway-server-agent-a.test.ts test(gateway): consolidate server suites for speed 2026-01-23 06:22:09 +00:00
server.agent.gateway-server-agent-b.test.ts test(gateway): consolidate server suites for speed 2026-01-23 06:22:09 +00:00
server.auth.test.ts test(gateway): consolidate server suites for speed 2026-01-23 06:22:09 +00:00
server.channels.test.ts test(gateway): consolidate server suites for speed 2026-01-23 06:22:09 +00:00
server.chat.gateway-server-chat-b.test.ts test(gateway): consolidate server suites for speed 2026-01-23 06:22:09 +00:00
server.chat.gateway-server-chat.test.ts test(gateway): consolidate server suites for speed 2026-01-23 06:22:09 +00:00
server.config-apply.test.ts test: speed up gateway suite setup 2026-01-23 04:28:02 +00:00
server.config-patch.test.ts test(gateway): consolidate server suites for speed 2026-01-23 06:22:09 +00:00
server.cron.test.ts test(gateway): consolidate server suites for speed 2026-01-23 06:22:09 +00:00
server.health.test.ts test: speed up gateway suite setup 2026-01-23 04:28:02 +00:00
server.hooks.test.ts test(gateway): consolidate server suites for speed 2026-01-23 06:22:09 +00:00
server.impl.ts fix: add explicit tailnet gateway bind 2026-01-21 20:36:09 +00:00
server.ios-client-id.test.ts test: speed up gateway suite setup 2026-01-23 04:28:02 +00:00
server.models-voicewake-misc.test.ts test(gateway): consolidate server suites for speed 2026-01-23 06:22:09 +00:00
server.reload.test.ts test(gateway): consolidate server suites for speed 2026-01-23 06:22:09 +00:00
server.roles-allowlist-update.test.ts test(gateway): consolidate server suites for speed 2026-01-23 06:22:09 +00:00
server.sessions-send.test.ts test(gateway): consolidate server suites for speed 2026-01-23 06:22:09 +00:00
server.sessions.gateway-server-sessions-a.test.ts test: speed up gateway suite setup 2026-01-23 04:28:02 +00:00
server.ts chore: migrate to oxlint and oxfmt 2026-01-14 15:02:19 +00:00
session-utils.fs.test.ts feat: add sessions preview rpc and menu prewarm 2026-01-22 10:21:50 +00:00
session-utils.fs.ts feat: add sessions preview rpc and menu prewarm 2026-01-22 10:21:50 +00:00
session-utils.test.ts feat: add search param to sessions.list RPC 2026-01-20 16:36:51 +00:00
session-utils.ts feat: add sessions preview rpc and menu prewarm 2026-01-22 10:21:50 +00:00
session-utils.types.ts feat: add sessions preview rpc and menu prewarm 2026-01-22 10:21:50 +00:00
sessions-patch.test.ts fix: normalize model override auth handling 2026-01-21 06:00:21 +00:00
sessions-patch.ts feat: add elevated ask/full modes 2026-01-22 05:41:11 +00:00
sessions-resolve.ts chore: migrate to oxlint and oxfmt 2026-01-14 15:02:19 +00:00
test-helpers.e2e.ts test: speed up test suite 2026-01-23 02:22:02 +00:00
test-helpers.mocks.ts fix: enforce secure control ui auth 2026-01-21 23:58:42 +00:00
test-helpers.openai-mock.ts test: speed up test suite 2026-01-23 02:22:02 +00:00
test-helpers.server.ts test: speed up gateway suite setup 2026-01-23 04:28:02 +00:00
test-helpers.ts refactor(src): split oversized modules 2026-01-14 01:17:56 +00:00
ws-log.test.ts fix: add agent context to ws logs 2026-01-17 20:37:36 +00:00
ws-log.ts refactor(logging): split config + subsystem imports 2026-01-19 00:15:44 +00:00
ws-logging.ts Gateway: optimize ws logs in normal mode 2025-12-18 13:27:52 +00:00