openclaw - 💡(How to fix) Fix Config schema rejects contextSafety even though runtime supports it [1 comments, 2 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#74462Fetched 2026-04-30 06:23:44
View on GitHub
Comments
1
Participants
2
Timeline
1
Reactions
2
Author
Timeline (top)
commented ×1

OpenClaw runtime reads cfg.session.contextSafety and cfg.contextSafety, but the durable config schema rejects both paths. This causes openclaw.json to be clobbered/restored when a user tries to configure context safety explicitly.

Error Message

  • Runtime commands work from defaults:
    • /context_status
    • /handoff_now
    • /handoff_latest
    • /rollover_now
  • Manual rollover successfully keeps the same Telegram peer/session key while switching to a new session id and carrying forward a handoff.
  • But adding session.contextSafety to openclaw.json causes config validation to fail.
  • OpenClaw saves the attempted config as .clobbered.* and restores the last-known-good config.
  • Top-level contextSafety is also rejected.

Root Cause

For Telegram/client-bot deployments, users will not manually run /new or manage sessions. Automatic context rollover/handoff is critical to avoid bloated sessions, compaction interruption, and degraded model behavior. The runtime feature appears to exist, but cannot currently be configured durably.

Code Example

const raw = cfg?.session?.contextSafety ?? cfg?.contextSafety ?? {};

---

const validated = OpenClawSchema.safeParse(normalizedRaw);

---

{
  "ok": false,
  "issues": [
    {
      "path": "session",
      "message": "Unrecognized key: \"contextSafety\""
    }
  ],
  "warnings": []
}

---

{
  "session": {
    "contextSafety": {
      "enabled": true,
      "autoRollover": true,
      "warnOnly": false,
      "clientSafeMode": true,
      "handoffDir": "~/.openclaw/workspace/session-handoffs",
      "maxHandoffChars": 12000,
      "maxContextTokens": 200000,
      "fallbackMaxTranscriptBytes": 800000,
      "fallbackMaxMessages": 1200,
      "thresholds": {
        "rollingSummaryPct": 70,
        "durableHandoffPct": 80,
        "autoRolloverPct": 85,
        "forceHandoffPct": 90,
        "emergencyPct": 95
      }
    }
  }
}
RAW_BUFFERClick to expand / collapse

Summary

OpenClaw runtime reads cfg.session.contextSafety and cfg.contextSafety, but the durable config schema rejects both paths. This causes openclaw.json to be clobbered/restored when a user tries to configure context safety explicitly.

Observed behavior

  • Runtime commands work from defaults:
    • /context_status
    • /handoff_now
    • /handoff_latest
    • /rollover_now
  • Manual rollover successfully keeps the same Telegram peer/session key while switching to a new session id and carrying forward a handoff.
  • But adding session.contextSafety to openclaw.json causes config validation to fail.
  • OpenClaw saves the attempted config as .clobbered.* and restores the last-known-good config.
  • Top-level contextSafety is also rejected.

Evidence

Runtime reads contextSafety in dist/context-safety.runtime-local.js:

const raw = cfg?.session?.contextSafety ?? cfg?.contextSafety ?? {};

Schema rejects it in dist/zod-schema-DjRHIl0Z.js.

Notes:

  • SessionSchema is strict.
  • It includes threadBindings and maintenance.
  • It does not include contextSafety.

Validator in dist/io-CFdEhZuM.js:

const validated = OpenClawSchema.safeParse(normalizedRaw);

Validation result:

{
  "ok": false,
  "issues": [
    {
      "path": "session",
      "message": "Unrecognized key: \"contextSafety\""
    }
  ],
  "warnings": []
}

Types also appear to omit it in dist/plugin-sdk/src/config/types.base.d.ts.

Notes:

  • SessionConfig has no contextSafety field.

Expected behavior

A durable supported config path should exist, preferably:

{
  "session": {
    "contextSafety": {
      "enabled": true,
      "autoRollover": true,
      "warnOnly": false,
      "clientSafeMode": true,
      "handoffDir": "~/.openclaw/workspace/session-handoffs",
      "maxHandoffChars": 12000,
      "maxContextTokens": 200000,
      "fallbackMaxTranscriptBytes": 800000,
      "fallbackMaxMessages": 1200,
      "thresholds": {
        "rollingSummaryPct": 70,
        "durableHandoffPct": 80,
        "autoRolloverPct": 85,
        "forceHandoffPct": 90,
        "emergencyPct": 95
      }
    }
  }
}

Suggested fix

  1. Add ContextSafetyConfigSchema.
  2. Add session.contextSafety?: ContextSafetyConfig to SessionSchema.
  3. Consider whether top-level contextSafety should be supported as a legacy alias since runtime already reads it.
  4. Add matching TypeScript config types.
  5. Add runtime-schema/config metadata/docs entries so config tooling knows the path exists.

Why this matters

For Telegram/client-bot deployments, users will not manually run /new or manage sessions. Automatic context rollover/handoff is critical to avoid bloated sessions, compaction interruption, and degraded model behavior. The runtime feature appears to exist, but cannot currently be configured durably.

Verified locally

  • dist/context-safety.runtime-local.js reads cfg?.session?.contextSafety ?? cfg?.contextSafety ?? {}.
  • dist/zod-schema-DjRHIl0Z.js defines a strict SessionSchema with no contextSafety field.
  • dist/io-CFdEhZuM.js validates config through OpenClawSchema.safeParse(normalizedRaw).
  • dist/plugin-sdk/src/config/types.base.d.ts omits contextSafety from SessionConfig.

extent analysis

TL;DR

The most likely fix is to add ContextSafetyConfigSchema and update SessionSchema to include session.contextSafety to support durable configuration of context safety.

Guidance

  • Update the SessionSchema to include an optional contextSafety field with its own schema, ContextSafetyConfigSchema.
  • Add TypeScript config types to match the updated schema, including ContextSafetyConfig and its properties.
  • Consider adding a legacy alias for top-level contextSafety to support existing runtime behavior.
  • Verify the changes by testing config validation with the updated schema and types.

Example

const ContextSafetyConfigSchema = z.object({
  enabled: z.boolean(),
  autoRollover: z.boolean(),
  // ... other properties ...
});

const SessionSchema = z.object({
  threadBindings: z.array(z.string()),
  maintenance: z.object({ /* ... */ }),
  contextSafety: ContextSafetyConfigSchema.optional(),
});

Notes

The provided issue suggests a clear path forward, but it's essential to test the changes thoroughly to ensure they don't introduce new issues.

Recommendation

Apply the suggested fix by adding ContextSafetyConfigSchema and updating SessionSchema to include session.contextSafety, as this will provide a durable configuration path for context safety.

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…

FAQ

Expected behavior

A durable supported config path should exist, preferably:

{
  "session": {
    "contextSafety": {
      "enabled": true,
      "autoRollover": true,
      "warnOnly": false,
      "clientSafeMode": true,
      "handoffDir": "~/.openclaw/workspace/session-handoffs",
      "maxHandoffChars": 12000,
      "maxContextTokens": 200000,
      "fallbackMaxTranscriptBytes": 800000,
      "fallbackMaxMessages": 1200,
      "thresholds": {
        "rollingSummaryPct": 70,
        "durableHandoffPct": 80,
        "autoRolloverPct": 85,
        "forceHandoffPct": 90,
        "emergencyPct": 95
      }
    }
  }
}

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 - 💡(How to fix) Fix Config schema rejects contextSafety even though runtime supports it [1 comments, 2 participants]