Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

fix: preserve runtime fallbacks and canonical Slack context (#1238)

Joshua France0de0c1906e73
diff --git a/src/model/pi-models.ts b/src/model/pi-models.ts
index ae1e2e8db..c223e440f 100644
--- a/src/model/pi-models.ts
+++ b/src/model/pi-models.ts
@@ -272,9 +272,9 @@ export function setModelOverlays(
overlayVersion += 1;
}
-export function selectableBaseModels(): ReadonlyArray<{ id: string; name: string }> {
+export function selectableBaseModels(includeAliased = false): ReadonlyArray<{ id: string; name: string }> {
return [
- ...gatewayModelCatalog(),
+ ...gatewayModelCatalog(includeAliased),
...SELECTABLE_BASE_MODELS.filter(({ id }) => resolveModel(id)),
...[...overlays.values()].filter((m) => m.base).map(({ id, name }) => ({ id, name })),
];
@@ -472,7 +472,7 @@ export function defaultModelForHarness(
return configured;
const preferred = harness === "codex" ? DEFAULT_CODEX_MODEL_ID : DEFAULT_AGENT_MODEL_ID;
if (!providers || modelServiceable(preferred, providers)) return preferred;
- const servable = selectableBaseModels().find(
+ const servable = selectableBaseModels(true).find(
(model) => modelSupportedByHarness(model.id, harness) && modelServiceable(model.id, providers),
);
return servable?.id ?? preferred;
diff --git a/src/slack/history.ts b/src/slack/history.ts
index 9033a0ff5..426cd15c7 100644
--- a/src/slack/history.ts
+++ b/src/slack/history.ts
@@ -88,9 +88,11 @@ export function createSlackHistoryReader(deps: {
if (threadTs) {
const [parents, replies] = await Promise.all([
read(channel, { at: threadTs, noFallback: true, ...(before ? { before } : {}) }),
- read(channel, { ...options, sub: threadTs, oldestFirst: true }),
+ read(channel, { ...options, sub: threadTs, oldestFirst: deps.source === "shadow" }),
]);
- return [...parents, ...replies].slice(0, 200);
+ return deps.source === "shadow"
+ ? [...parents, ...replies].slice(0, 200)
+ : [...parents, ...replies.slice(-(200 - parents.length))];
}
const roots = await read(channel, { ...options, channelHistory: true });
if (!expandThreads) return roots;
diff --git a/test/gateway-catalog.test.ts b/test/gateway-catalog.test.ts
index 00e5a67d6..d0628c753 100644
--- a/test/gateway-catalog.test.ts
+++ b/test/gateway-catalog.test.ts
@@ -1,3 +1,4 @@
+import { runtimeFallback } from "../src/api/runtime-config.ts";
import { validateWebTurnModelOptions } from "../src/core/turn-options.ts";
import { createMemoryConfigStore } from "../src/resolution/config-store.ts";
import { resolveRuntimeChoice } from "../src/harness/harness-router.ts";
@@ -268,3 +269,22 @@ test("resolvable aliases outside the picker do not hide discovered models", asyn
await f.catalog.refresh();
assert.ok(builtInModelCatalog().some((m) => m.id === "gateway/openai/gpt-4o"));
});
+
+test("gateway-only fallback retains models hidden by picker aliases", async () => {
+ const target = "openai/gpt-5.6-sol";
+ const f = fixture([group(target)], { "gpt-5.6-sol": target });
+ await f.catalog.refresh();
+ assert.ok(!builtInModelCatalog().some((model) => model.id === `gateway/${target}`));
+ const fallback = runtimeFallback({
+ deps: { harnessId: "pi", providerKeys: { anthropic: false, openai: false, openrouter: false } },
+ });
+ assert.equal(fallback.modelId, `gateway/${target}`);
+ assert.ok(
+ modelServiceable(fallback.modelId, {
+ anthropic: false,
+ openai: false,
+ openrouter: false,
+ modelIds: new Set([`gateway/${target}`]),
+ }),
+ );
+});
diff --git a/test/slack-mirror-ingestion.test.ts b/test/slack-mirror-ingestion.test.ts
index 3300dc563..f2d9e0233 100644
--- a/test/slack-mirror-ingestion.test.ts
+++ b/test/slack-mirror-ingestion.test.ts
@@ -567,3 +567,69 @@ test("reaction turns preserve the reacted message in the mirror", async () => {
assert.match(turns[1].text, /\[Slack reaction\].*removed/);
assert.deepEqual(await cache.readMessages("D1", { limit: 10 }), before);
});
+
+test("synthetic reaction turns preserve the canonical message snapshot", async () => {
+ const cache = createMemorySurfaceCache();
+ const directory = {
+ getChannelInfo: async () => ({ id: "D1" }),
+ allInternalRosters: async () => new Map([["D1", []]]),
+ classifyUserCached: async (_client: unknown, id: string) => ({
+ ok: true,
+ actor: { externalId: id, displayName: id },
+ }),
+ };
+ const mirror = createMirror({
+ core: { ingestSurfaceEvents: cache.ingest } as any,
+ ids,
+ directory: directory as any,
+ externalParticipantsEnabled: async () => false,
+ });
+ await mirror.mirrorMessageEvent(
+ {
+ channel: "D1",
+ channel_type: "im",
+ ts: "2",
+ thread_ts: "1",
+ user: "UAUTHOR",
+ text: "original message",
+ files: [{ id: "F1", name: "report.txt" }],
+ },
+ {},
+ { kind: "dm" },
+ );
+ const before = await cache.readMessages("D1", { at: "2" });
+ assert.equal(before[0]?.files?.length, 1);
+ const stop = new Error("serialization boundary reached");
+ const handler = createTurnHandler({
+ core: {},
+ flow: {},
+ directory,
+ mirror,
+ ids,
+ threads: createThreadTracker(),
+ serializer: {
+ serializeSlackConversation: async () => {
+ throw stop;
+ },
+ },
+ externalParticipantsEnabled: async () => false,
+ } as any);
+ await assert.rejects(
+ handler.handleIncoming(
+ {
+ kind: "dm",
+ channel: "D1",
+ userId: "UREACTOR",
+ ts: "2",
+ threadTs: "1",
+ rawText: "Reactor reacted with thumbs up",
+ files: [],
+ unprompted: true,
+ synthetic: true,
+ },
+ {},
+ ),
+ (error: unknown) => error === stop,
+ );
+ assert.deepEqual(await cache.readMessages("D1", { at: "2" }), before);
+});
diff --git a/test/slack-mirror-soak.test.ts b/test/slack-mirror-soak.test.ts
index aca0cb33c..d25849af0 100644
--- a/test/slack-mirror-soak.test.ts
+++ b/test/slack-mirror-soak.test.ts
@@ -239,7 +239,7 @@ test("shadow normalizes mentions without erasing literal entity or attachment di
assert.equal(result.liveMessagesMissingFromStorage, 0);
});
-test("mirror selects channel roots and expands five recent threads with Slack page ordering", async () => {
+test("mirror selects channel roots and retains newest thread replies", async () => {
const { createMemorySurfaceCache } = await import("../src/surface-cache/surface-cache.ts");
const cache = createMemorySurfaceCache();
const ts = (n: number) => String(n).padStart(6, "0");
@@ -259,10 +259,10 @@ test("mirror selects channel roots and expands five recent threads with Slack pa
const thread = await read({}, "C1", ts(204));
assert.equal(thread.raw.length, 200);
assert.equal(thread.raw[0]?.ts, ts(204));
- assert.equal(thread.raw.at(-1)?.ts, ts(498));
+ assert.equal(thread.raw.at(-1)?.ts, ts(549));
const expanded = await read({}, "C1", undefined, undefined, true);
assert.equal(expanded.raw.length, 399);
- assert.equal(expanded.raw.at(-1)?.ts, ts(498));
+ assert.equal(expanded.raw.at(-1)?.ts, ts(549));
});
test("shadow never certifies failed or truncated live thread expansion as complete", async (t) => {