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

@@ -47,7 +47,6 @@ export function finalizeRun(
exitCode: event.exitCode,
signal: event.signal,
model: event.model,
sessionDisplayId: event.sessionDisplayId,
unattributedCost: event.unattributedCost,
inputTokens: event.inputTokens,
outputTokens: event.outputTokens,
@@ -66,21 +65,6 @@ export function finalizeRun(
}
}
// Stamp pi-ai's transient per-turn state (session resume params,
// display id) onto the agent's current session row. Sessions are
// agent-scoped, so the session id comes from agents.session_id —
// not from a task pointer (that indirection was dropped in v41).
try {
const agent = db.getAgent(run.agentId);
if (agent.sessionId) {
db.updateSessionParams(agent.sessionId, event.sessionParams, event.sessionDisplayId ?? null);
}
} catch (error) {
logger.warn(
`[finalizeRun] updateSessionParams failed for run ${event.runId}: ${error instanceof Error ? error.message : String(error)}`,
);
}
leaseRenewalMap.delete(event.runId);
const runOutcome = db.finishRun(event);
if (run.workspaceId) {
-2
View File
@@ -41,7 +41,6 @@ export function handleWorkerExit(
exitCode: code,
signal: null,
model: null,
sessionDisplayId: null,
unattributedCost: true,
});
if (run.workspaceId) {
@@ -128,7 +127,6 @@ export function handleWorkerExit(
exitCode: null,
signal: null,
model: null,
sessionDisplayId: null,
unattributedCost: true,
});
if (candidate.workspaceId) {
-2
View File
@@ -107,8 +107,6 @@ function cancelRun(runId: string) {
exitCode: null,
signal: null,
model: null,
sessionParams: null,
sessionDisplayId: null,
unattributedCost: true,
inputTokens: null,
outputTokens: null,
-3
View File
@@ -16,7 +16,6 @@ export interface RunJob {
model: string | null;
thinkingEffort: string | null;
env: Record<string, string>;
sessionParams: Record<string, unknown> | null;
systemPrompt: string | null;
trigger: string | null;
taskSessionId: string;
@@ -41,8 +40,6 @@ export type ChildMessage =
exitCode: number | null;
signal: string | null;
model: string | null;
sessionParams: Record<string, unknown> | null;
sessionDisplayId: string | null;
unattributedCost: boolean;
inputTokens: number | null;
outputTokens: number | null;
-2
View File
@@ -194,8 +194,6 @@ export class WorkerRunner {
exitCode: null,
signal: null,
model: resolvedModelId,
sessionParams: job.sessionParams,
sessionDisplayId: null,
// Worker no longer owns cost attribution — CostWriter (main-side)
// writes per-message rows, finishRun sums them. This flag stays true
// only for run paths that never had a chance to emit usage (errors
-2
View File
@@ -30,8 +30,6 @@ export const workerMessageSchema = z.union([
exitCode: z.number().int().nullable(),
signal: z.string().nullable(),
model: z.string().nullable(),
sessionParams: z.record(z.string(), z.unknown()).nullable(),
sessionDisplayId: z.string().nullable(),
unattributedCost: z.boolean(),
inputTokens: z.number().nullable(),
outputTokens: z.number().nullable(),