Skip to content

feat(gateway): make chat history max chars configurable#58900

Merged
ImLukeF merged 3 commits into
openclaw:mainfrom
ImLukeF:imlukef/pr-27030
Apr 1, 2026
Merged

feat(gateway): make chat history max chars configurable#58900
ImLukeF merged 3 commits into
openclaw:mainfrom
ImLukeF:imlukef/pr-27030

Conversation

@ImLukeF

@ImLukeF ImLukeF commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • make chat.history max text truncation configurable via gateway.webchat.chatHistoryMaxChars and per-request maxChars
  • keep current assistant usage / cost metadata preservation intact while applying the new truncation limit
  • expose the new maxChars request parameter in the gateway protocol and macOS Swift client models
  • add a local prepush:ci mirror script and stabilize a few extension tests needed for local CI signal

Why

  • the old PR for this feature was stale and based on outdated chat.history behavior
  • current main still hardcodes the history text limit, so the feature is still useful, but it needed a fresh implementation on top of current semantics

Validation

  • pnpm exec vitest run src/gateway/server.chat.gateway-server-chat-b.test.ts src/gateway/server.chat.gateway-server-chat.test.ts src/config/schema.help.quality.test.ts
  • pnpm exec vitest run --config vitest.extensions.config.ts extensions/feishu/src/docx.test.ts extensions/thread-ownership/index.test.ts extensions/zalo/src/monitor.webhook.test.ts
  • clean-worktree bash scripts/prepush-ci.sh got through pnpm check, pnpm build:strict-smoke, pnpm lint:ui:no-raw-window-open, protocol generation, and bundle

Notes

  • the full clean-worktree mirror is still blocked by an unrelated serial extensions failure on current main: extensions/openshell/src/remote-fs-bridge.test.ts

@openclaw-barnacle openclaw-barnacle Bot added channel: zalo Channel integration: zalo app: macos App: macos app: web-ui App: web-ui gateway Gateway runtime scripts Repository scripts channel: feishu Channel integration: feishu size: M maintainer Maintainer-authored PR labels Apr 1, 2026
@ImLukeF ImLukeF marked this pull request as ready for review April 1, 2026 09:20
Copilot AI review requested due to automatic review settings April 1, 2026 09:20
@greptile-apps

greptile-apps Bot commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR makes chat.history text truncation configurable via a new gateway.webchat.chatHistoryMaxChars config field and a per-request maxChars RPC parameter, wiring the feature through the TypeBox protocol schema, the Zod config validator, the TypeScript gateway handler, and both Swift client models. The implementation is clean and well-tested — the new tests cover config-driven truncation, per-request override precedence, and boundary validation for invalid maxChars values. A prepush-ci.sh mirror script and three extension test stabilisation fixes are included as supporting changes.

Key observations:

  • The core precedence logic (rpcMaxChars → configMaxChars → default) is correct and consistently applied.
  • The TypeBox schema (minimum: 1, maximum: 500_000) and Zod schema (positive().max(500_000)) are aligned.
  • The default is raised from 12_000 to 64_000 (5×); existing deployments will see larger history payloads without a config change — confirm this is intentional and that all consumers can handle the new ceiling.
  • The has_native_swift_changes fallback in prepush-ci.sh mixes committed-history and working-tree semantics; low practical impact but slightly surprising.

Confidence Score: 5/5

Safe to merge — no P0/P1 issues found; the feature is correctly implemented and well-validated.

All remaining findings are P2 (informational / style). The default-increase observation is worth awareness but is documented and intentional. Tests cover the three key scenarios (config override, RPC override, rejection of invalid values).

No files require special attention; the default value change in src/gateway/server-methods/chat.ts is worth a quick confirmation with the team.

Prompt To Fix All With AI
This is a comment left during a code review.
Path: scripts/prepush-ci.sh
Line: 44-45

Comment:
**Fallback checks working-tree changes, not committed history**

When `origin/main` is reachable but no Swift changes appear in `origin/main...HEAD`, the function falls through to `git diff --name-only --relative` (line 45), which compares the *working tree* against HEAD — not against the remote. In a typical pre-push scenario all changes are committed, so this fallback will almost never match anything useful. If the intent is just to handle the "no remote tracking branch" case, the fallback could be scoped more explicitly (e.g. `git diff --name-only HEAD~1..HEAD`) to avoid the surprising mix of committed vs. uncommitted semantics.

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/gateway/server-methods/chat.ts
Line: 95

Comment:
**Default raised 5× — existing deployments will see larger history responses**

The previous hardcoded limit was `12_000`; the new default is `64_000`. Any existing deployment that relies on the old ceiling will now receive responses up to 5× larger without any config change. This is likely intentional (and documented in `schema.help.ts`), but worth confirming that any downstream consumers of `chat.history` — especially the macOS client — handle the larger payload gracefully without a memory or display regression.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "feat(gateway): make chat history max cha..." | Re-trigger Greptile

Comment thread scripts/prepush-ci.sh Outdated
Comment thread src/gateway/server-methods/chat.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b65ed1716a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/gateway/server-methods/chat.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds configurability for chat.history text truncation in the gateway (config + per-request override), updates the gateway protocol/Swift client models accordingly, and introduces a local pre-push CI mirror script while stabilizing a few extension tests.

Changes:

  • Make chat.history truncation limit configurable via gateway.webchat.chatHistoryMaxChars and RPC maxChars.
  • Extend the gateway protocol schema and Swift client models to include maxChars.
  • Add prepush:ci helper script and improve test robustness in several extensions.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/gateway/server.chat.gateway-server-chat-b.test.ts Adds gateway chat.history tests for config/RPC maxChars.
src/gateway/server-methods/chat.ts Implements configurable per-field truncation for chat.history sanitization.
src/gateway/protocol/schema/logs-chat.ts Extends chat.history params schema with maxChars.
src/config/zod-schema.ts Adds gateway.webchat.chatHistoryMaxChars to validated config schema.
src/config/types.gateway.ts Introduces GatewayWebchatConfig and gateway.webchat typing/docs.
src/config/schema.labels.ts Adds label for gateway.webchat.chatHistoryMaxChars.
src/config/schema.help.ts Adds help text for gateway.webchat.chatHistoryMaxChars.
scripts/prepush-ci.sh Adds a local CI mirror script (linux + conditional macOS checks).
package.json Adds prepush:ci script entry.
extensions/zalo/src/monitor.webhook.test.ts Improves HTTP server teardown by tracking/destroying sockets.
extensions/thread-ownership/index.test.ts Switches to vi.stubGlobal/vi.unstubAllGlobals for fetch mocking.
extensions/feishu/src/docx.test.ts Moves hoisted mocks to module scope for consistent mocking behavior.
apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift Updates generated protocol model ChatHistoryParams to include maxChars.
apps/macos/Sources/OpenClawProtocol/GatewayModels.swift Same protocol model update for macOS target.
apps/macos/Sources/OpenClaw/GatewayConnection.swift Exposes maxChars in macOS chatHistory API and request params.

Comment thread src/gateway/server.chat.gateway-server-chat-b.test.ts
Comment thread src/gateway/server-methods/chat.ts Outdated
@ImLukeF ImLukeF force-pushed the imlukef/pr-27030 branch from b65ed17 to eb5a4e6 Compare April 1, 2026 09:30
@openclaw-barnacle openclaw-barnacle Bot removed the channel: feishu Channel integration: feishu label Apr 1, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1ca388ce54

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +723 to 724
const text = extractAssistantTextForSilentCheck(message);
if (text !== undefined && isSilentReplyText(text, SILENT_REPLY_TOKEN)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Strip directives before silent-token history filtering

The silent-reply check now runs on the raw assistant message before sanitizeChatHistoryMessage(...) removes inline directive tags, so an entry like [[reply_to_current]]NO_REPLY is no longer recognized as silent and is returned by chat.history as a visible NO_REPLY message. This is a regression in suppression behavior for directive-tagged assistant text and can leak messages that should be dropped.

Useful? React with 👍 / 👎.

@ImLukeF ImLukeF merged commit 1654c3a into openclaw:main Apr 1, 2026
8 checks passed
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
* feat(gateway): make chat history max chars configurable

* fix(gateway): address review feedback

* docs(changelog): note configurable chat history limits
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
* feat(gateway): make chat history max chars configurable

* fix(gateway): address review feedback

* docs(changelog): note configurable chat history limits
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
* feat(gateway): make chat history max chars configurable

* fix(gateway): address review feedback

* docs(changelog): note configurable chat history limits
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
* feat(gateway): make chat history max chars configurable

* fix(gateway): address review feedback

* docs(changelog): note configurable chat history limits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: macos App: macos app: web-ui App: web-ui channel: zalo Channel integration: zalo gateway Gateway runtime maintainer Maintainer-authored PR scripts Repository scripts size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants