Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@dlauer
Copy link
Contributor

@dlauer dlauer commented Jan 22, 2026

Summary

This PR improves the auto-compaction system to handle edge cases that could cause compaction failures, and adds UI feedback for when compaction occurs.

Changes

Compaction Safeguard Improvements

  • Adaptive chunk sizing: computeAdaptiveChunkRatio() dynamically reduces chunk size when messages are large, preventing summarization requests from exceeding model limits
  • Oversized message detection: isOversizedForSummary() identifies messages too large to summarize (>50% of context window)
  • Progressive fallback: summarizeWithFallback() tries full summarization first, then falls back to partial summarization excluding oversized messages
  • Safety margin: Added 1.2x buffer for token estimation inaccuracy
  • Lower minimum chunk ratio: Reduced to 0.15 for very large messages

UI Improvements

  • Compaction indicator: Shows '🧹 Compacting context...' toast while active, '🧹 Context compacted' after completion
  • Error handling: Wrapped event handlers in try/catch to prevent uncaught errors from breaking the UI event loop
  • Console logging: Errors are now logged to devtools for debugging

Testing

  • Built UI successfully
  • Gateway restart with new code
  • Stress tested with many file reads

Related Issues

Addresses UI freezes during heavy agent activity and compaction edge cases with large tool outputs.

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.
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.
- 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.
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
TypeScript inferred the union type without agentId when falling back to
DEFAULT_ASSISTANT_IDENTITY, causing build errors at control-ui.ts:222-223.
@steipete steipete merged commit d03c404 into openclaw:main Jan 23, 2026
18 of 22 checks passed
@steipete
Copy link
Contributor

Landed via temp rebase onto main.

  • Gate: pnpm lint && pnpm build (ok); pnpm test (timeouts in server.cron, pi-embedded-runner beforeAll, onboard-non-interactive.gateway)
  • Land commit: 2e089ec
  • Merge commit: d03c404

Thanks @dlauer!

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.

2 participants