fix(p3): harness: an undo of a move always goes through, also for a conversation whose record is gone (Astra, round 3); the docs say a worker's direct SessionFacts.moveLocation is not checked (the worker is trusted plugin code, decision 111) (ERNDL-704)

This commit is contained in:
Mario Zechner 2026-11-27 06:06:59 +00:00
parent 836a1119d4
commit cb32f74f9b
5 changed files with 36 additions and 19 deletions

View file

@ -59,9 +59,12 @@ const id = await workspace.make({ kind: SessionKind.name, name: "Fix the build",
environment. A move with `location: null` is undone (the conversation follows its owner again); a subagent keeps its
own while archived (a restore finds it). A move is refused unless the folder is a full path and the agents have Work
on the machine in the session, and a person's unless the machine is available to them there (the environments plugin's
`checkMachine`, as Files and Terminals). The worker's path refuses a conversation the session does not have; Manage's
takes any well-formed id for now (carry-over of ERNDL-704). Manage shows the moved conversations (`detail`, one
document per session, by conversation id); the worker reads the same in `SessionFacts.detail`.
`checkMachine`, as Files and Terminals). The harness (`HarnessSession.moveLocation`, the path the agent's tool takes)
refuses to move a conversation the session does not have; an undo always goes through. A direct
`SessionFacts.moveLocation` call by the session's worker is not checked: the worker is trusted plugin code (decision
111). Manage's path takes any well-formed id for now (carry-over 3 of ERNDL-704: the server asking the session's
worker). Manage shows the moved conversations (`detail`, one document per session, by conversation id); the worker
reads the same in `SessionFacts.detail`.
- **What its workers keep** (their directory, `<data>/workers/<id>`) goes with the session: removing the session stops
its worker and deletes it (the runner's `remove`, refusing an id that names no session). A directory of a session
with no row is swept whenever a runner appears (at every start), each one reported as it goes, one that fails

View file

@ -536,7 +536,7 @@ describe("the harness plugin on a worker", () => {
});
// Opus, after push 4: a key that names no conversation would hold one of the session's 1000 moved places for good.
it("refuses to move a conversation the session does not have", async () => {
it("refuses to move a conversation the session does not have, and undoes any move", async () => {
const sessions: HarnessSession[] = [];
const server = await start([other("test.located", "l")], {}, [
{ kind: "test.located", seen: (session) => sessions.push(session) },
@ -546,9 +546,20 @@ describe("the harness plugin on a worker", () => {
assert.ok(session !== undefined);
const nowhere = 999_999 as ConversationId;
await assert.rejects(session.moveLocation(nowhere, { machine: "m", folder: "/srv" }, context), /no conversation/);
await assert.rejects(session.moveLocation(nowhere, null, context), /no conversation/);
await session.moveLocation(ROOT_CONVERSATION_ID, { machine: "m", folder: "/srv" }, context);
assert.deepEqual(Object.keys(server.moved()), ["1"]);
// Astra, round 3: a move whose conversation's record is gone (a store recovered without it) is still undone.
await session.call(
async (ctx) =>
(await ctx.get(SessionFacts, {})).moveLocation(
{ conversation: String(nowhere), location: { machine: "m", folder: "/srv" } },
ctx,
),
context,
);
assert.deepEqual(Object.keys(server.moved()).toSorted(), ["1", String(nowhere)]);
await session.moveLocation(nowhere, null, context);
assert.deepEqual(Object.keys(server.moved()), ["1"]);
});
// Opus M1, round 1 (R41): a session on no machine (its maker could use none) gives its agent no environment.

View file

@ -221,8 +221,9 @@ async function openAgent(sources: Sources, opening: Context): Promise<{ durable:
call: (fn, context) => worker.root(fn, context),
location,
moveLocation: async (conversation, location, context) => {
// Only a conversation the session has (Opus): any other key would hold one of the session's moved places.
if ((await record(conversation, context)) === undefined) {
// A move only for a conversation the session has (Opus): any other key would hold one of the session's moved
// places. An undo always goes through: it frees a place, also one whose record is gone (Astra, round 3).
if (location !== null && (await record(conversation, context)) === undefined) {
throw invalid("args", `harness: no conversation ${conversation}`);
}
await facts.moveLocation({ conversation: String(conversation), location }, context);

View file

@ -115,7 +115,9 @@ export type SessionDefaults = Static<typeof SessionDefaults>;
/**
* A session's own facts for its worker, which holds it as itself: its row (`null` for a session the server does not
* know), its moved conversations (`detail`), `report`, which says what its agent is doing now, and `moveLocation`,
* its agent's move of one conversation (refused unless the agents have Work there on that machine).
* its agent's move of one conversation (refused unless the agents have Work there on that machine). Whether the
* conversation exists is not checked here, the server cannot see it: the harness checks it for its agent's tool, and
* the worker is trusted plugin code (decision 111).
*/
export const SessionFacts = remote("sessions.facts", {
// Version 2: the row's model choice names a login (decision 118). Version 3: its moved conversations (`detail`,

View file

@ -39,17 +39,17 @@ export type HarnessLocation = { readonly machine: string; readonly folder: strin
/**
* What a kind's part has of the session's agent: the session's id, the workspace the agent holds its things in (the
* session's workspace; a part never assumes it equals the session's id), `call`, which runs `fn` as the session's
* worker (a tool reaches its plugin's objects with it, on the worker or the server), its references released when
* `fn` settles (`context` is the tool's, Durable's, so cancelling the tool cancels the call), `location`, where
* conversation `conversation` (Durable's id, a tool's `api.conversationId`) works now (its own location once moved,
* else its owner conversation's, a subagent's caller's, else the session's; `undefined`: nowhere, an unknown session
* or one on no machine; it may read Durable once per conversation, so never from Durable's Session line, an observer:
* a tool, the environment, a prompt section and a hook all run off it), and `moveLocation`, which moves the
* conversation to `location` (`null`: undoes its move, it follows its owner again): the next tool call works there, a
* call under way keeps its environment; refused for a conversation the session does not have (`invalid`), and, with a
* message, unless the folder is a full path (`invalid`) and the agents have Work here on its machine (`forbidden`, the
* machine kind's rule). `HarnessLocation` is the sessions plugin's `Location`, written again: this plugin never imports
* that one.
* worker (a tool reaches its plugin's objects with it, on the worker or the server), its references released when `fn`
* settles (`context` is the tool's, Durable's, so cancelling the tool cancels the call), `location`, where conversation
* `conversation` (Durable's id, a tool's `api.conversationId`) works now (its own location once moved, else its owner
* conversation's, a subagent's caller's, else the session's; `undefined`: nowhere, an unknown session or one on no
* machine; it may read Durable once per conversation, so never from Durable's Session line, an observer: a tool, the
* environment, a prompt section and a hook all run off it), and `moveLocation`, which moves the conversation to
* `location` (`null`: undoes its move, it follows its owner again): the next tool call works there, a call under way
* keeps its environment; a move is refused for a conversation the session does not have (`invalid`; an undo always goes
* through, `SessionFacts.moveLocation` itself checks no conversation), and, with a message, unless the folder is a full
* path (`invalid`) and the agents have Work here on its machine (`forbidden`, the machine kind's rule).
* `HarnessLocation` is the sessions plugin's `Location`, written again: this plugin never imports that one.
*/
export type HarnessSession = {
readonly session: string;