fix(sweep): בחירת הערת-יו"ר אחרונה לפי זמן, לא לפי מיקום-מערך #4

Merged
chaim merged 1 commits from fix/sweep-comment-ordering into main 2026-06-30 11:41:32 +00:00
Owner

הבאג (נתפס חי)

ה-sweep הניח ש-listComments מחזיר oldest-first ולקח comments[length-1] כ"הערה האחרונה". בפועל listComments מחזיר newest-first → ה-sweep ניתב את הערת-היו"ר הישנה ביותר, וללא בדיקה אם סוכן כבר ענה.

נתפס על CMPA-116: ה-sweep ניתב גְּריפה בת-6-ימים ("הסוכן לא הופעל ב-CMPA-89", שכבר נענתה דקות אחרי) במקום את הבקשה האמיתית התלויה של היו"ר ("צרפתי פסקי דין — תחזור להליך חוקר-תקדימים ותבדוק"). לכן ה-CEO עשה no-op בצדק, והבקשה האמיתית נשארה תקועה.

התיקון — order-independent

מחשב את הערת-היו"ר האחרונה ואת הערת-הסוכן האחרונה לפי createdAt, ומנתב רק כשהיו"ר דיבר אחרון בין המשתתפים האמיתיים (newest-user > newest-agent, או אין הערת-סוכן). כך תגובת-סוכן נחשבת "טופל", אבל שורת-system אוטומטית ("טיוטה מוכנה") לא. תוקן גם אותו latent array-order ב-fallback של ה-event handler (reduce-by-createdAt).

Self-heal: הסמן התקוע על CMPA-116 (שהוצמד בטעות להערה הישנה) ייפתר לבד — id הערת-היו"ר-האחרונה שונה.

בדיקות

tsc נקי · biome נקי · נמדד true-backlog = 2 issues (CMPA-116 + CMPA-89, שתי בקשות-יו"ר תקועות אמיתיות).

Refs legal-ai #164.

🤖 Generated with Claude Code

## הבאג (נתפס חי) ה-sweep הניח ש-`listComments` מחזיר oldest-first ולקח `comments[length-1]` כ"הערה האחרונה". בפועל `listComments` מחזיר **newest-first** → ה-sweep ניתב את הערת-היו"ר **הישנה ביותר**, וללא בדיקה אם סוכן כבר ענה. נתפס על **CMPA-116**: ה-sweep ניתב גְּריפה בת-6-ימים ("הסוכן לא הופעל ב-CMPA-89", שכבר נענתה דקות אחרי) במקום את הבקשה האמיתית התלויה של היו"ר ("צרפתי פסקי דין — תחזור להליך חוקר-תקדימים ותבדוק"). לכן ה-CEO עשה no-op בצדק, והבקשה האמיתית נשארה תקועה. ## התיקון — order-independent מחשב את **הערת-היו"ר האחרונה** ואת **הערת-הסוכן האחרונה** לפי `createdAt`, ומנתב רק כשהיו"ר דיבר אחרון בין המשתתפים האמיתיים (newest-user > newest-agent, או אין הערת-סוכן). כך תגובת-סוכן נחשבת "טופל", אבל שורת-**system** אוטומטית ("טיוטה מוכנה") **לא**. תוקן גם אותו latent array-order ב-fallback של ה-event handler (reduce-by-createdAt). **Self-heal:** הסמן התקוע על CMPA-116 (שהוצמד בטעות להערה הישנה) ייפתר לבד — id הערת-היו"ר-האחרונה שונה. ## בדיקות `tsc` נקי · `biome` נקי · נמדד true-backlog = 2 issues (CMPA-116 + CMPA-89, שתי בקשות-יו"ר תקועות אמיתיות). Refs legal-ai #164. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
chaim added 1 commit 2026-06-30 11:41:26 +00:00
The sweep assumed listComments returns oldest-first and took
comments[length-1] as "the last comment". listComments actually returns
newest-first, so the sweep routed the OLDEST user comment instead of the
newest — and routed it whether or not an agent had already answered. Caught
live on CMPA-116: the sweep routed a stale 6-day-old "agent didn't activate"
gripe (already answered minutes later) instead of the chair's real pending
request ("I attached case law — go back to the precedent-researcher and check
the docs"), so the CEO correctly no-op'd and the real request stayed dropped.

Fix: order-independent. Compute the newest USER comment and newest AGENT
comment by createdAt; route only when the chair spoke last among real
participants (newest user > newest agent, or no agent comment), so an agent
reply — but NOT an automated system "draft ready" line — counts as handled.
Also fix the same latent array-order assumption in the event-handler body
fallback (reduce-by-createdAt instead of comments[length-1]).

Self-heals the stuck marker on CMPA-116 (newest-user id differs from the
wrongly-stamped one). Refs legal-ai #164.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
chaim merged commit fc5d8725f1 into main 2026-06-30 11:41:32 +00:00
chaim deleted branch fix/sweep-comment-ordering 2026-06-30 11:41:33 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ezer-mishpati/plugin-legal-ai#4