Files
loki/scripts/test/same-request.ts
CatoandClaude bc9ecfcc53 fix(actions): one ask books one appointment (#1217)
Seen on the live site: "dentist on Monday at 9am" became two calendar
bookings. The message miner queued "Dentist Appointment" while the
model's propose_action, in parallel, queued "Dentist appointment"; the
pending-title index is case-sensitive and only covers drafts, and the
standing "put appointments in my calendar" rule approved both.

enqueueAction now treats an operator's ask as the same request when an
action of the same type, with overlapping title words, the same day and
(for messages) the same body, was proposed in the last ten minutes. The
second producer gets the first action back: the chat still shows its
card, and the model is told it is already being carried out.


Claude-Session: https://claude.ai/code/session_01CG9dupSVqoXCCqKfBCfd9B

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-15 05:53:30 -07:00

62 lines
2.0 KiB
TypeScript

/**
* One ask, one action. Case from the live site (2026-10-15): "dentist on
* Monday at 9am" was queued as "Dentist Appointment" by the message miner and
* "Dentist appointment" by the model's propose_action — and the standing
* calendar rule booked both.
*/
import { isSameRequest } from "@/lib/actions/same-request";
let passed = 0;
function check(label: string, cond: boolean): void {
if (!cond) throw new Error(`✗ ${label}`);
passed++;
console.log(` ✓ ${label}`);
}
const ev = (title: string, payload: Record<string, unknown> = {}) => ({
type: "create_event",
title,
payload,
});
check(
"case alone does not make a second booking",
isSameRequest(ev("Dentist Appointment"), ev("Dentist appointment")),
);
check(
"a shorter title inside a longer one is the same ask",
isSameRequest(ev("Dentist"), ev("Dentist appointment")),
);
check(
"same day, different time format",
isSameRequest(
ev("Dentist", { eventStart: "2026-10-19T09:00:00+02:00" }),
ev("Dentist appointment", { eventDate: "2026-10-19" }),
),
);
check(
"a different day is a different appointment",
!isSameRequest(
ev("Dentist", { eventStart: "2026-10-19T09:00:00+02:00" }),
ev("Dentist", { eventStart: "2026-10-26T09:00:00+01:00" }),
),
);
check("different things are different", !isSameRequest(ev("Dentist appointment"), ev("Team sync")));
check(
"an event and a commitment are different kinds",
!isSameRequest(ev("Dentist"), { type: "create_commitment", title: "Dentist" }),
);
check("an empty title never matches", !isSameRequest(ev(""), ev("Dentist")));
check(
"filler words do not count",
isSameRequest(ev("Dentist appointment on Monday"), ev("the dentist appointment Monday")),
);
const msg = (body: string) => ({ type: "send_message", title: "Message Anna", payload: { body } });
check("the same message twice is one", isSameRequest(msg("Running late"), msg("running late")));
check(
"two different messages to Anna are two",
!isSameRequest(msg("Running late"), msg("Dinner at 8?")),
);
console.log(`\nsame-request: ${passed} passed`);