Skip to content

Open-source status page, incident response and uptime monitoring

slack agent: bug on update (#2301)

Thibault Le Ouay29f79d022c8e
diff --git a/apps/server/src/routes/slack/handler.ts b/apps/server/src/routes/slack/handler.ts
index d78434105..a075966c0 100644
--- a/apps/server/src/routes/slack/handler.ts
+++ b/apps/server/src/routes/slack/handler.ts
@@ -330,7 +330,7 @@ async function handleConfirmation(
toolName: draft.toolName,
input: draft.input,
};
- const text = getConfirmationText({ tool, input: draft.input });
+ const text = getConfirmationText({ tool, input: draft.displayInput });
// findByThread + replace isn't atomic on its own — two concurrent
// events on the same thread could both see `existing` and race on
@@ -345,7 +345,7 @@ async function handleConfirmation(
const blocks = buildConfirmationBlocks({
actionId: existing.id,
tool,
- input: draft.input,
+ input: draft.displayInput,
});
await slack.chat.update({ channel, ts: thinkingTs, text, blocks });
await slack.chat.update({
@@ -368,7 +368,7 @@ async function handleConfirmation(
const blocks = buildConfirmationBlocks({
actionId,
tool,
- input: draft.input,
+ input: draft.displayInput,
});
await slack.chat.update({ channel, ts: thinkingTs, text, blocks });
}
diff --git a/apps/server/src/routes/slack/registry-runner.test.ts b/apps/server/src/routes/slack/registry-runner.test.ts
index e55c96097..dd1e74949 100644
--- a/apps/server/src/routes/slack/registry-runner.test.ts
+++ b/apps/server/src/routes/slack/registry-runner.test.ts
@@ -7,6 +7,7 @@ import { z } from "zod";
import {
buildSlackTools,
+ buildTool,
deriveDraftSchema,
executeRegistryAction,
getRegistryTool,
@@ -291,3 +292,52 @@ describe("executeRegistryAction", () => {
expect(output).toEqual({ value: 42 });
});
});
+
+describe("buildTool draft split", () => {
+ function destructiveTool(
+ prepareDraftInput?: NonNullable<
+ AnyAgentTool["approval"]
+ >["prepareDraftInput"],
+ ): AnyAgentTool {
+ return {
+ name: "split_tool",
+ description: "x",
+ scope: "write",
+ destructive: true,
+ inputSchema: z.object({ value: z.number() }),
+ outputSchema: z.object({ ok: z.boolean() }),
+ run: async () => ({ ok: true }),
+ approval: {
+ summarize: () => ({ title: "x", lines: [] }),
+ prepareDraftInput,
+ },
+ };
+ }
+
+ async function runExecute(t: AnyAgentTool) {
+ const built = buildTool(t, fakeCtx);
+ if (!built.execute) throw new Error("expected an execute fn");
+ return built.execute({ value: 7 }, { toolCallId: "t", messages: [] });
+ }
+
+ test("persists raw input but enriches a separate displayInput", async () => {
+ const result = await runExecute(
+ destructiveTool(async ({ input }) => ({
+ ...(input as { value: number }),
+ value: (input as { value: number }).value + 100,
+ })),
+ );
+ if (!isSlackToolDraft(result)) throw new Error("expected a draft");
+ // raw input is what gets persisted + re-run at approval (fresh carry there)
+ expect(result.input).toEqual({ value: 7 });
+ // displayInput is the enriched snapshot shown on the confirmation card
+ expect(result.displayInput).toEqual({ value: 107 });
+ });
+
+ test("displayInput mirrors input when no prepareDraftInput", async () => {
+ const result = await runExecute(destructiveTool());
+ if (!isSlackToolDraft(result)) throw new Error("expected a draft");
+ expect(result.input).toEqual({ value: 7 });
+ expect(result.displayInput).toEqual({ value: 7 });
+ });
+});
diff --git a/apps/server/src/routes/slack/registry-runner.ts b/apps/server/src/routes/slack/registry-runner.ts
index ee294b97f..cf5c64aec 100644
--- a/apps/server/src/routes/slack/registry-runner.ts
+++ b/apps/server/src/routes/slack/registry-runner.ts
@@ -11,11 +11,18 @@ import { ZodObject, type ZodType, type z } from "zod";
* Marker shape returned by destructive tool wrappers. The agent handler
* detects it and posts a Block Kit confirmation card; the user's button
* click then drives `executeRegistryAction` (see interactions.ts).
+ *
+ * `input` is the raw model input — it is persisted and re-runs through the
+ * tool at approval time, so carry-forward enrichment recomputes from fresh
+ * state then. `displayInput` is an enriched snapshot used only to render the
+ * confirmation card; freezing it into `input` would publish stale impacts if
+ * state changed between draft and approval.
*/
export type SlackToolDraft = {
needsConfirmation: true;
toolName: string;
input: unknown;
+ displayInput: unknown;
};
export function isSlackToolDraft(value: unknown): value is SlackToolDraft {
@@ -39,7 +46,7 @@ export function buildSlackTools(ctx: ServiceContext): Record<string, Tool> {
return out;
}
-function buildTool(t: AnyAgentTool, ctx: ServiceContext): Tool {
+export function buildTool(t: AnyAgentTool, ctx: ServiceContext): Tool {
// HITL is gated on `destructive`, not on scope: a non-destructive
// write (none today, but conceivable — e.g. an idempotent reconcile)
// should run inline like reads do.
@@ -63,10 +70,14 @@ function buildTool(t: AnyAgentTool, ctx: ServiceContext): Tool {
inputSchema: draftSchema,
execute: async (input: unknown) => {
const parsed = draftSchema.parse(input);
+ const displayInput = t.approval?.prepareDraftInput
+ ? await t.approval.prepareDraftInput({ ctx, input: parsed })
+ : parsed;
const draft: SlackToolDraft = {
needsConfirmation: true,
toolName: t.name,
input: parsed,
+ displayInput,
};
return draft;
},
diff --git a/packages/services/src/agent-tools/__tests__/status-report-impacts.test.ts b/packages/services/src/agent-tools/__tests__/status-report-impacts.test.ts
index 890a6b980..dd21661cc 100644
--- a/packages/services/src/agent-tools/__tests__/status-report-impacts.test.ts
+++ b/packages/services/src/agent-tools/__tests__/status-report-impacts.test.ts
@@ -9,7 +9,10 @@ import {
withTestTransaction,
} from "../../../test/helpers";
import type { DB, ServiceContext } from "../../context";
-import { getCurrentImpactsForReport } from "../../status-report/internal";
+import {
+ getComponentImpactsForUpdate,
+ getCurrentImpactsForReport,
+} from "../../status-report/internal";
import { agentTools } from "../index";
const TEST_PREFIX = "agent-tools-impacts-test";
@@ -166,3 +169,302 @@ describe("status-report agent tools: componentImpacts round-trip", () => {
expect(result.success).toBe(false);
});
});
+
+describe("add_status_report_update carries prior impacts forward", () => {
+ async function impactsByComponent(tx: DB, updateId: number) {
+ const rows = await getComponentImpactsForUpdate(tx, updateId);
+ return new Map(rows.map((r) => [r.pageComponentId, r.impact]));
+ }
+
+ test("carries prior non-operational impact into the new update's own rows", async () => {
+ await withTestTransaction(async (tx) => {
+ const ctx = { ...teamCtx, db: tx };
+ const { pageId, componentA } = await seedPageWithComponents(
+ tx,
+ ctx.workspace.id,
+ );
+
+ const created = await agentTools.create_status_report.run({
+ ctx,
+ input: agentTools.create_status_report.inputSchema.parse({
+ title: `${TEST_PREFIX}-carry`,
+ status: "investigating",
+ message: "down",
+ pageId,
+ pageComponentIds: [],
+ componentImpacts: [
+ { pageComponentId: componentA, impact: "major_outage" },
+ ],
+ notify: false,
+ }),
+ });
+
+ const update = await agentTools.add_status_report_update.run({
+ ctx,
+ input: agentTools.add_status_report_update.inputSchema.parse({
+ statusReportId: created.statusReport.id,
+ status: "monitoring",
+ message: "watching it",
+ notify: false,
+ }),
+ });
+
+ const rows = await impactsByComponent(tx, update.statusReportUpdateId);
+ expect(rows.get(componentA)).toBe("major_outage");
+ });
+ });
+
+ test("explicit change wins over carry-forward", async () => {
+ await withTestTransaction(async (tx) => {
+ const ctx = { ...teamCtx, db: tx };
+ const { pageId, componentA } = await seedPageWithComponents(
+ tx,
+ ctx.workspace.id,
+ );
+
+ const created = await agentTools.create_status_report.run({
+ ctx,
+ input: agentTools.create_status_report.inputSchema.parse({
+ title: `${TEST_PREFIX}-explicit`,
+ status: "investigating",
+ message: "down",
+ pageId,
+ pageComponentIds: [],
+ componentImpacts: [
+ { pageComponentId: componentA, impact: "major_outage" },
+ ],
+ notify: false,
+ }),
+ });
+
+ const update = await agentTools.add_status_report_update.run({
+ ctx,
+ input: agentTools.add_status_report_update.inputSchema.parse({
+ statusReportId: created.statusReport.id,
+ status: "monitoring",
+ message: "partial recovery",
+ componentImpacts: [
+ { pageComponentId: componentA, impact: "degraded_performance" },
+ ],
+ notify: false,
+ }),
+ });
+
+ const rows = await impactsByComponent(tx, update.statusReportUpdateId);
+ expect(rows.get(componentA)).toBe("degraded_performance");
+ });
+ });
+
+ test("recovery to operational is preserved, not re-inflated", async () => {
+ await withTestTransaction(async (tx) => {
+ const ctx = { ...teamCtx, db: tx };
+ const { pageId, componentA } = await seedPageWithComponents(
+ tx,
+ ctx.workspace.id,
+ );
+
+ const created = await agentTools.create_status_report.run({
+ ctx,
+ input: agentTools.create_status_report.inputSchema.parse({
+ title: `${TEST_PREFIX}-recovery`,
+ status: "investigating",
+ message: "down",
+ pageId,
+ pageComponentIds: [],
+ componentImpacts: [
+ { pageComponentId: componentA, impact: "major_outage" },
+ ],
+ notify: false,
+ }),
+ });
+
+ const update = await agentTools.add_status_report_update.run({
+ ctx,
+ input: agentTools.add_status_report_update.inputSchema.parse({
+ statusReportId: created.statusReport.id,
+ status: "monitoring",
+ message: "back up",
+ componentImpacts: [
+ { pageComponentId: componentA, impact: "operational" },
+ ],
+ notify: false,
+ }),
+ });
+
+ const rows = await impactsByComponent(tx, update.statusReportUpdateId);
+ expect(rows.get(componentA)).toBe("operational");
+ });
+ });
+
+ test("carries an unchanged component while adding a newly named one", async () => {
+ await withTestTransaction(async (tx) => {
+ const ctx = { ...teamCtx, db: tx };
+ const { pageId, componentA, componentB } = await seedPageWithComponents(
+ tx,
+ ctx.workspace.id,
+ );
+
+ const created = await agentTools.create_status_report.run({
+ ctx,
+ input: agentTools.create_status_report.inputSchema.parse({
+ title: `${TEST_PREFIX}-both`,
+ status: "investigating",
+ message: "down",
+ pageId,
+ pageComponentIds: [],
+ componentImpacts: [
+ { pageComponentId: componentA, impact: "major_outage" },
+ ],
+ notify: false,
+ }),
+ });
+
+ const update = await agentTools.add_status_report_update.run({
+ ctx,
+ input: agentTools.add_status_report_update.inputSchema.parse({
+ statusReportId: created.statusReport.id,
+ status: "identified",
+ message: "another component affected",
+ componentImpacts: [
+ { pageComponentId: componentB, impact: "partial_outage" },
+ ],
+ notify: false,
+ }),
+ });
+
+ const rows = await impactsByComponent(tx, update.statusReportUpdateId);
+ expect(rows.get(componentA)).toBe("major_outage");
+ expect(rows.get(componentB)).toBe("partial_outage");
+ });
+ });
+
+ test("prepareDraftInput enriches the confirmation preview with carried impacts", async () => {
+ await withTestTransaction(async (tx) => {
+ const ctx = { ...teamCtx, db: tx };
+ const { pageId, componentA } = await seedPageWithComponents(
+ tx,
+ ctx.workspace.id,
+ );
+
+ const created = await agentTools.create_status_report.run({
+ ctx,
+ input: agentTools.create_status_report.inputSchema.parse({
+ title: `${TEST_PREFIX}-preview`,
+ status: "investigating",
+ message: "down",
+ pageId,
+ pageComponentIds: [],
+ componentImpacts: [
+ { pageComponentId: componentA, impact: "major_outage" },
+ ],
+ notify: false,
+ }),
+ });
+
+ const approval = agentTools.add_status_report_update.approval;
+ if (!approval?.prepareDraftInput) {
+ throw new Error("expected prepareDraftInput to be defined");
+ }
+
+ const prepared = await approval.prepareDraftInput({
+ ctx,
+ input: {
+ statusReportId: created.statusReport.id,
+ status: "monitoring",
+ message: "watching it",
+ notify: false,
+ },
+ });
+
+ const impacts = prepared.componentImpacts ?? [];
+ expect(impacts).toContainEqual({
+ pageComponentId: componentA,
+ impact: "major_outage",
+ });
+
+ const summary = approval.summarize(prepared);
+ expect(
+ summary.lines.some((l) => l.label === "Impacts"),
+ "preview should include an Impacts line",
+ ).toBe(true);
+ });
+ });
+
+ test("status=resolved does not carry impacts forward, so resolve clears them", async () => {
+ await withTestTransaction(async (tx) => {
+ const ctx = { ...teamCtx, db: tx };
+ const { pageId, componentA, componentB } = await seedPageWithComponents(
+ tx,
+ ctx.workspace.id,
+ );
+
+ const created = await agentTools.create_status_report.run({
+ ctx,
+ input: agentTools.create_status_report.inputSchema.parse({
+ title: `${TEST_PREFIX}-resolve-clear`,
+ status: "investigating",
+ message: "down",
+ pageId,
+ pageComponentIds: [],
+ componentImpacts: [
+ { pageComponentId: componentA, impact: "major_outage" },
+ { pageComponentId: componentB, impact: "partial_outage" },
+ ],
+ notify: false,
+ }),
+ });
+
+ await agentTools.add_status_report_update.run({
+ ctx,
+ input: agentTools.add_status_report_update.inputSchema.parse({
+ statusReportId: created.statusReport.id,
+ status: "resolved",
+ message: "all fixed",
+ notify: false,
+ }),
+ });
+
+ const final = await getCurrentImpactsForReport(
+ tx,
+ created.statusReport.id,
+ );
+ expect(final.get(componentA)).toBe("operational");
+ expect(final.get(componentB)).toBe("operational");
+ });
+ });
+
+ test("legacy report (no impacts) stays legacy on follow-up updates", async () => {
+ await withTestTransaction(async (tx) => {
+ const ctx = { ...teamCtx, db: tx };
+ const { pageId } = await seedPageWithComponents(tx, ctx.workspace.id);
+
+ const created = await agentTools.create_status_report.run({
+ ctx,
+ input: agentTools.create_status_report.inputSchema.parse({
+ title: `${TEST_PREFIX}-legacy`,
+ status: "investigating",
+ message: "down",
+ pageId,
+ pageComponentIds: [],
+ notify: false,
+ }),
+ });
+
+ const update = await agentTools.add_status_report_update.run({
+ ctx,
+ input: agentTools.add_status_report_update.inputSchema.parse({
+ statusReportId: created.statusReport.id,
+ status: "monitoring",
+ message: "watching it",
+ notify: false,
+ }),
+ });
+
+ const rows = await getComponentImpactsForUpdate(
+ tx,
+ update.statusReportUpdateId,
+ );
+ expect(rows.length).toBe(0);
+ });
+ });
+});
diff --git a/packages/services/src/agent-tools/status-report.ts b/packages/services/src/agent-tools/status-report.ts
index 0408db279..a5e032f31 100644
--- a/packages/services/src/agent-tools/status-report.ts
+++ b/packages/services/src/agent-tools/status-report.ts
@@ -1,18 +1,61 @@
-import { statusReportStatusSchema } from "@openstatus/db/src/schema";
+import {
+ currentImpactsFromUpdates,
+ statusReportStatusSchema,
+} from "@openstatus/db/src/schema";
import { z } from "zod";
+import type { ServiceContext } from "../context";
import {
addStatusReportUpdate,
+ getStatusReport,
listStatusReports,
notifyStatusReport,
resolveStatusReport,
updateStatusReport,
} from "../status-report";
import { createStatusReport } from "../status-report/create";
-import { componentImpactsSchema } from "../status-report/schemas";
+import {
+ type ComponentImpacts,
+ componentImpactsSchema,
+ type StatusReportStatus,
+} from "../status-report/schemas";
import { formatComponentImpacts } from "../status-report/utils";
import type { AgentTool } from "./types";
+// Agent surfaces send only the impacts that CHANGED (see system prompt). Carry
+// the report's current non-operational impacts into the update so each update's
+// rows are self-contained for the per-update render — and so the confirmation
+// preview shows the full impact, not just the delta.
+async function withCarriedImpacts(
+ ctx: ServiceContext,
+ statusReportId: number,
+ status: StatusReportStatus,
+ componentImpacts: ComponentImpacts | undefined,
+): Promise<ComponentImpacts | undefined> {
+ // resolve clears every still-active component the update doesn't name; carrying
+ // them forward would mark them named and defeat that, so skip carry on resolve.
+ if (status === "resolved") return componentImpacts;
+ const report = await getStatusReport({
+ ctx,
+ input: { id: statusReportId },
+ });
+ const current = currentImpactsFromUpdates(
+ report.updates.map((u) => ({
+ id: u.id,
+ date: u.date,
+ componentImpacts: u.componentImpacts,
+ })),
+ );
+ const merged: ComponentImpacts = [...(componentImpacts ?? [])];
+ const named = new Set(merged.map((ci) => ci.pageComponentId));
+ for (const [pageComponentId, impact] of current) {
+ if (impact !== "operational" && !named.has(pageComponentId)) {
+ merged.push({ pageComponentId, impact });
+ }
+ }
+ return merged.length > 0 ? merged : componentImpacts;
+}
+
const componentImpactsInputShape = componentImpactsSchema
.optional()
.describe(
@@ -315,6 +358,15 @@ export const addStatusReportUpdateTool: AgentTool<
approval: {
extraFlags: [{ id: "notify", label: "Notify subscribers" }],
applyFlags: (input, flags) => ({ ...input, notify: flags.notify ?? false }),
+ prepareDraftInput: async ({ ctx, input }) => ({
+ ...input,
+ componentImpacts: await withCarriedImpacts(
+ ctx,
+ input.statusReportId,
+ input.status,
+ input.componentImpacts,
+ ),
+ }),
summarize: (input) => ({
title: `Add Status Report Update (${input.status})`,
lines: [
@@ -342,7 +394,12 @@ export const addStatusReportUpdateTool: AgentTool<
statusReportId: input.statusReportId,
status: input.status,
message: input.message,
- componentImpacts: input.componentImpacts,
+ componentImpacts: await withCarriedImpacts(
+ ctx,
+ input.statusReportId,
+ input.status,
+ input.componentImpacts,
+ ),
date: input.date ? new Date(input.date) : undefined,
},
});
diff --git a/packages/services/src/agent-tools/types.ts b/packages/services/src/agent-tools/types.ts
index ee463a9a9..d0338200a 100644
--- a/packages/services/src/agent-tools/types.ts
+++ b/packages/services/src/agent-tools/types.ts
@@ -60,6 +60,16 @@ export type ApprovalMeta<TInput> = {
* the flag value merged in — must not mutate the input.
*/
applyFlags?: (input: TInput, flags: Record<string, boolean>) => TInput;
+ /**
+ * Optional async enrichment applied to the draft input before the
+ * confirmation preview renders and the pending action is stored — so the
+ * card reflects what `run` will actually persist (e.g. carried-forward
+ * impacts). Surfaces that build a draft (Slack) call this; must not mutate.
+ */
+ prepareDraftInput?: (args: {
+ ctx: ServiceContext;
+ input: TInput;
+ }) => Promise<TInput>;
/** Surface-rendered confirmation summary. */
summarize: (input: TInput) => { title: string; lines: SummaryLine[] };
/**