Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1397d76
fix(server): append new messages when re-importing Codex history
qi-hey Nov 19, 2026
ba6d396
Merge remote-tracking branch 'origin/main' into codex/refresh-importe…
qi-hey Nov 19, 2026
aeca8a3
fix(codex): refresh native messages when returning to a chat
qi-hey Nov 19, 2026
af6169d
fix(codex): reconcile missed native history in order
qi-hey Nov 19, 2026
7247ad5
fix(codex): resume history scans and preserve native boundaries
qi-hey Nov 19, 2026
d9af5b3
test(codex): replay rollback by native checkpoint
qi-hey Nov 19, 2026
75594ee
Merge remote-tracking branch 'origin/main' into codex/refresh-history…
qi-hey Nov 20, 2026
e6afcc1
fix(codex): preserve history and checkpoints across refreshes
qi-hey Nov 20, 2026
06b117a
fix(codex): preserve repository checkpoints when syncing history with…
qi-hey Nov 23, 2026
82c9611
fix(codex): keep native rollback checks with the updated snapshot format
qi-hey Nov 23, 2026
c8d8e80
Merge remote-tracking branch 'origin/main' into codex/refresh-importe…
qi-hey Nov 23, 2026
aa53365
Merge remote-tracking branch 'origin/main' into codex/refresh-importe…
qi-hey Nov 23, 2026
7690290
Merge remote-tracking branch 'origin/main' into codex/refresh-importe…
qi-hey Nov 24, 2026
082d435
Merge remote-tracking branch 'refs/remotes/origin/main' into HEAD
qi-hey Nov 25, 2026
115e5c6
Merge remote-tracking branch 'refs/remotes/origin/main' into HEAD
qi-hey Nov 26, 2026
e219dd4
Merge branch 'main' into codex/refresh-imported-codex-history
qi-hey Nov 26, 2026
452d9aa
Merge upstream main into Codex history refresh
qi-hey Nov 27, 2026
3ac1b44
Merge upstream main into Codex history refresh
qi-hey Nov 28, 2026
a3dec90
Merge upstream main into Codex history refresh
qi-hey Nov 28, 2026
b318da3
Merge upstream main into Codex history refresh
qi-hey Nov 29, 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
1 change: 1 addition & 0 deletions apps/server/src/auth/RpcAuthorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export const RPC_REQUIRED_SCOPES = {
[WS_METHODS.filesystemGetMetadata]: AuthFilesystemReadScope,
[WS_METHODS.agentSessionsScan]: AuthOrchestrationReadScope,
[WS_METHODS.agentSessionsImport]: AuthOrchestrationOperateScope,
[WS_METHODS.agentSessionsRefreshCodexHistory]: AuthOrchestrationOperateScope,
[WS_METHODS.assetsCreateUrl]: AuthOrchestrationReadScope,
[WS_METHODS.assetsPersistChatAttachments]: AuthOrchestrationOperateScope,
[WS_METHODS.attachmentsCreateUploadUrl]: AuthOrchestrationOperateScope,
Expand Down
73 changes: 70 additions & 3 deletions apps/server/src/checkpointing/CheckpointDiffQuery.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
import * as NodeServices from "@effect/platform-node/NodeServices";
import { assert, it, vi } from "@effect/vitest";
import { CheckpointRef, CheckpointScopeId, RunId, ThreadId } from "@t3tools/contracts";
import {
CheckpointId,
CheckpointRef,
CheckpointScopeId,
RunId,
ThreadId,
} from "@t3tools/contracts";
import * as Effect from "effect/Effect";
import * as FileSystem from "effect/FileSystem";
import * as Layer from "effect/Layer";
Expand Down Expand Up @@ -36,6 +42,8 @@ function makeProjection(): ProjectionCheckpointContext {
],
checkpoints: [
{
id: CheckpointId.make("checkpoint:second"),
parentCheckpointId: null,
scopeId: secondScopeId,
runId: secondRunId,
ordinalWithinScope: 1,
Expand Down Expand Up @@ -112,6 +120,8 @@ function makeProjectionAfterStoppedRun(stoppedRunCheckpoint: boolean) {
ordinalWithinScope: number,
runId: RunId | null,
): ProjectionCheckpointContext["checkpoints"][number] => ({
id: CheckpointId.make(`checkpoint:root:${ordinalWithinScope}`),
parentCheckpointId: null,
scopeId: firstScopeId,
runId,
ordinalWithinScope,
Expand All @@ -132,6 +142,7 @@ function makeProjectionAfterStoppedRun(stoppedRunCheckpoint: boolean) {
checkpoints: [
{
...checkpoint(2, null),
id: CheckpointId.make("checkpoint:tool:2"),
scopeId: secondScopeId,
ref: CheckpointRef.make("refs/t3/test/tool/2"),
},
Expand Down Expand Up @@ -190,6 +201,44 @@ it.effect.each([false, true])(
},
);

it.effect(
"uses the captured parent when refreshed history separates app and scope ordinals",
() => {
const projection = makeProjectionAfterStoppedRun(true);
const parent = { ...projection.checkpoints[3]!, appRunOrdinal: 3 };
const unusedBaseline = { ...projection.checkpoints[4]!, runId: null, appRunOrdinal: null };
const target = {
...projection.checkpoints[4]!,
id: CheckpointId.make("checkpoint:root:4"),
parentCheckpointId: parent.id,
ordinalWithinScope: 4,
appRunOrdinal: 4,
ref: CheckpointRef.make("refs/t3/test/ordinal/4"),
};
const diffCheckpoints = vi.fn((_input: CheckpointStore.DiffCheckpointsInput) =>
Effect.succeed("diff --git a/file b/file"),
);
const layer = layerFor({
projection: Effect.succeed({
...projection,
runs: projection.runs.map((run) =>
run.ordinal === 1 ? run : { ...run, ordinal: run.ordinal + 1 },
),
checkpoints: [...projection.checkpoints.slice(0, 3), parent, unusedBaseline, target],
}),
diffCheckpoints,
});
return Effect.gen(function* () {
const query = yield* CheckpointDiffQuery.CheckpointDiffQuery;
yield* query.getTurnDiff({ threadId, fromTurnCount: 3, toTurnCount: 4 });
assert.deepEqual(
diffCheckpoints.mock.calls.map(([input]) => input.fromCheckpointRef),
[parent.ref],
);
}).pipe(Effect.provide(layer));
},
);

const layerVcsProcess = VcsProcess.layer.pipe(Layer.provide(NodeServices.layer));
const layerStore = CheckpointStore.layer.pipe(
Layer.provide(VcsDriverRegistry.layer.pipe(Layer.provide(layerVcsProcess))),
Expand Down Expand Up @@ -260,6 +309,8 @@ it.effect("shares the turn and full-thread diff budget across real Git batches",
checkpointScopes: [{ id: scopeId, runId, kind: "root_run", cwd }],
checkpoints: [
{
id: CheckpointId.make("checkpoint:patch-budget:1"),
parentCheckpointId: null,
scopeId,
runId,
ordinalWithinScope: 1,
Expand Down Expand Up @@ -360,6 +411,8 @@ it.effect("adds a patch for each tracked repository that changed in the range",
repositoryPath: cwd,
},
checkpoints: ordinals.map((ordinalWithinScope) => ({
id: CheckpointId.make(`checkpoint:${name}:${ordinalWithinScope}`),
parentCheckpointId: null,
scopeId: id,
runId: ordinalWithinScope === 2 ? secondRunId : null,
ordinalWithinScope,
Expand All @@ -380,14 +433,26 @@ it.effect("adds a patch for each tracked repository that changed in the range",
const layer = layerFor({
projection: Effect.succeed({
...projection,
runs: [
projection.runs[0]!,
{ id: RunId.make("imported-turn"), ordinal: 2, status: "completed" },
{ ...projection.runs[1]!, ordinal: 3 },
],
checkpointScopes: [
...projection.checkpointScopes.map((scope) => ({ ...scope, cwd: "/work/app" })),
sibling.scope,
nested.scope,
later.scope,
],
checkpoints: [
...projection.checkpoints,
{
...projection.checkpoints[0]!,
id: CheckpointId.make("checkpoint:first"),
runId: firstRunId,
appRunOrdinal: 1,
ref: CheckpointRef.make("refs/t3/test/first"),
},
{ ...projection.checkpoints[0]!, ordinalWithinScope: 2, appRunOrdinal: 3 },
...sibling.checkpoints,
...nested.checkpoints,
...later.checkpoints,
Expand All @@ -397,7 +462,7 @@ it.effect("adds a patch for each tracked repository that changed in the range",
});
return Effect.gen(function* () {
const query = yield* CheckpointDiffQuery.CheckpointDiffQuery;
const result = yield* query.getTurnDiff({ threadId, fromTurnCount: 0, toTurnCount: 2 });
const result = yield* query.getTurnDiff({ threadId, fromTurnCount: 2, toTurnCount: 3 });
assert.deepEqual(result.repositories, [
{
name: "shared",
Expand All @@ -412,6 +477,8 @@ it.effect("adds a patch for each tracked repository that changed in the range",
diffCheckpoints.mock.calls.find(([input]) => input.cwd === "/work/app")?.[0].excludePaths,
["packages/ui"],
);
const aggregate = yield* query.getFullThreadDiff({ threadId, toTurnCount: 3 });
assert.deepEqual(aggregate.repositories, result.repositories);
}).pipe(Effect.provide(layer));
});

Expand Down
49 changes: 38 additions & 11 deletions apps/server/src/checkpointing/CheckpointDiffQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,43 @@ type ContextCheckpoint = ProjectionCheckpointContext["checkpoints"][number];
*/
function repositoryDiffRange(
checkpoints: ReadonlyArray<ContextCheckpoint>,
range: { readonly fromTurnCount: number; readonly toTurnCount: number },
range: { readonly fromOrdinal: number; readonly toOrdinal: number },
): { readonly from: ContextCheckpoint; readonly to: ContextCheckpoint } | undefined {
const ready = checkpoints
.filter(
(checkpoint) =>
checkpoint.status === "ready" &&
checkpoint.ordinalWithinScope >= range.fromTurnCount &&
checkpoint.ordinalWithinScope <= range.toTurnCount,
checkpoint.ordinalWithinScope >= range.fromOrdinal &&
checkpoint.ordinalWithinScope <= range.toOrdinal,
)
.toSorted((left, right) => left.ordinalWithinScope - right.ordinalWithinScope);
const from = ready[0];
const to = ready.at(-1);
return from === undefined || to === undefined || from === to ? undefined : { from, to };
}

// Imported turns have no snapshots; a repository range starts at the first captured turn's baseline.
function repositoryRangeStart(
checkpoints: ReadonlyArray<ContextCheckpoint>,
range: { readonly fromTurnCount: number; readonly toTurnCount: number },
toOrdinal: number,
): number {
if (range.fromTurnCount === 0) return 0;
let firstOrdinal = toOrdinal;
for (const checkpoint of checkpoints) {
if (
checkpoint.status !== "stale" &&
checkpoint.appRunOrdinal !== null &&
checkpoint.appRunOrdinal > range.fromTurnCount &&
checkpoint.appRunOrdinal <= range.toTurnCount &&
checkpoint.ordinalWithinScope < firstOrdinal
) {
firstOrdinal = checkpoint.ordinalWithinScope;
}
}
return firstOrdinal - 1;
}

/** @public */
export const make = Effect.gen(function* () {
const threads = yield* ThreadManagement.ThreadManagementService;
Expand Down Expand Up @@ -193,8 +215,8 @@ export const make = Effect.gen(function* () {
const repositoryDiffs = Effect.fn("CheckpointDiffQuery.repositoryDiffs")(function* (input: {
readonly projection: ProjectionCheckpointContext;
readonly threadCwd: string;
readonly fromTurnCount: number;
readonly toTurnCount: number;
readonly fromOrdinal: number;
readonly toOrdinal: number;
readonly ignoreWhitespace: boolean;
readonly nested: ReadonlyMap<string, ReadonlyArray<string>>;
readonly maxBytes: number;
Expand Down Expand Up @@ -346,7 +368,7 @@ export const make = Effect.gen(function* () {
projection.checkpoints.some(
(checkpoint) =>
checkpoint.scopeId === scope.id &&
checkpoint.ordinalWithinScope <= input.toTurnCount,
checkpoint.ordinalWithinScope <= toCheckpoint.ordinalWithinScope,
),
),
]).pipe(
Expand All @@ -361,8 +383,12 @@ export const make = Effect.gen(function* () {
: yield* repositoryDiffs({
projection,
threadCwd: toScope.cwd,
fromTurnCount: input.fromTurnCount,
toTurnCount: input.toTurnCount,
fromOrdinal: repositoryRangeStart(
projection.checkpoints,
input,
toCheckpoint.ordinalWithinScope,
),
toOrdinal: toCheckpoint.ordinalWithinScope,
ignoreWhitespace,
nested,
maxBytes: Math.max(0, CHECKPOINT_DIFF_MAX_OUTPUT_BYTES - Buffer.byteLength(diff)),
Expand All @@ -378,15 +404,16 @@ export const make = Effect.gen(function* () {
});
if (toCheckpoint.status === "missing") return yield* withRepositories("");

// Capture compares against the preceding scope ordinal, even when that
// checkpoint belongs to a stopped run or has no run.
// Imported turns can move app ordinals while the captured parent and its ref stay in place.
const parentCheckpoint =
input.fromTurnCount === input.toTurnCount - 1
? projection.checkpoints.find(
(checkpoint) =>
checkpoint.status === "ready" &&
checkpoint.scopeId === toCheckpoint.scopeId &&
checkpoint.ordinalWithinScope === toCheckpoint.ordinalWithinScope - 1,
(toCheckpoint.parentCheckpointId === null
? checkpoint.ordinalWithinScope === toCheckpoint.ordinalWithinScope - 1
: checkpoint.id === toCheckpoint.parentCheckpointId),
)
: undefined;

Expand Down
1 change: 1 addition & 0 deletions apps/server/src/observability/RpcInstrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ const RPC_AGGREGATES = {
[WS_METHODS.filesystemGetMetadata]: "workspace",
[WS_METHODS.agentSessionsScan]: "workspace",
[WS_METHODS.agentSessionsImport]: "workspace",
[WS_METHODS.agentSessionsRefreshCodexHistory]: "workspace",
[WS_METHODS.assetsCreateUrl]: "workspace",
[WS_METHODS.assetsPersistChatAttachments]: "orchestration",
[WS_METHODS.attachmentsCreateUploadUrl]: "workspace",
Expand Down
Loading
Loading