Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Silence poll fires only through finish_silently, not sentinel reply text (#2450)

Regan Bell8c43def8af8e
diff --git a/src/core/orchestrator.ts b/src/core/orchestrator.ts
index 9b395b025..c76efcbc0 100644
--- a/src/core/orchestrator.ts
+++ b/src/core/orchestrator.ts
@@ -56,7 +56,7 @@ import { acquireLeaseWithin, isOverheardEntry } from "../sessions/session-store.
import { supportsProcessSessions, supportsScopeProfile } from "../sandbox/sandbox.ts";
import { createBackgroundBroker } from "../connectors/background-exec-broker.ts";
import { createMonitorBroker, readBackgroundOutputTail } from "../monitors/monitor-broker.ts";
-import { isPollSurface, isSilentPollReply } from "../triggers/run-trigger.ts";
+import { isPollSurface } from "../triggers/run-trigger.ts";
import { envKey } from "../credentials/connector-token.ts";
import {
credentialHandle,
@@ -3751,8 +3751,7 @@ export function createOrchestrator(deps: OrchestratorDeps): Orchestrator {
// directly instead of nudging it to re-post (a nudge here re-sends near-identical
// text, which surfaces that render assistant entries show twice).
const primaryReply = stripAckPrefix(result.reply ?? "", spineAckText).trim();
- const silentPollNarration = isPollFire && isSilentPollReply(primaryReply);
- if (primaryReply && !silentPollNarration && defaultDestination && deps.deliveries) {
+ if (primaryReply && defaultDestination && deps.deliveries) {
try {
const directKey = postKeys.key(defaultDestination, postKeys.take());
await reachEnqueue({
@@ -3768,7 +3767,7 @@ export function createOrchestrator(deps: OrchestratorDeps): Orchestrator {
reportFailure("orchestrator: direct reply delivery", e, `session=${session.id}`);
}
}
- if (spine.surfaceOutboundCount === 0 && !silentPollNarration) {
+ if (spine.surfaceOutboundCount === 0 && (!isPollFire || primaryReply)) {
const nudgeHistory = filterHistory(forModelContext((await historyWindow()).entries));
result = await runHarnessTurn(
"[system] You were addressed directly. Reply with the `slack` tool's `post` action, or decline explicitly with finish_silently — ending the turn without either is not allowed here.",
@@ -4025,7 +4024,7 @@ export function createOrchestrator(deps: OrchestratorDeps): Orchestrator {
...(sourceAssistantEntrySeq !== undefined ? { sourceAssistantEntrySeq } : {}),
}
: { status: "pending_approval", sessionId: session.id, pendingApprovals: approvals };
- } else if (isPollFire && !stagedAttachments.length && isSilentPollReply(reply)) {
+ } else if (isPollFire && !stagedAttachments.length && !reply.trim()) {
finalResult = { status: "silent", sessionId: session.id };
} else if (input.surfaceTools && surfaceToolDeps && !strictReadOnly) {
finalResult = { status: "silent", sessionId: session.id, ...(result.stopped ? { stopped: true } : {}) };
diff --git a/src/harness/mock-harness.ts b/src/harness/mock-harness.ts
index 6bb128a07..37d2320ec 100644
--- a/src/harness/mock-harness.ts
+++ b/src/harness/mock-harness.ts
@@ -324,19 +324,6 @@ export function createMockHarness(): Harness {
usedTool = true;
silent = turn.pollFire === true;
reply = turn.pollFire ? "" : preamble;
- } else if (command0.startsWith("!narrate-no-update")) {
- const narration =
- cmd.slice(cmd.indexOf("!narrate-no-update") + "!narrate-no-update".length).trim() || "Nothing new.";
- if (turn.onDelta) for (const chunk of streamChunks(narration)) turn.onDelta(chunk);
- await turn.emit({ type: "text", payload: { text: narration }, scopeLabel: turn.scopeLabel });
- await turn.emit({
- type: "tool_call",
- payload: { tool: "execute", command: "check" },
- scopeLabel: turn.scopeLabel,
- });
- await turn.emit({ type: "tool_result", payload: { tool: "execute", ok: true }, scopeLabel: turn.scopeLabel });
- usedTool = true;
- reply = `${narration}\n\n[no-update]`;
} else if (command0.startsWith("!phased-reply")) {
await turn.onTextBlockStart?.("commentary");
turn.onDelta?.("Checking.");
diff --git a/src/triggers/run-trigger.ts b/src/triggers/run-trigger.ts
index 3a1f989ae..0030b2d5f 100644
--- a/src/triggers/run-trigger.ts
+++ b/src/triggers/run-trigger.ts
@@ -77,22 +77,9 @@ function isTriggerFailure(outcome: TriggerOutcome): boolean {
return outcome.ran && outcome.status !== undefined && outcome.status !== "ok" && outcome.status !== "silent";
}
-const NO_UPDATE_SENTINEL = "[no-update]";
-const SILENT_POLL_MARKERS = new Set([NO_UPDATE_SENTINEL, "no_reply", "[silent]"]);
-
const POLL_SURFACES = new Set(["cron", "webhook", "monitor"]);
export const isPollSurface = (surface: string): boolean => POLL_SURFACES.has(surface);
-export function isSilentPollReply(reply: string): boolean {
- const finalLine = reply
- .trimEnd()
- .split(/\r?\n/)
- .findLast((line) => line.trim() !== "")
- ?.trim()
- .toLowerCase();
- return finalLine === undefined || SILENT_POLL_MARKERS.has(finalLine);
-}
-
function deliveryProvenance(spec: TriggerSpec, threadRef: string, res?: TurnResult): DeliveryProvenance {
return {
trigger: spec.surface,
diff --git a/test/admin-observability.test.ts b/test/admin-observability.test.ts
index 917815b01..c5d4fe884 100644
--- a/test/admin-observability.test.ts
+++ b/test/admin-observability.test.ts
@@ -295,7 +295,7 @@ test("recipient delivery rows expose origin provenance and gated origin context"
const delivery = await s.built.deliveries.enqueue({
destination: { type: "principal", target: "U-erica", audienceScopeId: "personal:U-erica", onBehalfOf: "U-alice" },
- text: "The script ran clean and posted the digest DM.\n\n[no-update]",
+ text: "The script ran clean and posted the digest DM.",
attachments: [
{
name: "digest.gif",
@@ -333,7 +333,7 @@ test("recipient delivery rows expose origin provenance and gated origin context"
assert.equal(orgBody.deliveryEvents.length, 1, "recipient transcript renders delivered output inline");
const event = orgBody.deliveryEvents[0];
assert.equal(event.type, "principal_delivery");
- assert.equal(event.text, "The script ran clean and posted the digest DM.\n\n[no-update]");
+ assert.equal(event.text, "The script ran clean and posted the digest DM.");
assert.equal(event.provenance.fireKey, "cron:c1:42");
assert.equal(event.provenance.sourceSessionId, source.id);
assert.equal(event.sourceSession.id, source.id);
@@ -363,7 +363,7 @@ test("recipient delivery rows expose origin provenance and gated origin context"
const sourceBody = (await sourceRead.json()) as any;
assert.equal(sourceBody.deliveryEvents.length, 1, "source transcript renders the outbound Slack delivery");
assert.equal(sourceBody.deliveryEvents[0].type, "outbound_delivery");
- assert.equal(sourceBody.deliveryEvents[0].text, "The script ran clean and posted the digest DM.\n\n[no-update]");
+ assert.equal(sourceBody.deliveryEvents[0].text, "The script ran clean and posted the digest DM.");
assert.equal(sourceBody.deliveryEvents[0].recipientThreadRef, "dm:D-erica");
assert.deepEqual(sourceBody.deliveryEvents[0].attachments, [
{
diff --git a/test/cron-scheduler.test.ts b/test/cron-scheduler.test.ts
index e48ccc34b..0b14b915c 100644
--- a/test/cron-scheduler.test.ts
+++ b/test/cron-scheduler.test.ts
@@ -9,7 +9,6 @@ import { createIdentityService } from "../src/identity/identity-service.ts";
import { createMemorySessionStore } from "../src/sessions/memory-session-store.ts";
import type { LeaderLease } from "../src/persistence/leader-lease.ts";
import { scopeId, type TurnRequest, type TurnResult } from "../src/types.ts";
-import { isPollSurface, isSilentPollReply } from "../src/triggers/run-trigger.ts";
import { createDirectoryStore, type DirectoryStore } from "../src/directory/directory-store.ts";
import { createMemoryMap } from "../src/persistence/durable-map.ts";
import type { Cron } from "../src/types.ts";
@@ -36,9 +35,6 @@ function harness(
const run = async (req: TurnRequest): Promise<TurnResult> => {
calls.push(req);
if (typeof reply === "function") return reply(req);
- if (req.triggered && req.surface && isPollSurface(req.surface) && isSilentPollReply(reply)) {
- return { status: "silent" };
- }
return { status: "ok", reply };
};
const scheduler = createScheduler({
@@ -133,49 +129,6 @@ test("a group-DM cron composed at another scope delivers verbatim (person-keyed
assert.equal((await deliveries.pending("group"))[0]?.text, "CRON-OUTPUT-XYZ");
});
-test("a poll cron whose turn replies [no-update] runs but delivers nothing", async () => {
- const { crons, deliveries, calls, scheduler } = harness(" [no-update]\n");
- const cron = await crons.create({
- schedule: { everyMs: 1000 },
- action: "check the status page; reply [no-update] if unchanged",
- owner: "U1",
- createdBy: "U1",
- ownerScopeId: scopeId("personal", "U1"),
- destination: { type: "slack", target: "D1", audienceScopeId: scopeId("personal", "U1") },
- });
- await runNowSettled(scheduler, cron.id);
- assert.equal(calls.length, 1);
- assert.equal((await deliveries.pending("slack")).length, 0);
-});
-
-test("a poll cron stays silent on an empty reply or a bare silence token", async (t) => {
- const cases = [
- ["empty reply — the natural nothing-to-report", ""],
- ["whitespace-only reply", " \n\n "],
- ["summary then canonical marker", "No unread mail in the last hour.\n\n[no-update]"],
- ["upper no reply marker", "Nothing changed.\nNO_REPLY"],
- ["lower no reply marker", "Nothing changed.\nno_reply"],
- ["silent marker", "All quiet.\n[SILENT]\n\n"],
- ["case-insensitive canonical marker", "No changes.\n[NO-UPDATE]"],
- ] as const;
- for (const [name, reply] of cases) {
- await t.test(name, async () => {
- const { crons, deliveries, calls, scheduler } = harness(reply);
- const cron = await crons.create({
- schedule: { everyMs: 1000 },
- action: "check the mailbox; output [no-update] if unchanged",
- owner: "U1",
- createdBy: "U1",
- ownerScopeId: scopeId("personal", "U1"),
- destination: { type: "slack", target: "D1", audienceScopeId: scopeId("personal", "U1") },
- });
- await runNowSettled(scheduler, cron.id);
- assert.equal(calls.length, 1);
- assert.equal((await deliveries.pending("slack")).length, 0);
- });
- }
-});
-
test("a channel cron fire gives the agent the people-here roster with real <@…> mention ids", async () => {
const directory = createDirectoryStore();
await directory.replace([
@@ -221,20 +174,6 @@ test("a DM cron fire carries no mention roster (DMs already notify their owner)"
assert.doesNotMatch(calls[0]?.text ?? "", /People here:/);
});
-test("a poll cron delivers when a silent marker is not the final non-empty line", async () => {
- const { crons, deliveries, scheduler } = harness("[no-update]\nFound one failed check");
- const cron = await crons.create({
- schedule: { everyMs: 1000 },
- action: "check the status page",
- owner: "U1",
- createdBy: "U1",
- ownerScopeId: scopeId("personal", "U1"),
- destination: { type: "slack", target: "D1", audienceScopeId: scopeId("personal", "U1") },
- });
- await runNowSettled(scheduler, cron.id);
- assert.equal((await deliveries.pending("slack"))[0]?.text, "[no-update]\nFound one failed check");
-});
-
test("a personal cron runs as a DM and delivers to the owner", async () => {
const { crons, deliveries, calls, scheduler } = harness();
const cron = await crons.create({
diff --git a/test/dm-relay.test.ts b/test/dm-relay.test.ts
index 80599b766..47d3a4046 100644
--- a/test/dm-relay.test.ts
+++ b/test/dm-relay.test.ts
@@ -118,12 +118,16 @@ describe("agent → teammate DM: the cron recipient route (§10)", () => {
it("accepts task/text aliases so user-facing cron creation doesn't expose internal modes", async () => {
const taskRes = await post(
"/v1/crons",
- { schedule: { cron: "* * * * *" }, task: "check mail; reply [no-update] if nothing changed", recipient: "Alice" },
+ {
+ schedule: { cron: "* * * * *" },
+ task: "check mail; call finish_silently if nothing changed",
+ recipient: "Alice",
+ },
{ "x-agent-capability": await capDm("U-carol") },
);
assert.equal(taskRes.status, 200);
const taskBody = (await taskRes.json()) as any;
- assert.equal(taskBody.cron.action, "check mail; reply [no-update] if nothing changed");
+ assert.equal(taskBody.cron.action, "check mail; call finish_silently if nothing changed");
assert.equal(taskBody.cron.message, undefined);
const textRes = await post(
diff --git a/test/keychain-ask.test.ts b/test/keychain-ask.test.ts
index 00449cf96..1e3a4500b 100644
--- a/test/keychain-ask.test.ts
+++ b/test/keychain-ask.test.ts
@@ -401,7 +401,7 @@ test("runTrigger: silent markers never silence a notification-shaped fire (keych
deliveries,
idempotency: createIdempotencyStore(createMemoryMap<IdempotencyRecord>()),
identity: createIdentityService(createMemoryMap()),
- run: async () => ({ status: "ok", reply: "The keychain ask was approved.\n\n[SILENT]" }) as TurnResult,
+ run: async () => ({ status: "ok", reply: "The keychain ask was approved." }) as TurnResult,
},
{
owner: "U_ALICE",
diff --git a/test/orchestrator.test.ts b/test/orchestrator.test.ts
index 1c44a455d..6559ab417 100644
--- a/test/orchestrator.test.ts
+++ b/test/orchestrator.test.ts
@@ -282,7 +282,7 @@ test("a silent cron source run stays out of normal human chat history", async ()
const built = freshApp();
const cron = await built.app.createCron({
schedule: { firstFireAt: Date.now() },
- action: "!run printf 'Posted the digest DM\\n\\n[no-update]\\n'",
+ action: "!preamble-then-quiet Posted the digest DM",
owner: "U1",
createdBy: "U1",
ownerScopeId: scopeId("personal", "U1"),
@@ -291,7 +291,7 @@ test("a silent cron source run stays out of normal human chat history", async ()
await runNowSettled(built.scheduler, cron.id);
- assert.equal((await built.deliveries.pending("principal")).length, 0, "final silent marker means no delivery");
+ assert.equal((await built.deliveries.pending("principal")).length, 0, "finish_silently means no delivery");
const source = (await built.sessions.scanAll()).find((s) => s.threadRef.startsWith(`cron:${cron.id}:fire:`));
assert.ok(source, "cron source run is still durably recorded (in its per-fire background thread)");
const sourceEntries = await built.sessions.getEntries(source!.id);
@@ -1966,16 +1966,25 @@ test("a poll fire that ends with no message resolves to silent, not a delivered
assert.ok(res.sessionId, "the turn still ran — it's silent, not skipped");
});
-test("a poll fire whose final line is a bare silence token resolves to silent", async () => {
+test("a poll fire whose reply is a bracketed token is an ordinary reply; only finish_silently silences it", async () => {
const { app } = freshApp();
const res = await app.turn({
surface: "cron",
actor: internalActor,
conversation: { kind: "dm", threadRef: "dm:U1:cron2" },
- text: "!run printf %s '[no-update]'",
+ text: "!run printf %s 'Nothing changed.\n\n[no-update]'",
triggered: true,
});
- assert.equal(res.status, "silent");
+ assert.equal(res.status, "ok");
+ assert.equal(res.reply, "Nothing changed.\n\n[no-update]");
+ const silenced = await app.turn({
+ surface: "cron",
+ actor: internalActor,
+ conversation: { kind: "dm", threadRef: "dm:U1:cron2b" },
+ text: "!finish-silent",
+ triggered: true,
+ });
+ assert.equal(silenced.status, "silent");
});
test("a poll fire with a real reply still delivers (status ok), and a non-triggered empty reply is not silenced", async () => {
diff --git a/test/poll-fire-silence.test.ts b/test/poll-fire-silence.test.ts
index e05a04c64..23b517f1a 100644
--- a/test/poll-fire-silence.test.ts
+++ b/test/poll-fire-silence.test.ts
@@ -58,20 +58,16 @@ test("poll fire: narration before a tool call is NOT auto-posted as an ack when
}
});
-test("poll fire: a closing reply whose final line is a silence marker is not direct-delivered", async () => {
+test("poll fire: a closing reply ending in a bracketed token is delivered, since only finish_silently silences", async () => {
const built = freshApp();
built.runtime.start();
try {
- const res = await built.app.turn(
- monitorFire("!narrate-no-update Still queued behind the newer deploy.", "C-watch2", "801.1", "monitor:m1:f2"),
- );
- assert.equal(res.status, "silent", "a marker-terminated poll reply resolves to silent");
+ const res = await built.app.turn(monitorFire("Still queued.\n\n[no-update]", "C-watch2", "801.1", "monitor:m1:f2"));
+ assert.equal(res.status, "silent", "surfaceTools turn: delivery happens via the surface, result is silent");
await sleep(300);
- assert.deepEqual(
- (await slackDeliveries(built.deliveries)).map((d) => d.text),
- [],
- "the narration + [no-update] reply must not be posted to Slack",
- );
+ const texts = (await slackDeliveries(built.deliveries)).map((d) => d.text);
+ assert.equal(texts.length, 1, JSON.stringify(texts));
+ assert.match(texts[0]!, /You said: Still queued\.\n\n\[no-update\]/);
} finally {
await built.runtime.stop();
}