Skip to content

fix(agents): preserve runtime settings overrides [AI-assisted] - #92237

Merged
vincentkoc merged 1 commit into
openclaw:mainfrom
sercada:fix/embedded-compaction-guard-preserve-reserve
Jul 1, 2026
Merged

vincentkoc merged 1 commit into
openclaw:mainfrom
sercada:fix/embedded-compaction-guard-preserve-reserve

Conversation

@sercada

@sercada sercada commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • keep SettingsManager.applyOverrides() as a runtime override layer instead of merging it only into the current settings snapshot
  • recompute effective settings from global + project + runtime overrides after save() and reload()
  • cover the embedded compaction path where reserveTokensFloor is applied before runtime auto-compaction/retry guards write settings

Why

Embedded agent runs can apply a configured compaction reserve floor, then call setters such as setCompactionEnabled(false) or setRetryEnabled(false). Those setters call save(), and save() previously rebuilt settings from global/project settings only. That dropped runtime overrides from applyOverrides(), so a configured reserve floor such as 50000 could fall back to the default runtime reserve (16384) inside the same turn.

Real behavior proof

  • Behavior or issue addressed: Embedded agent runtime settings keep configured compaction reserve overrides after runtime guard writes and reloads. This covers the case where reserveTokensFloor=50000 must remain the effective reserve after setCompactionEnabled(false) persists enabled=false.
  • Real environment tested: Local macOS source checkout of openclaw/openclaw at origin/main (575cae59d4) plus this patch, Node via the repo toolchain, no channel credentials or provider API keys used.
  • Exact steps or command run after this patch:
    1. Created a real SettingsManager.inMemory({ compaction: { enabled: true, reserveTokens: 16384 } }) from the patched source modules.
    2. Called applyAgentCompactionSettingsFromConfig() with agents.defaults.compaction.reserveTokensFloor=50000 and contextTokenBudget=200000.
    3. Called applyAgentAutoCompactionGuard() with compactionMode: "safeguard", which writes compaction.enabled=false through the real SettingsManager setter.
    4. Called settingsManager.reload() and printed settingsManager.getCompactionSettings().
  • Evidence after fix:
    node --import tsx -e 'import { SettingsManager } from "./src/agents/sessions/settings-manager.ts"; import { applyAgentAutoCompactionGuard, applyAgentCompactionSettingsFromConfig } from "./src/agents/agent-settings.ts"; const settingsManager = SettingsManager.inMemory({ compaction: { enabled: true, reserveTokens: 16384 } }); applyAgentCompactionSettingsFromConfig({ settingsManager, cfg: { agents: { defaults: { compaction: { reserveTokensFloor: 50000 } } } }, contextTokenBudget: 200000 }); applyAgentAutoCompactionGuard({ settingsManager, compactionMode: "safeguard" }); await settingsManager.reload(); console.log(JSON.stringify(settingsManager.getCompactionSettings()));'
    Output copied from the local run:
    {"enabled":false,"reserveTokens":50000,"keepRecentTokens":20000}
  • Observed result after fix: The effective settings keep enabled=false from the guard write and keep reserveTokens=50000 from the runtime override after reload. Before this patch, runtime overrides were only merged into the current settings snapshot, so a later write/reload path could drop the configured reserve back to the backing settings/default.
  • What was not tested: I did not run a live Telegram/OpenClaw gateway turn or a provider-backed model request for this PR. The proof uses the real local OpenClaw settings and compaction modules without external credentials.

AI-assisted PR; I understand the code path. Maintainer edits are OK on this fork branch.

Tests

  • node scripts/test-projects.mjs src/agents/agent-settings.test.ts src/agents/agent-project-settings.test.ts src/agents/sessions/settings-manager.test.ts
  • pnpm tsgo:core
  • pnpm exec oxlint src/agents/sessions/settings-manager.ts src/agents/sessions/settings-manager.test.ts src/agents/agent-project-settings.test.ts src/agents/agent-settings.test.ts
  • git diff --check
  • codex review --base origin/main (no actionable regressions)

Not fully run: pnpm check after the final patch. I ran it once; all preflight guards through shrinkwrap passed, then typecheck caught the missing definite assignment initializer that this commit fixes. A later pnpm tsgo:core passed. pnpm lint via scripts/run-oxlint-shards.mjs stalled locally with no worker CPU, so I ran oxlint directly on the touched files instead.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 11, 2026
@clawsweeper

clawsweeper Bot commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 21, 2026, 1:41 PM ET / 17:41 UTC.

Summary
The PR changes SettingsManager so non-persisted runtime overrides are retained across saves and reloads, with regression tests for embedded compaction reserve settings.

PR surface: Source +10, Tests +98. Total +108 across 4 files.

Reproducibility: yes. at source level: current main and v2026.6.9 apply a compaction override and then can drop it when retry or compaction setters recompute effective settings without runtime overrides. I did not execute tests because this review was read-only.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: serialized state: src/agents/sessions/settings-manager.test.ts, serialized state: src/agents/sessions/settings-manager.ts, unknown-data-model-change: src/agents/sessions/settings-manager.ts. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • none.

Next step before merge

  • No ClawSweeper repair lane is needed because the focused PR has sufficient proof and no actionable review findings.

Security
Cleared: The diff only changes TypeScript agent settings logic and tests; it does not touch dependencies, workflows, secrets, package metadata, or external code execution.

Review details

Best possible solution:

Land the narrow SettingsManager runtime-override layer after ordinary maintainer review and merge gates, keeping overrides non-persisted and covered by the added regression tests.

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

Yes, at source level: current main and v2026.6.9 apply a compaction override and then can drop it when retry or compaction setters recompute effective settings without runtime overrides. I did not execute tests because this review was read-only.

Is this the best way to solve the issue?

Yes. Keeping runtime overrides inside SettingsManager is the best owner-boundary fix because save, project writes, and reload all share that effective-settings recomputation point; reapplying overrides at individual callers would miss sibling setter paths.

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P2: This fixes a bounded embedded-agent settings bug that can change compaction reserve behavior during an active run, with limited blast radius.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes after-fix terminal proof using the real SettingsManager and agent compaction modules, with JSON output showing reserveTokens=50000 surviving a guard write and reload.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix terminal proof using the real SettingsManager and agent compaction modules, with JSON output showing reserveTokens=50000 surviving a guard write and reload.
Evidence reviewed

PR surface:

Source +10, Tests +98. Total +108 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 1 17 7 +10
Tests 3 98 0 +98
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 115 7 +108

What I checked:

  • Repository policy read and applied: Read the full root policy and scoped agents policy; the agent settings/config guidance made this a full-path, compatibility-sensitive review instead of a diff-only check. (AGENTS.md:1, eea777c9fc9c)
  • Current-main bug path: Current main rebuilds effective settings from only global and project settings in reload(), save(), and saveProjectSettings(), while applyOverrides() only mutates the current snapshot, so later writes can discard runtime-only overrides. (src/agents/sessions/settings-manager.ts:445, eea777c9fc9c)
  • Affected embedded-agent caller path: createPreparedEmbeddedAgentSettingsManager() applies compaction overrides and then calls setRetryEnabled(false), and applyAgentAutoCompactionGuard() can call setCompactionEnabled(false), both reaching the recompute path that drops overrides on current main. (src/agents/agent-project-settings.ts:63, eea777c9fc9c)
  • PR implementation evidence: The PR adds a runtimeOverrides layer, routes constructor/save/reload/project-save through recomputeSettings(), and adds settings-manager plus embedded compaction regression coverage. (src/agents/sessions/settings-manager.ts:250, 329020660517)
  • Latest release still has old behavior: Tag v2026.6.9 resolves to c645ec4555c017931de0e35ad9847dffae2741ef and shows the same applyOverrides() snapshot-only behavior plus save/reload recomputation from global/project settings only. (src/agents/sessions/settings-manager.ts:445, c645ec4555c0)
  • Related search: Search found nearby compaction reserve work such as Respect explicit compaction reserve tokens #94798, but that PR targets implicit reserve-floor semantics, not runtime override lifetime in SettingsManager.

Likely related people:

  • steipete: GitHub history ties this account to the large agent runtime internalization that carried SettingsManager and the embedded agent settings seams into the current source layout. (role: major runtime refactor author; confidence: medium; commits: bb46b79d3c14, f84460e62534; files: src/agents/sessions/settings-manager.ts, src/agents/agent-project-settings.ts, src/agents/agent-settings.ts)
  • vincentkoc: Recent commits touched the same agent-settings.ts compaction helper surface and current local blame for the reviewed lines points at the current-main agent settings snapshot. (role: recent area contributor; confidence: medium; commits: 4637b65470de, 9e3db6bedd28, 9f888d95e0; files: src/agents/agent-settings.ts, src/agents/agent-settings.test.ts, src/agents/sessions/settings-manager.ts)
  • openperf: Earlier merged reserve-floor work established the small-context compaction reserve behavior that the affected embedded compaction path builds on. (role: adjacent feature contributor; confidence: medium; commits: 4bc46ccfedc4; files: src/agents/pi-settings.ts, src/agents/pi-project-settings.ts, src/agents/pi-embedded-runner/run/attempt.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 11, 2026
@clawsweeper clawsweeper Bot added rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. P2 Normal backlog priority with limited blast radius. and removed rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. labels Jun 11, 2026
@vincentkoc
vincentkoc merged commit 1f75418 into openclaw:main Jul 1, 2026
245 of 261 checks passed
chenyangjun-xy pushed a commit to chenyangjun-xy/openclaw that referenced this pull request Jul 1, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

2 participants