Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (claude round 3): fix the completion contract on the path that runs

[._.]/ Adam Eivy12295a1c1cb7
diff --git a/server/lib/quotaBurnPresets.js b/server/lib/quotaBurnPresets.js
index e7c4665997..f45c1eb831 100644
--- a/server/lib/quotaBurnPresets.js
+++ b/server/lib/quotaBurnPresets.js
@@ -68,9 +68,9 @@ const auditContract = ({ labels, dedupeSearch }) => `
the existing issue only when you have genuinely new evidence.
4. **File each surviving finding as its own issue.** Write the body to a scratch
file OUTSIDE the repository — \`BODY=$(mktemp)\` — then
- \`gh issue create --title "..." --body-file "$BODY" --label ...\`. Never write
- scratch files into the working tree: an untracked leftover makes the run's
- worktree undeletable, so one is stranded on disk per burn. Suggested labels:
+ \`gh issue create --title "..." --body-file "$BODY" --label ...\`. Keep scratch
+ files out of the working tree — a run that ends dirty is indistinguishable
+ from one that edited code it was told not to touch. Suggested labels:
${labels}. Run \`gh label list\` first and use only labels that exist. One
problem per issue — never a bundle.
5. **Bodies must be decision-complete**, in this shape:
diff --git a/server/services/agentPromptBuilder.js b/server/services/agentPromptBuilder.js
index 8d4c91ac7a..dd75e4a59f 100644
--- a/server/services/agentPromptBuilder.js
+++ b/server/services/agentPromptBuilder.js
@@ -1722,16 +1722,23 @@ function buildLightContextSections(task, workspaceDir, worktreeInfo, isTruthyMet
}
// --- Completion / review-loop ------------------------------------------
- if (discardWorktree) {
- // Reasoning-only task: the sentinel payload (shape set by the task-type
- // output hook) is the sole output; the worktree is discarded on exit. Wins
- // over the isTui / CLI push-and-PR completion workflows below.
- sections.push(buildProgrammaticOutputCompletionSection(`${worktreeInfo?.worktreePath || workspaceDir}/.agent-done`));
- } else if (noCodeOutput) {
+ // Ordering matches the full path's (buildCompletionGuidelineBullet and the
+ // tuiCompletionSection ternary): the deliverable's destination
+ // (`noCodeOutput`) decides the contract, and only then does worktree disposal
+ // (`discardWorktree`) pick the reasoning-payload one. THIS is the branch that
+ // matters in production — every `tui`/`cli` provider returns from the light
+ // path above and never reaches the other two, so a fix applied only there is
+ // no fix at all for anything a subscription-quota job can run.
+ if (noCodeOutput) {
sections.push(buildActionOutputCompletionSection({
isTui,
sentinelPath: `${worktreeInfo?.worktreePath || workspaceDir}/.agent-done`,
}));
+ } else if (discardWorktree) {
+ // Reasoning-only task: the sentinel payload (shape set by the task-type
+ // output hook) is the sole output; the worktree is discarded on exit. Wins
+ // over the isTui / CLI push-and-PR completion workflows below.
+ sections.push(buildProgrammaticOutputCompletionSection(`${worktreeInfo?.worktreePath || workspaceDir}/.agent-done`));
} else if (isReadOnly) {
sections.push(buildReadOnlyCompletionSection({
isTui,
diff --git a/server/services/agentPromptBuilder.test.js b/server/services/agentPromptBuilder.test.js
index 0b17797051..ae6d983293 100644
--- a/server/services/agentPromptBuilder.test.js
+++ b/server/services/agentPromptBuilder.test.js
@@ -1621,6 +1621,46 @@ describe('discardWorktree (reasoning-only) completion contract', () => {
assertReasoningOnly(prompt);
});
+ // A discard task whose deliverable is an EXTERNAL action performed during the
+ // run (a filed issue, an endpoint call) must get the no-code-output contract,
+ // NOT "write your result to the sentinel" — otherwise it reports its findings
+ // into a file the cleanup then throws away, and the window produces nothing.
+ //
+ // Asserted on the LIGHT path specifically: every `tui`/`cli` provider returns
+ // from buildLightContextPrompt, so a quota-burn job (which only ever selects
+ // CLI/TUI providers — it exists to spend a subscription window) never reaches
+ // the full path. A unit test on buildCompletionGuidelineBullet alone passes
+ // while production is unchanged; that false green is how this shipped broken
+ // once already.
+ describe('with noCodeOutput — the deliverable is the action, not the sentinel', () => {
+ const auditTask = () => makeTask({ metadata: { discardWorktree: true, noCodeOutput: true, useWorktree: true, openPR: false } });
+
+ const assertActionOutput = (prompt) => {
+ expect(prompt).toMatch(/## Completion \(No Code Output\)/);
+ expect(prompt).not.toMatch(/## Completion \(Reasoning-Only Task\)/);
+ expect(prompt).not.toMatch(/in the exact payload format/);
+ expect(prompt).not.toMatch(/## Completion Workflow/);
+ };
+
+ it('light TUI path', () => {
+ const prompt = buildLightContextPrompt(auditTask(), '/r', wt, isTruthyMeta, { isTui: true });
+ assertActionOutput(prompt);
+ // The sentinel is still the done-signal for a TUI run — just not the
+ // place the deliverable goes.
+ expect(prompt).toMatch(/\.agent-done/);
+ });
+
+ it('light CLI (non-TUI) path', () => {
+ const prompt = buildLightContextPrompt(auditTask(), '/r', wt, isTruthyMeta, { isTui: false, providerId: 'codex' });
+ assertActionOutput(prompt);
+ });
+
+ it('full (api) path', async () => {
+ const prompt = await buildAgentPrompt(auditTask(), {}, '/r', wt, isTruthyMeta, { providerType: 'api' });
+ assertActionOutput(prompt);
+ });
+ });
+
it('full (api) path suppresses the commit/push instructions in Instructions + Git Hygiene', async () => {
const prompt = await buildAgentPrompt(liTask(), {}, '/r', wt, isTruthyMeta, { providerType: 'api' });
assertReasoningOnly(prompt);