Skip to content

[Feature]: Evaluate forkSession as alternative to /clear for batch isolation #351

@sjnims

Description

@sjnims

Parent Issue

Sub-issue of #344 (Leverage Additional SDK v0.2.25 Capabilities)

Feature Type

SDK integration (Agent SDK)

Problem or Need

Batch isolation currently uses persistSession: true + continue: true + explicit /clear command between scenarios (session-batching.ts:563-608). This adds a round-trip per scenario in a batch. The current approach is battle-tested and provides ~80% overhead reduction vs individual sessions.

Proposed Solution

Evaluate SDK v0.2.25 forkSession option as an alternative to /clear + continue for batch isolation.

Potential benefits:

  • Eliminate the /clear query round-trip, reducing per-scenario overhead
  • Fork semantics may provide better isolation than /clear

Key questions requiring investigation:

  1. Does forkSession fork the subprocess or the conversation state?
  2. How does it interact with enableFileCheckpointing and rewindFiles()?
  3. What are the performance characteristics vs /clear?
  4. Does forking preserve or reset tool state?

Files Affected

  • src/stages/3-execution/session-batching.ts — executeBatch, sendClearCommand, buildScenarioQueryInput
  • src/stages/3-execution/sdk-client.ts — QueryOptions

Risk Assessment

High risk — Session batching is a core optimization (80% overhead reduction). Any regression here impacts all batch execution. The interaction between forkSession, persistSession, continue, and file checkpointing needs careful testing.

Recommended Approach

  1. Create experimental branch for forkSession evaluation
  2. Benchmark against current /clear approach (latency, memory, isolation quality)
  3. Test interaction with file checkpointing
  4. If results are positive, implement as opt-in configuration option
  5. Only consider deprecating /clear approach after extensive production validation

Priority Rationale

Highest potential impact but also highest risk. Current approach works well and is battle-tested. Should be thoroughly evaluated before any production adoption.


🤖 Created with Claude Code

Metadata

Metadata

Assignees

Labels

batch-processingBatch API processingeffort:large> 4 hoursenhancementNew feature or requestperformancePerformance and efficiency improvementspriority:mediumShould be addressedsdk:agentClaude Agent SDK usage (Stage 3)stage:executionStage 3: Agent SDK execution with tool capturestatus:analyzedIssue has been analyzed by Claudestatus:needs-designNeeds design/architecture decision

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions