Skip to content

Config: expose Pi compaction tuning values - #21568

Merged
Takhoffman merged 2 commits into
mainfrom
split/pi-compaction-config-values
Feb 20, 2026
Merged

Takhoffman merged 2 commits into
mainfrom
split/pi-compaction-config-values

Conversation

@Takhoffman

@Takhoffman Takhoffman commented Feb 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Describe the problem and fix in 2–5 bullets:

  • Problem: OpenClaw did not expose Pi compaction tuning knobs (reserveTokens, keepRecentTokens) in agents.defaults.compaction, so users could not centrally tune Pi compaction behavior from OpenClaw config.
  • Why it matters: Tuning compaction thresholds is useful for stability and context retention, but required manual Pi-side settings changes.
  • What changed: Added config schema/types for agents.defaults.compaction.reserveTokens and agents.defaults.compaction.keepRecentTokens, and wired embedded Pi runners to apply those values via SettingsManager.applyOverrides, while continuing to enforce reserveTokensFloor.
  • What did NOT change (scope boundary): Did not expose compaction.enabled; did not change safeguard pruning logic; did not add docs/UI changes.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

  • Closes #
  • Related #

User-visible / Behavior Changes

  • agents.defaults.compaction.reserveTokens is now accepted and applied to embedded Pi runs.
  • agents.defaults.compaction.keepRecentTokens is now accepted and applied to embedded Pi runs.
  • agents.defaults.compaction.reserveTokensFloor continues to enforce a minimum floor for applied reserve tokens.
  • agents.defaults.compaction.enabled is intentionally not exposed in this PR.

Security Impact (required)

  • New permissions/capabilities? (Yes/No): No
  • Secrets/tokens handling changed? (Yes/No): No
  • New/changed network calls? (Yes/No): No
  • Command/tool execution surface changed? (Yes/No): No
  • Data access scope changed? (Yes/No): No
  • If any Yes, explain risk + mitigation:

Repro + Verification

Environment

  • OS: macOS
  • Runtime/container: Node 22+, pnpm
  • Model/provider: N/A (config + runner wiring)
  • Integration/channel (if any): Embedded Pi runner paths
  • Relevant config (redacted):
{
  "agents": {
    "defaults": {
      "compaction": {
        "reserveTokens": 15000,
        "keepRecentTokens": 12000,
        "reserveTokensFloor": 20000
      }
    }
  }
}

Steps

  1. Set compaction tuning values in openclaw.json under agents.defaults.compaction.
  2. Execute embedded run/compaction paths that create SettingsManager.
  3. Observe that applied Pi compaction settings include tuned values with floor enforcement.

Expected

  • Config parses successfully.
  • Pi settings overrides include tuned reserveTokens / keepRecentTokens.
  • reserveTokens never drops below configured/default floor.

Actual

  • Matches expected.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios:
    • pnpm tsgo
    • pnpm test src/config/config.compaction-settings.test.ts
    • pnpm exec vitest run -c vitest.e2e.config.ts src/agents/pi-settings.e2e.test.ts
  • Edge cases checked:
    • keepRecentTokens unset preserves current Pi setting (no forced safeguard override)
    • keepRecentTokens: 0 is treated invalid and preserves current setting
    • reserve floor enforcement still applies
  • What you did not verify:
    • Full end-to-end live provider run

Compatibility / Migration

  • Backward compatible? (Yes/No): Yes
  • Config/env changes? (Yes/No): No
  • Migration needed? (Yes/No): No
  • If yes, exact upgrade steps:

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly:
    • Revert commit a1801984b.
  • Files/config to restore:
    • src/agents/pi-settings.ts
    • src/agents/pi-embedded-runner/compact.ts
    • src/agents/pi-embedded-runner/run/attempt.ts
    • src/config/types.agent-defaults.ts
    • src/config/zod-schema.agent-defaults.ts
  • Known bad symptoms reviewers should watch for:
    • Compaction tuning values in config not reflected in runtime behavior.

Risks and Mitigations

List only real risks for this PR. Add/remove entries as needed. If none, write None.

  • Risk: Applying config overrides could unintentionally diverge from existing Pi local settings.
    • Mitigation: Overrides are narrow (only reserve/keepRecent), and tests cover preservation/fallback behavior.

Greptile Summary

Exposes Pi compaction tuning values (reserveTokens and keepRecentTokens) through OpenClaw config schema, enabling users to centrally tune Pi compaction behavior without manual Pi-side settings changes.

Key changes:

  • Added config schema fields for agents.defaults.compaction.reserveTokens and agents.defaults.compaction.keepRecentTokens
  • Created applyPiCompactionSettingsFromConfig() to handle both reserve and keepRecent token settings with proper validation
  • Refactored embedded Pi runners to use the new unified settings application function
  • Maintained reserveTokensFloor enforcement to prevent unsafe configurations
  • Added comprehensive test coverage for edge cases including zero values and floor enforcement

Validation alignment:

  • Zod schema validation matches runtime validation (nonnegative for reserveTokens, positive for keepRecentTokens)
  • Invalid values (negative, non-finite, zero for keepRecentTokens) fall back to current Pi settings
  • Floor enforcement correctly applies via Math.max() logic

Backward compatibility:

  • Existing ensurePiCompactionReserveTokens() function preserved
  • New config fields are optional with sensible fallback behavior
  • No breaking changes to existing configuration

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation is well-designed with proper validation at multiple layers (Zod schema + runtime), comprehensive test coverage including edge cases, maintains backward compatibility, and follows established patterns in the codebase. The refactoring from ensurePiCompactionReserveTokens to applyPiCompactionSettingsFromConfig is clean and maintains the floor enforcement safety mechanism. No security concerns, no breaking changes, and the scope is tightly focused on exposing existing Pi settings through config.
  • No files require special attention

Last reviewed commit: a180198

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Feb 20, 2026
@Takhoffman
Takhoffman force-pushed the split/pi-compaction-config-values branch from a180198 to c8e3809 Compare February 20, 2026 03:40
@Takhoffman
Takhoffman merged commit c1ac37a into main Feb 20, 2026
10 of 11 checks passed
@Takhoffman
Takhoffman deleted the split/pi-compaction-config-values branch February 20, 2026 03:41
@Takhoffman

Copy link
Copy Markdown
Contributor Author

Autoland completion summary:

Verification run in prep worktree:

  • pnpm install --frozen-lockfile
  • pnpm build
  • pnpm check
  • pnpm test:macmini

Notes:

  • Changelog line added under 2026.2.20 (Unreleased) / Fixes.
  • Recent-fix triage indicated this was new work (not superseded).

anisoptera pushed a commit to anisoptera/openclaw that referenced this pull request Feb 20, 2026
…akhoffman

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: Takhoffman <[email protected]>
vincentkoc pushed a commit that referenced this pull request Feb 21, 2026
Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: Takhoffman <[email protected]>
vincentkoc pushed a commit that referenced this pull request Feb 21, 2026
Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: Takhoffman <[email protected]>
mmyyfirstb pushed a commit to mmyyfirstb/openclaw that referenced this pull request Feb 21, 2026
…akhoffman

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: Takhoffman <[email protected]>
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
…akhoffman

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: Takhoffman <[email protected]>
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
…akhoffman

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: Takhoffman <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
…akhoffman

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: Takhoffman <[email protected]>
lhfer pushed a commit to lhfer/openclaw that referenced this pull request Oct 11, 2026
…akhoffman

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: Takhoffman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant