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

fix: rescue a printed hook payload from output.txt for direct CLI runs, not only the PTY raw.txt spool

[._.]/ Adam Eivy159b8ed41dd4
diff --git a/server/services/agentFinalization.js b/server/services/agentFinalization.js
index 4593fcc81a..28d66aec00 100644
--- a/server/services/agentFinalization.js
+++ b/server/services/agentFinalization.js
@@ -1097,7 +1097,13 @@ async function rescueTranscriptPayload({ agentId, taskType }) {
const isPayload = await getTaskOutputPayloadPredicate(taskType);
if (!isPayload) return null;
const { PATHS, readFileTail } = await import('../lib/fileUtils.js');
- const transcript = await readFileTail(join(PATHS.cosAgents, agentId, 'raw.txt'), TRANSCRIPT_RESCUE_TAIL_BYTES);
+ // A PTY/TUI run spools its terminal to raw.txt; a direct CLI run (every
+ // public-review stage, and any cli-typed provider) has only output.txt.
+ // Reading raw.txt alone made the tool-free Eligibility Gate's printed JSON
+ // invisible, so a valid decision was rejected as eligibility-response-invalid.
+ const agentDir = join(PATHS.cosAgents, agentId);
+ const transcript = await readFileTail(join(agentDir, 'raw.txt'), TRANSCRIPT_RESCUE_TAIL_BYTES)
+ || await readFileTail(join(agentDir, 'output.txt'), TRANSCRIPT_RESCUE_TAIL_BYTES);
if (!transcript) return null;
const { extractSentinelPayloadFromTranscript } = await import('../lib/agentSentinel.js');
const { payload } = await extractSentinelPayloadFromTranscript(transcript, isPayload);
diff --git a/server/services/agentFinalization.transcriptRescue.test.js b/server/services/agentFinalization.transcriptRescue.test.js
index ba0990ebe0..02f628fd26 100644
--- a/server/services/agentFinalization.transcriptRescue.test.js
+++ b/server/services/agentFinalization.transcriptRescue.test.js
@@ -79,14 +79,14 @@ const printedTranscript = (answer = REASONER_ANSWER, { echoSchema = false } = {}
].join('');
let agentId = 0;
-const setupRun = ({ transcript, sentinel = null }) => {
+const setupRun = ({ transcript, sentinel = null, spool = 'raw.txt' }) => {
agentId += 1;
const id = `agent-${agentId}`;
const agentDir = join(TEMP_ROOT, 'cos/agents', id);
const workspace = join(TEMP_ROOT, 'workspaces', id);
mkdirSync(agentDir, { recursive: true });
mkdirSync(workspace, { recursive: true });
- if (transcript !== null) writeFileSync(join(agentDir, 'raw.txt'), transcript);
+ if (transcript !== null) writeFileSync(join(agentDir, spool), transcript);
// The sentinel filename is scoped to the agent instance (doneSentinelName).
if (sentinel !== null) writeFileSync(join(workspace, `.agent-done-${id}`), sentinel);
return { agentId: id, workspacePath: workspace };
@@ -118,6 +118,17 @@ describe('printed-payload transcript rescue (#3640)', () => {
}));
});
+ it('reads output.txt when the run was a direct CLI spawn with no raw.txt spool', async () => {
+ // Every public-review stage spawns the CLI directly (stream-json to
+ // output.txt); only the PTY spawner writes raw.txt. Reading raw.txt alone
+ // rejected the tool-free Eligibility Gate's printed decision as invalid.
+ const hook = await runDispatch({ transcript: printedTranscript(), spool: 'output.txt' });
+
+ expect(hook).toHaveBeenCalledWith(expect.objectContaining({
+ payload: { analysis: 'Nothing worth proposing this cycle.', proposal: null, pause: null },
+ }));
+ });
+
it('prefers the model final answer over an earlier prompt echo of the schema', async () => {
const answer = '{"analysis": "Real answer", "proposal": {"scope": "self-improve", "title": "Do the thing"}}';
const hook = await runDispatch({ transcript: printedTranscript(answer, { echoSchema: true }) });