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 (codex): surface pre-onComplete finish() throw to the caller so it settles

[._.]/ Adam Eivy4dc00b590b19
diff --git a/server/lib/tuiPromptRunner.js b/server/lib/tuiPromptRunner.js
index 6d87009158..0498182ba2 100644
--- a/server/lib/tuiPromptRunner.js
+++ b/server/lib/tuiPromptRunner.js
@@ -324,6 +324,25 @@ ${prompt}`;
onComplete?.({ ...metadata, text: responseText, usedResponseFile, outputTruncated: outputBufferTruncated });
} catch (err) {
console.error(`❌ TUI run ${runId} finish() failed: ${err?.message || err}`);
+ // A step BEFORE onComplete threw, so the caller's onComplete-driven
+ // settle never fired. executeProviderRunOnce (promptRunner.js) settles
+ // its OUTER Promise only via onComplete (→ safeReject) or the returned
+ // promise rejecting — and our try/finally always resolves (never
+ // rejects), so `.catch(safeReject)` won't fire either. Without this,
+ // resolving the inner promise leaves the central-prompt/pipeline caller
+ // pending forever — the exact hang this patch exists to prevent. Deliver
+ // failure metadata so onComplete → safeReject settles the caller. Guard
+ // the callback itself: if IT was the throw source, don't re-throw out of
+ // finish() (which is un-awaited — an escape would become an unhandled
+ // rejection) and still fall through to resolve().
+ try {
+ onComplete?.({
+ runId, success: false, exitCode, error: `finish() failed: ${err?.message || err}`,
+ duration: Date.now() - startTime, completionReason: reason,
+ });
+ } catch (cbErr) {
+ console.error(`❌ TUI run ${runId} onComplete threw during finish() error handling: ${cbErr?.message || cbErr}`);
+ }
} finally {
resolve();
}
diff --git a/server/lib/tuiPromptRunner.test.js b/server/lib/tuiPromptRunner.test.js
index 699888595b..912946ca6e 100644
--- a/server/lib/tuiPromptRunner.test.js
+++ b/server/lib/tuiPromptRunner.test.js
@@ -742,9 +742,17 @@ describe('executeTuiRun', () => {
await expect(promise).resolves.toBeUndefined();
expect(console.error).toHaveBeenCalledWith(expect.stringContaining('finish() failed'));
- // The throw happens before onComplete is reached in finish()'s body,
- // so onComplete must never fire for this run.
- expect(onComplete).not.toHaveBeenCalled();
+ // The throw happens before onComplete is reached in finish()'s normal
+ // path, but resolving the inner promise alone is not enough: the sole
+ // caller (executeProviderRunOnce) settles its OUTER promise only via
+ // onComplete (→ safeReject) or a rejected promise. Since finish() always
+ // resolves, the catch must still surface the failure through onComplete
+ // with failure metadata, or the pipeline/central-prompt caller hangs
+ // forever despite the inner promise settling.
+ expect(onComplete).toHaveBeenCalledWith(expect.objectContaining({
+ success: false,
+ error: expect.stringContaining('finish() failed'),
+ }));
});
it('finishes with reason "killed" and surfaces the signal in the error when the PTY is terminated', async () => {