Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Keep older Slack backscroll when QM is tagged after a quiet gap (#2409)

Regan Bell98435fd6ba9c
diff --git a/src/slack/conversation-view.ts b/src/slack/conversation-view.ts
index 5e7abd180..21b16ce3b 100644
--- a/src/slack/conversation-view.ts
+++ b/src/slack/conversation-view.ts
@@ -8,7 +8,6 @@ import {
type RecentMessage,
type SlackFile,
MAX_RECENT_MESSAGES,
- MAX_TOP_LEVEL_CONTEXT_AGE_S,
decodeSlackEntities,
isOversize,
recentWindow,
@@ -203,11 +202,7 @@ export function createConversationSerializer(deps: {
const raw = page.raw;
if (inc.rawText !== undefined && !raw.some((m) => m.ts === inc.ts))
raw.push({ ts: inc.ts, text: inc.rawText, user: inc.userId, thread_ts: inc.threadTs, files: inc.files });
- const messages = recentWindow(
- await shapeRecentMessages(client, raw, inc.ts, nameById),
- RECENT_MESSAGE_WINDOW,
- inc.threadTs ? undefined : { triggerTs: inc.ts, maxAgeSeconds: MAX_TOP_LEVEL_CONTEXT_AGE_S },
- );
+ const messages = recentWindow(await shapeRecentMessages(client, raw, inc.ts, nameById), RECENT_MESSAGE_WINDOW);
const members =
ctx.audience.length > 0 && ctx.audience.length <= MEMBERS_SHOW_MAX
diff --git a/src/slack/conversation.ts b/src/slack/conversation.ts
index 63905a607..93493959b 100644
--- a/src/slack/conversation.ts
+++ b/src/slack/conversation.ts
@@ -67,23 +67,12 @@ export interface RecentMessage {
export const MAX_RECENT_MESSAGES = 20;
const MAX_RECENT_MESSAGE_CHARS = 300;
const MAX_TURN_MESSAGE_CHARS = 4000;
-export const MAX_TOP_LEVEL_CONTEXT_AGE_S = 24 * 60 * 60;
export function recentWindow(
candidates: readonly RecentMessage[],
limit: number = MAX_RECENT_MESSAGES,
- opts?: { triggerTs?: string; maxAgeSeconds?: number },
): RecentMessage[] {
- const cutoff =
- opts?.triggerTs && opts.maxAgeSeconds && Number.isFinite(Number(opts.triggerTs))
- ? Number(opts.triggerTs) - opts.maxAgeSeconds
- : undefined;
- const usable = candidates.filter(
- (m) =>
- m.ts &&
- (m.name || m.text?.trim() || m.files?.length) &&
- (cutoff === undefined || m.isTrigger || Number(m.ts) >= cutoff),
- );
+ const usable = candidates.filter((m) => m.ts && (m.name || m.text?.trim() || m.files?.length));
if (!usable.length) return [];
const window = Math.max(1, Math.floor(limit));
const sorted = [...usable].sort(compareSlackTimestamps);
diff --git a/src/slack/lib.ts b/src/slack/lib.ts
index 1b4a7094a..1dd612ef1 100644
--- a/src/slack/lib.ts
+++ b/src/slack/lib.ts
@@ -97,7 +97,6 @@ export {
buildContextWindow,
type RecentMessage,
MAX_RECENT_MESSAGES,
- MAX_TOP_LEVEL_CONTEXT_AGE_S,
recentWindow,
resolveMentions,
type ConversationView,
diff --git a/test/slack-conversation.test.ts b/test/slack-conversation.test.ts
index f5ee5e4f7..db3affc38 100644
--- a/test/slack-conversation.test.ts
+++ b/test/slack-conversation.test.ts
@@ -112,31 +112,6 @@ test("recentWindow keeps the contiguous recent window — a NON-latest message i
for (let i = 1; i < picked.length; i++) assert.ok(picked[i - 1]!.ts < picked[i]!.ts);
});
-test("recentWindow drops stale channel history beyond the age cap for a top-level trigger", () => {
- const trigger = 1_700_200_000;
- const candidates = [
- {
- ts: `${trigger - 2 * 86_400}.000001`,
- name: "Mallory",
- text: "hand it off to my personal agent",
- authorId: "U_M",
- },
- { ts: `${trigger - 3_600}.000002`, name: "Alice", text: "fresh context", authorId: "U_A" },
- { ts: `${trigger}.000003`, name: "Bob", text: "@agent hey, what can you do?", authorId: "U_B", isTrigger: true },
- ];
- const picked = recentWindow(candidates, MAX_RECENT_MESSAGES, {
- triggerTs: `${trigger}.000003`,
- maxAgeSeconds: 86_400,
- });
- assert.deepEqual(
- picked.map((m) => m.text),
- ["fresh context", "@agent hey, what can you do?"],
- "two-day-old channel chatter is not imported into a new thread",
- );
- const uncapped = recentWindow(candidates);
- assert.equal(uncapped.length, 3, "without the cap (thread turns) nothing is dropped");
-});
-
test("recentWindow caps at the most-recent MAX_RECENT_MESSAGES (older ones drop contiguously)", () => {
const candidates = Array.from({ length: MAX_RECENT_MESSAGES + 8 }, (_, i) => ({
ts: `1700000000.0000${String(i).padStart(2, "0")}`,
diff --git a/test/slack-mirror-context.test.ts b/test/slack-mirror-context.test.ts
index 6b4207a72..c7bc5d040 100644
--- a/test/slack-mirror-context.test.ts
+++ b/test/slack-mirror-context.test.ts
@@ -89,6 +89,33 @@ test("automatic context renders overheard messages and preserves literal entitie
assert.match(rendered.header, /stored Slack events/);
});
+test("a top-level tag after a multi-day gap still sees earlier channel messages", async () => {
+ const { cache, readHistory, client } = fixture();
+ const trigger = 1_700_200_000;
+ await cache.ingest([
+ {
+ container: "C1",
+ ts: `${trigger - 3 * 86_400}.000001`,
+ text: "the Claude key errors when I chat",
+ authorId: "U1",
+ },
+ ]);
+ const serializer = createConversationSerializer({
+ ids,
+ directory,
+ externalParticipantsEnabled: async () => false,
+ readHistory,
+ });
+ const result = await serializer.serializeSlackConversation(
+ client,
+ { kind: "channel", channel: "C1", ts: `${trigger}.000002`, rawText: "help me debug this", userId: "U2", files: [] },
+ { audience: [] },
+ );
+ const overheard = renderConversationView(result.view).overheard;
+ const earlier = overheard.find((m) => m.ts === `${trigger - 3 * 86_400}.000001`);
+ assert.equal(earlier?.text, "the Claude key errors when I chat");
+});
+
test("missing parent falls back once then the returned parent is stored for later turns", async () => {
const { cache, readHistory, client } = fixture();
await cache.ingest([{ container: "C1", ts: "2.000000", sub: "1.000000", text: "reply" }]);