fix(core): cancel branch snapshot reads (#163)
- commit
- 131edbad16b786ce784dcf000e9fab0f66e566da
- author
- bnema · · 2026-08-31 17:34 UTC
- committer
- GitHub · · 2026-08-31 17:34 UTC
- parent
- 01c3d31
- signature
- GPG Unverified
B5690EEEBB952194The key is unknown - refs
- tag: v0.27.1
2 files · +12 -1
M packages/core/session_log_test.go +11 -0
| @@ -53,6 +53,17 @@ func TestSessionLogProjectionsRejectInvalidRowsConsistently(t *testing.T) { | |||
| 53 | 53 | } | |
| 54 | 54 | } | |
| 55 | 55 | ||
| 56 | + | func TestBranchSessionHonorsCancellationBeforeSnapshotRead(t *testing.T) { | |
| 57 | + | root := t.TempDir() | |
| 58 | + | ctx, cancel := context.WithCancel(context.Background()) | |
| 59 | + | cancel() | |
| 60 | + | ||
| 61 | + | missingParent := filepath.Join(root, "missing.jsonl") | |
| 62 | + | if _, err := branchSession(ctx, missingParent, root, "/workspace", "test", 0, false); !errors.Is(err, context.Canceled) { | |
| 63 | + | t.Fatalf("branchSession error = %v, want context.Canceled", err) | |
| 64 | + | } | |
| 65 | + | } | |
| 66 | + | ||
| 56 | 67 | func TestBranchSessionThreadsCancellationToExtensionStateRead(t *testing.T) { | |
| 57 | 68 | root := t.TempDir() | |
| 58 | 69 | session, err := NewSession(root, "/workspace", "provider", "model", "test") | |
| @@ -53,6 +53,17 @@ func TestSessionLogProjectionsRejectInvalidRowsConsistently(t *testing.T) { | |||||
| 53 | } | 53 | } | ||
| 54 | } | 54 | } | ||
| 55 | 55 | ||||
| 56 | + | func TestBranchSessionHonorsCancellationBeforeSnapshotRead(t *testing.T) { | |||
| 57 | + | root := t.TempDir() | |||
| 58 | + | ctx, cancel := context.WithCancel(context.Background()) | |||
| 59 | + | cancel() | |||
| 60 | + | ||||
| 61 | + | missingParent := filepath.Join(root, "missing.jsonl") | |||
| 62 | + | if _, err := branchSession(ctx, missingParent, root, "/workspace", "test", 0, false); !errors.Is(err, context.Canceled) { | |||
| 63 | + | t.Fatalf("branchSession error = %v, want context.Canceled", err) | |||
| 64 | + | } | |||
| 65 | + | } | |||
| 66 | + | ||||
| 56 | func TestBranchSessionThreadsCancellationToExtensionStateRead(t *testing.T) { | 67 | func TestBranchSessionThreadsCancellationToExtensionStateRead(t *testing.T) { | ||
| 57 | root := t.TempDir() | 68 | root := t.TempDir() | ||
| 58 | session, err := NewSession(root, "/workspace", "provider", "model", "test") | 69 | session, err := NewSession(root, "/workspace", "provider", "model", "test") | ||
M packages/core/session_portable.go +1 -1
| @@ -301,7 +301,7 @@ func branchSession(ctx context.Context, parentPath, root, cwd, version string, u | |||
| 301 | 301 | return "", errors.New("branch: upToMessageIdx must be >= 0") | |
| 302 | 302 | } | |
| 303 | 303 | ||
| 304 | - | snapshot, err := ReadSessionSnapshot(parentPath) | |
| 304 | + | snapshot, err := readSessionSnapshot(ctx, parentPath) | |
| 305 | 305 | if err != nil { | |
| 306 | 306 | return "", fmt.Errorf("branch: read parent snapshot: %w", err) | |
| 307 | 307 | } | |
| @@ -301,7 +301,7 @@ func branchSession(ctx context.Context, parentPath, root, cwd, version string, u | |||||
| 301 | return "", errors.New("branch: upToMessageIdx must be >= 0") | 301 | return "", errors.New("branch: upToMessageIdx must be >= 0") | ||
| 302 | } | 302 | } | ||
| 303 | 303 | ||||
| 304 | - | snapshot, err := ReadSessionSnapshot(parentPath) | 304 | + | snapshot, err := readSessionSnapshot(ctx, parentPath) |
| 305 | if err != nil { | 305 | if err != nil { | ||
| 306 | return "", fmt.Errorf("branch: read parent snapshot: %w", err) | 306 | return "", fmt.Errorf("branch: read parent snapshot: %w", err) | ||
| 307 | } | 307 | } | ||