GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(server): Claude no longer gets MCP app notes again after a server… · patroza/t3code@bf961f8

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src
    • mcpApps
      • McpAppModelContext.ts
    • orchestration-v2
      • Adapters
        • AcpAdapterV2.test.ts
        • ClaudeAdapterV2.test.ts
        • ClaudeAdapterV2.ts
      • ProviderTurnControlService.test.ts
      • RunExecutionService.test.ts
  • packages
    • contracts/src
      • orchestrationV2.ts
    • provider-acp/src/server
      • adapter.ts
    • provider-core/src/server
      • ProviderAdapter.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/mcpApps/McpAppModelContext.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/mcpApps/McpAppModelContext.ts
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export interface McpAppModelContextEntry {
1919
readonly server: string;
2020
readonly tool: string;
2121
readonly text: string;
22+
/** ISO time the app last set the note. */
23+
readonly updatedAt: string;
2224
}
2325

2426
export class McpAppModelContext extends Context.Service<
@@ -58,6 +60,7 @@ export const forProvider = Effect.fn("McpAppModelContext.forProvider")(function*
5860
// the context in.
5961
key: `mcp_app_${entry.itemId.replace(/[^\w.-]/g, "_")}`,
6062
text: entry.text,
63+
updatedAt: entry.updatedAt,
6164
}));
6265
});
6366

@@ -118,7 +121,8 @@ export const layer = Layer.effect(
118121
LIMIT 1
119122
) IS NULL
120123
)
121-
SELECT context.item_id AS "itemId", context.server, context.tool, context.text
124+
SELECT context.item_id AS "itemId", context.server, context.tool, context.text,
125+
context.updated_at AS "updatedAt"
122126
FROM mcp_app_model_context AS context
123127
CROSS JOIN boundary
124128
JOIN orchestration_v2_projection_turn_items AS item
Collapse file

‎apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
+11-4Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13071,6 +13071,7 @@ describe("AcpAdapterV2", () => {
1307113071
const sessionId = providerThread.nativeThreadRef?.nativeId;
1307213072
if (sessionId == null) return assert.fail("expected native session id");
1307313073
let ordinal = 0;
13074+
const noteSetAt = "2026-11-23T14:02:17.000Z";
1307413075
const runTurn = (input: {
1307513076
readonly text: string;
1307613077
readonly note: string;
@@ -13091,7 +13092,7 @@ describe("AcpAdapterV2", () => {
1309113092
ordinal,
1309213093
messageText: input.text,
1309313094
}),
13094-
appContext: [{ key: "mcp_app_item-1", text: input.note }],
13095+
appContext: [{ key: "mcp_app_item-1", text: input.note, updatedAt: noteSetAt }],
1309513096
});
1309613097
const events = Array.from(
1309713098
yield* runtime.events.pipe(
@@ -13106,7 +13107,9 @@ describe("AcpAdapterV2", () => {
1310613107
};
1310713108
});
1310813109

13109-
const tag = (note: string) => `<external_mcp_app_item-1>${note}</external_mcp_app_item-1>`;
13110+
// Every send, a resend included, says when the app set the note.
13111+
const tag = (note: string) =>
13112+
`<external_mcp_app_item-1 updated_at="${noteSetAt}">${note}</external_mcp_app_item-1>`;
1311013113

1311113114
// An unsuccessful stop reason must not mark appContext delivered.
1311213115
const refusedTurn = yield* runTurn({
@@ -13137,7 +13140,9 @@ describe("AcpAdapterV2", () => {
1313713140
ordinal: interruptedOrdinal,
1313813141
messageText: "Interrupted attempt",
1313913142
}),
13140-
appContext: [{ key: "mcp_app_item-1", text: "Created Jira issue PROJ-42" }],
13143+
appContext: [
13144+
{ key: "mcp_app_item-1", text: "Created Jira issue PROJ-42", updatedAt: noteSetAt },
13145+
],
1314113146
});
1314213147
yield* Deferred.await(interruptedStarted);
1314313148
assert.include(prompts.at(-1) ?? "", tag("Created Jira issue PROJ-42"));
@@ -13237,7 +13242,9 @@ describe("AcpAdapterV2", () => {
1323713242
ordinal: restartOrdinal,
1323813243
messageText: "Trigger restart",
1323913244
}),
13240-
appContext: [{ key: "mcp_app_item-1", text: "Updated Jira issue PROJ-43" }],
13245+
appContext: [
13246+
{ key: "mcp_app_item-1", text: "Updated Jira issue PROJ-43", updatedAt: noteSetAt },
13247+
],
1324113248
});
1324213249
yield* Deferred.await(restartStarted);
1324313250
const restartInterruptFiber = yield* runtime
Collapse file

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+67-2Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7649,6 +7649,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
76497649
close: (sdkMessages) => Queue.shutdown(sdkMessages),
76507650
freshQueueOnReopen: true,
76517651
});
7652+
const noteSetAt = "2026-11-23T14:02:17.000Z";
76527653
const runTurn = Effect.fnUntraced(function* (ordinal: number, note: string) {
76537654
yield* harness.runtime.startTurn({
76547655
...makeClaudeTestTurnInput({
@@ -7660,7 +7661,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
76607661
text: "What did the app report?",
76617662
attachments: [],
76627663
}),
7663-
appContext: [{ key: "mcp_app_item-1", text: note }],
7664+
appContext: [{ key: "mcp_app_item-1", text: note, updatedAt: noteSetAt }],
76647665
});
76657666
return lastOffered();
76667667
});
@@ -7731,7 +7732,11 @@ describe("ClaudeAdapterV2 background wake turns", () => {
77317732
);
77327733
yield* finishTurn(4);
77337734
// Compaction summarizes the note away, so the next turn carries it again.
7734-
assert.include(yield* runTurn(5, "Created Jira issue PROJ-43"), "PROJ-43");
7735+
// The resent note says when it was set, so it does not read as news.
7736+
assert.include(
7737+
yield* runTurn(5, "Created Jira issue PROJ-43"),
7738+
`<external_mcp_app_item-1 updated_at="${noteSetAt}">Created Jira issue PROJ-43`,
7739+
);
77357740
}).pipe(
77367741
Effect.provide(
77377742
Layer.mergeAll(
@@ -7744,6 +7749,66 @@ describe("ClaudeAdapterV2 background wake turns", () => {
77447749
),
77457750
);
77467751

7752+
// regression: #42982 a server restart resent every stored note to a session that already had it
7753+
it.effect("does not resend an MCP app note Claude already has after the adapter restarts", () =>
7754+
Effect.gen(function* () {
7755+
const note = "Slack draft card: the message was sent.";
7756+
const startTurn = Effect.fnUntraced(function* (
7757+
harness: Effect.Success<ReturnType<typeof makeWakeHarnessWithOptions>>,
7758+
providerThread: OrchestrationV2ProviderThread,
7759+
ordinal: number,
7760+
) {
7761+
yield* harness.runtime.startTurn({
7762+
...makeClaudeTestTurnInput({
7763+
threadId: harness.threadId,
7764+
providerThread,
7765+
now: yield* DateTime.now,
7766+
attemptId: RunAttemptId.make(`mcp-app-restart-${ordinal}`),
7767+
providerTurnOrdinal: ordinal,
7768+
text: "Anything new?",
7769+
attachments: [],
7770+
}),
7771+
appContext: [{ key: "mcp_app_item-1", text: note }],
7772+
});
7773+
const content = harness.offeredMessages.at(-1)?.message.content;
7774+
return typeof content === "string"
7775+
? content
7776+
: (content ?? []).map((block) => (block.type === "text" ? block.text : "")).join("\n");
7777+
});
7778+
7779+
const before = yield* makeWakeHarnessWithOptions({
7780+
close: (sdkMessages) => Queue.shutdown(sdkMessages),
7781+
freshQueueOnReopen: true,
7782+
});
7783+
assert.include(yield* startTurn(before, before.providerThread, 0), note);
7784+
yield* before.offerAndWait(
7785+
makeResultFrame({ uuid: "mcp-app-restart-result-0", result: "Done." }),
7786+
);
7787+
yield* Queue.take(before.terminalReceipts);
7788+
const persisted = before.events
7789+
.filter((event) => event.type === "provider_thread.updated")
7790+
.at(-1)?.providerThread;
7791+
assert.isDefined(persisted);
7792+
7793+
// A new adapter resumes the same native session, whose history already holds the note.
7794+
const after = yield* makeWakeHarnessWithOptions({
7795+
close: (sdkMessages) => Queue.shutdown(sdkMessages),
7796+
freshQueueOnReopen: true,
7797+
});
7798+
assert.notInclude(yield* startTurn(after, persisted!, 1), note);
7799+
}).pipe(
7800+
Effect.scoped,
7801+
Effect.provide(
7802+
Layer.mergeAll(
7803+
IdAllocator.layer,
7804+
McpProviderSessions.layer,
7805+
NodeServices.layer,
7806+
NodeCrypto.layer,
7807+
),
7808+
),
7809+
),
7810+
);
7811+
77477812
it.effect("sends the model id Claude Code reported for the selected catalog model", () =>
77487813
Effect.scoped(
77497814
Effect.gen(function* () {
Collapse file

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+62-19Lines changed: 62 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ import {
141141
} from "@t3tools/contracts";
142142

143143
import { FILE_HEADERS_ONLY, formatPatch, structuredPatch } from "diff";
144+
// @effect-diagnostics-next-line nodeBuiltinImport:off -- A synchronous digest inside the pure note filter.
145+
import * as NodeCrypto from "node:crypto";
144146
import * as Cause from "effect/Cause";
145147
import * as Predicate from "effect/Predicate";
146148
import * as Clock from "effect/Clock";
@@ -3411,22 +3413,44 @@ const reserveClaudePdfBudget = (
34113413
}).pipe(Effect.andThen(persist)),
34123414
);
34133415

3416+
type ClaudeAppContext = NonNullable<ProviderAdapter.ProviderAdapterV2TurnInput["appContext"]>;
3417+
3418+
// Digests keep the persisted record of delivered notes small; notes can be 16 KiB each.
3419+
const claudeAppContextDigests = (appContext: ClaudeAppContext): ReadonlyMap<string, string> =>
3420+
new Map(
3421+
appContext.map((entry) => [
3422+
entry.key,
3423+
NodeCrypto.createHash("sha256").update(entry.text).digest("base64url"),
3424+
]),
3425+
);
3426+
3427+
const unseenClaudeAppContext = (
3428+
appContext: ClaudeAppContext,
3429+
seen: ReadonlyMap<string, string> | undefined,
3430+
): ClaudeAppContext => {
3431+
const digests = claudeAppContextDigests(appContext);
3432+
return appContext.filter((entry) => seen?.get(entry.key) !== digests.get(entry.key));
3433+
};
3434+
34143435
// MCP app notes are app-written, so they go as quoted user input like Codex's untrusted context.
34153436
// A slash command runs only when it opens a plain-text prompt; its note waits for the next turn.
34163437
// Returns `message` itself when it adds nothing.
34173438
const withClaudeAppContext = (
34183439
message: SDKUserMessage,
3419-
appContext: NonNullable<ProviderAdapter.ProviderAdapterV2TurnInput["appContext"]>,
3440+
appContext: ClaudeAppContext,
34203441
reservation: Effect.Success<ReturnType<typeof reserveClaudePdfBudget>>,
34213442
): SDKUserMessage => {
34223443
const content = message.message.content;
34233444
if (appContext.length === 0 || (typeof content === "string" && content.startsWith("/"))) {
34243445
return message;
34253446
}
3426-
const contextBlocks = appContext.map((entry) => ({
3427-
type: "text" as const,
3428-
text: `<external_${entry.key}>${entry.text}</external_${entry.key}>`,
3429-
}));
3447+
const contextBlocks = appContext.map((entry) => {
3448+
const updatedAt = entry.updatedAt === undefined ? "" : ` updated_at="${entry.updatedAt}"`;
3449+
return {
3450+
type: "text" as const,
3451+
text: `<external_${entry.key}${updatedAt}>${entry.text}</external_${entry.key}>`,
3452+
};
3453+
});
34303454
const bytes = Buffer.byteLength(encodeClaudeJson(contextBlocks));
34313455
reservation.budget.pending.bytes += bytes;
34323456
reservation.bytes += bytes;
@@ -6358,7 +6382,8 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
63586382
// Sessions Claude Code reported gone on resume; resumeThread fails them into a fresh session.
63596383
const missingNativeThreads = new Set<string>();
63606384
const pdfBudgets = new Map<string, ReturnType<typeof makeClaudeAttachmentBudget>>();
6361-
// MCP app notes already in each native session's history, by key. Cleared when it compacts.
6385+
// Digests of MCP app notes already in each native session's history, by key. Cleared when it
6386+
// compacts; persisted in native metadata so a restarted server does not resend them.
63626387
const deliveredAppContext = new Map<string, ReadonlyMap<string, string>>();
63636388
const latestPlanByKind = yield* Ref.make(new Map<string, OrchestrationV2PlanArtifact>());
63646389
// Claude 5 task tools edit one list per native session, across turns.
@@ -6699,13 +6724,24 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
66996724
const budget = pdfBudgets.get(nativeThreadId);
67006725
const hasAppliedTitle = appliedSessionTitles.has(nativeThreadId);
67016726
const recordedTitle = providerThread.nativeMetadata?.title;
6702-
if (budget === undefined && !hasAppliedTitle && recordedTitle === undefined) {
6727+
const delivered = deliveredAppContext.get(nativeThreadId);
6728+
if (
6729+
budget === undefined &&
6730+
!hasAppliedTitle &&
6731+
recordedTitle === undefined &&
6732+
delivered === undefined
6733+
) {
67036734
return providerThread;
67046735
}
6736+
const { claudeDeliveredAppContext: _recorded, ...nativeMetadata } =
6737+
providerThread.nativeMetadata ?? {};
67056738
return {
67066739
...providerThread,
67076740
nativeMetadata: {
6708-
...providerThread.nativeMetadata,
6741+
...(delivered === undefined ? providerThread.nativeMetadata : nativeMetadata),
6742+
...(delivered === undefined || delivered.size === 0
6743+
? {}
6744+
: { claudeDeliveredAppContext: Object.fromEntries(delivered) }),
67096745
...(budget === undefined
67106746
? {}
67116747
: {
@@ -11635,7 +11671,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
1163511671

1163611672
// Every trigger discards the conversation, so reset whatever the trigger is.
1163711673
if (message.type === "conversation_reset") {
11638-
deliveredAppContext.delete(context.nativeThreadId);
11674+
deliveredAppContext.set(context.nativeThreadId, new Map());
1163911675
context.appContextOffered = undefined;
1164011676
if (context.streamUsage !== null) context.streamUsage.usage = null;
1164111677
context.compactionTokens = 0;
@@ -11706,7 +11742,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
1170611742
budget.compacting = null;
1170711743
yield* persistAttachmentBudget(context.nativeThreadId);
1170811744
}
11709-
deliveredAppContext.delete(context.nativeThreadId);
11745+
deliveredAppContext.set(context.nativeThreadId, new Map());
1171011746
context.appContextOffered = undefined;
1171111747
if (context.streamUsage !== null) context.streamUsage.usage = null;
1171211748
const postTokens = message.compact_metadata.post_tokens;
@@ -14078,6 +14114,12 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
1407814114
const used = turnInput.providerThread.nativeMetadata?.claudeAttachmentBudget;
1407914115
pdfBudgets.set(nativeThreadId, makeClaudeAttachmentBudget(used));
1408014116
}
14117+
if (!deliveredAppContext.has(nativeThreadId)) {
14118+
const recorded = turnInput.providerThread.nativeMetadata?.claudeDeliveredAppContext;
14119+
if (recorded !== undefined) {
14120+
deliveredAppContext.set(nativeThreadId, new Map(Object.entries(recorded)));
14121+
}
14122+
}
1408114123
if (!appliedSessionTitles.has(nativeThreadId)) {
1408214124
const recordedTitle = turnInput.providerThread.nativeMetadata?.title;
1408314125
if (recordedTitle !== undefined && recordedTitle !== null) {
@@ -14135,7 +14177,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
1413514177
Effect.map((message) => {
1413614178
const withContext = withClaudeAppContext(
1413714179
message,
14138-
appContext.filter((entry) => delivered?.get(entry.key) !== entry.text),
14180+
unseenClaudeAppContext(appContext, delivered),
1413914181
pdfReservation,
1414014182
);
1414114183
appContextSent = withContext !== message;
@@ -14298,9 +14340,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
1429814340
offerCommitted = true;
1429914341
pdfReservation.commit();
1430014342
if (appContextSent) {
14301-
context.appContextOffered = new Map(
14302-
appContext.map((entry) => [entry.key, entry.text]),
14303-
);
14343+
context.appContextOffered = claudeAppContextDigests(appContext);
1430414344
}
1430514345
};
1430614346
const offerUserMessage =
@@ -14704,16 +14744,14 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
1470414744
currentTurn.appContextOffered ?? deliveredAppContext.get(existing.nativeThreadId);
1470514745
const userMessage = withClaudeAppContext(
1470614746
steerMessage,
14707-
appContext.filter((entry) => seenAppContext?.get(entry.key) !== entry.text),
14747+
unseenClaudeAppContext(appContext, seenAppContext),
1470814748
pdfReservation,
1470914749
);
1471014750
// `offer` may call this twice; a second call must not restore notes compaction cleared.
1471114751
let offerCommitted = false;
1471214752
const appContextBefore = currentTurn.appContextOffered;
1471314753
const appContextOffered =
14714-
userMessage === steerMessage
14715-
? undefined
14716-
: new Map(appContext.map((entry) => [entry.key, entry.text]));
14754+
userMessage === steerMessage ? undefined : claudeAppContextDigests(appContext);
1471714755
const commitOffer = () => {
1471814756
if (offerCommitted) return;
1471914757
offerCommitted = true;
@@ -15436,7 +15474,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
1543615474
const nativeThreadId = yield* getNativeThreadId(rollbackInput.providerThread);
1543715475
yield* closeLiveQueryForNativeThread(nativeThreadId);
1543815476
// The rewound history may no longer hold the turns that carried app notes.
15439-
deliveredAppContext.delete(nativeThreadId);
15477+
deliveredAppContext.set(nativeThreadId, new Map());
1544015478
const now = yield* DateTime.now;
1544115479
const resumeSessionAt = yield* resolveClaudeRollbackResumeSessionAt(rollbackInput);
1544215480

@@ -15465,9 +15503,14 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
1546515503
};
1546615504
}
1546715505

15506+
const { claudeDeliveredAppContext: _delivered, ...nativeMetadata } =
15507+
rollbackInput.providerThread.nativeMetadata ?? {};
1546815508
return {
1546915509
providerThread: {
1547015510
...rollbackInput.providerThread,
15511+
...(rollbackInput.providerThread.nativeMetadata === null
15512+
? {}
15513+
: { nativeMetadata }),
1547115514
providerSessionId: input.providerSessionId,
1547215515
nativeConversationHeadRef:
1547315516
resumeSessionAt === null
Collapse file

‎apps/server/src/orchestration-v2/ProviderTurnControlService.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ProviderTurnControlService.test.ts
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ it.effect("steers a running turn with its sender and the thread's MCP app model
438438
server: "tools",
439439
tool: "picker",
440440
text: "Pressed: blue",
441+
updatedAt: "2026-11-23T14:02:17.000Z",
441442
},
442443
]),
443444
}),
@@ -462,7 +463,11 @@ it.effect("steers a running turn with its sender and the thread's MCP app model
462463
'[T3 Code: the agent in T3 thread "thread:steer-sender" sent this message, not the user.]\n\nWhat did the app report?',
463464
);
464465
assert.deepEqual("appContext" in steered[0]! ? steered[0].appContext : undefined, [
465-
{ key: "mcp_app_turn-item_call-1", text: "Pressed: blue" },
466+
{
467+
key: "mcp_app_turn-item_call-1",
468+
text: "Pressed: blue",
469+
updatedAt: "2026-11-23T14:02:17.000Z",
470+
},
466471
]);
467472
}),
468473
);

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.