Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/web/src/session-logic.ts
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Critical

Issue on line in apps/web/src/session-logic.ts:367:

The sort comparator uses ?? to fall back to id comparison, but localeCompare returns 0 when strings are equal — not null or undefined. The expression 0 ?? left.id.localeCompare(right.id) evaluates to 0 instead of the ID comparison, breaking the tie-breaker and producing non-deterministic ordering when multiple plans share the same updatedAt. Consider restoring || so 0 triggers the secondary sort key.

🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file apps/web/src/session-logic.ts around line 367:

The sort comparator uses `??` to fall back to `id` comparison, but `localeCompare` returns `0` when strings are equal — not `null` or `undefined`. The expression `0 ?? left.id.localeCompare(right.id)` evaluates to `0` instead of the ID comparison, breaking the tie-breaker and producing non-deterministic ordering when multiple plans share the same `updatedAt`. Consider restoring `||` so `0` triggers the secondary sort key.

Evidence trail:
apps/web/src/session-logic.ts lines 375-377 and 391-393 (at REVIEWED_COMMIT) show the sort comparator using `??` operator: `left.updatedAt.localeCompare(right.updatedAt) ?? left.id.localeCompare(right.id)`. JavaScript specification confirms `??` only falls back on null/undefined, and `localeCompare` returns 0 for equal strings (not null/undefined).

Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ export function findLatestProposedPlan(
.filter((proposedPlan) => proposedPlan.turnId === latestTurnId)
.toSorted(
(left, right) =>
left.updatedAt.localeCompare(right.updatedAt) || left.id.localeCompare(right.id),
left.updatedAt.localeCompare(right.updatedAt) ?? left.id.localeCompare(right.id),
)
.at(-1);
if (matchingTurnPlan) {
Expand All @@ -390,7 +390,7 @@ export function findLatestProposedPlan(
const latestPlan = [...proposedPlans]
.toSorted(
(left, right) =>
left.updatedAt.localeCompare(right.updatedAt) || left.id.localeCompare(right.id),
left.updatedAt.localeCompare(right.updatedAt) ?? left.id.localeCompare(right.id),
)
.at(-1);
if (!latestPlan) {
Expand Down
Loading