Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
74af6b8
fix(server): a stopped run's late typed result no longer lands on the…
only21mil Nov 21, 2026
1c5eb98
Merge remote-tracking branch 'origin/main' into fix/typed-results-lat…
juliusmarminge Nov 21, 2026
dd21241
docs(server): t3_submit_output rejects late calls from a stopped turn
juliusmarminge Nov 21, 2026
ba18ef7
fix(server): MCP credential rotation keeps the old credential when it…
juliusmarminge Nov 21, 2026
8b9b34c
fix(acp): MCP credential rotation follows the installed agent's trans…
juliusmarminge Nov 21, 2026
4662b06
fix(server): typed turns run again on providers that cannot rotate MC…
juliusmarminge Nov 21, 2026
c37f851
fix(server): MCP rotation fallbacks stay on the runtime and agent the…
juliusmarminge Nov 21, 2026
b3eef25
fix(server): typed results name their run when the credential cannot
juliusmarminge Nov 21, 2026
f370950
fix(server): t3_submit_output's description fits the agent context bu…
juliusmarminge Nov 21, 2026
e4d0fea
test(server): the launch result test names the run it submits for
juliusmarminge Nov 21, 2026
e8ce63e
fix(server): an unconfirmed unload resumes natively, and continuation…
juliusmarminge Nov 21, 2026
f83b046
fix(server): harden MCP credential fallback, reload retirement, and A…
only21mil Nov 21, 2026
602806f
fix(server): close MCP capability sync, ACP restart, continuation run…
only21mil Nov 21, 2026
472d9de
Merge branch 'main' into fix/typed-results-late-submission-run-mismatch
only21mil Nov 22, 2026
3c35a7b
Merge branch 'main' into fix/typed-results-late-submission-run-mismatch
only21mil Nov 22, 2026
b2b378c
Merge branch 'main' into fix/typed-results-late-submission-run-mismatch
only21mil Nov 22, 2026
7ec2088
refactor(server): tighten MCP credential rotation paths and tests
only21mil Nov 22, 2026
19b1c3d
Merge branch 'main' into fix/typed-results-late-submission-run-mismatch
only21mil Nov 22, 2026
02eb3fd
Merge branch 'main' into fix/typed-results-late-submission-run-mismatch
only21mil Nov 22, 2026
d97fc16
fix(server): harden MCP credential unload records, error reasons, and…
only21mil Nov 23, 2026
26d82b9
Merge branch 'main' into fix/typed-results-late-submission-run-mismatch
only21mil Nov 23, 2026
8d0a455
Merge branch 'main' into fix/typed-results-late-submission-run-mismatch
only21mil Nov 23, 2026
f5c4fb4
Merge remote-tracking branch 'upstream/main' into fix/typed-results-l…
only21mil Nov 23, 2026
e8c4639
test(server): a warm Claude process with a rotated MCP credential is …
only21mil Nov 23, 2026
2200d7b
refactor(server): tighten typed-result submission paths and tests
only21mil Nov 23, 2026
f178dfd
Merge remote-tracking branch 'upstream/main' into fix/typed-results-l…
only21mil Nov 23, 2026
bbe733c
refactor(server): fold the turn MCP check into the tracked-turn wrapp…
only21mil Nov 23, 2026
29a8c41
fix(server): check a turn's MCP credential only once its session is busy
only21mil Nov 23, 2026
a8c775f
Merge remote-tracking branch 'upstream/main' into fix/typed-results-l…
only21mil Nov 24, 2026
029a970
fix(server): a typed result naming another run, or sent while its wak…
only21mil Nov 24, 2026
2c806d7
fix(server): only a thread's own background work keeps its MCP creden…
only21mil Nov 24, 2026
1d118da
fix(provider-acp): a reconnect after an MCP credential rotation no lo…
only21mil Nov 24, 2026
109c197
fix(server): a stopped wake's late result no longer lands on the run …
only21mil Nov 24, 2026
a6f6441
fix(server): a typed result must name its run
only21mil Nov 24, 2026
e730495
fix(server): a provider-started wake and a typed continuation submit …
only21mil Nov 24, 2026
6fc130a
fix(server): turn start checks a Codex thread's own work under the id…
only21mil Nov 24, 2026
395f8ee
fix(server): a typed resume on a provider without native resume is pr…
only21mil Nov 24, 2026
8a1f988
Merge remote-tracking branch 'upstream/main' into fix/typed-results-l…
only21mil Nov 24, 2026
885f061
Merge commit 'ff6b10e0a05' into fix/typed-results-late-submission-run…
only21mil Nov 24, 2026
e49dd6d
fix(server): MCP credential refreshes show their startup step
only21mil Nov 24, 2026
d3ec855
Merge commit 'de8551b05a9' into fix/typed-results-late-submission-run…
only21mil Nov 24, 2026
9662f69
Merge commit '5ac27b40071' into fix/typed-results-late-submission-run…
only21mil Nov 24, 2026
dc78604
refactor(server): drop the separate owed-run turn option and skip owe…
only21mil Nov 24, 2026
c951163
Merge commit '5f3cdab9b77' into fix/typed-results-late-submission-run…
only21mil Nov 25, 2026
b29dfc3
refactor(provider-acp): drop the unread initialize-result store on se…
only21mil Nov 25, 2026
b8605e0
fix(provider-acp): a credential-only session reload no longer re-adve…
only21mil Nov 25, 2026
d7ccb32
fix(provider-acp): only a credential-only reload keeps the published …
only21mil Nov 25, 2026
55b4e6b
Merge commit '3b5033a28cf' into fix/typed-results-late-submission-run…
only21mil Nov 25, 2026
d71df86
chore: retrigger checks after merge
only21mil Nov 25, 2026
42fa9ba
chore: retrigger checks after merge
only21mil Nov 25, 2026
ec9fe03
chore: retrigger checks after merge
only21mil Nov 25, 2026
ba524e1
Merge commit 'bf961f8121c' into fix/typed-results-late-submission-run…
only21mil Nov 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/server/src/mcp/McpInvocationContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
type ProviderInstanceId,
type ProviderInteractionMode,
type OrchestrationV2LinkedSender,
type RunAttemptId,
type RunId,
type RuntimeMode,
type ThreadId,
} from "@t3tools/contracts";
Expand All @@ -32,6 +34,8 @@ export interface McpThreadCaller {
readonly threadId: ThreadId;
readonly providerSessionId: string;
readonly providerInstanceId: ProviderInstanceId;
readonly runId?: RunId | undefined;
readonly attemptId?: RunAttemptId | undefined;
/** A delegated child task; its parent owns the work it hands back. */
readonly subagent?: boolean;
}
Expand Down
71 changes: 70 additions & 1 deletion apps/server/src/mcp/McpSessionRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
import * as NodeServices from "@effect/platform-node/NodeServices";
import * as Layer from "effect/Layer";
import { expect, it } from "@effect/vitest";
import { EnvironmentId, ProviderInstanceId, ThreadId } from "@t3tools/contracts";
import {
EnvironmentId,
ProviderInstanceId,
RunAttemptId,
RunId,
ThreadId,
} from "@t3tools/contracts";
import * as Effect from "effect/Effect";
import { HttpServer } from "effect/http";
import * as NetAddress from "effect/net/NetAddress";
Expand Down Expand Up @@ -261,3 +267,66 @@ it.effect.each(["provider-session", "thread", "all"] as const)(
expect(yield* registry.resolve(token)).toBeUndefined();
}),
);

it.effect("carries run and attempt identity on credentials and bounds per-thread retention", () =>
Effect.gen(function* () {
const registry = yield* makeRegistry(() => 1_000);
const threadId = ThreadId.make("thread-run-scoped");
const tokens: Array<string> = [];

for (let ordinal = 1; ordinal <= 18; ordinal++) {
const runId = RunId.make(`run-${ordinal}`);
const attemptId = RunAttemptId.make(`attempt-${ordinal}`);
const issued = yield* registry.issue({
threadId,
providerInstanceId: ProviderInstanceId.make("codex"),
capabilities: new Set(),
runId,
attemptId,
});
expect(issued.config.runId).toBe(runId);
expect(issued.config.attemptId).toBe(attemptId);
tokens.push(issued.config.authorizationHeader.replace(/^Bearer\s+/, ""));
}

// Oldest credentials beyond the 16-token retention bound are evicted; recent ones stay distinct.
expect(yield* registry.resolve(tokens[0]!)).toBeUndefined();
expect(yield* registry.resolve(tokens[1]!)).toBeUndefined();
const keptOldest = yield* registry.resolve(tokens[2]!);
const keptNewest = yield* registry.resolve(tokens[17]!);
expect(keptOldest?.thread.runId).toBe(RunId.make("run-3"));
expect(keptOldest?.thread.attemptId).toBe(RunAttemptId.make("attempt-3"));
expect(keptNewest?.thread.runId).toBe(RunId.make("run-18"));
expect(keptNewest?.thread.attemptId).toBe(RunAttemptId.make("attempt-18"));

yield* registry.revokeThread(threadId);
expect(yield* registry.resolve(tokens[2]!)).toBeUndefined();
expect(yield* registry.resolve(tokens[17]!)).toBeUndefined();

// Preserving providerSessionId across rotations keeps a stable owner id while revoking per credentialId.
const first = yield* registry.issue({
threadId,
providerInstanceId: ProviderInstanceId.make("codex"),
runId: RunId.make("run-owner-1"),
});
const second = yield* registry.issue({
threadId,
providerInstanceId: ProviderInstanceId.make("codex"),
providerSessionId: first.config.providerSessionId,
runId: RunId.make("run-owner-2"),
});
expect(second.config.providerSessionId).toBe(first.config.providerSessionId);
expect(second.config.credentialId).toBeDefined();
expect(second.config.credentialId).not.toBe(first.config.credentialId);
const firstToken = first.config.authorizationHeader.replace(/^Bearer\s+/, "");
const secondToken = second.config.authorizationHeader.replace(/^Bearer\s+/, "");
expect((yield* registry.resolve(secondToken))?.thread.providerSessionId).toBe(
first.config.providerSessionId,
);
yield* registry.revokeCredential(second.config.credentialId!);
expect(yield* registry.resolve(secondToken)).toBeUndefined();
expect((yield* registry.resolve(firstToken))?.thread.runId).toBe(RunId.make("run-owner-1"));
yield* registry.revokeProviderSession(first.config.providerSessionId);
expect(yield* registry.resolve(firstToken)).toBeUndefined();
}),
);
8 changes: 6 additions & 2 deletions apps/server/src/mcp/McpSessionRegistry.testkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import * as McpSessionRegistry from "./McpSessionRegistry.ts";
export const layer = Layer.succeed(
McpSessionRegistry.McpSessionRegistry,
McpSessionRegistry.McpSessionRegistry.of({
issue: ({ threadId, providerInstanceId }) =>
issue: ({ threadId, providerInstanceId, providerSessionId }) =>
Effect.succeed({
config: {
environmentId: EnvironmentId.make("environment:mcp-test"),
threadId,
providerSessionId: `mcp-test:${threadId}`,
providerSessionId: providerSessionId ?? `mcp-test:${threadId}`,
credentialId: `mcp-test-cred:${threadId}`,
providerInstanceId,
endpoint: "http://127.0.0.1/mcp",
authorizationHeader: `Bearer mcp-test:${threadId}`,
Expand All @@ -21,6 +22,9 @@ export const layer = Layer.succeed(
}),
resolve: () => Effect.undefined,
touch: () => Effect.void,
revokeCredential: () => Effect.void,
releaseRunBinding: () => Effect.void,
syncCapabilities: () => Effect.undefined,
revokeProviderSession: () => Effect.void,
revokeThread: () => Effect.void,
revokeAll: Effect.void,
Expand Down
103 changes: 100 additions & 3 deletions apps/server/src/mcp/McpSessionRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ProviderInstanceId, ThreadId } from "@t3tools/contracts";
import { ProviderInstanceId, RunAttemptId, RunId, ThreadId } from "@t3tools/contracts";
import * as Clock from "effect/Clock";
import * as Context from "effect/Context";
import * as Digest from "effect/crypto/Digest";
Expand All @@ -16,6 +16,10 @@ import * as McpProviderSession from "@t3tools/provider-core/server/mcpSession";
export interface McpCredentialRequest {
readonly threadId: ThreadId;
readonly providerInstanceId: ProviderInstanceId;
/** Stable session owner id preserved across run rotations on the same provider session. */
readonly providerSessionId?: string | undefined;
readonly runId?: RunId | undefined;
readonly attemptId?: RunAttemptId | undefined;
/** False omits the preview capability wherever the token is honored. Defaults to full access. */
readonly browserToolsAvailable?: boolean;
readonly capabilities?: ReadonlySet<McpInvocationContext.McpCapability>;
Expand All @@ -32,6 +36,18 @@ export interface McpSessionRegistryShape {
rawToken: string,
) => Effect.Effect<McpInvocationContext.McpThreadInvocationScope | undefined>;
readonly touch: (threadId: ThreadId) => Effect.Effect<void>;
readonly revokeCredential: (credentialId: string) => Effect.Effect<void>;
/** For runtimes that cannot take a new credential: the token stays valid but answers for no run. */
readonly releaseRunBinding: (credentialId: string) => Effect.Effect<void>;
/** Syncs dynamic access capabilities on a retained credential (revokes apply across the thread). */
readonly syncCapabilities: (
credentialId: string,
changes: {
readonly threadId: ThreadId;
readonly grant?: ReadonlyArray<McpInvocationContext.McpCapability>;
readonly revoke?: ReadonlyArray<McpInvocationContext.McpCapability>;
},
) => Effect.Effect<ReadonlySet<McpInvocationContext.McpCapability> | undefined>;
readonly revokeProviderSession: (providerSessionId: string) => Effect.Effect<void>;
readonly revokeThread: (threadId: ThreadId) => Effect.Effect<void>;
readonly revokeAll: Effect.Effect<void>;
Expand All @@ -48,6 +64,7 @@ interface AliveMark {
}

interface CredentialRecord {
readonly credentialId: string;
readonly tokenHash: string;
readonly scope: McpInvocationContext.McpThreadInvocationScope;
readonly lastAlive: AliveMark;
Expand All @@ -71,6 +88,8 @@ export interface McpSessionRegistryOptions {
* refresh the token its subprocess still holds; MCP requests cannot.
*/
const DEFAULT_LIVENESS_WINDOW_MS = 24 * 60 * 60 * 1_000;
// Bound retained prior-turn tokens per thread when rotating run identity without immediate revocation.
export const MAX_CREDENTIALS_PER_THREAD = 16;

const bytesToHex = (bytes: Uint8Array): string =>
Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
Expand Down Expand Up @@ -121,17 +140,23 @@ const makeWithOptions = Effect.fn("McpSessionRegistry.make")(function* (
const issue: McpSessionRegistryShape["issue"] = Effect.fn("McpSessionRegistry.issue")(
function* (request) {
const issuedAlive = yield* currentAliveMark;
const providerSessionId = yield* random.uuidV4();
const providerSessionId = request.providerSessionId ?? (yield* random.uuidV4());
const credentialId = yield* random.uuidV4();
const rawToken = yield* random.randomBytes(32).pipe(Effect.map(tokenFromBytes), Effect.orDie);
const tokenHash = yield* hashToken(rawToken);
const browserToolsAvailable = request.browserToolsAvailable ?? true;
const runId = request.runId === undefined ? undefined : RunId.make(request.runId);
const attemptId =
request.attemptId === undefined ? undefined : RunAttemptId.make(request.attemptId);
const scope: McpInvocationContext.McpThreadInvocationScope = {
environmentId,
requestNamespace: providerSessionId,
thread: {
threadId: ThreadId.make(request.threadId),
providerSessionId,
providerInstanceId: ProviderInstanceId.make(request.providerInstanceId),
...(runId === undefined ? {} : { runId }),
...(attemptId === undefined ? {} : { attemptId }),
subagent: request.subagent === true,
},
client: undefined,
Expand All @@ -146,15 +171,33 @@ const makeWithOptions = Effect.fn("McpSessionRegistry.make")(function* (
};
yield* SynchronizedRef.update(state, ({ records }) => {
const next = new Map(records);
next.set(tokenHash, { tokenHash, scope, lastAlive: issuedAlive, expired: false });
next.set(tokenHash, {
credentialId,
tokenHash,
scope,
lastAlive: issuedAlive,
expired: false,
});
const threadTokens: Array<string> = [];
for (const [hash, record] of next) {
if (record.scope.thread.threadId === scope.thread.threadId) {
threadTokens.push(hash);
}
}
for (let index = 0; index < threadTokens.length - MAX_CREDENTIALS_PER_THREAD; index += 1) {
next.delete(threadTokens[index]!);
}
return { records: next };
});
return {
config: {
environmentId,
threadId: scope.thread.threadId,
providerSessionId,
credentialId,
providerInstanceId: scope.thread.providerInstanceId,
...(runId === undefined ? {} : { runId }),
...(attemptId === undefined ? {} : { attemptId }),
endpoint,
authorizationHeader: `Bearer ${rawToken}`,
browserToolsAvailable: scope.capabilities.has("preview"),
Expand Down Expand Up @@ -208,6 +251,60 @@ const makeWithOptions = Effect.fn("McpSessionRegistry.make")(function* (
issue,
resolve,
touch,
revokeCredential: Effect.fn("McpSessionRegistry.revokeCredential")(function* (credentialId) {
yield* revokeWhere((record) => record.credentialId === credentialId);
}),
releaseRunBinding: Effect.fn("McpSessionRegistry.releaseRunBinding")(function* (credentialId) {
yield* SynchronizedRef.update(state, ({ records }) => {
let next: Map<string, CredentialRecord> | undefined;
for (const [tokenHash, record] of records) {
if (record.credentialId !== credentialId) continue;
const { runId: _runId, attemptId: _attemptId, ...thread } = record.scope.thread;
next ??= new Map(records);
next.set(tokenHash, { ...record, scope: { ...record.scope, thread } });
}
return next === undefined ? { records } : { records: next };
});
}),
syncCapabilities: Effect.fn("McpSessionRegistry.syncCapabilities")(
function* (credentialId, changes) {
const grant = changes.grant ?? [];
const revoke = changes.revoke ?? [];
return yield* SynchronizedRef.modify(state, ({ records }) => {
let updatedCapabilities: ReadonlySet<McpInvocationContext.McpCapability> | undefined;
let next: Map<string, CredentialRecord> | undefined;
for (const [tokenHash, record] of records) {
const isTarget = record.credentialId === credentialId;
const isThreadRevoke =
revoke.length > 0 && record.scope.thread.threadId === changes.threadId;
if (!isTarget && !isThreadRevoke) continue;
const remaining = new Set(record.scope.capabilities);
let changed = false;
if (isThreadRevoke) {
for (const capability of revoke) {
if (remaining.delete(capability)) changed = true;
}
}
if (isTarget) {
for (const capability of grant) {
if (!remaining.has(capability)) {
remaining.add(capability);
changed = true;
}
}
updatedCapabilities = changed ? remaining : record.scope.capabilities;
}
if (!changed) continue;
next ??= new Map(records);
next.set(tokenHash, { ...record, scope: { ...record.scope, capabilities: remaining } });
}
return [
updatedCapabilities,
next === undefined ? { records } : { records: next },
] as const;
});
},
),
revokeProviderSession: Effect.fn("McpSessionRegistry.revokeProviderSession")(
function* (providerSessionId) {
yield* revokeWhere((record) => record.scope.thread.providerSessionId === providerSessionId);
Expand Down
Loading
Loading