Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(desktop): mobile show sandbox memory kills in the task thread (#109045)

Tom Owers6b977857371a
diff --git a/products/desktop/apps/mobile/src/features/tasks/components/TaskSessionView.test.tsx b/products/desktop/apps/mobile/src/features/tasks/components/TaskSessionView.test.tsx
index 6da45f409728..e56292083921 100644
--- a/products/desktop/apps/mobile/src/features/tasks/components/TaskSessionView.test.tsx
+++ b/products/desktop/apps/mobile/src/features/tasks/components/TaskSessionView.test.tsx
@@ -12,6 +12,7 @@ vi.mock("phosphor-react-native", () => ({
CloudArrowDown: (props: Record<string, unknown>) =>
createElement("CloudArrowDown", props),
Robot: (props: Record<string, unknown>) => createElement("Robot", props),
+ Warning: (props: Record<string, unknown>) => createElement("Warning", props),
}));
vi.mock("@/features/chat", () => ({
@@ -32,7 +33,7 @@ vi.mock("@/lib/theme", () => ({
useThemeColors: () => ({
gray: { 8: "#888", 9: "#777", 11: "#555" },
accent: { 9: "#f60" },
- status: { error: "#d00" },
+ status: { error: "#d00", warning: "#d97706" },
}),
}));
@@ -146,6 +147,58 @@ describe("TaskSessionView", () => {
expect(humans[0].props.content).toBe("Ship it");
});
+ it.each([
+ {
+ name: "full-params kill → warning row",
+ params: {
+ pid: 4242,
+ comm: "vitest",
+ treeRssBytes: 13.46 * 1024 ** 3,
+ memoryCurrentBytes: 15 * 1024 ** 3,
+ memoryLimitBytes: 16 * 1024 ** 3,
+ signal: "SIGTERM",
+ at: "2026-01-01T00:00:00.000Z",
+ },
+ expectedContent:
+ "The sandbox stopped vitest because it was using 13.5 GiB of the 16.0 GiB available. The agent is still running.",
+ },
+ {
+ name: "missing sizes → nothing",
+ params: { comm: "vitest" },
+ expectedContent: null,
+ },
+ ])("process_killed acp_message: $name", ({ params, expectedContent }) => {
+ const renderer = renderTaskSessionView({
+ events: [
+ {
+ type: "acp_message" as const,
+ direction: "agent" as const,
+ ts: 2,
+ message: {
+ jsonrpc: "2.0",
+ method: "_posthog/process_killed",
+ params,
+ },
+ },
+ ],
+ });
+
+ const warnings = renderer.root.findAll(
+ (node) => (node.type as unknown as string) === "Warning",
+ );
+
+ if (expectedContent === null) {
+ expect(warnings).toHaveLength(0);
+ return;
+ }
+
+ expect(warnings).toHaveLength(1);
+ const matches = renderer.root.findAll(
+ (node) => node.props?.children === expectedContent,
+ );
+ expect(matches.length).toBeGreaterThan(0);
+ });
+
it("keeps question tools pending after the run goes idle", () => {
const events = [
{
diff --git a/products/desktop/apps/mobile/src/features/tasks/components/TaskSessionView.tsx b/products/desktop/apps/mobile/src/features/tasks/components/TaskSessionView.tsx
index 646eb5ff70a4..5e95d8ef5a87 100644
--- a/products/desktop/apps/mobile/src/features/tasks/components/TaskSessionView.tsx
+++ b/products/desktop/apps/mobile/src/features/tasks/components/TaskSessionView.tsx
@@ -1,3 +1,5 @@
+import { POSTHOG_NOTIFICATIONS } from "@posthog/core/sessions/acpNotifications";
+import { formatProcessKilledNotice } from "@posthog/core/sessions/processKilledNotice";
import { pickThinkingActivity } from "@posthog/core/sessions/thinkingActivities";
import {
ArrowDown,
@@ -5,6 +7,7 @@ import {
CaretRight,
CloudArrowDown,
Robot,
+ Warning,
} from "phosphor-react-native";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import {
@@ -92,7 +95,14 @@ interface ToolData {
interface ParsedMessage {
id: string;
- type: "user" | "agent" | "thought" | "tool" | "connecting" | "thinking";
+ type:
+ | "user"
+ | "agent"
+ | "thought"
+ | "tool"
+ | "connecting"
+ | "thinking"
+ | "process_killed";
content: string;
ts?: number;
toolData?: ToolData;
@@ -276,6 +286,7 @@ interface EventProcessorState {
agentMessageCount: number;
thoughtMessageCount: number;
userMessageCount: number;
+ processKilledCount: number;
toolMessages: Map<string, ParsedMessage>;
// Maps agent toolCallId → agent ParsedMessage for nesting children
agentTools: Map<string, ParsedMessage>;
@@ -297,6 +308,7 @@ function createProcessorState(): EventProcessorState {
agentMessageCount: 0,
thoughtMessageCount: 0,
userMessageCount: 0,
+ processKilledCount: 0,
toolMessages: new Map(),
agentTools: new Map(),
processedIdx: 0,
@@ -370,6 +382,25 @@ function processNewEvents(
for (let i = state.processedIdx; i < events.length; i++) {
const event = events[i];
+
+ if (event.type === "acp_message") {
+ const msg = event.message as { method?: string; params?: unknown };
+ if (msg.method === POSTHOG_NOTIFICATIONS.PROCESS_KILLED) {
+ const notice = formatProcessKilledNotice(msg.params);
+ if (notice) {
+ flushPending();
+ state.messages.push({
+ id: `process-killed-${state.processKilledCount++}`,
+ type: "process_killed",
+ content: notice,
+ ts: event.ts,
+ });
+ state.lastAgentMsgIdx = null;
+ }
+ }
+ continue;
+ }
+
if (event.type !== "session_update") continue;
const parsed = parseSessionNotification(event.notification);
@@ -542,6 +573,18 @@ function CollapsedThought({ content }: { content: string }) {
);
}
+function ProcessKilledNotice({ message }: { message: string }) {
+ const themeColors = useThemeColors();
+ return (
+ <View className="flex-row items-start gap-2 px-4 py-1">
+ <Warning size={14} color={themeColors.status.warning} />
+ <Text className="flex-1 text-[13px] text-gray-11 leading-4">
+ {message}
+ </Text>
+ </View>
+ );
+}
+
// Detect objects like {"0":"E","1":"r","2":"r",...,"isError":true} — a string
// serialized as char-per-key (possibly with extra metadata keys mixed in).
function tryReassembleString(obj: Record<string, unknown>): string | null {
@@ -977,6 +1020,8 @@ export function TaskSessionView({
);
case "thought":
return <CollapsedThought content={item.content} />;
+ case "process_killed":
+ return <ProcessKilledNotice message={item.content} />;
case "tool":
if (!item.toolData) return null;
if (
diff --git a/products/desktop/packages/core/src/sessions/acpNotifications.ts b/products/desktop/packages/core/src/sessions/acpNotifications.ts
index 4a9bbcb6b5f9..5083d6b236b2 100644
--- a/products/desktop/packages/core/src/sessions/acpNotifications.ts
+++ b/products/desktop/packages/core/src/sessions/acpNotifications.ts
@@ -22,6 +22,7 @@ export const POSTHOG_NOTIFICATIONS = {
PERMISSION_RESPONSE: "_posthog/permission_response",
PERMISSION_REQUEST: "_posthog/permission_request",
PERMISSION_RESOLVED: "_posthog/permission_resolved",
+ PROCESS_KILLED: "_posthog/process_killed",
} as const;
// Qualified id of the agent's `speak` narration tool, as it appears on the
diff --git a/products/desktop/packages/core/src/sessions/processKilledNotice.test.ts b/products/desktop/packages/core/src/sessions/processKilledNotice.test.ts
new file mode 100644
index 000000000000..1e96a0b5310d
--- /dev/null
+++ b/products/desktop/packages/core/src/sessions/processKilledNotice.test.ts
@@ -0,0 +1,52 @@
+import { describe, expect, it } from "vitest";
+import { formatProcessKilledNotice } from "./processKilledNotice";
+
+describe("formatProcessKilledNotice", () => {
+ it.each([
+ {
+ name: "full params → rendered notice",
+ params: {
+ pid: 4242,
+ comm: "vitest",
+ treeRssBytes: 13.46 * 1024 ** 3,
+ memoryCurrentBytes: 15 * 1024 ** 3,
+ memoryLimitBytes: 16 * 1024 ** 3,
+ signal: "SIGTERM",
+ at: "2026-01-01T00:00:00.000Z",
+ },
+ expected:
+ "The sandbox stopped vitest because it was using 13.5 GiB of the 16.0 GiB available. The agent is still running.",
+ },
+ {
+ name: "missing sizes → null",
+ params: { comm: "vitest" },
+ expected: null,
+ },
+ {
+ name: "empty comm → null",
+ params: { comm: "", treeRssBytes: 1, memoryLimitBytes: 2 },
+ expected: null,
+ },
+ {
+ name: "non-finite treeRssBytes → null",
+ params: {
+ comm: "vitest",
+ treeRssBytes: Number.POSITIVE_INFINITY,
+ memoryLimitBytes: 16 * 1024 ** 3,
+ },
+ expected: null,
+ },
+ {
+ name: "non-finite memoryLimitBytes → null",
+ params: {
+ comm: "vitest",
+ treeRssBytes: 1 * 1024 ** 3,
+ memoryLimitBytes: Number.NaN,
+ },
+ expected: null,
+ },
+ { name: "undefined params → null", params: undefined, expected: null },
+ ])("$name", ({ params, expected }) => {
+ expect(formatProcessKilledNotice(params)).toBe(expected);
+ });
+});
diff --git a/products/desktop/packages/core/src/sessions/processKilledNotice.ts b/products/desktop/packages/core/src/sessions/processKilledNotice.ts
new file mode 100644
index 000000000000..9b79a44d65be
--- /dev/null
+++ b/products/desktop/packages/core/src/sessions/processKilledNotice.ts
@@ -0,0 +1,32 @@
+export interface ProcessKilledParams {
+ pid: number;
+ comm: string;
+ treeRssBytes: number;
+ memoryCurrentBytes: number;
+ memoryLimitBytes: number;
+ signal: string;
+ at: string;
+}
+
+const BYTES_PER_GIB = 1024 ** 3;
+
+function formatGib(bytes: number): string {
+ return `${(bytes / BYTES_PER_GIB).toFixed(1)} GiB`;
+}
+
+export function formatProcessKilledNotice(params: unknown): string | null {
+ const { comm, treeRssBytes, memoryLimitBytes } = (params ?? {}) as Partial<
+ Record<keyof ProcessKilledParams, unknown>
+ >;
+ if (
+ typeof comm !== "string" ||
+ !comm ||
+ typeof treeRssBytes !== "number" ||
+ !Number.isFinite(treeRssBytes) ||
+ typeof memoryLimitBytes !== "number" ||
+ !Number.isFinite(memoryLimitBytes)
+ ) {
+ return null;
+ }
+ return `The sandbox stopped ${comm} because it was using ${formatGib(treeRssBytes)} of the ${formatGib(memoryLimitBytes)} available. The agent is still running.`;
+}