Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions apps/server/src/lazurio/threadTabs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,30 @@ describe("tabs an agent opens", () => {
expect(snapshot.tabs[0]?.revealRequest).toBeDefined();
});

it("a new binding to a tab another session is bound to or another strip holds is not taken in; one the strip holds already is revealed (LazurioPlatform#974)", async () => {
const w = await world();
// agent-browser left the thread's session on the tab another agent pinned and works in.
await w.bind("upload-fix", id(7), process.pid);
await w.bind(stripA, id(7));
await w.core.refresh();
expect(await w.stored()).toBeNull();
await w.storeFile(stripB, "Docs", [{ id: id(8), recordedAt: at(90) }]);
await w.bind(stripA, id(8));
await w.core.refresh();
expect(await w.stored()).toBeNull();
await w.core.hold(threadA, id(9));
await w.bind("codex-other", id(9));
await w.bind(stripA, id(9));
await w.core.refresh();
expect(
((await w.core.read(threadA)) as ThreadTabsSnapshot).tabs[0]?.revealRequest,
).toBeDefined();
// The thread's own new window is recorded as before.
await w.bind(stripA, id(10));
await w.core.refresh();
expect(tabIds(await w.core.read(threadA))).toEqual([id(9), id(10)]);
});

it("a binding unchanged after a release is not recorded again; a retired thread's is ignored", async () => {
const w = await world();
await w.bind(stripA, id(3));
Expand Down
26 changes: 25 additions & 1 deletion apps/server/src/lazurio/threadTabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ export function createThreadTabs(seams: ThreadTabsCoreSeams): ThreadTabsCore {
let holdsOf = new Map<string, TabHolder[]>();
/** Tabs a session with a live daemon is bound to. */
let working = new Set<string>();
/** The sessions whose binding names each tab, daemon or not. */
let boundBy = new Map<string, string[]>();
/** The tab each `t3-` session was last seen bound to: only another one is recorded. */
const lastBound = new Map<string, string>();
const threadOfSessionCache = new Map<string, string>();
Expand Down Expand Up @@ -391,6 +393,7 @@ export function createThreadTabs(seams: ThreadTabsCoreSeams): ThreadTabsCore {
async function readBindings(baseline: boolean): Promise<SessionBinding[]> {
if (seams.socketDirectory === undefined) {
working = new Set();
boundBy = new Map();
return [];
}
let bindings: SessionBinding[];
Expand All @@ -402,6 +405,12 @@ export function createThreadTabs(seams: ThreadTabsCoreSeams): ThreadTabsCore {
working = new Set(
bindings.filter((binding) => binding.working).map((binding) => binding.targetId),
);
boundBy = new Map();
for (const binding of bindings) {
const sessions = boundBy.get(binding.targetId);
if (sessions === undefined) boundBy.set(binding.targetId, [binding.session]);
else sessions.push(binding.session);
}
const fresh: SessionBinding[] = [];
for (const binding of bindings) {
if (!isThreadStrip(binding.session)) continue;
Expand Down Expand Up @@ -607,11 +616,26 @@ export function createThreadTabs(seams: ThreadTabsCoreSeams): ThreadTabsCore {
}
for (const binding of fresh) {
const threadId = await threadOfSession(binding.session);
if (threadId !== null) await record(threadId, binding.targetId, true);
if (threadId === null) continue;
if (anothersTab(stripOf(threadId), binding)) {
log("thread-tabs-binding-not-recorded", { session: binding.session });
continue;
}
await record(threadId, binding.targetId, true);
}
publish();
}

/** LazurioPlatform#974: agent-browser records a fresh daemon's pick of any tab even after a
* failed bind, so a tab another place holds or another session is bound to stays theirs. */
function anothersTab(strip: string, { session, targetId }: SessionBinding): boolean {
if (index.get(strip)?.tabs.has(targetId) === true) return false;
return (
(holdsOf.get(targetId) ?? []).some((holder) => holder.strip !== strip) ||
(boundBy.get(targetId) ?? []).some((other) => other !== session)
);
}

const track = (work: Promise<void>) => {
running.add(work);
void work.finally(() => running.delete(work));
Expand Down
6 changes: 5 additions & 1 deletion docs/operations/lazurio-overlay.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ k přestavbě na v0.1.0, Lazurio/t3code#70), a tak overlay dělá tohle:
`preview_open`, nebo sezení agent-browser vlákna `t3-<id>` naváže jinou záložku
(server sleduje `<socket dir>/t3-<id>.target` jako hub). Vazby nalezené při
startu se nezapisují a vazba, která se po puštění záložky nezmění, ji nevrátí:
vrátí ji jen nové okno agenta nebo `preview_open`.
vrátí ji jen nové okno agenta nebo `preview_open`. Novou vazbu na záložku,
kterou drží jiný pás nebo kterou jmenuje vazba jiného sezení, server do pásu
nepřevezme, pokud ji pás vlákna už nemá (LazurioPlatform#974): agent-browser
vazbu zapíše i po neúspěšném `tab <id>`, na záložku, kterou si čerstvý daemon
při připojení vybral sám, třeba na záložku jiného agenta.
- **Cesta pro web.** `GET /api/lazurio/thread-tabs?threadId=<id>` vrátí snímek
nebo `{"available": false}`, `GET …/events?threadId=<id>` je SSE se snímkem
hned a při každé změně (a s událostmi `foreign`), `POST …/hold` a
Expand Down
9 changes: 4 additions & 5 deletions scripts/lazurio-release-contract.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2017,17 +2017,16 @@ NodeTest.test("the panel opens on an agent's tab through its seams", async () =>
/environmentBrowserLink\(href, window\.location\.origin, snapshot\.viewOrigin\)/,
);
// The host records every tab preview_open opens or adopts in the thread's strip, revealed unless
// it asked for background work; the service records a new binding of the thread's session too.
// it asked for background work; the service records a new binding of the thread's session too,
// unless another strip holds that tab or another session's binding names it (LazurioPlatform#974).
NodeAssert.match(
host,
/const reveals = \(input: PreviewAutomationOpenInput\) => \(input\.open \?\? input\.show\) !== false;/,
);
NodeAssert.match(host, /yield\* adopt\(request\.threadId, targetId, reveals\(input\)\);/);
NodeAssert.match(host, /Effect\.andThen\(threadTabs\.record\(threadId, targetId, revealed\)\)/);
NodeAssert.match(
tabsService,
/if \(threadId !== null\) await record\(threadId, binding\.targetId, true\);/,
);
NodeAssert.match(tabsService, /if \(anothersTab\(stripOf\(threadId\), binding\)\) \{/);
NodeAssert.match(tabsService, /await record\(threadId, binding\.targetId, true\);/);
});

// A plain click on a thread's server in upstream's Servers panel (pingdotgg/t3code#22542) opens it in
Expand Down
Loading