Skip to content

Commit fa6b02a

Browse files
authored
fix: recovery compaction ignores Stop and loses committed counts (#133260)
* fix(agents): bind compaction recovery to its run owner Stop cancelled or replaced runs before further recovery work while retaining completed compaction facts. Accept successor identity at the host commit boundary, bind fresh-session writers on the initial insert, and account context in producer order without confusing billing usage or public metadata with ownership. Fixes #127523 * fix(agents): preserve bound compaction delegates Type-check the recovery fixture inputs, distinguish queued target projection, and keep the new QA scenario on the audited serial path. Preserve watchdog identity, caller signals, writer fencing, and committed accounting without suppression exceptions.
1 parent 4dfa35d commit fa6b02a

158 files changed

Lines changed: 13987 additions & 4999 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎config/assertion-safety-baseline.txt‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,7 +1730,6 @@ src/agents/codex-mcp-config.ts 1
17301730
src/agents/command/attempt-execution.helpers.ts 7
17311731
src/agents/command/attempt-execution.ts 3
17321732
src/agents/command/delivery.ts 2
1733-
src/agents/command/session-store.ts 2
17341733
src/agents/compaction-planning-projection.ts 6
17351734
src/agents/compaction-planning-worker.ts 1
17361735
src/agents/compaction-planning.ts 1
@@ -1761,7 +1760,7 @@ src/agents/embedded-agent-runner/cache-ttl.ts 2
17611760
src/agents/embedded-agent-runner/cli-backend-dispatch-transcript.ts 7
17621761
src/agents/embedded-agent-runner/cli-backend-dispatch.ts 1
17631762
src/agents/embedded-agent-runner/compact.hooks.harness.ts 8
1764-
src/agents/embedded-agent-runner/compact.queued.ts 5
1763+
src/agents/embedded-agent-runner/compact.queued.ts 3
17651764
src/agents/embedded-agent-runner/compaction-diagnostics.ts 5
17661765
src/agents/embedded-agent-runner/compaction-hooks.ts 1
17671766
src/agents/embedded-agent-runner/compaction-session-agent.ts 7
@@ -1864,7 +1863,7 @@ src/agents/embedded-agent-subscribe.handlers.messages.update.ts 6
18641863
src/agents/embedded-agent-subscribe.handlers.tools.completion.ts 3
18651864
src/agents/embedded-agent-subscribe.handlers.tools.results.ts 14
18661865
src/agents/embedded-agent-subscribe.handlers.tools.start.ts 8
1867-
src/agents/embedded-agent-subscribe.handlers.ts 11
1866+
src/agents/embedded-agent-subscribe.handlers.ts 10
18681867
src/agents/embedded-agent-subscribe.tool-text-diagnostics.ts 6
18691868
src/agents/embedded-agent-subscribe.ts 5
18701869
src/agents/embedded-agent-tool-media.ts 10
@@ -1977,7 +1976,6 @@ src/agents/session-suspension.ts 1
19771976
src/agents/session-tool-result-guard.ts 24
19781977
src/agents/session-transcript-repair.ts 15
19791978
src/agents/sessions/agent-session-base.ts 3
1980-
src/agents/sessions/agent-session-compaction.ts 1
19811979
src/agents/sessions/agent-session-extensions.ts 1
19821980
src/agents/sessions/agent-session-inspection.ts 2
19831981
src/agents/sessions/agent-session-models.ts 2

‎config/max-lines-baseline.txt‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ src/agents/embedded-agent-runner.run-embedded-agent.auth-profile-rotation.e2e.te
337337
src/agents/embedded-agent-runner.sanitize-session-history.test.ts
338338
src/agents/embedded-agent-runner/compact.hooks.harness.ts
339339
src/agents/embedded-agent-runner/compact.hooks.test.ts
340-
src/agents/embedded-agent-runner/compact.queued.ts
341340
src/agents/embedded-agent-runner/context-engine-maintenance.test.ts
342341
src/agents/embedded-agent-runner/extra-params.ts
343342
src/agents/embedded-agent-runner/model.provider-runtime.test-support.ts

‎docs/concepts/compaction.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ existing recovery outcome.
3838

3939
Auto-compaction is on by default. It runs when the session nears the context limit, or when the model returns a context-overflow error (in which case OpenClaw compacts and retries).
4040

41+
Stopping a run also stops its overflow or timeout recovery. The built-in OpenClaw runtime does not start further recovery hooks, maintenance, transcript truncation, or retries after cancellation. Cancellation is not rollback: a compaction that already completed remains in the transcript and is still counted, without sending a late reply. The context estimate follows the latest model or compaction observation; billing totals remain separate.
42+
4143
Normal replies check session usage before the next turn. Successful direct commands using the built-in OpenClaw runtime, including `openclaw agent --local`, run the same usage-based maintenance after recording the completed turn and protecting any pending reply. The following command then uses the compacted context. This works in safeguard mode even when memory flush is disabled; native runtimes retain their own compaction ownership.
4244

4345
If direct-command post-turn compaction fails, OpenClaw logs a warning and returns the completed reply while the run and session are still current. Cancellation, restart, or a replaced session still stops that result from being returned.
@@ -149,7 +151,9 @@ checkpoint artifacts are not the active compaction target.
149151

150152
### Successor transcripts
151153

152-
A context engine may return an explicit compacted successor session identity. OpenClaw adopts that successor and records checkpoint metadata against it. The built-in SQLite compactor keeps the current session identity and does not create a second runtime transcript.
154+
A context engine may return an explicit compacted successor session identity within the same agent, session key, and store. OpenClaw publishes the accepted successor before maintenance, hooks, or retries use it, while retaining the current writer's ownership. Cancelling afterward does not roll that completed transition back. The built-in SQLite compactor keeps the current session identity and does not create a second runtime transcript.
155+
156+
A [worker placement](/gateway/cloud-workers) cannot transfer ownership to a different session identity during compaction. Custom engines must keep the current identity while the placement owns the session, or the operator must move the session back to the Gateway before retrying. A rejected transition leaves the original session and worker claim intact.
153157

154158
OpenClaw no longer writes separate `.checkpoint.*.jsonl` copies for new
155159
compactions. Existing legacy checkpoint files can still be used while referenced
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
title: Gateway compaction preserves writer ownership and committed facts
2+
3+
scenario:
4+
id: gateway-compaction-abort
5+
surface: runtime
6+
coverage:
7+
primary:
8+
- session-memory.compaction-retry-policy
9+
secondary:
10+
- session-memory.compaction
11+
- session-memory.pruning
12+
objective: Verify that stock overflow compaction through the real Gateway cannot write after writer replacement or cancellation, while cancellation after its commit preserves completed accounting.
13+
successCriteria:
14+
- A real built Gateway receives a synthetic HTTP context overflow and starts an actual compaction summary request held by the provider fixture.
15+
- The retained active transcript includes a completed assistant tool call paired with a 180000-character tool result before cancellation.
16+
- chat.abort cancels the exact run, and releasing the summary does not change pre-existing durable rows, retained active entry identities, tool content, or compaction accounting.
17+
- Replacing the original run's durable writer through the real claim owner in the isolated producer child preserves the same session and lifecycle revision; without chat.abort, releasing the summary cannot append a stale compaction, change checkpoints or accounting, or retry the old turn. The original lifecycle independently settles as failed, and its verified terminal fields are the only allowed replacement-row changes.
18+
- A fresh turn on the same session reaches its own held provider request before final state assertions, proving the old session lane released without relying only on agent.wait.
19+
- Interrupted turns deliver no final marker, while their same-session successors deliver exactly one recovery marker through QA Channel, matched to the exact successor run rather than rejected by an earlier run's warning.
20+
- An independent summary failure while still active exercises tool-result truncation and recovers without a compaction count increment.
21+
- A separate successful summary control commits and counts exactly one compaction.
22+
- An ordinary explicitly enabled workspace hook proves its loaded gateway startup event, then holds session:compact:after after a real SQLite compaction; aborting the original caller must retain that compaction and settle count one while the hook is still held, before release or successor admission.
23+
- The committed-cancellation case releases the hook in finally, observes hook settlement and the next same-session provider request, then joins only the owned Gateway before its final SQLite and delivery assertions; no second compaction or late original reply is allowed.
24+
- The held internal after hook covers the enclosing ContextEngine cancellation race, not the earlier SDK session_compact extension-hook timing.
25+
regressionRefs:
26+
- https://github.com/openclaw/openclaw/issues/127523
27+
- https://github.com/openclaw/openclaw/issues/127551
28+
docsRefs:
29+
- docs/concepts/compaction.md
30+
- docs/automation/hooks.md
31+
- docs/concepts/qa-e2e-automation.md
32+
- docs/channels/qa-channel.md
33+
codeRefs:
34+
- test/e2e/qa-lab/runtime/gateway-compaction-abort.ts
35+
- test/e2e/qa-lab/runtime/gateway-compaction-provider.fixture.ts
36+
- test/e2e/qa-lab/runtime/gateway-compaction-state.fixture.ts
37+
- src/context-engine/delegate.ts
38+
- src/agents/embedded-agent-runner/compaction-session-execution.ts
39+
- src/agents/embedded-agent-runner/compaction-safety-timeout.ts
40+
- src/agents/embedded-agent-runner/run/session-bootstrap.ts
41+
- src/agents/embedded-agent-runner/run/compaction-runtime.ts
42+
- src/agents/embedded-agent-runner/run/overflow-context-recovery.ts
43+
- src/agents/embedded-agent-runner/tool-result-truncation.ts
44+
- src/gateway/server-methods/chat-abort-handler.ts
45+
execution:
46+
kind: script
47+
path: test/e2e/qa-lab/runtime/gateway-compaction-abort.ts
48+
timeoutMs: 660000
49+
summary: Run on Blacksmith Testbox after OPENCLAW_BUILD_PRIVATE_QA=1 pnpm build. The producer launches an environment-isolated child before importing OpenClaw and uses a built dist Gateway with owned state and ports. Pending cancellation, real writer replacement, independent summary failure, success, and cancellation during a loaded internal after hook record SQLite snapshots, held-hook accounting, provider checkpoints, QA Channel delivery, owned-process settlement, and a standard evidence verdict.
50+
config:
51+
requiredProviderMode: mock-openai
52+
args:
53+
- --artifact-base
54+
- ${outputDir}

0 commit comments

Comments
 (0)