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): fail a blank repoPath and contain the failure-path callbacks

[._.]/ Adam Eivy8a2ce9cefe16
diff --git a/server/lib/spawnCwd.js b/server/lib/spawnCwd.js
index c4449e4178..60081ded69 100644
--- a/server/lib/spawnCwd.js
+++ b/server/lib/spawnCwd.js
@@ -34,17 +34,30 @@ import { expandHome } from './fileUtils.js';
* @throws {Error} when `workspacePath` was supplied but is not an existing directory
*/
export function resolveSpawnCwd(workspacePath, fallbackRoot, label = 'run') {
- // expandHome so a repoPath saved as `~/Projects/App` resolves instead of
- // hard-failing as "does not exist" — `repoPath` is only validated as a
- // non-empty string, and every other user-supplied-path boundary in the repo
- // expands it too.
- const requested = expandHome(typeof workspacePath === 'string' ? workspacePath.trim() : '');
-
- if (!requested) {
+ // "Nothing was supplied" and "something blank was supplied" are different
+ // answers and must not collapse. `repoPath` is validated only as
+ // `z.string().min(1)`, so an app can hold " " — that is a MISCONFIGURED
+ // workspace, not an absent one. Deciding on the trimmed value would turn it
+ // back into the fallback root and silently run in the PortOS checkout: the
+ // exact bug this module exists to prevent, reachable through the one input
+ // the schema still lets through.
+ const supplied = typeof workspacePath === 'string' && workspacePath.length > 0;
+ if (!supplied) {
console.log(`📂 ${label} cwd: ${fallbackRoot} (no workspace selected)`);
return fallbackRoot;
}
+ // expandHome so a repoPath saved as `~/Projects/App` resolves instead of
+ // hard-failing as "does not exist" — every other user-supplied-path boundary
+ // in the repo expands it too.
+ const requested = expandHome(workspacePath.trim());
+ if (!requested) {
+ throw new Error(
+ `Workspace path is blank: the Repository Path for this app is only whitespace. `
+ + `Set it to the repo folder (Apps → edit → Repository Path) and run again.`
+ );
+ }
+
// Fail loudly instead of silently running in the PortOS checkout. A bad
// repoPath is a configuration error the user can fix; running the agent
// somewhere else and reporting success is not recoverable after the fact.
diff --git a/server/lib/spawnCwd.test.js b/server/lib/spawnCwd.test.js
index e45f83a297..ea0288c792 100644
--- a/server/lib/spawnCwd.test.js
+++ b/server/lib/spawnCwd.test.js
@@ -26,9 +26,16 @@ describe('resolveSpawnCwd', () => {
expect(resolveSpawnCwd(undefined, '/fallback')).toBe('/fallback');
expect(resolveSpawnCwd(null, '/fallback')).toBe('/fallback');
expect(resolveSpawnCwd('', '/fallback')).toBe('/fallback');
- // A whitespace-only value is a blank field, not a real path — it must not
- // reach existsSync and fail as "does not exist".
- expect(resolveSpawnCwd(' ', '/fallback')).toBe('/fallback');
+ });
+
+ // "Nothing supplied" and "something blank supplied" must not collapse.
+ // repoPath is validated as z.string().min(1), so an app CAN hold " ";
+ // treating that as absent hands the run the PortOS root and silently writes
+ // there — the bug this module exists to prevent, through the one input the
+ // schema still allows.
+ it('rejects a whitespace-only workspace instead of falling back', () => {
+ expect(() => resolveSpawnCwd(' ', '/fallback')).toThrow(/blank/);
+ expect(() => resolveSpawnCwd('\t\n ', '/fallback')).toThrow(/Repository Path/);
});
it('logs the effective cwd so a run is never silently misrouted', () => {
diff --git a/server/services/runner.js b/server/services/runner.js
index 535e64efbe..af6959a21e 100644
--- a/server/services/runner.js
+++ b/server/services/runner.js
@@ -146,11 +146,16 @@ export async function resolveRunCwd({ runId, workspacePath, label, startTime = D
return { cwd: resolveSpawnCwd(workspacePath, PATHS.root, label) };
} catch (err) {
const message = `❌ ${err.message}`;
- onData?.(message);
+ // Settle the caller's callbacks through the same guard the close handler
+ // uses. A throwing (or rejecting) onComplete here would reject
+ // resolveRunCwd itself AFTER the failed run was already persisted — and
+ // since /runs never awaits its executor, that lands as the unhandled
+ // rejection + hung-looking run this helper exists to prevent.
+ safeSettle(() => onData?.(message), 'onData');
const failure = await finalizeRunRecord({
runId, output: message, exitCode: null, success: false, error: err.message, startTime,
});
- onComplete?.(failure);
+ safeSettle(() => onComplete?.(failure), 'onComplete');
return { failure };
}
}
diff --git a/server/services/runner.test.js b/server/services/runner.test.js
index e8a717e98f..2f536b5a4f 100644
--- a/server/services/runner.test.js
+++ b/server/services/runner.test.js
@@ -770,3 +770,52 @@ describe('executeCliRun — workspace validation (#3180)', () => {
expect(onComplete.mock.calls[0][0]).toMatchObject({ success: false });
});
});
+
+describe('resolveRunCwd — callback containment (#3180)', () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ setAIToolkit(fakeToolkit(), { dataDir: '/tmp/test-runner' });
+ });
+
+ // /runs never awaits its executor, so a throwing onComplete here would reject
+ // resolveRunCwd AFTER the failed run was persisted — landing as the unhandled
+ // rejection and hung-looking run this helper exists to prevent.
+ it('does not reject when the caller onComplete throws on the failure path', async () => {
+ const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
+ const onComplete = vi.fn(() => { throw new Error('caller exploded'); });
+
+ await expect(runner.resolveRunCwd({
+ runId: 'run-cb-throws',
+ workspacePath: '/definitely/not/a/real/repo/path',
+ label: 'Run cb',
+ onComplete,
+ })).resolves.toMatchObject({ failure: expect.objectContaining({ success: false }) });
+
+ expect(onComplete).toHaveBeenCalledTimes(1);
+ errSpy.mockRestore();
+ });
+
+ it('does not reject when the caller onComplete rejects asynchronously', async () => {
+ const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
+ const onComplete = vi.fn(async () => { throw new Error('async caller exploded'); });
+
+ await expect(runner.resolveRunCwd({
+ runId: 'run-cb-rejects',
+ workspacePath: '/definitely/not/a/real/repo/path',
+ label: 'Run cb2',
+ onComplete,
+ })).resolves.toBeTruthy();
+ errSpy.mockRestore();
+ });
+
+ // The whitespace-only repoPath z.string().min(1) still lets through.
+ it('fails the run for a whitespace-only workspace rather than using the root', async () => {
+ const onComplete = vi.fn();
+ const { failure, cwd } = await runner.resolveRunCwd({
+ runId: 'run-blank-ws', workspacePath: ' ', label: 'Run blank', onComplete,
+ });
+ expect(cwd).toBeUndefined();
+ expect(failure).toMatchObject({ success: false });
+ expect(failure.error).toMatch(/blank/);
+ });
+});