Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions docs/features/session-persistence.md
Original file line number Diff line number Diff line change
Expand Up @@ -433,14 +433,26 @@ await client.deleteSession("user-123-task-456");

## Automatic Cleanup: Idle Timeout

The CLI has a built-in 30-minute idle timeout. Sessions without activity are automatically cleaned up:
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.sessionIdleTimeoutSeconds`:

```typescript
const client = new CopilotClient({
sessionIdleTimeoutSeconds: 30 * 60, // 30 minutes
});
```

When a timeout is configured, sessions without activity for that duration are automatically cleaned up. The minimum value is 300 seconds (5 minutes). Set to `0` or omit to disable.

> **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.

```mermaid
flowchart LR
A["⚡ Last Activity"] --> B["⏳ 25 min<br/>timeout_warning"] --> C["🧹 30 min<br/>destroyed"]
A["⚡ Last Activity"] --> B["⏳ ~5 min before<br/>timeout_warning"] --> C["🧹 Timeout<br/>destroyed"]
```

Listen for idle events to know when work completes:
Sessions with active work (running commands, background agents) are always protected from idle cleanup, regardless of the timeout setting.

Listen for idle events to react to session inactivity:

```typescript
session.on("session.idle", (event) => {
Expand Down
11 changes: 11 additions & 0 deletions nodejs/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ export class CopilotClient {
// Default useLoggedInUser to false when githubToken is provided, otherwise true
useLoggedInUser: options.useLoggedInUser ?? (options.githubToken ? false : true),
telemetry: options.telemetry,
sessionIdleTimeoutSeconds: options.sessionIdleTimeoutSeconds ?? 0,
};
Comment on lines 339 to 343
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sessionIdleTimeoutMs is documented as having a minimum of 300000ms, but the client currently forwards any positive value to the runtime without validation. This can lead to unexpected runtime failures or behavior when users pass values < 300000, negative numbers, non-integers, or NaN. Consider validating in the constructor (e.g., finite number, integer, >= 0, and if > 0 then >= 300000) and throwing a clear error when invalid.

Copilot uses AI. Check for mistakes.
}

Expand Down Expand Up @@ -1385,6 +1386,16 @@ export class CopilotClient {
args.push("--no-auto-login");
}

if (
this.options.sessionIdleTimeoutSeconds !== undefined &&
this.options.sessionIdleTimeoutSeconds > 0
) {
args.push(
"--session-idle-timeout",
this.options.sessionIdleTimeoutSeconds.toString()
);
}

// Suppress debug/trace output that might pollute stdout
const envWithoutNodeDebug = { ...this.options.env };
delete envWithoutNodeDebug.NODE_DEBUG;
Expand Down
9 changes: 9 additions & 0 deletions nodejs/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ export interface CopilotClientOptions {
* instead of the server's default local filesystem storage.
*/
sessionFs?: SessionFsConfig;

/**
* Server-wide idle timeout for sessions in seconds.
* Sessions without activity for this duration are automatically cleaned up.
* Set to 0 or omit to disable (sessions live indefinitely).
* Minimum value: 300 (5 minutes).
* @default undefined (disabled)
*/
sessionIdleTimeoutSeconds?: number;
}

/**
Expand Down
Loading