Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -340,6 +340,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 thread
MackinnonBuck marked this conversation as resolved.
}

Expand Down Expand Up @@ -1414,6 +1415,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 @@ -184,6 +184,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;
Comment thread
MackinnonBuck marked this conversation as resolved.
}
Comment thread
MackinnonBuck marked this conversation as resolved.

/**
Expand Down
Loading