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 2): make the discard posture actually deliver

[._.]/ Adam Eivy479e0c9541e5
diff --git a/client/src/components/quotaBurn/PresetPicker.jsx b/client/src/components/quotaBurn/PresetPicker.jsx
index 0ea7f8051e..cc7be75411 100644
--- a/client/src/components/quotaBurn/PresetPicker.jsx
+++ b/client/src/components/quotaBurn/PresetPicker.jsx
@@ -15,10 +15,12 @@
import { inputClass } from './fields';
-export default function PresetPicker({ id, label, presets, jobType = null, onPick, hint }) {
- // Presets declare the job type they seed, so a plan with several job types
- // only ever offers the ones that can apply here.
- const rows = (presets || []).filter((preset) => !jobType || preset.jobType === jobType);
+export default function PresetPicker({ id, label, presets, onPick, hint }) {
+ // Deliberately unfiltered by the row's current job type: a preset carries the
+ // job type it needs, so picking one CONVERTS the step rather than being
+ // inapplicable to it. Filtering hid the control entirely on a non-agent row,
+ // leaving delete-and-re-add as the only way to turn a step into an audit.
+ const rows = presets || [];
if (!rows.length) return null;
return (
diff --git a/server/lib/quotaBurnPresets.js b/server/lib/quotaBurnPresets.js
index 3e30634d79..e7c4665997 100644
--- a/server/lib/quotaBurnPresets.js
+++ b/server/lib/quotaBurnPresets.js
@@ -87,8 +87,11 @@ const auditContract = ({ labels, dedupeSearch }) => `
filed. Never paste a secret, credential, token, hostname, IP address, absolute
path containing a username, or any personal record into a title or body — cite
the location and redact the value (\`<token>\`, \`<hostname>\`, \`<user-email>\`).
- This applies even when the value IS the finding: "\`config/dev.js:42\` commits a
- live API key" is the report; the key itself never appears.
+ For a LIVE credential, do not file an ordinary issue at all: a public tracker
+ entry naming the file and line is a world-readable map to a working secret.
+ Report it in your final summary to the user, say it needs rotating, and file
+ at most a location-free issue ("a committed credential needs rotating and
+ purging from history — details in the run summary").
8. **Change no code.** No commits, no branches, no pull requests. The deliverable
is the filed issues, and the run should end with a clean \`git status\`.
9. **Report at the end**: the slice you audited, each issue number and title, and
@@ -97,9 +100,8 @@ const auditContract = ({ labels, dedupeSearch }) => `
If \`gh\` cannot reach the network (errors like "bad file descriptor" or a
connect timeout), do not give up silently — fall back to the REST API with the
token from the local keyring:
-\`TOK=$(command gh auth token)\` then, with the payload in a \`mktemp\` file outside
-the repo,
-\`curl -sS -H "Authorization: Bearer $TOK" -H "Accept: application/vnd.github+json" -d @"$PAYLOAD" https://api.github.com/repos/<owner>/<repo>/issues\`.
+\`TOK=$(command gh auth token)\`, then with the JSON payload in \`BODY=$(mktemp)\`:
+\`curl -sS -H "Authorization: Bearer $TOK" -H "Accept: application/vnd.github+json" -d @"$BODY" https://api.github.com/repos/<owner>/<repo>/issues\`.
A window spent finding real problems and filing none is a wasted window.
Read this repository's \`CLAUDE.md\` (and any nested per-directory ones covering
diff --git a/server/services/agentPromptBuilder.js b/server/services/agentPromptBuilder.js
index 19746eebe4..8d4c91ac7a 100644
--- a/server/services/agentPromptBuilder.js
+++ b/server/services/agentPromptBuilder.js
@@ -902,12 +902,21 @@ export function buildCompletionGuidelineBullet({
if (isPrFollowUp && !discardWorktree && !noCodeOutput && !isReadOnly) {
return 'Follow the follow-up section above — it is the whole task. Commit and push only fixes you actually make; the deliverable is the PR\'s final state, not a commit. Do NOT open a new PR, and do NOT expect this branch to be merged back for you.';
}
+ // `noCodeOutput` is checked FIRST because the two flags answer different
+ // questions: `discardWorktree` decides what happens to the checkout, while
+ // `noCodeOutput` decides where the deliverable goes. A task that sets both —
+ // "do your work through an API/CLI action during the run, and never land
+ // code" — must be told its output channel is that action, NOT the sentinel.
+ // Telling it "write your result to the sentinel" is how a run files nothing
+ // and reports its findings into a file that gets thrown away (PLAN.md records
+ // this exact hazard from the 2026-07-16 codex review). No pre-existing task
+ // sets both, so this ordering changes nothing that shipped before it.
+ if (noCodeOutput) {
+ return '**This task produces no code output.** Its result is the API request or command your instructions describe (a PortOS endpoint call, a filed tracker issue, …) — do NOT run `/do:push`, `/do:pr`, `/simplify`, `git commit`, `git push`, or open a PR. Write the completion sentinel (see the Completion section) and stop.';
+ }
if (discardWorktree) {
return '**This is a reasoning-only task.** The worktree is discarded on exit — do NOT commit, push, merge, or open a PR. Write your result to the completion sentinel (see the Completion section) and stop.';
}
- if (noCodeOutput) {
- return '**This task produces no code output.** Its result is the API request your instructions describe — do NOT run `/do:push`, `/do:pr`, `/simplify`, `git commit`, `git push`, or open a PR. Write the completion sentinel (see the Completion section) and stop.';
- }
if (isReadOnly) {
return '**This is a read-only task.** Do NOT commit, push, or modify any files in the repository. Only read data and generate reports.';
}
@@ -1075,7 +1084,7 @@ export function buildReadOnlyCompletionSection({ isTui = false, sentinelPath = n
* reaper.
*/
export function buildActionOutputCompletionSection({ isTui = false, sentinelPath = null } = {}) {
- const notice = '## Completion (No Code Output)\nThis task produces **no code change** — its result is delivered by the API request your instructions describe (a PATCH to a PortOS endpoint), not by a commit. Do NOT run `/do:push`, `/do:pr`, `/simplify`, `git commit`, `git push`, or open a pull request; there is nothing to push.';
+ const notice = '## Completion (No Code Output)\nThis task produces **no code change** — its result is delivered DURING the run by the API request or command your instructions describe (a PATCH to a PortOS endpoint, a filed tracker issue, …), not by a commit and not by this sentinel. Do NOT run `/do:push`, `/do:pr`, `/simplify`, `git commit`, `git push`, or open a pull request; there is nothing to push.';
if (!isTui || !sentinelPath) return notice;
return [
notice,
@@ -1304,10 +1313,15 @@ After completing your work and before committing, ${simplifyInstruction}. Fix an
// A discard task's completion is the sentinel-only contract (no push/PR/merge),
// and this applies to every provider type — so it wins over the isTui fork and
// over the fallback template's commit/push instructions below.
- const tuiCompletionSection = discardWorktree
- ? buildProgrammaticOutputCompletionSection(sentinelPath)
- : noCodeOutput
- ? buildActionOutputCompletionSection({ isTui, sentinelPath })
+ // Same precedence as buildCompletionGuidelineBullet: where the deliverable
+ // goes (`noCodeOutput`) decides the completion contract, and only then does
+ // worktree disposal (`discardWorktree`) pick the reasoning-payload contract.
+ // A task doing external work during the run must not be told the sentinel is
+ // its output channel.
+ const tuiCompletionSection = noCodeOutput
+ ? buildActionOutputCompletionSection({ isTui, sentinelPath })
+ : discardWorktree
+ ? buildProgrammaticOutputCompletionSection(sentinelPath)
: isTui
? buildTuiCompletionSection({
willOpenPR, prCompletion, simplifyEnabled,
diff --git a/server/services/agentPromptBuilder.test.js b/server/services/agentPromptBuilder.test.js
index 82db750504..0b17797051 100644
--- a/server/services/agentPromptBuilder.test.js
+++ b/server/services/agentPromptBuilder.test.js
@@ -1565,6 +1565,25 @@ describe('buildCompletionGuidelineBullet', () => {
expect(bullet).toMatch(/discarded on exit/);
expect(bullet).not.toMatch(/`\/do:pr`/);
});
+
+ it('noCodeOutput wins over discardWorktree — the deliverable is the action, not the sentinel', () => {
+ // The two flags answer different questions: discardWorktree decides what
+ // happens to the checkout, noCodeOutput decides where the deliverable goes.
+ // A task that does its work through an external action DURING the run (an
+ // endpoint call, a filed issue) and also throws the tree away must not be
+ // told "write your result to the sentinel" — that is how a run performs no
+ // action and reports its findings into a file that is then discarded.
+ const bullet = buildCompletionGuidelineBullet({
+ isReadOnly: false, isTui: true, tuiCompletionCommand: '/do:pr',
+ worktreeInfo: { worktreePath: '/wt' }, willOpenPR: true,
+ discardWorktree: true, noCodeOutput: true,
+ });
+ expect(bullet).toMatch(/produces no code output/i);
+ expect(bullet).not.toMatch(/reasoning-only task/i);
+ // It names /do:pr only to forbid it — the TUI arm would have INSTRUCTED it.
+ expect(bullet).toMatch(/do NOT run `\/do:push`, `\/do:pr`/);
+ expect(bullet).not.toMatch(/YOU run the Completion Workflow/);
+ });
});
// A discardWorktree (reasoning-only) task — the layered-intelligence pattern —
diff --git a/server/services/agentWorktreeCleanup.js b/server/services/agentWorktreeCleanup.js
index 9d783d1976..f72045f739 100644
--- a/server/services/agentWorktreeCleanup.js
+++ b/server/services/agentWorktreeCleanup.js
@@ -102,7 +102,11 @@ async function runCleanupAgentWorktree(agentId, success, { openPR = false, prCom
const discardWorktree = isTruthyMeta(originalTask?.metadata?.discardWorktree);
if (discardWorktree) {
emitLog('info', `🌳 Discarding worktree for reasoning agent ${agentId} (no merge, no PR)`, { agentId, branchName: worktreeBranch });
- const result = await removeWorktree(agentId, sourceWorkspace, worktreeBranch, { merge: false }).catch(err => {
+ // `discardDirt`: the discard prompt explicitly invites scratch edits ("only
+ // the completion sentinel is kept"), and removeWorktree otherwise ABORTS on
+ // any non-lockfile dirt — so an agent that took its own prompt at its word
+ // stranded a full checkout on disk, once per run, forever.
+ const result = await removeWorktree(agentId, sourceWorkspace, worktreeBranch, { merge: false, discardDirt: true }).catch(err => {
emitLog('warn', `🌳 Worktree discard failed for ${agentId}: ${err.message}`, { agentId });
return { warnings: [`Worktree discard failed: ${err.message}`] };
});
diff --git a/server/services/cleanupAgentWorktree.test.js b/server/services/cleanupAgentWorktree.test.js
index 3443276da1..6f1812507e 100644
--- a/server/services/cleanupAgentWorktree.test.js
+++ b/server/services/cleanupAgentWorktree.test.js
@@ -1643,7 +1643,10 @@ describe('cleanupAgentWorktree - discardWorktree (throwaway reasoning worktree)'
});
expect(removeWorktree).toHaveBeenCalledTimes(1);
- expect(removeWorktree).toHaveBeenCalledWith('agent-1', '/mock/workspace', 'cos/task-abc123', { merge: false });
+ // `discardDirt` is part of the posture, not an optimization: the discard
+ // prompt invites scratch edits, and removeWorktree otherwise ABORTS on dirt
+ // — stranding one full checkout per run.
+ expect(removeWorktree).toHaveBeenCalledWith('agent-1', '/mock/workspace', 'cos/task-abc123', { merge: false, discardDirt: true });
// Discard wins over openPR — no code is ever pushed or PR'd.
expect(git.push).not.toHaveBeenCalled();
expect(git.createPR).not.toHaveBeenCalled();
@@ -1655,7 +1658,7 @@ describe('cleanupAgentWorktree - discardWorktree (throwaway reasoning worktree)'
originalTask: { metadata: { discardWorktree: 'true' } }
});
- expect(removeWorktree).toHaveBeenCalledWith('agent-1', '/mock/workspace', 'cos/task-abc123', { merge: false });
+ expect(removeWorktree).toHaveBeenCalledWith('agent-1', '/mock/workspace', 'cos/task-abc123', { merge: false, discardDirt: true });
expect(git.push).not.toHaveBeenCalled();
expect(git.createPR).not.toHaveBeenCalled();
});
diff --git a/server/services/cosTaskStore.js b/server/services/cosTaskStore.js
index afd9640641..f364c797a3 100644
--- a/server/services/cosTaskStore.js
+++ b/server/services/cosTaskStore.js
@@ -300,6 +300,10 @@ export async function addTask(taskData, taskType = 'user', { raw = false, ignore
// failure (code work). Both booleans are meaningful, so persist either.
if (taskData.worktreeChangesExpected === true) metadata.worktreeChangesExpected = true;
else if (taskData.worktreeChangesExpected === false) metadata.worktreeChangesExpected = false;
+ // Deliverable is an API call or CLI action performed DURING the run, not a
+ // commit and not the sentinel. Previously only the raw path could set it
+ // (creativeDirector/agentBridge.js builds its task object by hand).
+ if (taskData.noCodeOutput === true) metadata.noCodeOutput = true;
if (taskData.reviewLoop === true) metadata.reviewLoop = true;
else if (taskData.reviewLoop === false) metadata.reviewLoop = false;
// Ordered multi-reviewer list (normalizes legacy single `reviewer` too).
diff --git a/server/services/cosTaskStore.test.js b/server/services/cosTaskStore.test.js
index 3ffc6f6c98..791022675b 100644
--- a/server/services/cosTaskStore.test.js
+++ b/server/services/cosTaskStore.test.js
@@ -478,6 +478,30 @@ describe('cosTaskStore.addTask', () => {
expect(task.metadata.openPR).toBeUndefined();
});
+ it('persists the throwaway-worktree posture so a non-raw caller can ask for it', async () => {
+ // Load-bearing: `useWorktree` + `openPR:false` AUTO-MERGES onto the source
+ // workspace's default branch. `discardWorktree` is the only thing standing
+ // between an audit-style task and an unreviewed commit landing there, and
+ // before this passthrough only the raw path could set it — a non-raw caller
+ // silently got the auto-merge default instead.
+ const task = await addTask({
+ description: 'audit only', useWorktree: true, openPR: false,
+ discardWorktree: true, worktreeChangesExpected: false, noCodeOutput: true,
+ }, 'internal');
+ expect(task.metadata.discardWorktree).toBe(true);
+ expect(task.metadata.worktreeChangesExpected).toBe(false);
+ expect(task.metadata.noCodeOutput).toBe(true);
+ });
+
+ it('leaves the throwaway keys absent when the caller did not ask for them', async () => {
+ // Absent means "normal posture"; stamping `false` onto every task would put
+ // an opt-in marker on records that never opted in.
+ const task = await addTask({ description: 'ordinary', useWorktree: true }, 'internal');
+ expect(task.metadata.discardWorktree).toBeUndefined();
+ expect(task.metadata.noCodeOutput).toBeUndefined();
+ expect(task.metadata.worktreeChangesExpected).toBeUndefined();
+ });
+
it('raw=true stores the pre-built object verbatim', async () => {
const raw = { id: 'sys-raw', description: 'raw\nmultiline', status: 'pending', metadata: { context: 'ctx' } };
const task = await addTask(raw, 'internal', { raw: true });
diff --git a/server/services/quotaBurnJobs/agentPrompt.js b/server/services/quotaBurnJobs/agentPrompt.js
index 2708a69caa..9cbaa8b9df 100644
--- a/server/services/quotaBurnJobs/agentPrompt.js
+++ b/server/services/quotaBurnJobs/agentPrompt.js
@@ -86,8 +86,14 @@ export async function run({ params, job, family, candidate, context } = {}) {
provider: provider.id,
model: job?.model || undefined,
useWorktree: params?.useWorktree !== false,
- openPR: params?.openPR !== false,
- simplify: params?.simplify !== false,
+ // A discarding job can never produce a PR — the worktree is thrown away
+ // before anything is pushed. Leaving `openPR: true` on it (the param's
+ // default, one checkbox away) makes the spawner expect a PR that cannot
+ // exist: the run is downgraded to `pr-missing` and RETRIED, burning up to
+ // five agent runs of subscription quota per misconfigured job. Coerced here
+ // rather than only in the UI so a hand-edited plan can't reach that state.
+ openPR: params?.discardWorktree !== true && params?.openPR !== false,
+ simplify: params?.discardWorktree !== true && params?.simplify !== false,
// Opt-in throwaway posture for jobs whose deliverable is NOT code (the audit
// presets). Without it, `useWorktree + !openPR` auto-merges whatever the
// agent happened to commit onto the managed app's default branch, unreviewed
@@ -95,6 +101,12 @@ export async function run({ params, job, family, candidate, context } = {}) {
// idle-complete gate, which expects a dirty tree.
discardWorktree: params?.discardWorktree === true,
worktreeChangesExpected: params?.discardWorktree !== true,
+ // Where the deliverable goes. A discarding burn job's output is whatever it
+ // did during the run (files an issue, calls an endpoint) — never a commit
+ // and never the completion sentinel, which is only the done-signal. Without
+ // this the prompt tells it "write your result to the sentinel", and an audit
+ // dutifully writes its findings into a file that is then thrown away.
+ noCodeOutput: params?.discardWorktree === true,
reviewLoop: false,
}, 'internal');
diff --git a/server/services/quotaBurnJobs/agentPrompt.test.js b/server/services/quotaBurnJobs/agentPrompt.test.js
index e32ab43f2e..f6698398be 100644
--- a/server/services/quotaBurnJobs/agentPrompt.test.js
+++ b/server/services/quotaBurnJobs/agentPrompt.test.js
@@ -88,6 +88,17 @@ describe('run', () => {
// the idle-complete gate, which otherwise requires a dirty tree.
expect(state.added[1].task).toMatchObject({ discardWorktree: true, worktreeChangesExpected: false });
});
+
+ it('forces off the flags a discarded worktree makes impossible', async () => {
+ // `openPR` defaults to true and sits one checkbox from `discardWorktree`.
+ // The combination makes the spawner expect a PR that cannot exist (the
+ // worktree is thrown away before any push), which downgrades the run to
+ // `pr-missing` and RETRIES it — up to five agent runs of quota burned on a
+ // job that already did its work. `noCodeOutput` rides along so the prompt
+ // names the real output channel instead of the sentinel.
+ await run({ params: { appId: 'app-1', prompt: 'x', discardWorktree: true, openPR: true, simplify: true }, job: { id: 'j3' }, family, candidate });
+ expect(state.added[0].task).toMatchObject({ openPR: false, simplify: false, noCodeOutput: true });
+ });
});
describe('renderBurnPrompt', () => {
diff --git a/server/services/taskTypeHooks.js b/server/services/taskTypeHooks.js
index 5177fc6661..0b7e763670 100644
--- a/server/services/taskTypeHooks.js
+++ b/server/services/taskTypeHooks.js
@@ -42,7 +42,7 @@
* importing anything, so a normal task type pays ~zero cost.
*/
-import { isFalsyMeta } from './agentState.js';
+import { isFalsyMeta, isTruthyMeta } from './agentState.js';
import { TRACKER_FILING_TASK_TYPES } from '../lib/workTracker.js';
// taskType → () => import('./path/to/hookModule.js'). A module may export either
@@ -192,6 +192,12 @@ export function isNonCommittingCoordinatorTask(task) {
*/
export function declaresNoCommitCriterion(task) {
if (isNonCommittingCoordinatorTask(task)) return true;
+ // A discarded worktree cannot leave a `[task-<id>]` commit behind by
+ // construction — cleanup removes it without merging, and the prompt forbids
+ // committing at all. Scoring the commit check against it marks every
+ // SUCCESSFUL run a validation miss and drags that provider/model's learning
+ // bucket toward 0% — the #2696/#3273 artifact, arriving by a third route.
+ if (isTruthyMeta(task?.metadata?.discardWorktree)) return true;
// Resolved the same way isNonCommittingCoordinatorTask (and the learning
// bucket) resolves it, so a LIVE queue task (`analysisType`) and the archived
// agent projection (`taskAnalysisType`) agree.
diff --git a/server/services/worktreeManager.js b/server/services/worktreeManager.js
index e95bfb46c7..d3cecfe8aa 100644
--- a/server/services/worktreeManager.js
+++ b/server/services/worktreeManager.js
@@ -488,6 +488,12 @@ async function adoptWorktreeUnlocked(agentId, sourceWorkspace, existingWorktreeP
* than deleting it) whenever it still holds commits the default branch doesn't,
* so a retry can resume the work instead of restarting. Used by the FAILED-agent
* cleanup path; the PR path leaves it off so its local branch is still tidied up.
+ * @param {boolean} [options.discardDirt] - remove even when the tree is dirty.
+ * The dirty-abort exists to protect work that might still be wanted; the
+ * throwaway-worktree posture has already declared this tree's contents
+ * worthless (its own prompt invites scratch edits and forbids committing), so
+ * for it the abort protects nothing and instead strands a full checkout per
+ * run, forever. ONLY the discard path may pass this.
*/
export async function removeWorktree(agentId, sourceWorkspace, branchName, options = {}) {
const worktreePath = join(WORKTREES_DIR, agentId);
@@ -528,7 +534,14 @@ export async function removeWorktree(agentId, sourceWorkspace, branchName, optio
warnings.push(`Worktree preserved — git status failed: ${err.message}`);
return { merged: false, removed: false, uncommittedSaved: false, warnings };
}
- if (dirtyFiles) {
+ if (dirtyFiles && options.discardDirt) {
+ // Throwaway posture: the caller has already established that nothing in this
+ // tree is wanted. Log what is being dropped so a surprising loss is at least
+ // traceable, then fall through to removal.
+ const dirt = classifyWorktreeDirt(dirtyFiles);
+ const shown = dirt.realChangePaths.slice(0, DIRT_PATHS_IN_WARNING);
+ if (shown.length) console.log(`🌳 Discarding uncommitted changes in throwaway worktree ${agentId}: ${shown.join(', ')}`);
+ } else if (dirtyFiles) {
// Discard auto-generated lockfile changes that agents don't intend to commit
// (e.g., npm install resolving ^version to exact version in package-lock.json)
const dirt = classifyWorktreeDirt(dirtyFiles);