openclaw - ✅(Solved) Fix feat: per-agent session maintenance config overrides [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#52775Fetched 2026-04-08 01:19:34
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Author
Participants
Timeline (top)
cross-referenced ×1

Error Message

"maintenance": { "mode": "warn", "maxEntries": 50, "pruneAfter": "1d" }

Fix Action

Fixed

PR fix notes

PR #50755: feat: per-agent session maintenance config overrides

Description (problem / solution / changelog)

Closes #52775

Summary

  • Allow each agent to define its own maintenance config (mode, pruneAfter, maxEntries, rotateBytes, maxDiskBytes, highWaterBytes) that overrides the global session.maintenance settings
  • Extract SessionMaintenanceSchema into a shared zod-schema.maintenance.ts module, reused by both SessionSchema and AgentEntrySchema
  • Merge per-agent overrides over global config in resolveMaintenanceConfig(), with unset fields falling through to global defaults
  • Thread agentId through sessions-cleanup and saveSessionStore paths

Motivation

Different agents may have very different session lifecycle needs. A lightweight approval bot might only need 50 sessions retained for 1 day, while a heavy research agent might need 500 sessions for 30 days. This change lets operators tune maintenance per-agent without affecting the global baseline.

Example config

{
  "session": {
    "maintenance": { "mode": "enforce", "pruneAfter": "30d", "maxEntries": 500 }
  },
  "agents": {
    "list": [
      {
        "id": "approval",
        "maintenance": { "mode": "warn", "maxEntries": 50, "pruneAfter": "1d" }
      }
    ]
  }
}

Test plan

  • Added store-maintenance.per-agent.test.ts with 7 test cases covering:
    • Global-only config (no agentId)
    • Per-agent overrides merged over global
    • Agent with no maintenance config (falls through)
    • Unknown agentId (falls through)
    • Built-in defaults when no config exists
    • Per-agent maxDiskBytes/highWaterBytes override
    • Per-agent config without global maintenance
  • Fixed bug: cleanup command now resolves mode per-target instead of using global mode
  • Run pnpm test to verify all tests pass
  • Run pnpm check to verify lint/format

Changed files

  • src/commands/sessions-cleanup.ts (modified, +7/-7)
  • src/config/schema.base.generated.ts (modified, +74/-0)
  • src/config/sessions/store-maintenance.per-agent.test.ts (added, +185/-0)
  • src/config/sessions/store-maintenance.ts (modified, +46/-4)
  • src/config/sessions/store.ts (modified, +6/-1)
  • src/config/types.agents.ts (modified, +3/-1)
  • src/config/zod-schema.agent-runtime.ts (modified, +2/-0)
  • src/config/zod-schema.maintenance.ts (added, +75/-0)
  • src/config/zod-schema.session.ts (modified, +4/-73)

Code Example

{
  "session": {
    "maintenance": { "mode": "enforce", "pruneAfter": "30d", "maxEntries": 500 }
  },
  "agents": {
    "list": [
      {
        "id": "approval",
        "maintenance": { "mode": "warn", "maxEntries": 50, "pruneAfter": "1d" }
      }
    ]
  }
}
RAW_BUFFERClick to expand / collapse

Problem

Currently, session.maintenance settings (mode, pruneAfter, maxEntries, rotateBytes, maxDiskBytes, highWaterBytes) are global — every agent shares the same lifecycle policy. In practice, different agents have very different session retention needs:

  • A lightweight approval bot might only need 50 sessions retained for 1 day
  • A heavy research agent might need 500 sessions for 30 days
  • A customer support agent might need aggressive disk budgets while a dev agent doesn't

Operators currently have no way to tune these per-agent without affecting the global baseline.

Proposed Solution

Allow each agent entry in agents.list[] to define its own maintenance config that overrides the global session.maintenance settings. Unset fields fall through to the global defaults.

Example config

{
  "session": {
    "maintenance": { "mode": "enforce", "pruneAfter": "30d", "maxEntries": 500 }
  },
  "agents": {
    "list": [
      {
        "id": "approval",
        "maintenance": { "mode": "warn", "maxEntries": 50, "pruneAfter": "1d" }
      }
    ]
  }
}

Implementation approach

  1. Extract SessionMaintenanceSchema into a shared zod module (reused by both SessionSchema and AgentEntrySchema)
  2. Add maintenance?: SessionMaintenanceConfig to AgentConfig
  3. Merge per-agent overrides over global config in resolveMaintenanceConfig(agentId?)
  4. Thread agentId through sessions cleanup command and saveSessionStore paths
  5. Incrementally wire agentId through runtime write paths in follow-up PRs

Related PR

#50755

extent analysis

Fix Plan

To implement per-agent session maintenance settings, follow these steps:

  • Extract the SessionMaintenanceSchema into a shared zod module.
  • Update the AgentConfig to include an optional maintenance field.
  • Implement the resolveMaintenanceConfig(agentId?) function to merge per-agent overrides with the global config.
  • Update the sessions cleanup command and saveSessionStore paths to use the agentId.

Example Code

// shared zod module
import { z } from 'zod';

export const SessionMaintenanceSchema = z.object({
  mode: z.string().optional(),
  pruneAfter: z.string().optional(),
  maxEntries: z.number().optional(),
  rotateBytes: z.number().optional(),
  maxDiskBytes: z.number().optional(),
  highWaterBytes: z.number().optional(),
});

// AgentConfig update
import { SessionMaintenanceSchema } from './shared-zod-module';

const AgentConfig = z.object({
  id: z.string(),
  maintenance: SessionMaintenanceSchema.optional(),
});

// resolveMaintenanceConfig function
function resolveMaintenanceConfig(agentId) {
  const globalMaintenance = getGlobalMaintenanceConfig();
  const agentMaintenance = getAgentMaintenanceConfig(agentId);

  return {
    ...globalMaintenance,
    ...agentMaintenance,
  };
}

// Update sessions cleanup command and saveSessionStore paths
function cleanupSessions(agentId) {
  const maintenanceConfig = resolveMaintenanceConfig(agentId);
  // use maintenanceConfig to cleanup sessions
}

function saveSessionStore(agentId, session) {
  const maintenanceConfig = resolveMaintenanceConfig(agentId);
  // use maintenanceConfig to save session
}

Verification

To verify the fix, test the following scenarios:

  • Create an agent with custom maintenance settings and verify that the sessions are cleaned up according to the custom settings.
  • Create an agent without custom maintenance settings and verify that the sessions are cleaned up according to the global settings.
  • Update the global maintenance settings and verify that the changes are reflected in the agents without custom settings.

Extra Tips

  • Make sure to handle cases where the agentId is not provided or is invalid.
  • Consider adding logging or monitoring to track the usage of custom maintenance settings.
  • Review the related PR #50755 for any additional context or requirements.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix feat: per-agent session maintenance config overrides [1 pull requests, 1 participants]