From 5f57f51f34c21b96472bdf5a27bb950aa7990c6c Mon Sep 17 00:00:00 2001 From: Yichen Jiang Date: Fri, 7 Aug 2026 15:55:24 +0800 Subject: [PATCH] refactor(session-query-sqlite): bind the header columns once Both session upserts write the same eight header columns and differ only in what they append; the agent_preset column made the pair long enough for the duplication gate to flag it. --- .../session-query-sqlite/src/index.ts | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/packages/session-query/session-query-sqlite/src/index.ts b/packages/session-query/session-query-sqlite/src/index.ts index 045834f7c0..dc67665f77 100644 --- a/packages/session-query/session-query-sqlite/src/index.ts +++ b/packages/session-query/session-query-sqlite/src/index.ts @@ -556,14 +556,7 @@ export class SessionQuerySqlite extends SessionQueryService { (id, version, created_at, cwd, parent_session, seed_length, delegation_depth, agent_preset, revision, generation) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) `).run( - entry.header.id, - entry.header.version, - entry.header.createdAt, - entry.header.cwd ?? null, - entry.header.parentSession ?? null, - entry.header.seedLength ?? null, - entry.header.delegationDepth ?? null, - entry.header.agentPreset ?? null, + ...headerBindings(entry.header), revision, generation, ) @@ -593,14 +586,7 @@ export class SessionQuerySqlite extends SessionQueryService { (id, version, created_at, cwd, parent_session, seed_length, delegation_depth, agent_preset, fingerprint, persisted, generation) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) `).run( - entry.header.id, - entry.header.version, - entry.header.createdAt, - entry.header.cwd ?? null, - entry.header.parentSession ?? null, - entry.header.seedLength ?? null, - entry.header.delegationDepth ?? null, - entry.header.agentPreset ?? null, + ...headerBindings(entry.header), entry.fingerprint, persisted ? 1 : 0, generation, @@ -753,6 +739,25 @@ export class SessionQuerySqlite extends SessionQueryService { } } +/** + * The header columns both session upserts bind, in the order their INSERT + * lists them. The two statements differ only in what they append after these. + * @param header - the session header being written. + * @returns one bound value per header column. + */ +function headerBindings(header: SessionHeader): (string | number | null)[] { + return [ + header.id, + header.version, + header.createdAt, + header.cwd ?? null, + header.parentSession ?? null, + header.seedLength ?? null, + header.delegationDepth ?? null, + header.agentPreset ?? null, + ] +} + function selectedDocumentsSql(): { sql: string } { return { sql: `WITH candidates AS (