refactor(session): nuke dead sessionParams / sessionDisplayId pipeline (v43)

These columns and the messages that plumbed them existed for the CLI-
adapter era — Gemini's resume id and provider-specific session params
rode the run-finished envelope back onto the session row so the next
turn could resume. Pi Mono dispatches every provider through pi-ai and
emits neither value. The worker has been posting literal null on every
finish, finalizeRun has been writing null into task_sessions, and
rotateSession has been carrying null forward.

Remove the wire, the writer, the carry-forward, and the columns:

  - v43 migration rebuilds task_sessions without session_params_json /
    session_display_id, and runs without session_display_id. Follows
    the idempotent "create new, copy, swap, reindex" pattern used by
    v41. context_snapshot_json is preserved (also unreferenced today
    but outside this cleanup's scope).
  - RunJob / EnqueueRunPayload / ChildMessage / worker-types zod
    schema no longer carry the fields. finishRun() / createNewSession()
    signatures tighten in lockstep.
  - rotateSession starts the new session with fresh counters and no
    carry-forward.
  - turn-context resolveSession returns just the session id.
  - TaskSessionRecord / RunRecord lose the dead fields.

498/498 unit tests pass. typecheck + build clean.
This commit is contained in:
ZacharyZhang-NY committed 2026-04-18 23:22:17 -04:00
1 parent 88a1f8b334
commit e0e43d6127
32 files changed
+167 -205

No files matched your search

-4
View File
@@ -196,7 +196,6 @@ describe("CAS checkout", () => {
exitCode: 0,
signal: null,
model: null,
sessionDisplayId: null,
unattributedCost: false,
});
@@ -337,7 +336,6 @@ describe("CAS checkout", () => {
exitCode: null,
signal: null,
model: null,
sessionDisplayId: null,
unattributedCost: true,
});
@@ -382,7 +380,6 @@ describe("CAS checkout", () => {
exitCode: null,
signal: null,
model: null,
sessionDisplayId: null,
unattributedCost: true,
});
@@ -417,7 +414,6 @@ describe("CAS checkout", () => {
exitCode: 1,
signal: null,
model: null,
sessionDisplayId: null,
unattributedCost: false,
});
-1
View File
@@ -27,7 +27,6 @@ function makeRun(overrides: Partial<RunRecord> = {}): RunRecord {
exitCode: null,
signal: null,
model: null,
sessionDisplayId: null,
costUsd: null,
unattributedCost: false,
startedAt: null,
-2
View File
@@ -296,7 +296,6 @@ describe("AppDatabase", () => {
exitCode: 0,
signal: null,
model: "gpt-5",
sessionDisplayId: "session-budget",
unattributedCost: false,
});
@@ -515,7 +514,6 @@ describe("AppDatabase", () => {
exitCode: 0,
signal: null,
model: null,
sessionDisplayId: null,
unattributedCost: true,
});
-7
View File
@@ -167,7 +167,6 @@ describe("Edge Case: Budget Exhaustion Mid-Run (D-05.2)", () => {
exitCode: 0,
signal: null,
model: "gemini-pro",
sessionDisplayId: null,
unattributedCost: false,
});
@@ -182,7 +181,6 @@ describe("Edge Case: Budget Exhaustion Mid-Run (D-05.2)", () => {
exitCode: 0,
signal: null,
model: "gemini-pro",
sessionDisplayId: null,
unattributedCost: false,
});
@@ -234,7 +232,6 @@ describe("Edge Case: Budget Exhaustion Mid-Run (D-05.2)", () => {
exitCode: 0,
signal: null,
model: "gemini-pro",
sessionDisplayId: null,
unattributedCost: false,
});
@@ -283,7 +280,6 @@ describe("Edge Case: Budget Exhaustion Mid-Run (D-05.2)", () => {
exitCode: 0,
signal: null,
model: "gemini-pro",
sessionDisplayId: null,
unattributedCost: false,
});
@@ -341,7 +337,6 @@ describe("Edge Case: Budget Exhaustion Mid-Run (D-05.2)", () => {
exitCode: 0,
signal: null,
model: "gemini-pro",
sessionDisplayId: null,
unattributedCost: false,
});
@@ -394,7 +389,6 @@ describe("Edge Case: Budget Exhaustion Mid-Run (D-05.2)", () => {
exitCode: 0,
signal: null,
model: "gemini-pro",
sessionDisplayId: null,
unattributedCost: false,
});
@@ -443,7 +437,6 @@ describe("Edge Case: Budget Exhaustion Mid-Run (D-05.2)", () => {
exitCode: 0,
signal: null,
model: "gemini-pro",
sessionDisplayId: null,
unattributedCost: false,
});
-18
View File
@@ -118,8 +118,6 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
companyId,
agentId,
adapterType: "gemini-cli",
sessionParamsJson: null,
sessionDisplayId: null,
});
// Simulate runs until we reach the maxRuns threshold (20)
@@ -146,8 +144,6 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
companyId,
agentId,
adapterType: "gemini-cli",
sessionParamsJson: null,
sessionDisplayId: null,
});
// Accumulate tokens past the threshold in one big call
@@ -172,8 +168,6 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
companyId,
agentId,
adapterType: "gemini-cli",
sessionParamsJson: null,
sessionDisplayId: null,
});
// Accumulate enough to trigger rotation
@@ -197,7 +191,6 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
exitCode: 0,
signal: null,
model: "gemini-pro",
sessionDisplayId: null,
unattributedCost: false,
});
@@ -229,8 +222,6 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
companyId,
agentId,
adapterType: "gemini-cli",
sessionParamsJson: JSON.stringify({ resumeKey: "abc" }),
sessionDisplayId: "gemini-session-1",
});
// Add usage to the old session
@@ -244,8 +235,6 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
companyId,
agentId,
adapterType: "gemini-cli",
sessionParamsJson: JSON.stringify({ resumeKey: "abc" }),
sessionDisplayId: "gemini-session-2",
});
// Get the new active session
@@ -268,8 +257,6 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
companyId,
agentId,
adapterType: "claude-pro",
sessionParamsJson: null,
sessionDisplayId: null,
});
// Accumulate way past all thresholds
@@ -292,8 +279,6 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
companyId,
agentId,
adapterType: "openai-codex",
sessionParamsJson: null,
sessionDisplayId: null,
});
// Accumulate way past all thresholds
@@ -317,8 +302,6 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
companyId,
agentId,
adapterType: "gemini-cli",
sessionParamsJson: null,
sessionDisplayId: null,
});
db.incrementSessionUsage(sessionId, 300000, 200000, "run-1");
@@ -338,7 +321,6 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
exitCode: 0,
signal: null,
model: "gemini-pro",
sessionDisplayId: null,
unattributedCost: false,
});
+1 -44
View File
@@ -106,8 +106,6 @@ describe("task_sessions CRUD", () => {
companyId,
agentId,
adapterType: "claude-pro",
sessionParamsJson: JSON.stringify({ sessionId: "abc123" }),
sessionDisplayId: "claude-abc123",
});
const session = db.getSessionById(sessionId);
@@ -116,8 +114,6 @@ describe("task_sessions CRUD", () => {
expect(session!.companyId).toBe(companyId);
expect(session!.agentId).toBe(agentId);
expect(session!.adapterType).toBe("claude-pro");
expect(session!.sessionParamsJson).toBe(JSON.stringify({ sessionId: "abc123" }));
expect(session!.sessionDisplayId).toBe("claude-abc123");
expect(session!.runCount).toBe(0);
expect(session!.totalInputTokens).toBe(0);
expect(session!.totalOutputTokens).toBe(0);
@@ -132,8 +128,6 @@ describe("task_sessions CRUD", () => {
companyId,
agentId,
adapterType: "claude-pro",
sessionParamsJson: null,
sessionDisplayId: null,
});
db.incrementSessionUsage(sessionId, 1000, 500, "run-001");
@@ -159,8 +153,6 @@ describe("task_sessions CRUD", () => {
companyId,
agentId,
adapterType: "claude-pro",
sessionParamsJson: null,
sessionDisplayId: null,
});
db.archiveSession(sessionId, "max_runs", "# Handoff\nSession reached 20 runs.");
@@ -178,8 +170,6 @@ describe("task_sessions CRUD", () => {
companyId,
agentId,
adapterType: "gemini-cli",
sessionParamsJson: JSON.stringify({ key: "val" }),
sessionDisplayId: "gemini-session-1",
});
expect(typeof sessionId).toBe("string");
@@ -204,7 +194,6 @@ describe("task_sessions CRUD", () => {
exitCode: 0,
signal: null,
model: "claude-4-opus",
sessionDisplayId: null,
unattributedCost: false,
});
@@ -217,7 +206,6 @@ describe("task_sessions CRUD", () => {
exitCode: 1,
signal: null,
model: "claude-4-opus",
sessionDisplayId: null,
unattributedCost: false,
});
@@ -292,8 +280,6 @@ describe("session management service", () => {
companyId: "co-1",
agentId: "agent-1",
adapterType: "gemini-cli",
sessionParamsJson: null,
sessionDisplayId: null,
lastRunId: null,
lastError: null,
runCount: 5,
@@ -317,8 +303,6 @@ describe("session management service", () => {
companyId: "co-1",
agentId: "agent-1",
adapterType: "gemini-cli",
sessionParamsJson: null,
sessionDisplayId: null,
lastRunId: null,
lastError: null,
runCount: 20,
@@ -342,8 +326,6 @@ describe("session management service", () => {
companyId: "co-1",
agentId: "agent-1",
adapterType: "gemini-cli",
sessionParamsJson: null,
sessionDisplayId: null,
lastRunId: null,
lastError: null,
runCount: 3,
@@ -368,8 +350,6 @@ describe("session management service", () => {
companyId: "co-1",
agentId: "agent-1",
adapterType: "gemini-cli",
sessionParamsJson: null,
sessionDisplayId: null,
lastRunId: null,
lastError: null,
runCount: 1,
@@ -398,8 +378,6 @@ describe("session management service", () => {
companyId: "co-1",
agentId: "agent-1",
adapterType: "claude-pro",
sessionParamsJson: null,
sessionDisplayId: null,
lastRunId: null,
lastError: null,
runCount: 100, // Way over threshold
@@ -428,8 +406,6 @@ describe("session management service", () => {
companyId: "co-1",
agentId: "agent-1",
adapterType: "gemini-cli",
sessionParamsJson: null,
sessionDisplayId: null,
lastRunId: null,
lastError: null,
runCount: 5,
@@ -453,8 +429,6 @@ describe("session management service", () => {
companyId: "co-1",
agentId: "agent-1",
adapterType: "gemini-cli",
sessionParamsJson: null,
sessionDisplayId: null,
lastRunId: null,
lastError: null,
runCount: 10, // Below default 20
@@ -478,8 +452,6 @@ describe("session management service", () => {
companyId: "co-1",
agentId: "agent-1",
adapterType: "gemini-cli",
sessionParamsJson: null,
sessionDisplayId: null,
lastRunId: null,
lastError: null,
runCount: 19, // Just below default 20
@@ -512,8 +484,6 @@ describe("session management service", () => {
companyId,
agentId,
adapterType: "claude-pro",
sessionParamsJson: null,
sessionDisplayId: null,
});
const svc = createSessionManagementService({ db, logger: mockLogger });
@@ -537,8 +507,6 @@ describe("session management service", () => {
companyId,
agentId,
adapterType: "gemini-cli",
sessionParamsJson: null,
sessionDisplayId: null,
});
// Create a completed run for history
@@ -551,7 +519,6 @@ describe("session management service", () => {
exitCode: 0,
signal: null,
model: "gemini-pro",
sessionDisplayId: null,
unattributedCost: false,
});
@@ -584,8 +551,6 @@ describe("session management service", () => {
companyId,
agentId,
adapterType: "gemini-cli",
sessionParamsJson: JSON.stringify({ resumeId: "old-abc" }),
sessionDisplayId: "gemini-old",
});
// Add some usage
@@ -606,14 +571,12 @@ describe("session management service", () => {
expect(archivedRows[0].rotationReason).toBe("threshold_exceeded");
expect(archivedRows[0].handoffMarkdown).toContain("# Session Handoff");
// New session is a distinct row, with fresh counters and copied params
// New session is a distinct row with fresh counters.
const newSession = db.getSessionById(newSessionId)!;
expect(newSession.id).toBe(newSessionId);
expect(newSession.runCount).toBe(0);
expect(newSession.totalInputTokens).toBe(0);
expect(newSession.totalOutputTokens).toBe(0);
expect(newSession.sessionParamsJson).toBe(JSON.stringify({ resumeId: "old-abc" }));
expect(newSession.sessionDisplayId).toBe("gemini-old");
});
});
@@ -630,8 +593,6 @@ describe("session management service", () => {
companyId,
agentId,
adapterType: "gemini-cli",
sessionParamsJson: null,
sessionDisplayId: null,
});
db.incrementSessionUsage(session1Id, 100000, 50000, "run-1");
const session1 = db.getSessionById(session1Id)!;
@@ -648,8 +609,6 @@ describe("session management service", () => {
companyId,
agentId,
adapterType: "gemini-cli",
sessionParamsJson: null,
sessionDisplayId: null,
});
const svc = createSessionManagementService({ db, logger: mockLogger });
@@ -668,8 +627,6 @@ describe("session management service", () => {
companyId,
agentId,
adapterType: "gemini-cli",
sessionParamsJson: null,
sessionDisplayId: null,
});
// Pre-populate some usage
-2
View File
@@ -270,7 +270,6 @@ const fakeTask = (id: string, title = "Task"): TaskRecord => ({
priority: "medium",
activeRunId: null,
sessionJson: null,
sessionDisplayId: null,
requiresUserReview: false,
startedAt: null,
completedAt: null,
@@ -292,7 +291,6 @@ const fakeRun = (id: string): RunRecord => ({
exitCode: null,
signal: null,
model: null,
sessionDisplayId: null,
unattributedCost: false,
startedAt: null,
finishedAt: null,