Skip to content

fix(compaction): preserve active request provenance - #180214

Merged
RomneyDa merged 2 commits into
mainfrom
fix/compaction-request-provenance
Nov 2, 2026
Merged

RomneyDa merged 2 commits into
mainfrom
fix/compaction-request-provenance

Conversation

@RomneyDa

@RomneyDa RomneyDa commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Problem

Compaction could replace the active human request with a later internal observation, or revive completed human work during an independent internal run. The first revision also rejected a second recovery after the production semantic-window reader archived the original admitted request.

Solution

  • Carry the admitted request boundary from the runtime through AgentSession into core compaction, with explicit unresolved/none/legacy-inference selection.
  • Centralize recorded-source attribution for summary input, preserved excerpts, and token accounting. Clear stale generated pending asks without rewriting unrelated summary sections.
  • When a processed request is outside the current semantic window, reuse the existing bounded checkpoint request. Newer human steering wins; internal updates preserve that request or authoritative none. Missing unprocessed admitted input still rejects.
  • Reuse the existing compaction checkpoint; no new persisted state, configuration, or schema. Replace the redundant in-memory mapping test with persisted, repeated-recovery coverage.

This is an independent remediation related to #178477, with credit to @dmitryvostryakov for the original report and implementation. Request provenance remains separate from general model-quality concerns.

Verification

  • Base red: all three repeated-recovery cases fail at a085f281e904 with invalid_session: Compaction cannot find the admitted request. on the second recovery.
  • Exact head: a9c37408306168b27b2b777de4e9165e0c9eb76b, based on main 3523ef6747820e3253442a633dc09888c4cdf5fe. Both commits are patch-identical to the published pre-rebase revision; no conflicts or new behavior changes.
  • Live exact-head E2E: built the shipped CLI from this head and ran it with a private state/config/workspace, a token-authenticated loopback Gateway, and a real openai-responses request to gpt-6.1-sol through an explicit embedded-runtime provider route.
    1. openclaw agent --local admitted RQ-180214-EMBEDDED (review the patch and do not deploy it) and the live model returned exactly ACK-RQ-180214-EMBEDDED.
    2. openclaw sessions compact crossed the production Gateway RPC and live summarizer path. It compacted 15,191 tokens and retained both the marker and the no-deploy request in the generated summary.
    3. After that compaction, a second shipped-CLI turn added newer human steering RQ-180214-STEER; the live model returned exactly ACK-RQ-180214-STEER.
    4. A second Gateway compaction succeeded at 15,318 tokens. Its summary retained the prior checkpoint request and selected the newer steering under Original Request, including the no-deploy constraint.
    5. chat.history on the isolated Gateway recorded two successful proof-openai/gpt-6.1-sol model completions and two compaction records, with no pending inputs; the final session runtime was openclaw.
  • Persisted internal-update proof: the committed regression reopens through production SessionManager.openAsync(..., { compaction: true }), verifies the original request is absent from the semantic window, and completes a second automatic compaction. Human request survives internal updates; authoritative internal selection remains none; newer human steering supersedes the checkpoint request. Missing pending input still rejects.
  • Current-head focused proof: 96 tests passed across eight files, including persisted repeated recovery, compaction provenance and request selection, registered safeguards, runtime recovery, and host seed handling.
  • Focused lint, formatting, mock-export ratchet, and git diff --check passed on the rebased tree. The mock-export ratchet was the failing check in the prior CI run.
  • The prior repair's independent P0–P2 review was scoped-clean; unchanged patches retain that review. Earlier core, agents-sessions tests, and Plugin SDK test TypeScript checks passed.
  • The live proof deliberately did not fabricate an inter-session source: the Gateway rejected CLI-exec attempts that would lose sessions_send attribution. That branch remains covered by the persisted production integration test above.

Scope

Ready-for-review preparation only. Do not merge or backport.

@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: L labels Oct 22, 2026
@RomneyDa
RomneyDa force-pushed the fix/compaction-request-provenance branch 2 times, most recently from 740e30e to 9b9a4e8 Compare October 22, 2026 03:02
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 22, 2026
@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Preserves the active human request and recorded input sources across compaction, fallback summaries, and repeated recovery.

Example: “Review the patch; do not deploy it.” is followed by an inter-session “Worker update” before compaction.

  • Before: The worker update can replace the human request, and another recovery can reject the archived request.
  • After: Compaction retains the bounded human request from its checkpoint while keeping the worker update attributed separately.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, source-verified repair with passing exact-head gates, live CLI/Gateway evidence, and persisted recovery regressions; the internal-update branch has integration rather than live-channel proof.
Proof confidence 🐚 platinum hermit (4/6) The maintainer-authored PR is outside the contributor proof gate; its exact-head CLI/Gateway evidence reports two model completions and two compactions with retained constraints and newer steering, complemented by persisted integration coverage of internal updates and repeated automatic recovery.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Long conversations can resume an internal observation or completed task instead of the current human request.
Reason: The maintainer-authored direction repairs a demonstrated continuity defect using existing compaction and checkpoint contracts.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR addresses a current compaction defect, and the reviewed head has no actionable findings.

Priority: P2
Reviewed head: a9c37408306168b27b2b777de4e9165e0c9eb76b

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Live evidence covers human turns and manual Gateway compaction; inter-session updates during repeated automatic recovery remain covered by the persisted integration regression.
Agent review details

How this fits together

The embedded runtime passes the admitted request boundary into AgentSession; core compaction and safeguards turn transcript history into a bounded summary and retained messages.

flowchart TD
 A[Admitted request] --> B[Embedded recovery runtime]
 B --> C[AgentSession compaction]
 D[Transcript and prior checkpoint] --> C
 C --> E[Core preparation and safeguards]
 E --> F[Persisted compaction checkpoint]
 F --> G[Resumed model context]
Loading

Technical review

Best possible solution:

Carry the admitted request through existing compaction owners and reuse its bounded checkpoint after archival, preserving source labels and unprocessed input.

Do we have a high-confidence way to reproduce the issue?

Current-main source shows internal user-role observations can replace the active human request; supplied red/green results and persisted regressions identify the repeated-recovery failure without a reviewer-run reproduction.

Is this the best way to solve the issue?

The patch fixes selection at existing runtime and compaction owners, consolidates attribution, and reuses established persistence rather than adding another state owner.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 187b16c78550.

Provenance checked

  • Run-owned unresolved request keeps the original intent (bc1dfcd: Keep the active request ahead of superseded tasks and preserve it across compaction generations.)
  • Sender attribution and token accounting keeps the original intent (8446968: Preserve recorded stable sender identity in summaries and charge its rendered metadata to budgets.)
  • Pending-input retention keeps the original intent (60adac1: Fit the foreground request while preserving admitted unprocessed input and complete exchanges.)
  • Deterministic summary fallback keeps the original intent (c0c6ca3: Recover from summary timeouts while retaining the recent suffix, bounded request, and existing checkpoint.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +199, Tests +498, Docs +2, Other 0. Total +699 across 19 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 9 277 78 +199
Tests 8 520 22 +498
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 19 800 101 +699

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +277/-78; tests +520/-22 Growth carries request identity through existing owners and covers distinct attribution, fallback, rotation, and persisted recovery boundaries.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P2: Repairs request continuity during long-session compaction without changing configuration or public defaults.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (8 earlier review cycles)
  • reviewed 2026-10-22T03:18:36.162Z sha 9b9a4e896c44f18c7346a30606bef53a64b885ad :: blocked before merge. :: [P2] Preserve a prior pending request when no replacement was selected | [P2] Shrink the assertion baseline after moving the text projection
  • reviewed 2026-10-22T22:56:13.582Z sha 7c2284c :: blocked before merge. :: [P2] Preserve a prior pending request when no replacement was selected
  • reviewed 2026-10-22T23:04:00.559Z sha 60e64c8 :: needs changes before merge. :: [P2] Preserve a prior pending request when no replacement was selected
  • reviewed 2026-10-23T08:08:09.685Z sha 3e4421a :: needs changes before merge. :: [P3] Reuse the existing provenance-test fixtures
  • reviewed 2026-10-23T23:41:34.174Z sha 28bc2a9 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-27T18:54:32.783Z sha a085f28 :: needs changes before merge. :: [P1] [P1] Preserve the active request after its source entry is compacted
  • reviewed 2026-10-28T23:58:09.519Z sha 027796a :: needs maintainer review before merge. :: none
  • reviewed 2026-10-30T20:11:29.296Z sha a9c3740 :: needs maintainer review before merge. :: none

Reviewed October 31, 2026, 5:01 AM ET / 09:01 UTC (Revision 9).

@RomneyDa

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 22, 2026
@RomneyDa
RomneyDa force-pushed the fix/compaction-request-provenance branch from 7c2284c to 60e64c8 Compare October 22, 2026 22:57
@RomneyDa

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Oct 28, 2026
@RomneyDa

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Addressed the accepted P1 on 027796a84a1244b2c10c91fd35da96056cb05a91: recovery now uses the existing bounded checkpoint request after its processed source is archived, while newer human steering wins and missing unprocessed input still rejects.

The new persisted regression reopens through the production semantic-window reader and performs two automatic recoveries. All three cases failed the old head at the reported invalid_session guard, then passed with the fix. Focused proof is 76/76 tests, including 14 stable-prefix tests and 27 runtime/session-rotation recovery tests; core and affected session/Plugin SDK type checks pass. The PR body has current evidence and proof limits.

Rebased onto 4ed78e5246bb for the unrelated CI correction from #186233 and current test-line budget. Please review the current head; this task is ready-for-review preparation only, not authorization to merge.

@clawsweeper

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 28, 2026
@RomneyDa
RomneyDa force-pushed the fix/compaction-request-provenance branch from 027796a to a9c3740 Compare October 29, 2026 18:40
@RomneyDa

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review current head a9c37408306168b27b2b777de4e9165e0c9eb76b. Both commits are patch-identical to the previous reviewed head (verified with git range-diff); current-head focused proof is documented in the PR body, and both required CI gates now pass. Ready-for-review preparation only; do not merge.

@clawsweeper

clawsweeper Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 30, 2026
@RomneyDa

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Added live exact-head E2E evidence for a9c37408306168b27b2b777de4e9165e0c9eb76b to the PR body.

The shipped CLI ran against private isolated state and a token-authenticated loopback Gateway with a real OpenAI Responses model on the embedded OpenClaw runtime. The model completed the original marked request, Gateway compaction retained its no-deploy constraint, a later live human steering turn completed, and a second Gateway compaction retained the checkpoint while selecting the newer request. Gateway history recorded two real model completions and two compactions with no pending inputs.

I did not fabricate the remaining inter-session case: the Gateway correctly rejected CLI-exec input that would lose sessions_send attribution. That branch remains covered by the committed SQLite-backed production integration regression. No code or head changed; this request is review-only and does not authorize merge.

@clawsweeper

clawsweeper Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants