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(shell): start default sessions after Socket.IO serialization

[._.]/ Adam Eivyf9ca138a5550
diff --git a/server/lib/socketValidation.js b/server/lib/socketValidation.js
index d0cbfc1486..032deee108 100644
--- a/server/lib/socketValidation.js
+++ b/server/lib/socketValidation.js
@@ -72,11 +72,13 @@ export const shellSessionIdSchema = z.object({
// shell:start — every field optional. `providerId` is resolved server-side to a
// launch command; `cwd` / `initialCommand` must be strings so a malformed
// payload never reaches createShellSession or the deferred submit.
+// Socket.IO encodes an explicit undefined argument as null. Normalize both
+// before validateSocketData uses null to signal a validation failure.
export const shellStartSchema = z.object({
cwd: z.string().max(1000).optional(),
initialCommand: z.string().max(10000).optional(),
providerId: z.string().max(200).optional()
-}).nullish();
+}).nullish().transform(options => options ?? {});
// shell:attach — session id + optional claim flag.
// `claim: true` means "attach only if currently unattached or already mine" — used by
diff --git a/server/sockets/shell.test.js b/server/sockets/shell.test.js
index 7d561721f3..457f79c02f 100644
--- a/server/sockets/shell.test.js
+++ b/server/sockets/shell.test.js
@@ -1,4 +1,8 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
+import { createServer } from 'node:http';
+import { once } from 'node:events';
+import { Server } from 'socket.io';
+import { io as connect } from 'socket.io-client';
const createShellSession = vi.fn(() => 'sess-1');
const resizeSession = vi.fn(() => true);
@@ -36,6 +40,29 @@ describe('shell:start payload validation', () => {
expect(createShellSession).toHaveBeenCalledTimes(1);
expect(socket.emit).toHaveBeenCalledWith('shell:started', { sessionId: 'sess-1' });
});
+
+ it('starts the default shell across Socket.IO when the client emits undefined options', async () => {
+ const http = createServer();
+ const server = new Server(http);
+ server.on('connection', registerShellHandlers);
+ let client;
+ try {
+ http.listen(0, '127.0.0.1');
+ await once(http, 'listening');
+ client = connect(`http://127.0.0.1:${http.address().port}`, {
+ transports: ['websocket'], reconnection: false
+ });
+ await once(client, 'connect');
+ const started = once(client, 'shell:started', { signal: AbortSignal.timeout(2000) });
+ // This is the Shell page's empty-options emit: the wire turns undefined into null.
+ client.emit('shell:start', undefined);
+ expect(await started).toEqual([{ sessionId: 'sess-1' }]);
+ expect(createShellSession).toHaveBeenCalledTimes(1);
+ } finally {
+ client?.disconnect();
+ await new Promise(resolve => server.close(resolve));
+ }
+ });
});
describe('shell:resize handler', () => {