Skip to content

fix(memory): inherit default context limits when an agent overrides one - #164633

Merged
steipete merged 1 commit into
mainfrom
fix/w5-compaction
Oct 4, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/w5-compaction

Conversation

@steipete

@steipete steipete commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

memory_get injected far more text into the model context than the configured limit when an agent overrode only part of its memory context limits. With a default memoryGetMaxChars: 2000 and an agent that overrides only postCompactionMaxChars, a read returned 7,999 untruncated characters and no continuation pointer. The default excerpt cap, which bounds model-visible context, silently stopped applying.

Why This Change Was Made

packages/memory-host-sdk/src/host/config-utils.ts resolved agent context limits by replacing the defaults object with the agent's partial object instead of merging field by field (introduced by 025081dbc576). Any agent-level override therefore dropped every inherited limit it did not repeat. The resolver now merges agent fields over the defaults, so unspecified limits are inherited.

User Impact

Agents that customize one memory limit keep the default excerpt bound on memory_get: reads return a bounded excerpt plus continuation guidance (nextFrom) instead of flooding the context.

Evidence

  • Regression fails before (7,999 characters, untruncated) and passes after (1,999 excerpt characters plus continuation guidance, nextFrom: 21).
  • Blacksmith Testbox on rebased 3562b697df6: 108 tests across eight related suites, pnpm build, and check-changed pass.
  • Stub-Gateway long-session flows: 14 turns with three automatic compactions, preserved history and model context, manual compaction, restart during/after compaction, concurrent turns without duplication, visible summarization-error recovery, and memory write/read/search with cross-session continuity and cross-agent isolation.
  • Production +2/-1 LOC; tests +31.

Merge per-agent context-limit overrides over the defaults instead of
replacing the entire object. An unrelated postCompactionMaxChars override
must not silently discard the documented memoryGetMaxChars inheritance.

The host adapter consolidation in 025081d
introduced the raw-object fallback. Cover omitted, partial, and explicit
agent limits through readAgentMemoryFile without changing config or SDK
contracts.

Before: an isolated Gateway returned all 7,999 characters despite a 2,000
character default. After: the same flow returns a 1,999-character excerpt,
truncation metadata, and continuation at line 21 (2,051 characters total).
The regression failed before the fix and passes afterward.

Validation on Blacksmith Testbox, rebased onto 3562b69:
- 108 related memory tests across eight files passed.
- pnpm test packages/memory-host-sdk/src/host/read-file.test.ts --maxWorkers=1:
  18 passed, 2.55s Testbox wall time, 1.44s Vitest duration.
- pnpm build and node scripts/check-changed.mjs passed.
- Stub-provider Gateway proof passed automatic/manual compaction, history
  retention, concurrent turns, visible summarization failure, and restart
  after and during compaction.
- Agent-driven memory write, cross-session read/search, cross-agent isolation,
  and restart continuity passed with isolated state and no real credentials.

Formatting and validation ran remotely; local hooks were skipped to honor
the campaign's no-local-build/test/tooling requirement.
@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review October 4, 2026 00:27
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 4, 2026
@clawsweeper

clawsweeper Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 3, 2026, 8:32 PM ET / October 4, 2026, 00:32 UTC.

ClawSweeper review

What this changes

The PR merges per-agent memory context limits over shared defaults and adds file-read regression cases for omitted, partial, and explicit overrides.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: pinned current main still drops inherited memory limits when an agent supplies a partial override. The focused repair matches the documented contract, and no blocking patch defect was found.

Priority: P2
Reviewed head: e43c0e5e57dfd55fac35675a4f6ccc1ca28df6e5

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, maintainable repair with meaningful boundary regression coverage and no identified blocking defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The repository-state MEMBER classification exempts this PR from the external-contributor proof gate. The pinned commit nevertheless records an isolated Gateway memory_get before/after result matching the changed resolver; no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The repository-state MEMBER classification exempts this PR from the external-contributor proof gate. The pinned commit nevertheless records an isolated Gateway memory_get before/after result matching the changed resolver; no stored-data contract changes.
Evidence reviewed 6 items Pinned introduced change: The introduced production hunk merges defaults before agent overrides; the added table exercises actual memory-file reads rather than mocking limit resolution.
Still needed on current main: The fetched main revision still returns the entire agent contextLimits object instead of merging omitted fields from defaults. No current-main implementation of this repair was established.
Existing inheritance contract: The configuration documentation explicitly says omitted per-agent context-limit fields inherit from agents.defaults.contextLimits. The existing core agent resolver already merges these fields, supporting the same semantics at the memory-host boundary.
Findings None None.
Security None None.

How this fits together

OpenClaw's memory reader turns agent configuration and Markdown files into model-visible excerpts. Resolved character limits control truncation and continuation guidance returned by memory_get.

flowchart TD
 A[Shared context limits] --> C[Resolve agent limits]
 B[Agent overrides] --> C
 C --> E[Read memory file]
 D[Memory request and Markdown file] --> E
 E --> F[Apply excerpt budget]
 F --> G[Excerpt and continuation guidance]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +1, Tests +30. Total +31 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 2 1 +1
Tests 1 30 0 +30
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 32 1 +31

Review metrics

None.

Technical review

Best possible solution:

Keep memory reads aligned with the existing field-by-field inheritance contract while preserving explicit agent limits and continuation behavior.

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

Yes, from source: configure a 2,000-character default, override only postCompactionMaxChars for an agent, and read a longer memory file. Pinned main loses the configured cap; execution was not performed in this read-only review.

Is this the best way to solve the issue?

Yes. Merging at the existing memory-host resolver restores documented semantics without changing the public API or persisted config, and the regression cases protect inherited and explicit caps.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 2df2d8455db0.

Labels

Label changes:

  • add P2: This repairs a bounded memory-context budgeting defect triggered by partial per-agent overrides.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The repository-state MEMBER classification exempts this PR from the external-contributor proof gate. The pinned commit nevertheless records an isolated Gateway memory_get before/after result matching the changed resolver; no stored-data contract changes.

Label justifications:

  • P2: This repairs a bounded memory-context budgeting defect triggered by partial per-agent overrides.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The repository-state MEMBER classification exempts this PR from the external-contributor proof gate. The pinned commit nevertheless records an isolated Gateway memory_get before/after result matching the changed resolver; no stored-data contract changes.

Evidence

What I checked:

  • Pinned introduced change: The introduced production hunk merges defaults before agent overrides; the added table exercises actual memory-file reads rather than mocking limit resolution. (packages/memory-host-sdk/src/host/config-utils.ts:187, e43c0e5e57df)
  • Still needed on current main: The fetched main revision still returns the entire agent contextLimits object instead of merging omitted fields from defaults. No current-main implementation of this repair was established. (packages/memory-host-sdk/src/host/config-utils.ts:187, 2df2d8455db0)
  • Existing inheritance contract: The configuration documentation explicitly says omitted per-agent context-limit fields inherit from agents.defaults.contextLimits. The existing core agent resolver already merges these fields, supporting the same semantics at the memory-host boundary. Public docs: docs/gateway/config-agents/workspace-and-bootstrap.md. (docs/gateway/config-agents/workspace-and-bootstrap.md:258, e43c0e5e57df)
  • Production read boundary: readAgentMemoryFile passes the resolved memoryGetMaxChars to the existing reader. Result shaping preserves line-aware continuation and the raw-read fallback for oversized single lines; the patch changes neither path authorization nor stored configuration. (packages/memory-host-sdk/src/host/read-file.ts:170, e43c0e5e57df)
  • Recorded validation: The pinned commit reports an isolated Gateway changing from 7,999 unbounded characters to a 1,999-character excerpt with nextFrom 21. It also records 108 related tests and a focused test cost of 2.55 seconds wall time and 1.44 seconds Vitest duration. These are author-recorded observations; this read-only review did not execute tests. (e43c0e5e57df)
  • Area history and inspection limits: Current-main file history includes prior memory-host work by Peter Steinberger and PollyBot13. Deeper pickaxe and blame inspection encountered unavailable historical blobs whose retrieval returned HTTP 403, so no exact source-line introduction attribution is asserted. (packages/memory-host-sdk/src/host/config-utils.ts, 2df2d8455db0)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • PollyBot13: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

@steipete
steipete merged commit d2dec0c into main Oct 4, 2026
192 of 194 checks passed
@steipete
steipete deleted the fix/w5-compaction branch October 4, 2026 01:32
@steipete

steipete commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 4, 2026
…164633)

Merge per-agent context-limit overrides over the defaults instead of
replacing the entire object. An unrelated postCompactionMaxChars override
must not silently discard the documented memoryGetMaxChars inheritance.

The host adapter consolidation in 280b6c5
introduced the raw-object fallback. Cover omitted, partial, and explicit
agent limits through readAgentMemoryFile without changing config or SDK
contracts.

Before: an isolated Gateway returned all 7,999 characters despite a 2,000
character default. After: the same flow returns a 1,999-character excerpt,
truncation metadata, and continuation at line 21 (2,051 characters total).
The regression failed before the fix and passes afterward.

Validation on Blacksmith Testbox, rebased onto fa864a2:
- 108 related memory tests across eight files passed.
- pnpm test packages/memory-host-sdk/src/host/read-file.test.ts --maxWorkers=1:
  18 passed, 2.55s Testbox wall time, 1.44s Vitest duration.
- pnpm build and node scripts/check-changed.mjs passed.
- Stub-provider Gateway proof passed automatic/manual compaction, history
  retention, concurrent turns, visible summarization failure, and restart
  after and during compaction.
- Agent-driven memory write, cross-session read/search, cross-agent isolation,
  and restart continuity passed with isolated state and no real credentials.

Formatting and validation ran remotely; local hooks were skipped to honor
the campaign's no-local-build/test/tooling requirement.

Co-authored-by: Peter Steinberger <[email protected]>
LibraHo added a commit to LibraHo/openclaw that referenced this pull request Oct 21, 2026
…irs for 8.35-D

Adapt official PRs openclaw#140388, openclaw#156842, openclaw#168738, openclaw#169010, openclaw#165444, openclaw#164633 and openclaw#169029 to the existing synchronous 2026.8.35 custom queue and plugin baseline. Preserve prior A/B/C repairs, UI, locked dependencies, database schemas, configuration and build customizations.

Canonical build source: 7fdcb8a1f5b9cec7c1e9d66bc8ae551a38f0ed70
Verified complete source tree: 6511c79
Upstream base: 713ba57

Selected regression boundaries: 247 tests passed; core and plugin production typechecks passed; bounded P0 autoreview scoped-clean. Broader Windows cleanup/symlink EPERM limits are recorded in local verification. No live Telegram-group test or full repository-green claim.

Saved ordinary inbound final text permits one retry after typed ambiguous transport failure, at most two total sends, with possible duplicate after a lost acknowledgement. Media, controls and accepted partial/identityless evidence remain excluded. This does not grant all cron/invest completion paths replay permission.

Candidate build only; no production deployment or memory reset.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant