Skip to content

Commit 7e794c4

Browse files
Add sessionIdleTimeoutMs option to CopilotClientOptions
Add a new optional sessionIdleTimeoutMs field to CopilotClientOptions that allows consumers to configure the server-wide session idle timeout. When set to a positive value, the SDK passes --session-idle-timeout to the CLI process. Sessions have no idle timeout by default (infinite lifetime). The minimum configurable value is 300000ms (5 minutes). Also updates the session persistence documentation to reflect the new default behavior and configuration option. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 883cc02 commit 7e794c4

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

docs/features/session-persistence.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,14 +433,26 @@ await client.deleteSession("user-123-task-456");
433433
434434
## Automatic Cleanup: Idle Timeout
435435

436-
The CLI has a built-in 30-minute idle timeout. Sessions without activity are automatically cleaned up:
436+
By default, sessions have **no idle timeout** and live indefinitely until explicitly disconnected or deleted. You can optionally configure a server-wide idle timeout via `CopilotClientOptions.sessionIdleTimeoutMs`:
437+
438+
```typescript
439+
const client = new CopilotClient({
440+
sessionIdleTimeoutMs: 30 * 60 * 1000, // 30 minutes
441+
});
442+
```
443+
444+
When a timeout is configured, sessions without activity for that duration are automatically cleaned up. The minimum value is 5 minutes (300,000ms). Set to `0` or omit to disable.
445+
446+
> **Note:** This option only applies when the SDK spawns the runtime process. When connecting to an existing server via `cliUrl`, the server's own timeout configuration applies.
437447
438448
```mermaid
439449
flowchart LR
440-
A["⚡ Last Activity"] --> B["⏳ 25 min<br/>timeout_warning"] --> C["🧹 30 min<br/>destroyed"]
450+
A["⚡ Last Activity"] --> B["⏳ ~5 min before<br/>timeout_warning"] --> C["🧹 Timeout<br/>destroyed"]
441451
```
442452

443-
Listen for idle events to know when work completes:
453+
Sessions with active work (running commands, background agents) are always protected from idle cleanup, regardless of the timeout setting.
454+
455+
Listen for idle events to react to session inactivity:
444456

445457
```typescript
446458
session.on("session.idle", (event) => {

nodejs/src/client.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ export class CopilotClient {
339339
// Default useLoggedInUser to false when githubToken is provided, otherwise true
340340
useLoggedInUser: options.useLoggedInUser ?? (options.githubToken ? false : true),
341341
telemetry: options.telemetry,
342+
sessionIdleTimeoutMs: options.sessionIdleTimeoutMs ?? 0,
342343
};
343344
}
344345

@@ -1385,6 +1386,10 @@ export class CopilotClient {
13851386
args.push("--no-auto-login");
13861387
}
13871388

1389+
if (this.options.sessionIdleTimeoutMs !== undefined && this.options.sessionIdleTimeoutMs > 0) {
1390+
args.push("--session-idle-timeout", this.options.sessionIdleTimeoutMs.toString());
1391+
}
1392+
13881393
// Suppress debug/trace output that might pollute stdout
13891394
const envWithoutNodeDebug = { ...this.options.env };
13901395
delete envWithoutNodeDebug.NODE_DEBUG;

nodejs/src/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,15 @@ export interface CopilotClientOptions {
182182
* instead of the server's default local filesystem storage.
183183
*/
184184
sessionFs?: SessionFsConfig;
185+
186+
/**
187+
* Server-wide idle timeout for sessions in milliseconds.
188+
* Sessions without activity for this duration are automatically cleaned up.
189+
* Set to 0 or omit to disable (sessions live indefinitely).
190+
* Minimum value: 300000 (5 minutes).
191+
* @default 0 (disabled)
192+
*/
193+
sessionIdleTimeoutMs?: number;
185194
}
186195

187196
/**

0 commit comments

Comments
 (0)