Skip to content

fix(channels): group-capable channels reject the documented historyLimit override - #118152

Closed
ayaangazali wants to merge 10 commits into
openclaw:mainfrom
ayaangazali:fix/history-limit-schema-parity
Closed

ayaangazali wants to merge 10 commits into
openclaw:mainfrom
ayaangazali:fix/history-limit-schema-parity

Conversation

@ayaangazali

@ayaangazali ayaangazali commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

docs/gateway/config-channels.md:841 documents the per-channel group history override:

messages.groupChat.historyLimit sets the global default. Channels can override with channels.<channel>.historyLimit (or per-account). Set 0 to disable.

Six group-capable bundled channels reject that key, so following the docs refuses the whole config: buzz, clickclack, line, mattermost, qa-channel, zalo.

The reader is provider-agnostic. src/agents/embedded-agent-runner/history.ts:117-146 matches cfg.channels by normalized provider id with no fixed list, then :163-166 returns providerConfig.historyLimit for channel and group sessions.

Why This Change Was Made

Same owner-boundary shape as the merged #112392 and #117206: the runtime and docs agree on a key, and individual strict schemas do not. historyLimit is part of the shared common channel account shape and of ReplyRuntimeConfigSchemaShape, which is why the other bundled channels already accept it. These six hand-roll their account schema and omit it.

Each gets the same one-line optional non-negative integer beside its existing configWrites entry, matching the shared shape's definition and the documented 0 semantics.

User Impact

Operators of these six channels can set channels.<id>.historyLimit (and the per-account form where the channel is multi-account) as documented, including 0 to disable group history. Purely additive and optional: absent means the existing messages.groupChat.historyLimit default applies exactly as before.

Evidence

The contract test derives its channel list from the generated metadata rather than hardcoding, so future group-capable channels are covered automatically. Before the schema change:

× buzz accepts channels.<id>.historyLimit
× clickclack accepts channels.<id>.historyLimit
× line accepts channels.<id>.historyLimit
× mattermost accepts channels.<id>.historyLimit
× qa-channel accepts channels.<id>.historyLimit
× zalo accepts channels.<id>.historyLimit
  (plus the accounts.<account> cases)

After:

$ node scripts/run-vitest.mjs src/plugins/contracts/channel-history-limit.contract.test.ts
Tests  41 passed (41)

$ node scripts/run-vitest.mjs extensions/mattermost   714 passed
$ node scripts/run-vitest.mjs extensions/line         521 passed
$ node scripts/run-vitest.mjs extensions/clickclack   310 passed
$ node scripts/run-vitest.mjs extensions/zalo         159 passed

$ node --import tsx scripts/generate-bundled-channel-config-metadata.ts --check   (clean)
$ node --import tsx scripts/generate-config-doc-baseline.ts --check               (clean)

What I checked and deliberately did not change:

  • I scoped this to group-capable channels on purpose. nostr, raft, reef, sms, tlon and twitch also lack the key, but they declare no groupPolicy, groups or groupAllowFrom, so no channel or group session exists for them and the resolver never reaches that branch. Adding it there would be inert config surface. The contract test applies the same filter rather than hardcoding a list.
  • I did not touch dmHistoryLimit or the per-DM dms.<id>.historyLimit; those are a separate documented path and are handled in fix(channels): DM-capable channels reject the documented DM history overrides #117306.
  • I did not touch the resolver, its precedence, or the global default.
  • The contract helper walks composed schemas, treating a union as accepting when any alternative accepts and allOf as an intersection where one closed component still refuses.
  • The regenerated metadata snapshot and config-surface baseline came from the repo generators, not hand editing.

AI-assisted: researched, written, and validated with Claude Code under my direction. I have read and understand the change.

Review follow-up

P1, account-scope over-claim: fixed by removing the claim. getHistoryLimitFromSessionKey reads the root provider object and takes no account id, so asserting that every account schema accepts historyLimit would have advertised precedence the resolver does not implement, exactly the "validates then gets silently ignored" trap you describe. I removed the account-scope assertion and left a comment at the call site saying why, rather than plumbing account identity through the resolver, which is a runtime behavior change and a maintainer call.

The key still validates at account scope because it sits on the shared account base alongside its siblings, but this PR no longer claims the resolver honors it. Same resolution I applied on #117306 for dmHistoryLimit.

Real behavior proof, from from-scratch builds on both sides (rm -rf dist && pnpm build), isolated state dir:

Before, clean build of main (b7f9cd0a016):

$ openclaw config get channels.mattermost
- channels.mattermost: invalid config: must not have additional properties: "historyLimit"

After, clean build of this branch:

$ openclaw config get channels.mattermost
  "baseUrl": "https://mm.example.org",
  "historyLimit": 25,
$ node scripts/run-vitest.mjs src/plugins/contracts/channel-history-limit.contract.test.ts
Tests  21 passed (21)

Copilot AI review requested due to automatic review settings August 2, 2026 19:45

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: line Channel integration: line channel: mattermost Channel integration: mattermost channel: zalo Channel integration: zalo channel: qa-channel Channel integration: qa-channel channel: buzz size: S labels Aug 2, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 25, 2026, 6:54 PM ET / 22:54 UTC.

ClawSweeper review

What this changes

This PR adds documented group-history-limit validation to bundled channel schemas and makes LINE and Mattermost pending-history buffers use the resolved channel/account setting.

Merge readiness

⚠️ Needs maintainer review before merge - 4 items remain

Keep open: the PR still validates account-scoped limits that its LINE and Mattermost buffers honor, while the canonical prompt and compaction limiter on current main only reads the channel-root value.

Priority: P1
Reviewed head: 62537abe6ae55bbaad814e3e43646ed69f51c67f

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The root-schema repair has credible terminal proof, but the account-scope inconsistency remains a merge-blocking correctness issue.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The PR body includes a clean-build before/after CLI configuration read showing Mattermost rejects historyLimit on main and preserves it after the branch change; the later buffer coverage is supplemental mock-based evidence.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body includes a clean-build before/after CLI configuration read showing Mattermost rejects historyLimit on main and preserves it after the branch change; the later buffer coverage is supplemental mock-based evidence.
Evidence reviewed 7 items Documented account scope: The documentation explicitly permits a per-account channel history override.
Canonical resolver is account-blind on current main: The resolver accepts only session key and config, returns the root provider object, and reads its root historyLimit for group/channel sessions.
Both canonical consumers retain the account-blind behavior: Prompt assembly and compaction each call the resolver with only sessionKey and config.
Findings 1 actionable finding [P1] Gate account-scoped history limits on the core resolver
Security None None.

Live Verification

Command: pnpm openclaw config validate --help

Result: PASS (completed)

$ node scripts/run-node.mjs config validate --help
[openclaw] Building TypeScript (dist is stale: missing_build_stamp - build stamp missing).
[openclaw] Building bundled plugin assets.
[canvas] build: node scripts/bundle-a2ui.mjs
[log] ‹DIR›/a2ui.bundle.js  chunk │ size: 399.96 kB
[log] ‹DIR›/a2ui-v0.9.bundle.js  chunk │ size: 615.66 kB
[log]
[success] rolldown v1.2.0 Finished in 112.28 ms
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[tsdown-build] invocation 1/2 finished in 0.8s
node_modules/playwright-core/lib/coreBundle.js (65821:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65821:29 ]
       │
 65821 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/playwright-core/lib/coreBundle.js (65828:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65828:29 ]
       │
 65828 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2343:30) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2343:31 ]
      │
 2343 │           ASM_CONSTS[start] = eval(func);
      │                               ──┬─
      │                                 ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2366:32) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2366:33 ]
      │
 2366 │           moduleExports[name] = eval(func);
      │                                 ──┬─
      │                                   ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

[tsdown-build] invocation 2/2 finished in 14.7s
[plugin-control-plane-loads] verified 35 built modules with native require and checked doctor closures
runtime-postbuild: 11 phases completed in 4401ms (slowest: built plugin control-plane loads 3622ms)
│
◇

OpenClaw 2026.8.1 (62537ab) — All your chats, one OpenClaw.

Usage: openclaw config validate [options]

Validate the current config against the schema without starting the gateway

Options:
  -h, --help  Display help for command
  --json      Output validation result as JSON (default: false)
$ node scripts/run-node.mjs config validate --help
│
◇

OpenClaw 2026.8.1 (62537ab) — All your chats, one OpenClaw.

Usage: openclaw config validate [options]

Validate the current config against the schema without starting the gateway

Options:
  -h, --help  Display help for command
  --json      Output va
… output truncated …

Assertions:

  • PASS expect_output: validate

How this fits together

Channel schemas accept operator configuration before channel plugins process inbound group messages and before the embedded agent trims its transcript. Pending-message context and the core transcript limiter must apply the same retention policy for one routed account.

flowchart LR
  A[Operator channel config] --> B[Bundled channel schemas]
  B --> C[Resolved channel account]
  C --> D[LINE and Mattermost pending buffers]
  C --> E[Core history resolver]
  D --> F[Inbound group context]
  E --> G[Prompt and compaction transcript]
Loading

Before merge

  • Gate account-scoped history limits on the core resolver (P1) - This shared base is reused for accounts.&lt;id>, and the PR's LINE/Mattermost pending buffers honor that account value. Current main's prompt and compaction callers still invoke the canonical resolver without an account ID, so it reads the root value instead; one routed account can therefore retain different context windows. Land the account-aware resolver repair first, or stop accepting this field at account scope.
  • Resolve merge risk (P1) - An account-specific value can set LINE or Mattermost pending context to one retention limit while prompt construction and compaction retain the root-channel limit for the same routed session.
  • Resolve merge risk (P1) - The bug-fix diff is production +27 net lines; the local schema declarations and two plugin owner paths are necessary without broadening the shared plugin contract, but the added scope should remain bounded to this documented behavior.
  • Complete next step (P2) - Hold this PR until the canonical account-aware resolver work is landed and the branch is rebased; a separate repair job would duplicate the linked core work.

Findings

  • [P1] Gate account-scoped history limits on the core resolver — extensions/line/src/config-schema.ts:26
Agent review details

Security

None.

PR surface

Source +27, Tests +366, Generated 0. Total +393 across 21 files.

View PR surface stats
Area Files Added Removed Net
Source 12 29 2 +27
Tests 6 367 1 +366
Docs 0 0 0 0
Config 0 0 0 0
Generated 3 26 26 0
Other 0 0 0 0
Total 21 422 29 +393

Review metrics

Metric Value Why it matters
Production versus test delta production +27 net; tests +366 net; generated files 0 net The production growth is limited to schema/type declarations and two pending-buffer precedence paths, while focused tests cover those paths.
Documented config surface 15 generated channel-schema paths added (3584 to 3599) These additions broaden accepted operator configuration and therefore need consistent runtime resolution before merge.

Stored data model

Persistent data-model change detected: unknown-data-model-change: src/config/bundled-channel-config-metadata.generated.ts, vector/embedding metadata: src/plugins/contracts/channel-history-limit.contract.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Complete canonical account resolution (recommended)
    Route the active account into the core history resolver for prompt preparation and compaction, then retain account-scope schema support.
  2. Restrict this PR to root scope
    Do not accept account-scoped historyLimit values until the core resolver can honor them consistently.

Technical review

Best possible solution:

Make the core history resolver account-aware at both prompt and compaction call sites, add direct account/root/zero coverage there, then rebase this schema repair on that canonical behavior.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: configure a multi-account LINE or Mattermost channel with account historyLimit 3 and root historyLimit 20; the plugin buffer reads 3 while the current core limiter reads 20. This read-only review did not execute the contributor branch.

Is this the best way to solve the issue?

No. The schema and plugin changes are useful, but account scope must be implemented by the canonical core resolver rather than leaving two retention owners to disagree.

Full review comments:

  • [P1] Gate account-scoped history limits on the core resolver — extensions/line/src/config-schema.ts:26
    This shared base is reused for accounts.&lt;id>, and the PR's LINE/Mattermost pending buffers honor that account value. Current main's prompt and compaction callers still invoke the canonical resolver without an account ID, so it reads the root value instead; one routed account can therefore retain different context windows. Land the account-aware resolver repair first, or stop accepting this field at account scope.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against df9b7a5fbe9b.

Labels

Label justifications:

  • P1: Merging would give one account conflicting history-retention rules across pending context, prompt construction, and compaction.
  • merge-risk: 🚨 compatibility: The PR broadens accepted root and account configuration for existing multi-account channel setups.
  • merge-risk: 🚨 session-state: The same routed account can retain different message windows in plugin-local pending history and the core transcript.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): The PR body includes a clean-build before/after CLI configuration read showing Mattermost rejects historyLimit on main and preserves it after the branch change; the later buffer coverage is supplemental mock-based evidence.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes a clean-build before/after CLI configuration read showing Mattermost rejects historyLimit on main and preserves it after the branch change; the later buffer coverage is supplemental mock-based evidence.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Authored a recent merged LINE webhook reliability repair in the same inbound owner path. (role: recent LINE inbound contributor; confidence: medium; commits: 819c92d17558; files: extensions/line/src/bot.ts)
  • Pavan Kumar Gondhi: Authored recent merged Mattermost inbound-state work in the post-handler area. (role: recent Mattermost inbound contributor; confidence: medium; commits: e2dc4067c701; files: extensions/mattermost/src/mattermost/monitor-posts.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Land or incorporate the account-aware core resolver repair and prove account/root/zero behavior through both prompt and compaction callers.
  • Rebase this PR onto that repair and show a redacted after-fix configuration/runtime trace for the resulting exact head.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (17 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-21T18:06:46.196Z sha 815c4b6c07b37a2f05ce33a4ceabcce016d15088 :: found issues before merge. :: [P1] Honor account-scoped limits before accepting them
  • reviewed 2026-08-22T17:25:43.518Z sha 6aac22e2e413bc8fef294e5f7bbd5bc1632a7bca :: found issues before merge. :: [P1] Honor account-scoped limits in the shared transcript limiter
  • reviewed 2026-08-23T22:04:29.857Z sha fa99e0c4d2b66622fa73c18c833a624cca73e409 :: found issues before merge. :: [P1] Honor account-scoped limits in the shared transcript limiter
  • reviewed 2026-08-23T22:54:35.705Z sha 1797f05061ff76828bebdc3326fc494f825fa07a :: found issues before merge. :: [P1] Honor account-scoped limits before accepting them
  • reviewed 2026-08-24T06:26:55.259Z sha 3991328f68b56e58a2aa29fde5577a30a73d4cfa :: found issues before merge. :: [P1] Honor account-scoped limits before accepting them
  • reviewed 2026-08-24T19:10:13.580Z sha 29e53243d266a43a46282b8128355c6141ab3324 :: found issues before merge. :: [P1] Honor account-scoped limits in the shared history limiter
  • reviewed 2026-08-24T19:37:33.743Z sha 575d04ce14fcb122d4f899ac6e8e70821282f5c9 :: found issues before merge. :: [P1] Honor account-scoped limits in the shared history limiter
  • reviewed 2026-08-25T21:30:25.731Z sha 8ccf0a272ba82877a40a5054900f316400fb2818 :: found issues before merge. :: [P1] Gate account-scoped acceptance on the canonical resolver

@ayaangazali

Copy link
Copy Markdown
Contributor Author

Both items addressed.

P1 account-scope claim: removed rather than papered over. You are right that getHistoryLimitFromSessionKey reads only the root provider object and has no account input, so my assertion would have let the documented account override validate and then be silently ignored. I dropped the account-scope assertion and left a comment at that spot explaining why, instead of plumbing account identity into the resolver, which is a runtime behavior change and a maintainer decision. This is the same resolution that settled the equivalent finding on #117306.

Real behavior proof added, from from-scratch builds on both sides so a stale dist cannot flatter the result:

before (clean build of main b7f9cd0a016):
  - channels.mattermost: invalid config: must not have additional properties: "historyLimit"

after (clean build of this branch):
  "baseUrl": "https://mm.example.org",
  "historyLimit": 25,

Contract test is 21 passing. PR body updated with the same evidence.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 3, 2026
@ayaangazali

Copy link
Copy Markdown
Contributor Author

On the remaining P1, I want to lay out the structural constraint rather than guess at it, because I think this is the maintainer-direction item your own next-step note flags.

The finding is right that the account form is accepted while the resolver ignores it. getHistoryLimitFromSessionKey resolves the provider object at src/agents/embedded-agent-runner/history.ts:117-146 and reads providerConfig.historyLimit at :163-166; it never receives or consults an account id.

The reason I cannot simply stop accepting the account form is that these channels build both scopes from one object. ClickClack is representative: ClickClackAccountConfigSchema (extensions/clickclack/src/config-schema.ts:10) is passed to buildMultiAccountChannelSchema at :57, which reuses that same base for the channel root and for every accounts.<id> entry. So any key added for the documented root override is automatically accepted at account scope. Declining the account form means giving these channels a second, divergent account schema, which is a bigger structural change than the documented root override warrants and would make them inconsistent with every channel that inherits the shared account shape.

That leaves the two options you named, and both are maintainer calls:

  1. Plumb the selected account id into getHistoryLimitFromSessionKey so account precedence becomes real. That is a runtime behavior change affecting every channel, not just these six.
  2. Keep the root-only contract and accept that the key validates at account scope because it rides the shared base, as it already does for dmHistoryLimit, textChunkLimit, responsePrefix and the rest of that shape.

What I have already done is remove the false advertisement: the contract test no longer asserts account-scope support, and there is a comment at that spot explaining that the resolver takes no account id. So the PR does not claim precedence that does not exist.

I am happy to implement either direction. I did not pick one myself because option 1 changes shared runtime semantics and option 2 is a deliberate contract decision, and guessing would either overreach or bake in something you would rather not have.

@ayaangazali

Copy link
Copy Markdown
Contributor Author

This P1 is correct, and I am taking the first of the two options it offers, resolving the active account before reading the limit.

Short version of why, with the detail and citations in #117306 (comment) so I am not pasting it twice:

  • Account-scope acceptance is already shipped well beyond this PR. buildCommonChannelAccountShape puts historyLimit/dmHistoryLimit in the common account shape (src/config/zod-schema.channel-messaging-common.ts:126-128), so on main twelve channels already accept accounts.<id>.historyLimit, discord, telegram, and whatsapp among them. Narrowing only the schemas in this PR would make these channels inconsistent with that, and would leave the same no-op in place everywhere else.
  • The account-blind reader is the outlier, not the schemas. contextVisibility, heartbeatVisibility, configWrites, responsePrefix, and mediaMaxMb all already resolve account then root in core. historyLimit and dmHistoryLimit were the only keys in the group whose reader stopped at the channel root.
  • The fact needed to fix it is already at the call site: attempt.agentAccountId carries the channel account id, so getHistoryLimitFromSessionKey can resolve account then root without new plumbing.

So the repair goes in the resolver at the owner boundary, which fixes every channel at once instead of per schema. That is a separate core PR, which I will link here as soon as it is up; this one stays schema-only. Happy to rebase this on top of it if you would rather they land in order.

Thanks for holding the line on this one. The silent-no-op framing was the right call and it turned out to point at a real gap in core rather than just in this diff.

@ayaangazali

Copy link
Copy Markdown
Contributor Author

The resolver fix is up as #119326. It makes getHistoryLimitFromSessionKey resolve the active account before the channel root, so the account-scoped values this PR accepts stop being inert. Happy to rebase this one on top of it if you would rather they land in order.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 4, 2026
@clawsweeper clawsweeper Bot removed the rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. label Aug 5, 2026
@ayaangazali
ayaangazali force-pushed the fix/history-limit-schema-parity branch 2 times, most recently from c8bb395 to 3b03d24 Compare August 16, 2026 17:48
@ayaangazali
ayaangazali requested review from a team as code owners August 16, 2026 17:48
@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord channel: imessage Channel integration: imessage channel: matrix Channel integration: matrix channel: msteams Channel integration: msteams channel: signal Channel integration: signal channel: slack Channel integration: slack labels Aug 16, 2026
@ayaangazali

Copy link
Copy Markdown
Contributor Author

Acted on the sequencing rather than restating it. This branch is now stacked on #119326, so the account scope it accepts is also honored.

First, the premise still holds on today's main, checked rather than assumed: getHistoryLimitFromSessionKey is still (sessionKey, config) with zero accounts reads, and attempt-history.ts:537 still calls it with two arguments.

Same trace, same config, on upstream/main versus this stacked head:

config: channels.line.dmHistoryLimit = 50, historyLimit = 50
        channels.line.accounts["Work Team"].dmHistoryLimit = 2, historyLimit = 3

                          main          this branch
DM, account routed        undefined  ->  2
DM, account in key only   undefined  ->  2
DM, no account            50         ->  50
group, account routed     50         ->  3
group, no account         50         ->  50

Worth calling out the first two rows: on main an account-scoped DM session resolves to undefined, so it gets no history limit at all, not even the root fallback. That is a bit worse than the divergence described in the finding.

I could not take the other branch of your suggestion. "Stop accepting account scope" is awkward here because these channels build root and account from one object through buildMultiAccountChannelSchema, so refusing the account form means splitting those schemas apart, which fights the helper and adds surface rather than removing it. Stacking was the cleaner half of the same instruction.

Two things happened while rebasing that are worth flagging:

  • fix(agents): honor account-scoped history limits instead of silently ignoring them #119326 was itself behind main, so my first stack attempt pulled 231 stale commits and conflicted. Rebased that branch onto current main first, then restacked this one. Both are clean now, 14 and 23 commits respectively.
  • That rebase surfaced two failing cases in commands-compact.test.ts asserting per-agent context cap precedence over the global cap. Those passed before the rebase and fail after, because refactor(config): consolidate context budget to one per-model knob #124665 consolidated context budget onto one per-model knob a few hours ago. Since that commit ships doctor migrations and deprecation compat, the precedence was deliberately retired, so I deleted the two obsolete cases and kept the no-cap fallback rather than re-fitting expectations to whatever the code now does.

Validation on the stacked head: config-cli 188, schema.help.quality 24, channel-history-limit.contract 22, history 20, commands-compact 30, both generator --check gates clean, merges clean with main.

If you would rather keep these as two independent PRs, say so and I will unstack; merging #119326 first makes this rebase collapse to nothing.

AI-assisted.

@ayaangazali

Copy link
Copy Markdown
Contributor Author

Unstacked. You are right that embedding the core resolver work here made this PR unreviewable on its own, so it is back to channel scope only.

Concretely, I replayed just this branch's own commits onto current main with git rebase --onto upstream/main <prereq>. The result:

  • 9 commits over main, down from 23
  • production delta +422/-29, down from the +97 net that came from carrying the core work
  • no commands-compact, history.ts, or attempt-history files in the diff at all

That removes the unrelated compaction and legacy-model coverage in one move, since it only existed here because the prerequisite's commits were riding along. #119326 stays independently reviewable and this PR no longer depends on it landing first.

On the P3: with the core work gone from this head, getHistoryLimitFromSessionKey is back to (sessionKey, config) with no account id, so the existing comment in the contract test is accurate again rather than stale. I would rather leave it saying "no account-scope assertion on purpose, the resolver takes no account id" than assert a per-account precedence this branch does not implement. Once #119326 lands, the account assertion becomes truthful and I will add it then.

Worth stating plainly, since I went the other way last time on your earlier note: I read "land and rebase on #119326" as an instruction to stack, and that was the wrong call. Reducing this to channel scope and letting the core land separately is clearly the better shape.

Validation on the unstacked head: channel-history-limit.contract 22, schema.help.quality 24, config-cli 188, line 523, mattermost 759, both generator --check gates clean.

AI-assisted.

@ayaangazali

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (46e44baf460). This branch had picked up the recurring conflict in the generated config baseline (docs/.generated/config-baseline.counts.json and config-baseline.sha256); it is now 0 commits behind and merge-clean.

The baseline was not hand-merged. I reset both generated files to main and re-ran both generators, so the artifacts match what CI regenerates:

node --import tsx scripts/generate-config-doc-baseline.ts --check                  clean
node --import tsx scripts/generate-bundled-channel-config-metadata.ts --check      clean

Local proof at head dd955861e81:

src/plugins/contracts + src/config/schema.help.quality.test.ts   43 files, 1058 passed
src/cli/config-cli.test.ts                                      190 passed

On the red marks: check-lint, check-lint-core-5 and check-docs are failing here, and I do not believe any of them are this branch. All three die during pnpm install before their actual check step runs (::error::pnpm install failed, then Process completed with exit code 1), with no rule violations or docs drift reported. check-lint and check-lint-core-5 are also currently red on main itself (for example 44b41d5686d). This branch touches no package.json, pnpm-lock.yaml or pnpm-workspace.yaml.

I also think I made that worse: I pushed nine rebases within about a minute, so nine fork CI runs hit dependency install at once. That was my mistake in batching, not a change in the code. Happy to re-push to re-trigger if you would rather see a clean run.

AI-assisted.

@ayaangazali

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (d8c1d90edb4), 0 behind and merge-clean. Both generated-artifact gates pass and the contract suites are green:

node scripts/run-vitest.mjs src/plugins/contracts src/config/schema.help.quality.test.ts   43 files
node scripts/run-vitest.mjs src/cli/config-cli.test.ts                                     190 passed
node --import tsx scripts/generate-config-doc-baseline.ts --check                           clean
node --import tsx scripts/generate-bundled-channel-config-metadata.ts --check               clean

One thing in the regenerated baseline is worth calling out so it is not mistaken for something this PR did. docs/.generated/config-baseline.counts.json moves core from 2324 to 2329 here. That growth is not from this change, which only touches channel schemas, and the channel count is the number this PR actually moves.

The core number is stale on main itself. On a pristine checkout of main with no changes at all:

$ node --import tsx scripts/generate-config-doc-baseline.ts --check
core: current 2329 > budget 2324; config surface grew; either remove config elsewhere or
consciously raise the budget in docs/.generated/config-baseline.counts.json in this PR
and justify it in the PR body.
Config baseline drift detected.
Hash mismatch: docs/.generated/config-baseline.sha256
exit 1

I confirmed the direction by forcing core back to 2324 on this branch, which reproduces that same current 2329 > budget 2324 failure. So the real core surface is already 2329 on main and only the committed budget is behind. Any PR that has to regenerate this file inherits the bump.

I did not want to silently raise a ratchet budget, and I also did not want to hand you a red gate, so I have kept the regenerated value and am flagging it here instead. If you would rather this PR pin core back to 2324 and let the check fail the way it already does on main, say so and I will switch it.

Separately, that drift looks worth a maintainer look on its own: the lane appears not to run on main pushes that touch no config path, so the budget can fall behind quietly and then surfaces on whichever contributor PR next touches config. I have not opened anything for it since raising the budget is a judgement call that belongs to you.

AI-assisted.

@ayaangazali

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (19c916be139), 0 behind and merge-clean.

The check-lint and check-docs red on the previous head was not this branch. Both lanes run oxfmt --check, and it was failing repo-wide on .agents/skills/openclaw-release-validation/SKILL.md, which drifted in with #126055. That is fixed on main now by #126060, so this rebase picks the repair up and those lanes should go green.

Verified at this head, both generated-artifact gates clean and the suites this PR owns passing. Nothing about the change itself moved; same diff, newer base.

AI-assisted.

@ayaangazali

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (784676537c9), 0 behind and merge-clean.

The jump to ten red checks on the previous head, including check-test-types and check-additional-extension-package-boundary, was a stale base rather than anything in this branch. My earlier rebase landed on main during a window where this was broken:

src/agents/subagents/announce/subagent-announce-direct-delivery.ts(85,5):
error TS2353: Object literal may only specify known properties, and
'resolveGatewayContext' does not exist ...
[tsgo] FAILED (exit 1)

main has since fixed it (#126040 and #126062 bound those dispatches to the Gateway instance, and that file now carries the comment "No resolveGatewayContext: this dispatch is bound to the Gateway instance"). I confirmed the current tip is clean by running the same lane on a pristine checkout of main, which exits 0, and again on this rebased head:

node scripts/run-tsgo-core-test-shards.mjs    exit 0

So this push simply moves the branch past that window. Nothing about the change itself moved; same diff, newer base.

AI-assisted.

@ayaangazali

Copy link
Copy Markdown
Contributor Author

On the P1 here: I agree with the diagnosis, and I do not think it should be fixed inside this PR.

You are right that accounts.<id>.historyLimit is accepted by the reusable account schemas and consumed by the LINE and Mattermost pending buffers, while normal prompt construction and compaction still call an account-blind resolver. With root 20 and account 3 that gives one session two different retention rules.

That account-blind resolver is exactly what #119326 repairs. It threads the routed account through getHistoryLimitFromSessionKey, and both remaining call sites read it:

  • prompt preparation, run/attempt-history.ts:537
  • compaction, compaction-session-execution.ts:349

I posted a before/after trace there showing the split: pre-fix an account with historyLimit: 2 resolves 10 and retains 12/12 messages, post-fix it resolves 2 and retains 4/12.

So the inconsistency you describe closes when #119326 lands, and duplicating that resolver change here would put the same repair in two PRs. This PR stays what it says on the tin: the schema accepts the documented key. Happy to reorder them if you would rather #119326 go first, or to close this one and fold the schema change into that branch if keeping them together reviews better.

Rebased and green either way.

Both pending-history buffers read only messages.groupChat.historyLimit, so the
documented per-channel and per-account override parsed and did nothing. Resolve
account then channel then global, matching the zalouser precedent, and declare
the key on both account config types.
Both build kind:group routes, so the session-key resolver applies
channels.<id>.historyLimit for them, but their strict schemas rejected it. The
contract selector keyed on groupPolicy/groups/groupAllowFrom, which neither
publishes, so it could not catch the gap.
Twitch validates as a two-branch union and both branches are closed, so
declaring historyLimit only on the account shape left
channels.twitch.historyLimit rejected whenever accounts is present. Move it to
the shared base so both branches accept it.
…ttermost

Covers account over channel root, channel root when the account sets nothing,
neither scope set, and an explicit 0 surviving rather than reading as unset.
Drives the spool deliver callback and reads what the handlers were given, so
account, channel-root, global, and explicit-zero values are pinned at the
boundary rather than only at the resolver.
…window

Drives the post handler through the missing-mention drop path, which is where an
inbound group post lands in the pending-history window, and asserts the limit
handed to it for account, global-fallback, and explicit-zero settings.
The hoisted mock declared only mediaMaxBytes, so reading the history cap the bot
hands to the handlers failed check-test-types even though vitest passed.
@steipete

Copy link
Copy Markdown
Contributor

Superseded by merged #129710 (4c4152e). The replacement preserves all seven working root-level channel settings and the real LINE/Mattermost account-aware pending-history fixes, removes unsupported Buzz and inert account options, and preserves credit to @ayaangazali. Generic account-scoped transcript/compaction behavior remains tracked separately in #119326.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: buzz channel: line Channel integration: line channel: mattermost Channel integration: mattermost channel: qa-channel Channel integration: qa-channel channel: tlon Channel integration: tlon channel: twitch Channel integration: twitch channel: zalo Channel integration: zalo docs Improvements or additions to documentation extensions: clickclack merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants