Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

fix(console): open a remote session at its pane size (CHOO-2066) (#223)

Louis Amaudruz304245cb780b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f705f4ce8..00766ffd6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -518,6 +518,18 @@ version of their own to them without also giving them a release of their own.
upstream. **Help → Report Issue** remains the way to send us something; it
opens an issue on this repository (CHOO-2040).
+#### Fixed
+
+- **A session on a remote agent now opens at the size of the pane it opens
+ into**, instead of a fraction of it that only corrected itself when the window
+ was resized or the session was switched away from and back (CHOO-2066). A
+ remote session opens its terminal over SSH, and the renderer mounts and
+ measures its pane partway through that: the measurement arrived after the
+ spawn size had been read and before there was a PTY to resize, so it was
+ discarded and the session kept the 80x24 it was spawned with. Measured
+ dimensions are now kept whether or not a PTY is live yet, and applied to the
+ PTY when it registers.
+
### [0.24.0] - 2026-08-14
#### Added
diff --git a/console/apps/switch-console-desktop/src/main/core/agent-runtime/impl/ssh-agent-runtime.test.ts b/console/apps/switch-console-desktop/src/main/core/agent-runtime/impl/ssh-agent-runtime.test.ts
index b4fe0ab15..9c2560af5 100644
--- a/console/apps/switch-console-desktop/src/main/core/agent-runtime/impl/ssh-agent-runtime.test.ts
+++ b/console/apps/switch-console-desktop/src/main/core/agent-runtime/impl/ssh-agent-runtime.test.ts
@@ -828,6 +828,29 @@ describe('SshAgentRuntime', () => {
expect(provider.isAttached()).toBe(true);
});
+ // Covers a re-open, where a size is already on record: the attach spawns at it
+ // rather than the 80x24 default. It does NOT cover a first open — nothing has
+ // measured the pane by then, and the fix for that is in the registry, which
+ // applies a late-arriving size when the pty registers (CHOO-2066).
+ it('attaches at a size already on record rather than the default', async () => {
+ mockSpawn([]);
+ const provider = sshProvider({ tmux: true });
+ const item = session();
+ const ptySessionId = makeAgentPtySessionId('location-1', item.id);
+
+ ptySessionRegistry.resize(ptySessionId, 203, 51);
+
+ await provider.ensureAttachable(item);
+ await provider.attach();
+
+ expect(openSsh2Pty).toHaveBeenCalledWith(
+ expect.anything(),
+ expect.objectContaining({ cols: 203, rows: 51 })
+ );
+
+ ptySessionRegistry.unregister(ptySessionId);
+ });
+
it('does not report the agent as exited when a session is evicted', async () => {
// The sidebar derives status from hook events; a deliberate detach must not
// look like the agent stopping, or every eviction would flip it to idle.
diff --git a/console/apps/switch-console-desktop/src/main/core/pty/pty-session-registry.test.ts b/console/apps/switch-console-desktop/src/main/core/pty/pty-session-registry.test.ts
index 23bcf95a6..158f668c4 100644
--- a/console/apps/switch-console-desktop/src/main/core/pty/pty-session-registry.test.ts
+++ b/console/apps/switch-console-desktop/src/main/core/pty/pty-session-registry.test.ts
@@ -138,6 +138,42 @@ describe('PtySessionRegistry', () => {
expect(registry.getLastSize('session-1')).toEqual({ cols: 120, rows: 50 });
});
+ it('remembers a resize that arrives before the PTY exists', () => {
+ const registry = new PtySessionRegistry();
+
+ const resized = registry.resize('session-1', 203, 51);
+
+ expect(resized).toBe(false);
+ expect(registry.getLastSize('session-1')).toEqual({ cols: 203, rows: 51 });
+ });
+
+ // The ordering an actual remote attach produces, taken from the logs: the
+ // spawn size is read (nothing recorded yet), the renderer mounts mid-attach
+ // and reports twice while there is still no pty, and only then does the pty
+ // register. Every resize misses, and the session sat at its 80x24 spawn size
+ // until the pane moved (CHOO-2066).
+ it('applies a size reported before the PTY registered once it does', () => {
+ const registry = new PtySessionRegistry();
+ const pty = fakePty();
+
+ expect(registry.getLastSize('session-1')).toBeUndefined();
+ registry.resize('session-1', 105, 34);
+ registry.resize('session-1', 105, 34);
+
+ registry.register('session-1', pty);
+
+ expect(pty.resize).toHaveBeenCalledWith(105, 34);
+ });
+
+ it('leaves a PTY at its spawn size when nothing was reported', () => {
+ const registry = new PtySessionRegistry();
+ const pty = fakePty();
+
+ registry.register('session-1', pty);
+
+ expect(pty.resize).not.toHaveBeenCalled();
+ });
+
it('clears last observed size when preserving output after exit', () => {
const registry = new PtySessionRegistry();
const pty = fakePty();
diff --git a/console/apps/switch-console-desktop/src/main/core/pty/pty-session-registry.ts b/console/apps/switch-console-desktop/src/main/core/pty/pty-session-registry.ts
index 17c4fcfa4..35ae596c6 100644
--- a/console/apps/switch-console-desktop/src/main/core/pty/pty-session-registry.ts
+++ b/console/apps/switch-console-desktop/src/main/core/pty/pty-session-registry.ts
@@ -40,6 +40,16 @@ export class PtySessionRegistry {
this.ptyMap.set(sessionId, pty);
+ // Apply a size that arrived while this pty was still being created.
+ //
+ // A remote session opens its terminal over SSH, and the renderer mounts and
+ // measures its pane partway through: the measurement lands after the spawn
+ // size was read and before there is a pty to resize. Without this the pty
+ // keeps the size it was spawned with — 80x24 in a pane twice that — until
+ // something moves the pane, which is why switching away and back fixed it.
+ const desiredSize = this.lastSizes.get(sessionId);
+ if (desiredSize) pty.resize(desiredSize.cols, desiredSize.rows);
+
let buffer = '';
let flushTimer: ReturnType<typeof setTimeout> | null = null;
@@ -157,10 +167,23 @@ export class PtySessionRegistry {
return this.metadata.get(sessionId);
}
+ /**
+ * Record the dimensions the renderer measured and apply them to the pty.
+ *
+ * The size is remembered whether or not a pty is live, because for a remote
+ * session it routinely is not: its terminal is opened asynchronously by the
+ * attachment pool, long after the renderer measured its pane and reported.
+ * The renderer reports once and then only on an actual pane change, so a size
+ * dropped here is not sent again — the attach falls back to 80x24 and stays
+ * there. Keeping it means the attach spawns at the size the pane already has.
+ *
+ * The return value still reports only whether a live pty was resized, so a
+ * remembered size cannot be mistaken for one that reached a process.
+ */
resize(sessionId: string, cols: number, rows: number): boolean {
+ this.lastSizes.set(sessionId, { cols, rows });
const pty = this.ptyMap.get(sessionId);
if (!pty) return false;
- this.lastSizes.set(sessionId, { cols, rows });
pty.resize(cols, rows);
return true;
}