mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 21:50:42 +00:00
fix: use reference identity instead of length check for assembled view
- Compare assembled.messages !== sourceMessages instead of length, so engines that rewrite content without changing array count are respected - Add test for same-count-different-reference assembly
This commit is contained in:
@@ -392,7 +392,25 @@ describe("installContextEngineLoopHook", () => {
|
||||
expect(transformed).toBe(compactedView);
|
||||
});
|
||||
|
||||
it("returns the source messages when the assembled view has the same length", async () => {
|
||||
it("returns the assembled view when the engine rewrites content without changing count", async () => {
|
||||
const agent = makeGuardableAgent();
|
||||
const rewrittenView = [makeUser("rewritten-1"), makeUser("rewritten-2")];
|
||||
const engine = makeMockEngine({
|
||||
assemble: async () => ({ messages: rewrittenView, estimatedTokens: 0 }),
|
||||
});
|
||||
installHook(agent, engine);
|
||||
|
||||
const initial = [makeUser("first"), makeToolResult("call_1", "r")];
|
||||
await callTransform(agent, initial);
|
||||
|
||||
const withNew = [...initial, makeToolResult("call_2", "r2")];
|
||||
const transformed = await callTransform(agent, withNew);
|
||||
|
||||
// Same count (2) but different array reference — engine's view should be used
|
||||
expect(transformed).toBe(rewrittenView);
|
||||
});
|
||||
|
||||
it("returns the source when the engine returns the same array reference", async () => {
|
||||
const agent = makeGuardableAgent();
|
||||
const engine = makeMockEngine();
|
||||
installHook(agent, engine);
|
||||
|
||||
@@ -239,11 +239,7 @@ export function installContextEngineLoopHook(params: {
|
||||
tokenBudget,
|
||||
model: modelId,
|
||||
});
|
||||
if (
|
||||
assembled &&
|
||||
Array.isArray(assembled.messages) &&
|
||||
assembled.messages.length !== sourceMessages.length
|
||||
) {
|
||||
if (assembled && Array.isArray(assembled.messages) && assembled.messages !== sourceMessages) {
|
||||
lastAssembledView = assembled.messages;
|
||||
return assembled.messages;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user