Repository navigation
fix(active-memory): bound assembled recall context - #110898
Conversation
… current request Production event.prompt envelopes reached 609K-693K UTF-16 chars and drove 30s blocking-hook timeouts (openclaw#88077, openclaw#92013). buildQuery now bounds the complete model-facing recall context: the current user request survives verbatim (event.prompt stays the current-turn source), generated <conversation_context> blocks keep only a sanitized newest tail with tool traces dropped, quoted-reply channel sections are preserved, and the memory_search query is seeded from the bounded request while keeping its 480-char clamp as defense in depth. Recall start logs gain queryCharsRaw= and queryBounded= when bounding engages.
…emission Adversarial review: a request containing the literal </conversation_context> could redirect the lastIndexOf split and drop the real current request (falling back to the stale envelope head — the same stale-query class that sank the messageMaxChars attempt). Split on the projection's exact joint emission instead; quoting either marker alone can no longer move the split. Also: cite the real reply-target producer and drop recognizers that had no producer in-tree, cover '[unserializable payload omitted]', and make the oversized-envelope test builders linear.
|
Codex review: needs maintainer review before merge. What this changesBounds assembled Active Memory recall context to 4,000 UTF-16 units, prioritizing the current request over older history. Example: A current request contains 12,097 UTF-16 units, including quoted context and an ending question.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR retains useful size protection absent from main, resolves the earlier correctness findings, and has sufficient Gateway proof and passing exact-head CI. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe Active Memory prompt-build hook combines the admitted request with eligible conversation history, sends it to a recall subagent, and supplies the resulting memory summary to the answering model. flowchart LR
A[Admitted request and history] --> B[Prompt build hook]
B --> C[Bounded recall query]
C --> D[Recall subagent]
D --> E[Memory search]
E --> D
D --> F[Answering model]
Technical reviewBest possible solution: Land the focused query-owner repair with its documented, intentionally bounded history behavior. Do we have a high-confidence way to reproduce the issue? Current-main source directly exposes unbounded current requests and full-history assembly; the supplied baseline Gateway observation records a 12,097-unit query, and no target code was executed during this review. Is this the best way to solve the issue? The repair belongs in the existing query owner, avoids content-derived request boundaries, preserves the independent search seed, and uses existing UTF-16 slicing helpers without adding configuration or persistence. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 11c24cfd6dbd. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +11, Tests +89, Docs +9. Total +109 across 3 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (3 earlier review cycles)
Reviewed October 16, 2026, 5:23 AM ET / 09:23 UTC (Revision 4). |
|
Real after-fix behavior proof added to the PR body Evidence section: an isolated source gateway built from this branch processed the same 620,391-char envelope shape as a live @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Prioritize the current request within one bounded recall query and use the remaining space for recent history. Keep the existing search seed and current-request ownership, with no new configuration or schema. Co-authored-by: Joey Krug <[email protected]>
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
* fix(active-memory): bound recall context to 25K chars, preserving the current request Production event.prompt envelopes reached 609K-693K UTF-16 chars and drove 30s blocking-hook timeouts (openclaw#88077, openclaw#92013). buildQuery now bounds the complete model-facing recall context: the current user request survives verbatim (event.prompt stays the current-turn source), generated <conversation_context> blocks keep only a sanitized newest tail with tool traces dropped, quoted-reply channel sections are preserved, and the memory_search query is seeded from the bounded request while keeping its 480-char clamp as defense in depth. Recall start logs gain queryCharsRaw= and queryBounded= when bounding engages. * fix(active-memory): preserve native reply context when bounding * fix(active-memory): anchor envelope split on the joint close+request emission Adversarial review: a request containing the literal </conversation_context> could redirect the lastIndexOf split and drop the real current request (falling back to the stale envelope head — the same stale-query class that sank the messageMaxChars attempt). Split on the projection's exact joint emission instead; quoting either marker alone can no longer move the split. Also: cite the real reply-target producer and drop recognizers that had no producer in-tree, cover '[unserializable payload omitted]', and make the oversized-envelope test builders linear. Co-authored-by: Joey Krug <[email protected]>
* fix(active-memory): bound recall context to 25K chars, preserving the current request Production event.prompt envelopes reached 609K-693K UTF-16 chars and drove 30s blocking-hook timeouts (#88077, #92013). buildQuery now bounds the complete model-facing recall context: the current user request survives verbatim (event.prompt stays the current-turn source), generated <conversation_context> blocks keep only a sanitized newest tail with tool traces dropped, quoted-reply channel sections are preserved, and the memory_search query is seeded from the bounded request while keeping its 480-char clamp as defense in depth. Recall start logs gain queryCharsRaw= and queryBounded= when bounding engages. * fix(active-memory): preserve native reply context when bounding * fix(active-memory): anchor envelope split on the joint close+request emission Adversarial review: a request containing the literal </conversation_context> could redirect the lastIndexOf split and drop the real current request (falling back to the stale envelope head — the same stale-query class that sank the messageMaxChars attempt). Split on the projection's exact joint emission instead; quoting either marker alone can no longer move the split. Also: cite the real reply-target producer and drop recognizers that had no producer in-tree, cover '[unserializable payload omitted]', and make the oversized-envelope test builders linear. Co-authored-by: Joey Krug <[email protected]> (cherry picked from commit a9fe8ab) Co-authored-by: RomneyDa <[email protected]>
Related: #88077, #92013
What Problem This Solves
Fixes oversized Active Memory recall context overwhelming a small local model or spending the recall deadline on old conversation text.
User Impact
Recall context is bounded to 4,000 UTF-16 code units in all query modes. The current request takes priority over history.
fullmode considers all available history within that limit and drops older material first. When the current request alone exceeds the limit, recall retains its beginning and end with an explicit middle-omission marker. The original request delivered to the answering model is unchanged.Why This Change Was Made
The existing query owner now assembles and bounds one recall context. It keeps the producer-owned current-request contract and independent bounded search seed, and removes the old PR's envelope-marker parsing and extra diagnostics plumbing. No new setting or schema is added.
Thanks @joeykrug for diagnosing and reproducing the oversized recall requests. All contributor commits are retained; this update merges current main and modernizes the repair around the current query owner.
Evidence
Budget calibration on macOS with Qwen3:4b: an exact captured Gateway recall envelope used 3,744 prompt tokens with a 4K query, leaving 3,936 tokens in an 8K window after a 512-token output reserve. Denser controls explain the conservative cap: a 12K Chinese query plus the plugin instructions/tools used 9,436 tokens, and a 6K emoji query used 7,997; oversized native inputs could silently truncate. A character cap is a best-effort bound, not a universal token guarantee.
Baseline through the real Gateway assembled a 12,097-character query. A deterministic recall-model fixture exercised the real
memory_search/embeddinggemma path, then the real main Qwen model answered with the seeded phrase. Focused tests reproduced six size failures while all 13 existing/under-limit cases passed (30.01s wall).The same 19 focused query tests pass on the fix with the explicit Node runtime (92.88s wall). The first default-Bun attempt stalled before assertions and was stopped; it is not counted as product evidence. Prompt snapshot generation passed (63.67s), with zero generated-file delta; these static snapshots do not render dynamic Active Memory queries. The measured real-envelope query saving is 1,333 prompt tokens (5,077 to 3,744).
Production: +41/−30 lines (net +11). Tests: +91/−2. The new limit and UTF-16-safe head/tail logic require the remaining growth after merging duplicate full/recent assembly. Isolated Codex review reports no actionable P0–P2 finding.
Fixed-head Gateway boundary proof: the same 12,097-unit current request produced exactly 4,000 units, retained the quoted sentinel and ending question, and completed in 10.744s. The first recall request had no answer; the real
memory_searchresult contained the seeded phrase; the deterministic recall-model fixture then returned its grounded summary (2.912s recall), and the real LM Studio Gemma 4 E4B answering model returned the phrase. The tool used the real Nomic embedding backend. An initial proof-relay JSON forwarding bug was repaired and the isolated synthetic index rebuilt before this successful run; that failed harness attempt is not counted as product proof.Full build passed (1,831.09s wall, including SDK exports and UI). Scoped type-aware lint passed (2,212.93s including waiting for the build lock and declaration preparation). Production extension types passed (14.99s), test extension types passed (16.47s).
Fully native control also passed with LM Studio Gemma 4 E4B and Nomic embeddings, using the existing explicit
tools.toolSearch: falseoption in isolated proof config. Gemma itself calledmemory_search; the first recall request lacked the phrase and the subsequent tool result contained it. Both captured requests held the exact 4,000-unit query, quote, and final question. Recall completed in 9.639s and the complete answering request in 14.250s. With default Tool Search, this model first sent an invalid search argument shape and returned no relevant memory; that model/tool-selection limitation is recorded separately from the bounded-query behavior. No production tool-publication policy changes are included.Formatting, line-cap, assertion safety, timeout-race, mock-export, config/docs, plugin inventory, and diff checks passed. Max-lines reports the same pre-existing suppression in
ui/src/pages/chat/components/chat-message.test.tsx; this file is byte-identical to tested baseb62a8f8dab531b3909fa63ef74b28f45d2fda5b9, where the identical failure was already reproduced (18.09s). Local validation is macOS-only; cross-platform coverage comes from PR CI.Exact-head CI passed all query-limit cases and all 266 config-shard tests. CI test-types is red from the inherited Codex session-binding test rename mismatch introduced by #173951: three call sites retain names that their imports now alias. The exact CI base has the same file blob as the previously verified failing base; this PR does not change that file.