@devries-cameron20 / t3code Mirror · read-only / commits / b0a46d2848
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 09:45 UTC

fix(acp): preserve literal monitor-event text in imported history (#37545)

Wout Stiens committed Nov 16, 2026 at 08:55 UTC b0a46d28482fcfbd6fa73f67423b6cd6ffeff7a8
2 files changed +40 -14
apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
+34 -7
@@ -3380,15 +3380,27 @@ describe("AcpAdapterV2", () => {
3380 update: { sessionUpdate, messageId, content: { type: "text", text } },
3381 });
3382
3383 - yield* replay("user_message_chunk", "u1", "hel");
3384 - yield* replay("user_message_chunk", "u1", "lo");
3383 + yield* replay("user_message_chunk", "u1", "<monitor-event> is ");
3384 + yield* replay("user_message_chunk", "u1", "XML");
3385 yield* replay("agent_message_chunk", "a1", "hi");
3386 yield* replay("user_message_chunk", "u2", "next");
3387 yield* replay("agent_message_chunk", "a1", " ");
3388 yield* replay("agent_message_chunk", "a1", "there");
3389 yield* replay("agent_message_chunk", "a3", "\t");
3390 - yield* replay("agent_message_chunk", "a3", "code");
3390 + yield* replay("agent_message_chunk", "a3", "code with <monitor-event>");
3391 yield* replay("agent_message_chunk", "a4", "\n\n");
3392 + yield* replay("user_message_chunk", "u3", "Why did Monitor 0123abcd ended appear?");
3393 + // Grok's injected monitor wakes replay as user chunks and stay out of history.
3394 + yield* replay(
3395 + "user_message_chunk",
3396 + "u4",
3397 + '\n<monitor-event task_id="019f44a5-87d1-7640-8e35-6a4667ffc873">\nline\n</monitor-event>',
3398 + );
3399 + yield* replay(
3400 + "user_message_chunk",
3401 + "u5",
3402 + 'Monitor "019f44a5-87d1-7640-8e35-6a4667ffc873" ended: exit 0',
3403 + );
3404 const first = yield* runtime.readThreadSnapshot({ providerThread });
3405 yield* replay("agent_message_chunk", "a2", "done");
3406 yield* replay("user_message_chunk", "u2", "\n");
@@ -3398,16 +3410,18 @@ describe("AcpAdapterV2", () => {
3410 const texts = (snapshot: typeof first) =>
3411 snapshot.messages.map((message) => `${message.role}:${message.text}`);
3412 assert.deepEqual(texts(first), [
3401 - "user:hello",
3413 + "user:<monitor-event> is XML",
3414 "assistant:hi there",
3415 "user:next",
3404 - "assistant:\tcode",
3416 + "assistant:\tcode with <monitor-event>",
3417 + "user:Why did Monitor 0123abcd ended appear?",
3418 ]);
3419 assert.deepEqual(texts(second), [
3407 - "user:hello",
3420 + "user:<monitor-event> is XML",
3421 "assistant:hi there",
3422 "user:next\n\tone",
3410 - "assistant:\tcode",
3423 + "assistant:\tcode with <monitor-event>",
3424 + "user:Why did Monitor 0123abcd ended appear?",
3425 "assistant:done",
3426 ]);
3427 }).pipe(Effect.provide(layerTest), Effect.scoped),
@@ -11189,4 +11203,17 @@ describe("acpPostSettleContinuationOfferEvidence", () => {
11203 }),
11204 );
11205 });
11206 + it("offers on a reply that only mentions monitor markup, not on monitor chatter", () => {
11207 + const reply = (text: string) =>
11208 + ({
11209 + sessionId,
11210 + update: { sessionUpdate: "agent_message_chunk", content: { type: "text", text } },
11211 + }) as const;
11212 + assert.isTrue(acpPostSettleContinuationOfferEvidence(reply("<monitor-event> tags wrap it")));
11213 + assert.isFalse(
11214 + acpPostSettleContinuationOfferEvidence(
11215 + reply('<monitor-event task_id="019f44a5-87d1-7640-8e35-6a4667ffc873">line</monitor-event>'),
11216 + ),
11217 + );
11218 + });
11219 });
packages/provider-acp/src/server/adapter.ts
+6 -7
@@ -1576,6 +1576,10 @@ function acpRootSessionUpdateIngestsOutput(
1576 }
1577 }
1578
1579 +/** Monitor wakes arrive as their own chunk led by a tagged `<monitor-event task_id=…>`; bare mentions are content. */
1580 +const acpIsMonitorChatter = (text: string) =>
1581 + /^\s*(?:<monitor-event\s|Monitor\s+["']?[0-9a-f-]{8,}["']?\s+ended)/i.test(text);
1582 +
1583 export function acpPostSettleWakeEvidence(
1584 notification: EffectAcpSchema.SessionNotification,
1585 flavor: Pick<AcpAdapterV2Flavor, "extractBackgroundToolMutation"> = {},
@@ -1590,9 +1594,7 @@ export function acpPostSettleWakeEvidence(
1594 const text = update.content.text;
1595 if ((flavor.extractBackgroundToolMutation?.(text) ?? []).length > 0) return false;
1596 if (update.sessionUpdate === "agent_message_chunk" && text.trim().length === 0) return false;
1593 - if (/<monitor-event\b/i.test(text) || /Monitor\s+["']?[0-9a-f-]{8,}["']?\s+ended/i.test(text)) {
1594 - return false;
1595 - }
1597 + if (acpIsMonitorChatter(text)) return false;
1598 }
1599 return true;
1600 }
@@ -5536,10 +5538,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
5538 for (const lateBackgroundMutation of lateBackgroundMutations) {
5539 yield* applyLateBackgroundMutation(notification.sessionId, lateBackgroundMutation);
5540 }
5539 - const lateMonitorChatter =
5540 - /<monitor-event\b/i.test(text) ||
5541 - /Monitor\s+["']?[0-9a-f-]{8,}["']?\s+ended/i.test(text);
5542 - if (lateBackgroundMutations.length === 0 && !lateMonitorChatter) {
5541 + if (lateBackgroundMutations.length === 0 && !acpIsMonitorChatter(text)) {
5542 yield* appendLoadedHistory(
5543 notification,
5544 update.sessionUpdate === "user_message_chunk"