Skip to content

fix(agents): preserve history when context assembly fails - #117328

Merged
fuller-stack-dev merged 10 commits into
mainfrom
codex/qa400-context-engine-rollback
Sep 16, 2026
Merged

fuller-stack-dev merged 10 commits into
mainfrom
codex/qa400-context-engine-rollback

Conversation

@steipete

@steipete steipete commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes conversation and tool-result history being lost when a context-engine hook mutates the message array and then throws or returns malformed assembled context.

User Impact

Failed context assembly preserves the original ordered model-visible history and message identity instead of dropping instructions or tool results. Successful context windowing, cancellation, and retry behavior remain covered.

Why This Change Was Made

The post-tool owner snapshots history before plugin hooks and restores the same array in place on failure, preserving caller identity and retry fences. Startup already has the canonical isolation fix from #125714; the owning runner retains that behavior and adds malformed-result coverage. Pending tool turns and token-budget handling are preserved.

The signed published head is f90a6fc156d21be04bebceadee7cf92c58c879a2, tree cfd4e3d976331a8b75a53954cd2e192517389e48. It retains the reviewed real integration 20d56e64127f616d489fef2d5dc95c4e190f95d2, fixture correction bdf98b30d79954ea0343e08c14690abbc4cf501d, acquired main 43286efa75666f29030bdd9c93873410698dc79c, and previous published ancestry.

Peter Steinberger's original commit 5bb11e9ae7fc77d9f39cca908521630e04a88e66 and contributor attribution remain intact. GitHub verifies the new publication signature by fuller-stack-dev; historical unsigned commits are not relabeled as signed.

Scope and Evidence

  • Exactly three Context files differ from the integrated main. All other tree entries match it. The earlier native-PR fixture finding is resolved through real main integration, including landed fix: PR workflow tests fail during repository identity checks #149294; no competing prerequisite patch or replayed prerequisite proof.
  • Completed source/composition review found no actionable P0-P2 source findings. The signed head has the identical reviewed tree.
  • On exact f90a6fc156d21be04bebceadee7cf92c58c879a2 and lock SHA256 a6a6f2aecc88c5a04c7f268a2ffbbc998deead2567e7161773f753b7ca4370c2: 139 owning tests passed (77 post-tool, 62 startup); core types and owning agent-test types both passed. Synthetic context plugins exercise production owner boundaries; no real provider accounts were used.
  • Qualification used the complete matching private application graph and pnpm 12.3.4 frozen offline reconciliation (exit 0). Prior parser failure (exit 2) and the cold-install attempt with unknown exit remain in the retained evidence; they are not counted as successful installs.
  • Earlier five red regressions, earlier green checks, and original contributor/prerequisite proof remain preserved as historical evidence, not new-head qualification or reruns.
  • New-head native initialization, PR checkout, guard, artifact initialization and semantic review validation completed. The prior published-head NEEDS WORK review is preserved through native supersession. The original historical initialization exit remains UNKNOWN.

Remaining Gates

Exact-head CI is still active. New-head security detection succeeded; required enforcement and governance remain separate gates. This does not identify or erase the historical HTTP500 detection failure.

The completed local review remains NEEDS WORK pending required hosted CI/security/governance. No native READY stamp, preparation, merge approval or landing is claimed. Release-manager and secops review requests remain in place. No broad local suite/build, CI retry/cancellation, or watcher was introduced.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Aug 1, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Aug 1, 2026
@clawsweeper

clawsweeper Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 16, 2026, 2:28 PM ET / 18:28 UTC (Revision 19).

ClawSweeper review

What this changes

Preserves ordered conversation history when context-engine hooks mutate the message array and fail, adds failure and recovery coverage, and extracts shared test fixtures.

Merge readiness

✅ Ready for maintainer review

Keep open: the post-tool rollback remains useful beyond the merged assembly-isolation fix, and no actionable introduced defect was found. The maintainer-protected PR is not eligible for automatic cleanup.

Priority: P2
Reviewed head: 9042c5119a3ab830dfcfa1a1d0c36d4c31bc0a29

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful regression coverage and no supported blocking finding.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate. Its recorded synthetic-plugin tests exercise the changed lifecycle owner, but remain historical test evidence rather than a live-provider demonstration.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate. Its recorded synthetic-plugin tests exercise the changed lifecycle owner, but remain historical test evidence rather than a live-provider demonstration.
Evidence reviewed 8 items Introduced rollback: The verified merge-base-to-head diff snapshots providerMessages before lifecycle callbacks, restores the same array on failure, and routes malformed assembly results through the existing retry path.
Current-main gap: Current main passes transcriptMessages directly to afterTurn and returns providerMessages after failure without restoring array membership. Assembly already receives a working copy, so the remaining hook rollback is distinct.
Latest-release check: Inspection of the supplied latest release revision shows the same unprotected afterTurn path; the requested rollback is not already present there.
Findings None None.
Security None None.

How this fits together

Context engines prepare conversation history for the next model request. The embedded runner invokes their lifecycle hooks after tool results arrive, then uses assembled context or falls back to the existing history.

flowchart TD
  A[Conversation and tool results] --> B[Snapshot ordered history]
  B --> C[Context engine hooks]
  C --> D{Assembly succeeds?}
  D -->|Yes| E[Use assembled context]
  D -->|No| F[Restore history and retry fence]
  E --> G[Next model request]
  F --> G
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +2, Tests +121. Total +123 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 1 11 9 +2
Tests 3 333 212 +121
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 344 221 +123

Review metrics

None.

Technical review

Best possible solution:

Keep rollback in the existing tool-loop owner, preserving message identity, successful windowing, cancellation, and pending-turn boundaries.

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

Yes, from source: an unmarked history array passed to a non-deferred afterTurn hook can be spliced and then returned corrupted after the hook throws. The added regression exercises this path; execution was not performed.

Is this the best way to solve the issue?

Yes. Restoring array membership at the existing lifecycle boundary closes the remaining gap while respecting the established shared-message-object contract.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded context-engine failure-recovery fix; no widespread urgent regression is established.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate. Its recorded synthetic-plugin tests exercise the changed lifecycle owner, but remain historical test evidence rather than a live-provider demonstration.

Evidence

What I checked:

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (18 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-17T10:14:48.379Z sha 5bb11e9 :: found issues before merge. :: [P1] Snapshot complete startup message records | [P1] Snapshot complete tool-loop message records
  • reviewed 2026-08-19T04:07:05.452Z sha 5bb11e9 :: found issues before merge. :: [P1] Deep-clone startup history before assembly | [P1] Deep-clone the tool-loop input before lifecycle callbacks
  • reviewed 2026-08-19T12:43:15.491Z sha 5bb11e9 :: found issues before merge. :: [P1] Snapshot complete startup message records before assembly | [P1] Isolate complete loop records before lifecycle callbacks
  • reviewed 2026-08-25T13:26:17.301Z sha 5bb11e9 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-02T08:06:57.149Z sha 5bb11e9 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-16T01:03:14.573Z sha f90a6fc :: needs maintainer review before merge. :: none
  • reviewed 2026-09-16T01:21:52.125Z sha f90a6fc :: needs maintainer review before merge. :: none
  • reviewed 2026-09-16T18:10:12.189Z sha e4f1faf :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 2, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 14, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed P1 High-priority user-facing bug, regression, or broken workflow. 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. labels Aug 25, 2026
@fuller-stack-dev fuller-stack-dev self-assigned this Sep 15, 2026
@fuller-stack-dev
fuller-stack-dev requested a review from a team as a code owner September 15, 2026 17:27
@openclaw-barnacle openclaw-barnacle Bot added size: XL and removed agents Agent runtime and tooling size: S labels Sep 15, 2026
@github-actions

github-actions Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Security-sensitive guard cleared

This PR no longer has blocked security-sensitive file changes. A future security-sensitive change requires a fresh /allow-security-sensitive-change comment after the guard blocks that new head SHA.

  • Current SHA: 9042c5119a3ab830dfcfa1a1d0c36d4c31bc0a29

@github-actions github-actions Bot added security-sensitive-changed dependencies-changed PR changes dependency-related files labels Sep 15, 2026
@github-actions

github-actions Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Dependency graph guard cleared

This PR no longer has blocked dependency graph changes. A future dependency graph change requires a fresh /allow-dependencies-change comment after the guard blocks that new head SHA.

  • Current SHA: 9042c5119a3ab830dfcfa1a1d0c36d4c31bc0a29

steipete and others added 5 commits September 15, 2026 11:45
…149230)

Bind native PR initialization to GitHub's authoritative node/database ID pair while preserving exact historical repository objects and recovery provenance. Reject unknown identities, numeric strings, and extra fields.

Consume the landed prerequisite unchanged for #117328 CI fixture repair.

(cherry picked from commit 7e8a52c)
Consume Peter's canonical #149289 fixture repair unchanged. Original 133-case proof retained with exact fixture, runtime, runner and dependency bindings; no replay.

(cherry picked from commit 89321f8)
Preserve the two remaining fixture corrections from Peter Steinberger's
landed #149294 after adopting the earlier #149289 repair. Both files
match the landed source exactly; Context history source is unchanged.

Source-commit: 7dc8a1e
Merge retained fixture correction bdf98b3 with acquired main 43286ef.
The resulting main-relative delta is exactly the three reviewed Context
history files. Preserve original PR and fixture ancestry without rewriting.

Co-authored-by: Peter Steinberger <[email protected]>
Preserve the reviewed Context rollback composition and original contributor
ancestry in a signed merge adoption for same-branch publication.

Co-authored-by: Peter Steinberger <[email protected]>
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. label Sep 16, 2026
@github-actions github-actions Bot removed the dependencies-changed PR changes dependency-related files label Sep 16, 2026
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M and removed size: XL labels Sep 16, 2026
Move unchanged message and guard fixtures into a shared test-support module.
Preserve every test body and keep the line-cap configuration unchanged.
@fuller-stack-dev
fuller-stack-dev merged commit f75b266 into main Sep 16, 2026
188 checks passed
@fuller-stack-dev
fuller-stack-dev deleted the codex/qa400-context-engine-rollback branch September 16, 2026 20:30
@fuller-stack-dev

Copy link
Copy Markdown
Member

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 17, 2026
…17328)

* fix(agents): restore history after failed context assembly

* fix(agents): restore validated history after failed context hooks

* fix(scripts): preserve merge receipts across repository ID formats (openclaw#149230)

Bind native PR initialization to GitHub's authoritative node/database ID pair while preserving exact historical repository objects and recovery provenance. Reject unknown identities, numeric strings, and extra fields.

Consume the landed prerequisite unchanged for openclaw#117328 CI fixture repair.

(cherry picked from commit 3492551)

* test: refresh repository identity fixtures for PR workflows

Consume Peter's canonical openclaw#149289 fixture repair unchanged. Original 133-case proof retained with exact fixture, runtime, runner and dependency bindings; no replay.

(cherry picked from commit 89321f8)

* test: align native PR identity fixtures with landed repair

Preserve the two remaining fixture corrections from Peter Steinberger's
landed openclaw#149294 after adopting the earlier openclaw#149289 repair. Both files
match the landed source exactly; Context history source is unchanged.

Source-commit: 3df0afa

* test(agents): extract context guard fixtures for line caps

Move unchanged message and guard fixtures into a shared test-support module.
Preserve every test body and keep the line-cap configuration unchanged.

---------

Co-authored-by: Jason (Json) <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR 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