Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

eval: cover attachment ownership across chat handoffs

louis335513fa3dd4
diff --git a/evals/coding-agent/README.md b/evals/coding-agent/README.md
index 98695f711..1658c0aa1 100644
--- a/evals/coding-agent/README.md
+++ b/evals/coding-agent/README.md
@@ -931,3 +931,7 @@ Run `bun test evals/coding-agent/calibrate-account-standing.test.js` for the
known-broken/correct, unused fix, permissive admission, blanket refusal, equivalent
private field and missing-source controls. Dependency setup errors are separate
from intended behavior failures. Use the shared runner's `--verify` for the case.
+
+### Attachment owner handoff
+
+`app-attachment-owner-handoff` exercises the actual attachment hook and in-memory chat store across delayed file reads, pane unmount, foreground navigation, pointer-scoped drops, cancellation and read failure. Hidden/deleted owners stay absent and ordinary multiple-file attachment survives. Native file/dialog/extraction and locale ports are synthetic; this does not establish native delivery, disk persistence or full composer integration. Run `bun test evals/coding-agent/calibrate-attachment-owner.test.js` with the desktop test dependencies available. Historical verification and mutation calibration are not model trials or an isolation claim.
diff --git a/evals/coding-agent/calibrate-attachment-owner.test.js b/evals/coding-agent/calibrate-attachment-owner.test.js
new file mode 100644
index 000000000..330169bd6
--- /dev/null
+++ b/evals/coding-agent/calibrate-attachment-owner.test.js
@@ -0,0 +1,38 @@
+// screenpipe — AI that knows everything you've seen, said, or heard
+// https://screenpipe.com
+import {afterAll, expect, test} from 'bun:test';
+import {execFileSync, spawnSync} from 'node:child_process';
+import {mkdirSync,mkdtempSync,readFileSync,rmSync,symlinkSync,writeFileSync} from 'node:fs';
+import {dirname,join,resolve} from 'node:path';
+import {tmpdir} from 'node:os';
+const repo=resolve(import.meta.dir,'../..');
+const item=JSON.parse(readFileSync(join(import.meta.dir,'cases.json'))).cases.find(c=>c.id==='app-attachment-owner-handoff');
+const root=mkdtempSync(join(tmpdir(),'attachment-owner-calibration-'));
+afterAll(()=>rmSync(root,{recursive:true,force:true}));
+function grade(name){
+ const cwd=join(root,name),desktop=join(cwd,'apps/screenpipe-app-tauri');mkdirSync(cwd);
+ const ref=['parent','unused'].includes(name)?item.base_ref:item.oracle_ref;
+ execFileSync('tar',['-x','-C',cwd],{input:execFileSync('git',['archive',ref,'apps/screenpipe-app-tauri/components','apps/screenpipe-app-tauri/lib','apps/screenpipe-app-tauri/package.json','apps/screenpipe-app-tauri/tsconfig.json'],{cwd:repo,maxBuffer:32*1024*1024})});
+ const hook=join(desktop,'components/chat/standalone/hooks/use-chat-attachments.ts');
+ const replace=(before,after)=>{const text=readFileSync(hook,'utf8');expect(text.split(before)).toHaveLength(2);writeFileSync(hook,text.replace(before,after));};
+ if(name==='unused')writeFileSync(hook+'.unused.ts',execFileSync('git',['show',`${item.oracle_ref}:apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-chat-attachments.ts`],{cwd:repo}));
+ if(name==='unscoped')replace('if (scopeDrops && "position" in event.payload)', 'if (false && "position" in event.payload)');
+ if(name==='wrong-owner')replace('updateSessionDraftField<K, T>(owner, key, update)','updateSessionDraftField<K, T>(sessionIdRef?.current ?? owner, key, update)');
+ if(name==='blanket')replace('const handleFilePicker = useCallback(async () => {','const handleFilePicker = useCallback(async () => { return;');
+ if(name==='equivalent'){const text=readFileSync(hook,'utf8');expect(text).toContain('captureAttachmentWriters');writeFileSync(hook,text.replaceAll('captureAttachmentWriters','captureOriginalDraftSetters'));}
+ if(name==='missing')rmSync(hook);
+ for(const fixture of item.grader.fixtures){const dest=join(cwd,fixture.destination_path);mkdirSync(dirname(dest),{recursive:true});writeFileSync(dest,readFileSync(join(import.meta.dir,fixture.local_path)));}
+ symlinkSync(join(repo,'apps/screenpipe-app-tauri/node_modules'),join(desktop,'node_modules'),'dir');
+ const result=spawnSync(process.execPath,['x','--no-install','vitest','run','--config','eval-attachment-owner.config.mjs'],{cwd:desktop,encoding:'utf8',timeout:60000,env:{PATH:process.env.PATH,HOME:cwd,CI:'true',NO_COLOR:'1'}});
+ if(process.env.EVAL_CALIBRATION_RESULTS){const out=resolve(process.env.EVAL_CALIBRATION_RESULTS);mkdirSync(out,{recursive:true});for(const ext of ['stdout','stderr'])writeFileSync(join(out,name+'.'+ext),result[ext]||'');writeFileSync(join(out,name+'.json'),JSON.stringify({status:result.status,signal:result.signal,error:result.error?.message||null})+'\n');}
+ return result;
+}
+function fails(r){expect(r.error).toBeUndefined();expect(r.signal).toBeNull();expect(r.status).toBe(1);expect(r.stderr).toContain('AssertionError');expect(r.stderr).not.toContain('Failed to resolve import');}
+test('parent has three intended failures with five preserved outcomes',()=>{const r=grade('parent');fails(r);expect(r.stdout).toContain('3 failed');expect(r.stdout).toContain('5 passed');});
+test('reference passes eight outcomes',()=>{const r=grade('reference');expect(r.status).toBe(0);expect(r.stdout).toContain('8 passed');});
+test('unused correct code does not fix the hook',()=>fails(grade('unused')));
+test('window-wide drop bypass fails pane ownership',()=>fails(grade('unscoped')));
+test('late current-chat write fails original ownership',()=>fails(grade('wrong-owner')));
+test('blanket picker suppression loses valid attachments',()=>fails(grade('blanket')));
+test('equivalent private helper name passes',()=>expect(grade('equivalent').status).toBe(0));
+test('missing hook is a setup failure, not baseline behavior',()=>{const r=grade('missing');expect(r.status).not.toBe(0);expect(r.stderr).toContain('Failed to resolve import');expect(r.stderr).not.toContain('AssertionError');});
diff --git a/evals/coding-agent/cases.json b/evals/coding-agent/cases.json
index bbf0f1c16..c1a2e2d61 100644
--- a/evals/coding-agent/cases.json
+++ b/evals/coding-agent/cases.json
@@ -1,7 +1,7 @@
{
"schema_version": 1,
"suite": "screenpipe-app-coding-agent-regressions",
- "dataset_version": "2026-09-25.3",
+ "dataset_version": "2026-09-25.4",
"suite_type": "regression",
"owner": "screenpipe engineering",
"policy": {
@@ -3341,6 +3341,53 @@
],
"command": "cd packages/ai-gateway && \"${BUN_BIN:-bun}\" test src/test/eval-standing-http.test.ts"
}
+ },
+ {
+ "id": "app-attachment-owner-handoff",
+ "name": "Keep asynchronous file attachments with their initiating chat",
+ "source": {
+ "kind": "git_regression",
+ "fix_commit": "f1bcd5bbbb9d838e471cb73e3ec0e88316ef89e7"
+ },
+ "base_ref": "1f35d982415a6ebb5509dcbd8243772cd8a128b9",
+ "oracle_ref": "f1bcd5bbbb9d838e471cb73e3ec0e88316ef89e7",
+ "tags": [
+ "regression",
+ "escaped-failure",
+ "chat",
+ "attachments",
+ "ownership"
+ ],
+ "prompt": "File attachments can disappear or reach the wrong chat when file reads finish after a pane closes or the foreground chat changes. Fix the attachment hook so a secondary pane file completion remains in its initiating session draft after unmount. A pending foreground read must complete in its original chat, clear its pending entry, and leave the newly selected chat and its local attachment list untouched. Window-level drops must reach only the pane under their pointer, using physical coordinates and device pixel ratio; keep every file in a multiple-file foreground drop. Cancelled pickers must perform no file read or draft creation. Failed reads must clear pending work without adding an attachment or disturbing another draft. Late completion must not recreate a deleted or hidden chat draft. Keep ordinary successful attachment handling working. Checks exercise the actual hook and in-memory chat store with synthetic native dialog/file/document-extraction and locale ports. Native webview delivery, disk persistence, and rendered composer integration are outside this task. Add or update focused tests as needed.",
+ "agent_timeout_seconds": 900,
+ "grader": {
+ "timeout_seconds": 60,
+ "fixtures": [
+ {
+ "local_path": "graders/attachment-owner.fixture.tsx.txt",
+ "destination_path": "apps/screenpipe-app-tauri/components/chat/standalone/hooks/eval-attachment-owner.test.tsx"
+ },
+ {
+ "local_path": "graders/attachment-owner.config.mjs",
+ "destination_path": "apps/screenpipe-app-tauri/eval-attachment-owner.config.mjs"
+ },
+ {
+ "local_path": "graders/attachment-owner-locale.ts.txt",
+ "destination_path": "apps/screenpipe-app-tauri/eval-attachment-locale.ts"
+ }
+ ],
+ "command": "cd apps/screenpipe-app-tauri && bun x --no-install vitest run --config eval-attachment-owner.config.mjs"
+ },
+ "oracle_paths": [
+ "apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-chat-attachments.ts",
+ "apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-session-draft-field.ts"
+ ],
+ "grader_dependency_links": [
+ {
+ "source_path": "apps/screenpipe-app-tauri/node_modules",
+ "destination_path": "apps/screenpipe-app-tauri/node_modules"
+ }
+ ]
}
]
}
diff --git a/evals/coding-agent/graders/attachment-owner-locale.ts.txt b/evals/coding-agent/graders/attachment-owner-locale.ts.txt
new file mode 100644
index 000000000..06ffca612
--- /dev/null
+++ b/evals/coding-agent/graders/attachment-owner-locale.ts.txt
@@ -0,0 +1,3 @@
+// screenpipe — AI that knows everything you've seen, said, or heard
+// https://screenpipe.com
+export const useGT = () => (text: string) => text;
diff --git a/evals/coding-agent/graders/attachment-owner.config.mjs b/evals/coding-agent/graders/attachment-owner.config.mjs
new file mode 100644
index 000000000..8600e7c6f
--- /dev/null
+++ b/evals/coding-agent/graders/attachment-owner.config.mjs
@@ -0,0 +1,5 @@
+// screenpipe — AI that knows everything you've seen, said, or heard
+// https://screenpipe.com
+import {defineConfig} from 'vitest/config';
+import path from 'node:path';
+export default defineConfig({esbuild:{jsx:'automatic'},test:{environment:'jsdom',include:['components/chat/standalone/hooks/eval-attachment-owner.test.tsx'],pool:'forks',poolOptions:{forks:{singleFork:true}}},resolve:{alias:{'@':path.resolve('.'),'gt-react':path.resolve('eval-attachment-locale.ts')}},css:{postcss:{plugins:[]}}});
diff --git a/evals/coding-agent/graders/attachment-owner.fixture.tsx.txt b/evals/coding-agent/graders/attachment-owner.fixture.tsx.txt
new file mode 100644
index 000000000..fe8c56433
--- /dev/null
+++ b/evals/coding-agent/graders/attachment-owner.fixture.tsx.txt
@@ -0,0 +1,216 @@
+// screenpipe — AI that knows everything you've seen, said, or heard
+// https://screenpipe.com
+import {afterEach} from 'vitest';
+import {cleanup} from '@testing-library/react';
+vi.mock('@/lib/i18n/provider',()=>({useUiLocale:()=> 'en'}));
+vi.mock('@/components/ui/use-toast',()=>({toast:vi.fn()}));
+afterEach(()=>cleanup());
+import { act, renderHook } from "@testing-library/react";
+import { beforeEach, expect, it, vi } from "vitest";
+import { useChatAttachments } from "./use-chat-attachments";
+import { useChatStore, type SessionRecord } from "@/lib/stores/chat-store";
+const mock = vi.hoisted(() => ({
+ open: vi.fn(),
+ read: vi.fn(),
+ listeners: [] as ((event: any) => void)[],
+}));
+vi.mock("@tauri-apps/plugin-dialog", () => ({ open: mock.open }));
+vi.mock("@tauri-apps/plugin-fs", () => ({ readFile: mock.read }));
+vi.mock("@tauri-apps/api/webview", () => ({
+ getCurrentWebview: () => ({
+ onDragDropEvent: (fn: (event: any) => void) => {
+ mock.listeners.push(fn);
+ return Promise.resolve(() => {});
+ },
+ }),
+}));
+vi.mock("@/lib/pi/extract-document", () => ({
+ DOC_PICKER_EXTENSIONS: ["txt"],
+ extFromName: () => "txt",
+ isSupportedDocExt: () => true,
+ extractDocument: async (name: string) => ({
+ name,
+ text: "notes",
+ charCount: 5,
+ truncated: false,
+ ext: "txt",
+ }),
+}));
+const session = (id: string): SessionRecord => ({
+ id,
+ title: id,
+ status: "idle",
+ preview: "",
+ messageCount: 0,
+ createdAt: 1,
+ updatedAt: 1,
+ pinned: false,
+ unread: false,
+});
+function options(id: string, x = 0) {
+ const root = document.createElement("div");
+ Object.defineProperty(root, "offsetParent", { value: document.body });
+ root.getBoundingClientRect = () =>
+ ({ left: x, right: x + 100, top: 0, bottom: 100 }) as DOMRect;
+ return {
+ draftSessionId: id,
+ isEmbedded: true,
+ scopeDrops: true,
+ dropRootRef: { current: root },
+ inputRef: { current: document.createElement("textarea") },
+ setInput: vi.fn(),
+ setShowMentionDropdown: vi.fn(),
+ setMentionFilter: vi.fn(),
+ };
+}
+beforeEach(() => {
+ Object.defineProperty(window, "devicePixelRatio", {configurable:true, value:2});
+ mock.open.mockReset();
+ mock.read.mockReset();
+ mock.listeners.length = 0;
+ mock.read.mockResolvedValue(new Uint8Array([1]));
+ useChatStore.setState({
+ sessions: { a: session("a"), b: session("b") },
+ currentId: "a",
+ });
+});
+it("attaches a picked file to the secondary draft even when its read finishes after unmount", async () => {
+ let resolve!: (bytes: Uint8Array) => void;
+ mock.read.mockReturnValue(
+ new Promise<Uint8Array>((r) => {
+ resolve = r;
+ }),
+ );
+ mock.open.mockResolvedValue(["/notes.txt"]);
+ const { result, unmount } = renderHook(() =>
+ useChatAttachments(options("b")),
+ );
+ let picking!: Promise<void>;
+ await act(async () => {
+ picking = result.current.handleFilePicker();
+ });
+ expect(result.current.pendingDocs).toHaveLength(1);
+ unmount();
+ await act(async () => {
+ resolve(new Uint8Array([1]));
+ await picking;
+ });
+ expect(
+ useChatStore.getState().sessions.b.composerDraft?.attachedDocs,
+ ).toEqual([expect.objectContaining({ name: "notes.txt" })]);
+ expect(
+ useChatStore.getState().sessions.b.composerDraft?.pendingDocs,
+ ).toHaveLength(0);
+ expect(useChatStore.getState().sessions.a.composerDraft).toBeUndefined();
+});
+it("routes a window-level file drop to only the pane under the pointer", async () => {
+ const a = options("a", 0),
+ b = options("b", 100);
+ renderHook(() => useChatAttachments(a));
+ renderHook(() => useChatAttachments(b));
+ await act(async () => {
+ for (const listener of mock.listeners)
+ listener({
+ payload: {
+ type: "drop",
+ position: {
+ x: 150 * window.devicePixelRatio,
+ y: 50 * window.devicePixelRatio,
+ },
+ paths: ["/notes.txt"],
+ },
+ });
+ });
+ expect(mock.read).toHaveBeenCalledTimes(1);
+ expect(
+ useChatStore.getState().sessions.b.composerDraft?.attachedDocs,
+ ).toHaveLength(1);
+ expect(useChatStore.getState().sessions.a.composerDraft).toBeUndefined();
+});
+it("keeps a main-pane file with its original chat when the foreground changes", async () => {
+ let resolve!: (bytes: Uint8Array) => void;
+ mock.read.mockReturnValue(
+ new Promise<Uint8Array>((r) => {
+ resolve = r;
+ }),
+ );
+ mock.open.mockResolvedValue(["/notes.txt"]);
+ const sessionIdRef = { current: "a" as string | null };
+ const opts = { ...options("a"), draftSessionId: undefined, sessionIdRef };
+ const { result } = renderHook(() => useChatAttachments(opts));
+ let picking!: Promise<void>;
+ await act(async () => {
+ picking = result.current.handleFilePicker();
+ });
+ expect(result.current.pendingDocs).toHaveLength(1);
+ act(() => {
+ sessionIdRef.current = "b";
+ result.current.setAttachedDocs([]);
+ result.current.setPendingDocs([]);
+ });
+ await act(async () => {
+ resolve(new Uint8Array([1]));
+ await picking;
+ });
+ expect(
+ useChatStore.getState().sessions.a.composerDraft?.attachedDocs,
+ ).toHaveLength(1);
+ expect(
+ useChatStore.getState().sessions.a.composerDraft?.pendingDocs,
+ ).toHaveLength(0);
+ expect(useChatStore.getState().sessions.b.composerDraft).toBeUndefined();
+ expect(result.current.attachedDocs).toHaveLength(0);
+});
+
+it("keeps every file when several are dropped into the foreground in one event", async () => {
+ const opts = {
+ ...options("a"),
+ draftSessionId: undefined,
+ sessionIdRef: { current: "a" },
+ };
+ const { result } = renderHook(() => useChatAttachments(opts));
+ await act(async () => {
+ for (const listener of mock.listeners)
+ listener({
+ payload: {
+ type: "drop",
+ position: {
+ x: 50 * window.devicePixelRatio,
+ y: 50 * window.devicePixelRatio,
+ },
+ paths: ["/one.txt", "/two.txt"],
+ },
+ });
+ });
+ expect(result.current.attachedDocs.map((doc) => doc.name)).toEqual([
+ "one.txt",
+ "two.txt",
+ ]);
+ expect(result.current.pendingDocs).toHaveLength(0);
+});
+
+it('preserves a cancelled picker without reading files or creating drafts', async () => {
+ mock.open.mockResolvedValue(null);
+ const {result}=renderHook(()=>useChatAttachments(options('b')));
+ await act(async()=>{await result.current.handleFilePicker()});
+ expect(mock.read).not.toHaveBeenCalled();
+ expect(result.current.pendingDocs).toEqual([]);
+ expect(useChatStore.getState().sessions.a.composerDraft).toBeUndefined();
+ expect(useChatStore.getState().sessions.b.composerDraft).toBeUndefined();
+});
+it('clears pending work on file read failure and preserves unrelated drafts', async () => {
+ useChatStore.getState().actions.setComposerDraft('a',{input:'keep this',pastedImages:[],attachedDocs:[],pendingDocs:[]});
+ mock.open.mockResolvedValue(['/failed.txt']);mock.read.mockRejectedValue(new Error('synthetic unavailable'));
+ const {result}=renderHook(()=>useChatAttachments(options('b')));
+ await act(async()=>{await result.current.handleFilePicker()});
+ expect(result.current.pendingDocs).toEqual([]);expect(result.current.attachedDocs).toEqual([]);
+ expect(useChatStore.getState().sessions.a.composerDraft?.input).toBe('keep this');
+});
+it.each(['hidden','deleted'])('late file completion does not resurrect a %s owner', async (state) => {
+ let finish!:(bytes:Uint8Array)=>void;mock.read.mockReturnValue(new Promise<Uint8Array>(r=>{finish=r}));mock.open.mockResolvedValue(['/late.txt']);
+ const {result}=renderHook(()=>useChatAttachments(options('b')));let picking!:Promise<void>;
+ await act(async()=>{picking=result.current.handleFilePicker()});
+ act(()=>{if(state==='hidden')useChatStore.setState({sessions:{a:session('a'),b:{...session('b'),hidden:true}}});else useChatStore.setState({sessions:{a:session('a')}})});
+ await act(async()=>{finish(new Uint8Array([1]));await picking});
+ expect(useChatStore.getState().sessions.b?.composerDraft).toBeUndefined();expect(useChatStore.getState().sessions.a.composerDraft).toBeUndefined();
+});