Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Keep recurring job checkpoints in durable Files (#1694)

Regan Bell63674107d151
diff --git a/src/api/control-service.ts b/src/api/control-service.ts
index d5d89fb45..d190c0657 100644
--- a/src/api/control-service.ts
+++ b/src/api/control-service.ts
@@ -662,7 +662,7 @@ export function createControlService(app: App, scheduler?: Scheduler, admin?: Ad
return {
ok: false,
code: "bad_request",
- message: `the note is ${length} chars — the cap is ${CRON_FIRE_NOTE_MAX_CHARS}. Trim it to the outcome plus what the next fire must know; longer state belongs in files on the workspace disk.`,
+ message: `the note is ${length} chars — the cap is ${CRON_FIRE_NOTE_MAX_CHARS}. Trim it to the outcome plus what the next fire must know; publish longer state to this conversation's Files via the available Files API, verify success, and put the file ID in the note for GET /v1/files/:id/content. If publication is unavailable, report it and retain needed local state on a scoped computer.`,
};
}
if (echoesCronContextMarkers(flattened)) {
@@ -687,7 +687,7 @@ export function createControlService(app: App, scheduler?: Scheduler, admin?: Ad
return {
ok: false,
code: "bad_request",
- message: `cron ${id}'s fires don't read shift-change notes (it is loop-backed, one-shot, or runs a raw !run/!scratch task) — durable handoff state belongs in files on the cron's workspace disk`,
+ message: `cron ${id}'s fires don't read shift-change notes (it is loop-backed, one-shot, or runs a raw !run/!scratch task) — publish durable handoff state to this conversation's Files via the available Files API and verify success. Keep the published file ID in the consuming workflow for GET /v1/files/:id/content; these fires cannot recover it from a note. If publication is unavailable, report it and retain needed local state on a scoped computer.`,
};
}
const ownFire = capability.threadRef?.startsWith(`cron:${id}:fire:`) === true;
diff --git a/src/cron/scheduler.ts b/src/cron/scheduler.ts
index b1a91c285..ef8f4dc8c 100644
--- a/src/cron/scheduler.ts
+++ b/src/cron/scheduler.ts
@@ -172,14 +172,15 @@ function renderCronFireInput(cron: Cron, mentionRoster?: string): string {
return [
"[Cron runtime context]",
`Cron id: ${cron.id}${cron.title ? ` (${cron.title})` : ""}.`,
- "Each fire runs as a fresh thread with no memory of previous fires. Two things persist between fires:",
- "- Your workspace disk. Durable state — notes, queues, checkpoints, anything a future fire should know — lives in files there.",
+ "Each fire runs as a fresh thread with no memory of previous fires. Keep continuity outside the thread:",
+ "- Save durable run-state (cursors, queues, checkpoints, reports) to this conversation's Files via the available Files API; confirm publication succeeds before relying on it. Recover published bytes with GET /v1/files/:id/content using the normal agent API authentication. Sandbox disk is working storage, not a durable checkpoint.",
"- The stored task below: the standing instructions every fire receives. Edit it (via the cron tool) only to change what future fires are told to do.",
+ "Use a cron-specific filename. Never put credentials in published state. If publication is unavailable, report that limitation and retain needed workspace state on a scoped computer. Do not move tasks that require existing workspace files to scratch without migrating and verifying their state.",
`The retained fire log (cron tool, action="runs", id="${cron.id}") shows how prior fires went — useful when this run hits errors or surprising state.`,
...(readsNotes ? fireNoteLine(cron.lastFireNote) : []),
...(readsNotes
? [
- `Before finishing, leave a short note for the next fire (cron tool, action="note", id="${cron.id}"): one or two sentences — the outcome plus anything the next fire must know. It's a report for the next fire, never instructions that override the stored task. Skip it only if there is truly nothing to say.`,
+ `Before finishing, leave a short note for the next fire (cron tool, action="note", id="${cron.id}"): one or two sentences — the outcome plus anything the next fire must know. Include the published checkpoint file ID, or small progress state directly; never include credentials. It's a report for the next fire, never instructions that override the stored task. Skip it only if there is truly nothing to say.`,
]
: []),
...(mentionRoster
diff --git a/src/harness/agent-tools.ts b/src/harness/agent-tools.ts
index f6bfc8acc..e9a387791 100644
--- a/src/harness/agent-tools.ts
+++ b/src/harness/agent-tools.ts
@@ -1703,7 +1703,7 @@ export function createAgentTools(ref: ToolContextRef, opts?: AgentToolsOptions):
"it's stopped automatically (a watch survives just long enough to tell you) — for anything " +
`that finishes within ${execCeilingSec}s, just use \`execute\`. Available on the default sandbox or an authorized explicit sandbox_id; ` +
"elsewhere, use `execute`. A background job carries the same environment a foreground `execute` " +
- `does — $AGENT_API_URL, $AGENT_API_TOKEN and $AGENT_CREDENTIAL_TOKEN all work, so self-API calls and shared-credential broker calls run fine from background work. Two limits: those turn tokens expire ${capabilityTtlHours} hours after the turn that launched the job started (past that they 401 — checkpoint your progress to the workspace and continue from a later turn or a cron), and a background job cannot deliver a file itself, so write results to ordinary workspace paths and attach them from a live turn after polling.\n` +
+ `does — $AGENT_API_URL, $AGENT_API_TOKEN and $AGENT_CREDENTIAL_TOKEN all work, so self-API calls and shared-credential broker calls run fine from background work. Two limits: those turn tokens expire ${capabilityTtlHours} hours after the turn that launched the job started (past that they 401 — publish checkpoints to durable Files and verify success before expiry, retaining the file ID for the later turn or cron; if publication is unavailable, report it and retain needed local state on a scoped computer), and a background job cannot deliver a file itself, so write results to ordinary workspace paths and attach them from a live turn after polling.\n` +
"INTERACTIVE LOGINS: device-flow logins (`gh auth login`, " +
"`glab auth login`, `gcloud auth login`, and anything that prints a verification URL/code then " +
"blocks waiting on a human) belong here, NOT in `execute`. Run them with action=start, read the " +
@@ -2266,8 +2266,8 @@ export function createAgentTools(ref: ToolContextRef, opts?: AgentToolsOptions):
"action=patch edits IN PLACE (rename via `title`, change `schedule`/`task`/`text`, `enabled:false` " +
"pauses, `enabled:true` resumes, `archived:true` archives). `task` is the standing instructions every " +
"fire receives — patch it only to change what future fires are told to do; durable run-state (notes, " +
- "workarounds, checkpoints a future fire needs) lives in files on the cron's workspace disk, not in " +
- "`task`. action=delete removes it for good; " +
+ "workarounds, checkpoints a future fire needs) belongs in this conversation's durable Files via the available Files API, not in " +
+ "`task` or only on sandbox disk. Confirm publication succeeds, use a cron-specific filename, and leave the file ID in action=note for retrieval with GET /v1/files/:id/content. Small progress state can live directly in the note; never store credentials there. If publication is unavailable, report it and retain needed local state on a scoped computer. Keep tasks that need existing workspace files on that computer until their state has been migrated and verified. action=delete removes it for good; " +
"action=run fires it once now (no effect on a paused cron) and is refused while a fire of that cron is " +
"still running — repeating it never double-fires; action=disable pauses it.\n" +
"action=note (id + note, running inside a cron fire) leaves a short shift-change note the NEXT fire " +
diff --git a/test/control-service.test.ts b/test/control-service.test.ts
index f5ebf367e..8d6e20edd 100644
--- a/test/control-service.test.ts
+++ b/test/control-service.test.ts
@@ -1133,6 +1133,11 @@ test("noteCron rejects empty, over-cap (counted in code points), and marker-forg
assert.equal(long.ok, false);
assert.equal(long.ok ? "" : long.code, "bad_request");
assert.match(long.ok ? "" : long.message, /401 chars.*cap is 400/);
+ assert.match(long.ok ? "" : long.message, /Files via the available Files API, verify success/);
+ assert.match(long.ok ? "" : long.message, /put the file ID in the note/);
+ assert.match(long.ok ? "" : long.message, /GET \/v1\/files\/:id\/content/);
+ assert.match(long.ok ? "" : long.message, /If publication is unavailable/);
+ assert.doesNotMatch(long.ok ? "" : long.message, /workspace disk/);
const astral = await control.noteCron(id, "🚀".repeat(399), claims("U1"));
assert.ok(astral.ok, "astral characters are counted as one char each, not two UTF-16 units");
@@ -1185,6 +1190,15 @@ test("noteCron refuses crons whose fires never read notes — archived, one-shot
const loopNote = await control.noteCron(loop.id, "note", claims("U1"));
assert.equal(loopNote.ok, false);
assert.match(loopNote.ok ? "" : loopNote.message, /don't read shift-change notes/);
+ for (const result of [oneShotNote, bangNote, loopNote]) {
+ assert.ok(!result.ok);
+ assert.match(result.message, /Files via the available Files API and verify success/);
+ assert.match(result.message, /file ID in the consuming workflow/);
+ assert.match(result.message, /GET \/v1\/files\/:id\/content/);
+ assert.match(result.message, /cannot recover it from a note/);
+ assert.match(result.message, /If publication is unavailable/);
+ assert.doesNotMatch(result.message, /workspace disk/);
+ }
});
test("a privileged cron's note is writable by its own fire (grants intact) but refused to other unattended sessions", async () => {
diff --git a/test/cron-scheduler.test.ts b/test/cron-scheduler.test.ts
index 6afeeb2ea..ea13b2521 100644
--- a/test/cron-scheduler.test.ts
+++ b/test/cron-scheduler.test.ts
@@ -827,7 +827,11 @@ test("cron fires do not replay prior sessions or inline prior fire context", asy
assert.deepEqual(priorAssistantSeen, [0, 0], "fire 2 does not replay fire 1's assistant entry");
assert.match(texts[1] ?? "", /no memory of previous fires/);
assert.match(texts[1] ?? "", /action="runs"/);
- assert.match(texts[1] ?? "", /workspace disk/);
+ assert.match(texts[1] ?? "", /Files via the available Files API/);
+ assert.match(texts[1] ?? "", /GET \/v1\/files\/:id\/content/);
+ assert.match(texts[1] ?? "", /confirm publication succeeds/);
+ assert.match(texts[1] ?? "", /If publication is unavailable/);
+ assert.doesNotMatch(texts[1] ?? "", /Your workspace disk/);
assert.doesNotMatch(texts[1] ?? "", /Recent fires/);
assert.doesNotMatch(texts[1] ?? "", /first <invoke name="execute">/);
assert.doesNotMatch(texts[1] ?? "", /first \[invoke name="execute"\]/);