mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-11-22 13:29:19 +08:00
## Description
OpenClaw history can contain text on both sides of an assistant tool
call. If the compression response changes the call arguments while
leaving the wire text intact, restoring that message currently moves
both pieces of text ahead of the call and joins them into a single
block.
## Type of Change
- [x] Bug fix
## Changes Made
- Compare the returned assistant text with the text sent for that
message. Keep the original blocks when the text matches, then apply the
changed arguments to the matching tool call.
- Extend the assemble regression to check the order and content of both
text blocks, the signed thinking block, and the updated tool call.
## Testing
- [x] Regression and existing OpenClaw tests pass.
- [x] Manual testing performed.
### Test Output
```text
cd plugins/openclaw
npm test # 11 files, 162 tests passed
npm run typecheck # passed
npm run build # passed
git diff --check # passed
```
The repository commit hooks and Rust formatting check passed. The full
local pre-push suite stopped at Rust dependency resolution after the
registry fetch stalled. I used the hook's documented push override for
this TypeScript-only change. The verification above covers the changed
plugin.
## Real Behavior Proof
- Environment: macOS arm64, Node 22.22.2, built OpenClaw plugin with the
pinned JavaScript SDK, and a Node HTTP server listening on loopback. The
payload was synthetic and did not need a model.
- Exact command / steps: Run `npm run build` in `plugins/openclaw` on
base `9f2cc01` and the patched tree. In Node, import
`HeadroomContextEngine` from the built `dist/index.js`. Start a loopback
server that answers `GET /v1/retrieve/stats` with `{"store":{}}`. For
`POST /v1/compress`, echo the submitted messages and set the first tool
call's argument string to `{"id":7}`. Return `tokens_before: 100`,
`tokens_after: 25`, and `tokens_saved: 75`. Create the engine with that
`proxyUrl`, `autoStart: false`, and `minContextChars: 0`. Await
`ensureProxyUrl()`, then call `assemble()` with one assistant message
whose blocks are signed thinking, text `Checking.`, a `lookup` call with
ID `lookup-1` and arguments `{id: 7, notes: "fixture ".repeat(80)}`, and
text `Awaiting result.`.
- Observed result: the SDK sent one actual compression request in both
runs. Base returned `thinking, text("Checking.Awaiting result."),
toolCall({id:7})`. The patch returned `thinking, text("Checking."),
toolCall({id:7}), text("Awaiting result.")`. The signature and call ID
were preserved, and the engine reported 25 tokens in both runs.
- Not tested: a remote proxy, model calls, or an OpenClaw host process.
The runtime proof exercised the built plugin and SDK over HTTP with a
deterministic compression response.
## Runtime Rollout Safety
- Rollout-managed feature(s): OpenClaw context restoration.
- Minimum rollout channel: existing plugin channel.
- Stable/default behavior changed: text block placement is preserved
when only assistant tool arguments change.
- Kill switch / disable path: existing OpenClaw plugin enablement.
- Unsafe override required: none.
- Qualification impact: OpenClaw plugin suite and loopback verification
above.
- Rollback path: revert the commit.
## Review Readiness
- [x] I have performed a self-review
- [x] This PR is ready for human review
## Checklist
- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [x] I did **not** edit `CHANGELOG.md` — it is generated by
release-please from my Conventional Commit PR title (a CI guard enforces
this)
## Additional Notes
This is a small correction to the restoration path introduced by #3826.
AI assistance was used to investigate, implement, and verify the change.
<!-- devin-review-badge-begin -->
---
<a href="https://app.devin.ai/review/headroomlabs-ai/headroom/pull/4829"
target="_blank"><picture><source media="(prefers-color-scheme: dark)"
srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img
src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4"
alt="Devin Review"></picture></a>
<!-- devin-review-badge-end -->
Co-authored-by: 123XieC <323077714+123XieC@users.noreply.github.com>