Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Show the newest suggested-activities run, not the oldest (#1993)

Regan Bell54a74da48d8d
diff --git a/src/suggestions/activities.ts b/src/suggestions/activities.ts
index 50d951d62..bf95b48e7 100644
--- a/src/suggestions/activities.ts
+++ b/src/suggestions/activities.ts
@@ -153,7 +153,7 @@ export function createSuggestedActivityService(deps: {
if (!owned(cron, principalId) || cron.archived) return fallback;
const { runs } = await deps.crons.listFires(cron.id, { limit: 10 });
let pending = runs.some((run) => run.status === "running");
- for (const run of runs) {
+ for (const run of runs.toReversed()) {
if (run.status !== "ok" || !run.sessionId) continue;
const session = await deps.sessions.get(run.sessionId);
if (!session || session.scopeId !== scopeId("personal", principalId) || session.threadRef !== run.threadRef)
diff --git a/test/suggested-activities.test.ts b/test/suggested-activities.test.ts
index b5b4572d0..c54064a69 100644
--- a/test/suggested-activities.test.ts
+++ b/test/suggested-activities.test.ts
@@ -235,6 +235,18 @@ test("old valid results are returned while a newer refresh is running", async ()
assert.deepEqual(await f.service.get("alice", []), { activities, pending: true });
});
+test("the newest valid run wins over older ones", async () => {
+ const f = fixture();
+ await f.service.get("alice", []);
+ await f.settle();
+ const newer = activities.map((activity) => ({ ...activity, title: `${activity.title} today` }));
+ f.output(JSON.stringify(newer));
+ await new Promise((resolve) => setTimeout(resolve, 5));
+ await f.deps.scheduler.runNow((await f.crons.list())[0]!.id);
+ await f.settle();
+ assert.deepEqual(await f.service.get("alice", []), { activities: newer, pending: false });
+});
+
test("fire results cannot point at another personal scope or an unrelated thread", async () => {
for (const foreignScope of [true, false]) {
const f = fixture();