Commit 3000217
Eva
fix(sessions): bump fallback-guard default to 2mb + add boot-time guard + operator recovery prompt (#76940)
Three follow-ups to the initial guard addition based on operator feedback:
1) Default threshold 1mb → 2mb. 1MiB jsonl is roughly 250k tokens of message
content; 2MiB is roughly 500k tokens. 500k tokens already overflows every
shipping context window — for models in the 200-256k effective-window
range it overflows much sooner. Operators on smaller-context models can
still dial down via session.maintenance.contextFallbackGuard.sizeBytes.
2) Boot-time guard (applyContextEngineBootGuard). The on-fallback path only
catches "configured engine failed to load." It misses the much more common
case: no context engine was ever configured. The legacy engine windows
the prompt in-memory at request time but never shrinks the on-disk jsonl,
so an unmanaged session grows append-only until the gateway stalls on
next start. The boot guard runs once at startup and applies the same
policy when slots.contextEngine is unset/legacy or the configured plugin
is missing from loadedPluginIds. Both triggers funnel into the same
applyContextEngineFallbackGuard implementation; one config knob, one
policy, two entry points.
3) Operator-facing message rewrite. The terse single-line warn/archive log
is replaced with a structured block that names the file, the engine that
failed, the size, the available repair commands (openclaw doctor --fix /
sessions archive / config set slots), AND a copy-pasteable recovery
prompt for the next agent turn. The prompt instructs the agent to read
the archived tail (last ~200 non-system messages, group into chunks of
1-2k tokens each, stop at ~40k tokens aggregate), giving the fresh
session enough context to continue meaningfully. Sized so we use the
fresh session's available context window — not so miserly that the user
loses their working state, not so generous that we eat the whole window.
Tests:
- 17 unit tests pass (12 original + 5 new for boot-guard / recovery prompt)
- Existing 34 src/context-engine tests unchanged
- Lint clean on changed files
Wiring:
- fallback-guard.ts: bump DEFAULT_FALLBACK_GUARD_SIZE_BYTES, add
renderWarnMessage / renderArchiveMessage / renderRecoveryPrompt,
add applyContextEngineBootGuard
- server-startup-post-attach.ts: invoke boot guard right after
logGatewayStartup; never let guard exceptions stall startup
- CHANGELOG: expanded entry covering both trigger paths and threshold
rationale
Refs #76940.1 parent 10b9df7 commit 3000217
4 files changed
Lines changed: 418 additions & 21 deletions
File tree
- src
- context-engine
- gateway
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
107 | 108 | | |
108 | 109 | | |
109 | 110 | | |
110 | | - | |
| 111 | + | |
111 | 112 | | |
112 | 113 | | |
113 | 114 | | |
| |||
200 | 201 | | |
201 | 202 | | |
202 | 203 | | |
203 | | - | |
| 204 | + | |
204 | 205 | | |
205 | 206 | | |
206 | 207 | | |
| |||
214 | 215 | | |
215 | 216 | | |
216 | 217 | | |
| 218 | + | |
217 | 219 | | |
218 | 220 | | |
219 | 221 | | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
220 | 359 | | |
221 | 360 | | |
222 | 361 | | |
| |||
0 commit comments