Skip to content

Commit fe400dc

Browse files
Merge remote-tracking branch 'origin/main' into pr-123575-prep
2 parents 5182444 + f870d93 commit fe400dc

3 files changed

Lines changed: 63 additions & 0 deletions

File tree

‎.github/workflows/vitest-cache-warm.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,9 @@ jobs:
5858
EOF
5959
6060
- name: Warm transform and compile caches
61+
env:
62+
# Match the CI shard lanes running the same envelopes: without the
63+
# raised ceiling a heavy suite's worker can die under default heap
64+
# (run 31874567859), skipping every cache save for the day.
65+
NODE_OPTIONS: --max-old-space-size=8192
6166
run: node --import tsx scripts/ci-run-node-test-shard.mts

‎ui/src/lib/sessions/reconcile.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,33 @@ test("sessions.changed removes a label when the event carries null", () => {
8989
expect(reconciled.result?.sessions[0]?.displayName).toBeUndefined();
9090
});
9191

92+
test("reconciling the same sessions.changed twice keeps result identity on the second pass", () => {
93+
const result: SessionsListResult = {
94+
ts: 1,
95+
path: "",
96+
count: 1,
97+
defaults: { modelProvider: null, model: null, contextTokens: null },
98+
sessions: [{ key: "agent:main:main", kind: "direct", updatedAt: 1 }],
99+
};
100+
const payload = {
101+
sessionKey: "agent:main:main",
102+
reason: "patch",
103+
updatedAt: 2,
104+
label: "Renamed",
105+
};
106+
107+
const first = reconcileSessionChanged(result, payload);
108+
expect(first.applied).toBe(true);
109+
expect(first.result).not.toBe(result);
110+
expect(first.result?.sessions[0]?.label).toBe("Renamed");
111+
112+
// The capability handler and the chat page both drive the same event; the
113+
// second reconcile must return the identical result object so downstream
114+
// result === state.result publish gates skip the duplicate re-render.
115+
const second = reconcileSessionChanged(first.result ?? null, payload);
116+
expect(second.result).toBe(first.result);
117+
});
118+
92119
test("sessions.changed deletes every null-tombstoned field, not a hand-kept list", () => {
93120
// The gateway tombstones more fields than the old per-field cascade knew
94121
// about; these five leaked literal null into rows typed optional-not-null.

‎ui/src/lib/sessions/reconcile.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,27 @@ function stripThinkingMetadata<T extends ThinkingMetadataCarrier>(value: T): T {
195195
return next;
196196
}
197197

198+
/** Same-content merge detection; row values are wire scalars/plain objects, so one level suffices. */
199+
function isShallowEqualSessionRow(
200+
incoming: GatewaySessionRow,
201+
existing: GatewaySessionRow,
202+
): boolean {
203+
const incomingKeys = Object.keys(incoming);
204+
if (incomingKeys.length !== Object.keys(existing).length) {
205+
return false;
206+
}
207+
return incomingKeys.every((key) => {
208+
const a = (incoming as Record<string, unknown>)[key];
209+
const b = (existing as Record<string, unknown>)[key];
210+
return (
211+
a === b ||
212+
(a !== null && b !== null && typeof a === "object" && typeof b === "object"
213+
? JSON.stringify(a) === JSON.stringify(b)
214+
: false)
215+
);
216+
});
217+
}
218+
198219
function isOlderSessionSnapshot(
199220
incoming: GatewaySessionRow,
200221
existing: GatewaySessionRow | undefined,
@@ -551,6 +572,16 @@ export function reconcileSessionHistory(
551572
// result === state.result publish gate can skip a spurious re-render.
552573
return defaults ? { ...result, defaults: nextDefaults } : result;
553574
}
575+
if (
576+
existing &&
577+
isShallowEqualSessionRow(visibleSession, existing) &&
578+
sessionMatchesArchivedFilter(visibleSession, archivedFilter)
579+
) {
580+
// The same event reconciled twice (capability handler + chat page) must
581+
// no-op the second pass; a fresh array here defeats every downstream
582+
// result === state.result publish gate and re-renders per event.
583+
return defaults ? { ...result, defaults: nextDefaults } : result;
584+
}
554585
const sessions = sessionMatchesArchivedFilter(visibleSession, archivedFilter)
555586
? [
556587
...result.sessions.filter((candidate) => candidate.key !== visibleKey),

0 commit comments

Comments
 (0)