Skip to content
This repository was archived by the owner on Jun 8, 2026. It is now read-only.

Commit d3aea1e

Browse files
committed
FEA-1548: Review feedback - legacy sync backward compat, omit null identity fields
- Guard loadSyncedSessions against legacy sidecar DBs without identity columns by checking PRAGMA table_info and falling back to NULL aliases - Omit userId/organizationId from sync payload when null to avoid sending null fields to receivers that don't know about them Testing: typecheck and lint pass
1 parent fb13233 commit d3aea1e

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

apps/desktop/src/main/agent-session-sync-service.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,12 @@ export function loadSyncedSessions(
919919
return [];
920920
}
921921

922+
const hasIdentityCols =
923+
columnExists(db, "sessions", "user_id")
924+
&& columnExists(db, "sessions", "organization_id");
925+
const identityColsSql = hasIdentityCols
926+
? "user_id, organization_id"
927+
: "NULL AS user_id, NULL AS organization_id";
922928
const sessionRows = selectRowsByIds<SessionRow>(
923929
db,
924930
`
@@ -935,8 +941,7 @@ export function loadSyncedSessions(
935941
metadata,
936942
harness,
937943
billing_mode,
938-
user_id,
939-
organization_id
944+
${identityColsSql}
940945
FROM sessions
941946
WHERE id IN (__IDS__)
942947
`,
@@ -1044,8 +1049,8 @@ export function loadSyncedSessions(
10441049
awaitingInputSince: row.awaiting_input_since,
10451050
metadata: parseJsonObjectText(row.metadata),
10461051
...(attribution ? { attribution } : {}),
1047-
userId: row.user_id,
1048-
organizationId: row.organization_id,
1052+
...(row.user_id != null ? { userId: row.user_id } : {}),
1053+
...(row.organization_id != null ? { organizationId: row.organization_id } : {}),
10491054
agents: (agentsBySessionId.get(id) ?? []).map((agentRow) => ({
10501055
externalAgentId: agentRow.id,
10511056
name: agentRow.name,
@@ -1111,6 +1116,17 @@ export function resolveBillingModeForRow(row: SessionRow): BillingMode {
11111116
});
11121117
}
11131118

1119+
function columnExists(
1120+
db: DatabaseSync,
1121+
table: string,
1122+
column: string,
1123+
): boolean {
1124+
const rows = db
1125+
.prepare(`PRAGMA table_info(${table})`)
1126+
.all() as Array<{ name: string }>;
1127+
return rows.some((row) => row.name === column);
1128+
}
1129+
11141130
function selectRowsByIds<T>(
11151131
db: DatabaseSync,
11161132
sql: string,

0 commit comments

Comments
 (0)