The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 01:45 UTC
fix(claude): show automatic compaction while it runs (#15631)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
maria committed
Oct 19, 2026 at 18:07 UTC
fc21184afbb85604660f459ca43bbbe55ad020e4
6 files changed
+477
-43
apps/mobile/src/lib/threadActivity.test.ts
+9
-13
@@ -1740,9 +1740,14 @@ describe("retained v2 feed presentation", () => {
1740
expect(afterPresentation[1]).toBe(beforePresentation[1]);
1741
});
1742
1743
- it.each(["running", "completed", "interrupted"] as const)(
1744
- "uses the compaction row as the live activity only while %s",
1745
- (status) => {
1743
+ it.each([
1744
+ { status: "running", summary: "Compacting context" },
1745
+ { status: "completed", summary: "Context compacted 899K → 19K tokens" },
1746
+ { status: "failed", summary: "Context compaction failed" },
1747
+ { status: "interrupted", summary: "Context compaction stopped" },
1748
+ ] as const)(
1749
+ "uses the compaction row as the live activity only while $status",
1750
+ ({ status, summary }) => {
1751
const compact = projected(
1752
{
1753
...base("compacted", "2026-06-20T00:00:02.000Z", 1),
@@ -1769,16 +1774,7 @@ describe("retained v2 feed presentation", () => {
1774
);
1775
expect(rows.some((row) => row.type === "thinking")).toBe(status !== "running");
1776
expect(rows.find((row) => row.type === "activity-group")).toMatchObject({
1772
- activities: [
1773
- {
1774
- summary:
1775
- status === "running"
1776
- ? "Compacting context"
1777
- : status === "completed"
1778
- ? "Context compacted 899K → 19K tokens"
1779
- : "Context compacted",
1780
- },
1781
- ],
1777
+ activities: [{ summary }],
1778
});
1779
},
1780
);
apps/mobile/src/state/use-thread-composer-state.ts
+12
-1
@@ -334,6 +334,14 @@ export function useThreadComposerState() {
334
if (queuedCompact) return true;
335
const activeRunId = selectedThreadRuntime?.activeRunId;
336
if (!activeRunId || !threadRuntimeIsActive(selectedThreadRuntime)) return false;
337
+ if (
338
+ selectedThreadVisibleTurnItems.some(
339
+ ({ item }) =>
340
+ item.runId === activeRunId && item.type === "compaction" && item.status === "running",
341
+ )
342
+ ) {
343
+ return true;
344
+ }
345
const compactMessage = selectedThreadVisibleTurnItems.findLast(
346
({ item }) =>
347
item.runId === activeRunId &&
@@ -346,7 +354,10 @@ export function useThreadComposerState() {
354
({ item }) =>
355
item.runId === activeRunId &&
356
item.type === "compaction" &&
349
- (item.status === "completed" || item.status === "failed"),
357
+ (item.status === "completed" ||
358
+ item.status === "failed" ||
359
+ item.status === "interrupted" ||
360
+ item.status === "cancelled"),
361
);
362
})();
363
// A compacting turn cannot take steering input, so follow-ups queue meanwhile.
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+343
-1
@@ -3705,6 +3705,13 @@ describe("ClaudeAdapterV2 background wake turns", () => {
3705
}),
3706
]
3707
: []),
3708
+ claudeSdkFrame({
3709
+ type: "system",
3710
+ subtype: "status",
3711
+ status: "compacting",
3712
+ uuid: "00000000-0000-4000-8000-000000000610",
3713
+ session_id: WAKE_NATIVE_SESSION,
3714
+ }),
3715
claudeSdkFrame({
3716
type: "system",
3717
subtype: "status",
@@ -3716,10 +3723,44 @@ describe("ClaudeAdapterV2 background wake turns", () => {
3723
uuid: "00000000-0000-4000-8000-000000000612",
3724
session_id: WAKE_NATIVE_SESSION,
3725
}),
3719
- compact ? claudeSdkFrame({ ...result, local_command: "compact" }) : result,
3726
+ claudeSdkFrame({
3727
+ type: "system",
3728
+ subtype: "informational",
3729
+ content: "Compaction finished; turn continues.",
3730
+ level: "warning",
3731
+ uuid: "00000000-0000-4000-8000-000000000614",
3732
+ session_id: WAKE_NATIVE_SESSION,
3733
+ }),
3734
]);
3735
+ yield* Queue.take(harness.systemNoticeReceipts);
3736
+ const updates = harness.events.flatMap((event) =>
3737
+ event.type === "turn_item.updated" && event.turnItem.type === "compaction"
3738
+ ? [event.turnItem]
3739
+ : [],
3740
+ );
3741
+ assert.lengthOf(updates, 2);
3742
+ const [running, settled] = updates;
3743
+ assert.equal(running?.status, "running");
3744
+ assert.equal(settled?.status, compaction === "success" ? "completed" : "failed");
3745
+ assert.equal(settled?.id, running?.id);
3746
+ assert.equal(settled?.ordinal, running?.ordinal);
3747
+ assert.deepEqual(settled?.startedAt, running?.startedAt);
3748
+ assert.isNotNull(settled?.completedAt);
3749
+ assert.isEmpty(harness.terminalEvents());
3750
3751
+ yield* Queue.offer(
3752
+ harness.sdkMessages,
3753
+ compact ? claudeSdkFrame({ ...result, local_command: "compact" }) : result,
3754
+ );
3755
const terminal = yield* Queue.take(harness.terminalReceipts);
3756
+ assert.deepEqual(
3757
+ harness.events.flatMap((event) =>
3758
+ event.type === "turn_item.updated" && event.turnItem.type === "compaction"
3759
+ ? [event.turnItem]
3760
+ : [],
3761
+ ),
3762
+ updates,
3763
+ );
3764
assert.equal(terminal.status, status);
3765
if (terminal.status !== "failed") return;
3766
assert.equal(terminal.failure.class, "usage_limit");
@@ -4443,6 +4484,307 @@ describe("ClaudeAdapterV2 background wake turns", () => {
4484
),
4485
);
4486
4487
+ it.effect("shows automatic compaction before its boundary and completes the same item", () =>
4488
+ Effect.gen(function* () {
4489
+ const harness = yield* makeWakeHarness;
4490
+ const observeCompactions = Effect.fnUntraced(function* (uuid: string) {
4491
+ // A later notice receipt confirms the event subscriber consumed preceding updates.
4492
+ yield* Queue.offer(
4493
+ harness.sdkMessages,
4494
+ claudeSdkFrame({
4495
+ type: "system",
4496
+ subtype: "informational",
4497
+ content: "Context checkpoint",
4498
+ level: "warning",
4499
+ session_id: WAKE_NATIVE_SESSION,
4500
+ uuid,
4501
+ }),
4502
+ );
4503
+ yield* Queue.take(harness.systemNoticeReceipts);
4504
+ return harness.events.flatMap((event) =>
4505
+ event.type === "turn_item.updated" && event.turnItem.type === "compaction"
4506
+ ? [event.turnItem]
4507
+ : [],
4508
+ );
4509
+ });
4510
+ yield* harness.runtime.startTurn(
4511
+ makeClaudeTestTurnInput({
4512
+ threadId: harness.threadId,
4513
+ providerThread: harness.providerThread,
4514
+ now: yield* DateTime.now,
4515
+ attemptId: RunAttemptId.make("claude-auto-compact-attempt"),
4516
+ text: "Continue working.",
4517
+ attachments: [],
4518
+ }),
4519
+ );
4520
+ for (const index of [1, 2]) {
4521
+ yield* harness.offerAndWait(
4522
+ claudeSdkFrame({
4523
+ type: "system",
4524
+ subtype: "status",
4525
+ status: "compacting",
4526
+ uuid: `00000000-0000-4000-8000-00000000021${index}`,
4527
+ session_id: WAKE_NATIVE_SESSION,
4528
+ }),
4529
+ );
4530
+ }
4531
+ const beforeBoundary = yield* observeCompactions("00000000-0000-4000-8000-000000000215");
4532
+ assert.lengthOf(beforeBoundary, 1);
4533
+ const running = beforeBoundary[0]!;
4534
+ assert.equal(running.status, "running");
4535
+ assert.isNull(running.completedAt);
4536
+ assert.isNotNull(running.startedAt);
4537
+
4538
+ yield* TestClock.adjust(1_000);
4539
+ yield* harness.offerAndWait(
4540
+ claudeSdkFrame({
4541
+ type: "system",
4542
+ subtype: "status",
4543
+ status: null,
4544
+ compact_result: "success",
4545
+ uuid: "00000000-0000-4000-8000-000000000222",
4546
+ session_id: WAKE_NATIVE_SESSION,
4547
+ }),
4548
+ );
4549
+ const reported = yield* observeCompactions("00000000-0000-4000-8000-000000000223");
4550
+ assert.lengthOf(reported, 2);
4551
+ assert.equal(reported[1]?.id, running.id);
4552
+ assert.equal(reported[1]?.status, "completed");
4553
+ assert.isUndefined(reported[1]?.afterTokenCount);
4554
+ assert.isEmpty(harness.terminalEvents());
4555
+ yield* TestClock.adjust(1_000);
4556
+ yield* harness.offerAndWait(
4557
+ claudeSdkFrame({
4558
+ type: "system",
4559
+ subtype: "compact_boundary",
4560
+ compact_metadata: { trigger: "auto", pre_tokens: 1500, post_tokens: 400 },
4561
+ uuid: "00000000-0000-4000-8000-000000000213",
4562
+ session_id: WAKE_NATIVE_SESSION,
4563
+ }),
4564
+ );
4565
+ const afterBoundary = yield* observeCompactions("00000000-0000-4000-8000-000000000216");
4566
+ assert.lengthOf(afterBoundary, 3);
4567
+ const completed = afterBoundary[2]!;
4568
+ assert.equal(completed.status, "completed");
4569
+ assert.equal(completed.id, running.id);
4570
+ assert.equal(completed.ordinal, running.ordinal);
4571
+ assert.deepEqual(completed.startedAt, running.startedAt);
4572
+ assert.equal(completed.beforeTokenCount, 1500);
4573
+ assert.equal(completed.afterTokenCount, 400);
4574
+ assert.deepEqual(completed.completedAt, reported[1]?.completedAt);
4575
+
4576
+ yield* harness.offerAndWait(
4577
+ claudeSdkFrame({
4578
+ type: "system",
4579
+ subtype: "compact_boundary",
4580
+ compact_metadata: { trigger: "manual", pre_tokens: 2000, post_tokens: 500 },
4581
+ uuid: "00000000-0000-4000-8000-000000000217",
4582
+ session_id: WAKE_NATIVE_SESSION,
4583
+ }),
4584
+ );
4585
+ yield* harness.offerAndWait(
4586
+ claudeSdkFrame({
4587
+ type: "system",
4588
+ subtype: "status",
4589
+ status: "compacting",
4590
+ uuid: "00000000-0000-4000-8000-000000000218",
4591
+ session_id: WAKE_NATIVE_SESSION,
4592
+ }),
4593
+ );
4594
+ const nextCompactions = yield* observeCompactions("00000000-0000-4000-8000-000000000219");
4595
+ assert.lengthOf(nextCompactions, 5);
4596
+ const boundaryOnly = nextCompactions[3]!;
4597
+ const nextRunning = nextCompactions[4]!;
4598
+ assert.equal(boundaryOnly.status, "completed");
4599
+ assert.notEqual(boundaryOnly.id, completed.id);
4600
+ assert.isAbove(boundaryOnly.ordinal, completed.ordinal);
4601
+ assert.equal(boundaryOnly.beforeTokenCount, 2000);
4602
+ assert.equal(boundaryOnly.afterTokenCount, 500);
4603
+ assert.equal(nextRunning.status, "running");
4604
+ assert.notEqual(nextRunning.id, boundaryOnly.id);
4605
+ assert.isAbove(nextRunning.ordinal, boundaryOnly.ordinal);
4606
+
4607
+ yield* harness.offerAndWait(
4608
+ claudeSdkFrame({
4609
+ type: "system",
4610
+ subtype: "status",
4611
+ status: null,
4612
+ permissionMode: "default",
4613
+ uuid: "00000000-0000-4000-8000-000000000233",
4614
+ session_id: WAKE_NATIVE_SESSION,
4615
+ }),
4616
+ );
4617
+ assert.deepEqual(
4618
+ yield* observeCompactions("00000000-0000-4000-8000-000000000234"),
4619
+ nextCompactions,
4620
+ );
4621
+
4622
+ let retryRunning = nextRunning;
4623
+ for (const [index, outcome] of [
4624
+ { compact_result: "failed", compact_error: "Temporary compaction failure." },
4625
+ {},
4626
+ ].entries()) {
4627
+ yield* harness.offerAndWait(
4628
+ claudeSdkFrame({
4629
+ type: "system",
4630
+ subtype: "status",
4631
+ status: null,
4632
+ ...outcome,
4633
+ uuid: `00000000-0000-4000-8000-00000000024${index}`,
4634
+ session_id: WAKE_NATIVE_SESSION,
4635
+ }),
4636
+ );
4637
+ const stopped = yield* observeCompactions(`00000000-0000-4000-8000-00000000025${index}`);
4638
+ assert.lengthOf(stopped, 6 + index * 2);
4639
+ const settled = stopped.at(-1)!;
4640
+ assert.equal(settled.id, retryRunning.id);
4641
+ assert.equal(settled.ordinal, retryRunning.ordinal);
4642
+ assert.deepEqual(settled.startedAt, retryRunning.startedAt);
4643
+ assert.equal(
4644
+ settled.status,
4645
+ outcome.compact_result === "failed" ? "failed" : "interrupted",
4646
+ );
4647
+ assert.equal(
4648
+ settled.title,
4649
+ outcome.compact_result === "failed"
4650
+ ? "Context compaction failed"
4651
+ : "Context compaction stopped",
4652
+ );
4653
+ assert.isNotNull(settled.completedAt);
4654
+ assert.isEmpty(harness.terminalEvents());
4655
+
4656
+ yield* harness.offerAndWait(
4657
+ claudeSdkFrame({
4658
+ type: "system",
4659
+ subtype: "status",
4660
+ status: "compacting",
4661
+ uuid: `00000000-0000-4000-8000-00000000026${index}`,
4662
+ session_id: WAKE_NATIVE_SESSION,
4663
+ }),
4664
+ );
4665
+ const retried = yield* observeCompactions(`00000000-0000-4000-8000-00000000027${index}`);
4666
+ assert.lengthOf(retried, stopped.length + 1);
4667
+ retryRunning = retried.at(-1)!;
4668
+ assert.equal(retryRunning.status, "running");
4669
+ assert.notEqual(retryRunning.id, settled.id);
4670
+ assert.isAbove(retryRunning.ordinal, settled.ordinal);
4671
+ }
4672
+
4673
+ yield* harness.offerAndWait(
4674
+ claudeSdkFrame({
4675
+ type: "system",
4676
+ subtype: "compact_boundary",
4677
+ compact_metadata: { trigger: "auto", pre_tokens: 3000, post_tokens: 600 },
4678
+ uuid: "00000000-0000-4000-8000-000000000220",
4679
+ session_id: WAKE_NATIVE_SESSION,
4680
+ }),
4681
+ );
4682
+ const allCompactions = yield* observeCompactions("00000000-0000-4000-8000-000000000221");
4683
+ assert.lengthOf(allCompactions, 10);
4684
+ assert.equal(allCompactions[9]?.id, retryRunning.id);
4685
+ assert.equal(allCompactions[9]?.ordinal, retryRunning.ordinal);
4686
+ assert.equal(allCompactions[9]?.status, "completed");
4687
+ assert.equal(allCompactions[9]?.beforeTokenCount, 3000);
4688
+ assert.equal(allCompactions[9]?.afterTokenCount, 600);
4689
+
4690
+ yield* Queue.offer(
4691
+ harness.sdkMessages,
4692
+ makeResultFrame({
4693
+ uuid: "00000000-0000-4000-8000-000000000214",
4694
+ result: "Work complete.",
4695
+ }),
4696
+ );
4697
+ yield* Queue.take(harness.terminalReceipts);
4698
+ assert.deepEqual(
4699
+ harness.events.flatMap((event) =>
4700
+ event.type === "turn_item.updated" && event.turnItem.type === "compaction"
4701
+ ? [event.turnItem]
4702
+ : [],
4703
+ ),
4704
+ allCompactions,
4705
+ );
4706
+ }).pipe(
4707
+ Effect.scoped,
4708
+ Effect.provide(
4709
+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
4710
+ ),
4711
+ ),
4712
+ );
4713
+
4714
+ it.effect.each([
4715
+ { outcome: "result", turnStatus: "completed", itemStatus: "failed" },
4716
+ { outcome: "interrupt", turnStatus: "interrupted", itemStatus: "interrupted" },
4717
+ { outcome: "query_exit", turnStatus: "failed", itemStatus: "failed" },
4718
+ ] as const)(
4719
+ "settles unfinished compaction before the $outcome terminal receipt",
4720
+ ({ outcome, turnStatus, itemStatus }) =>
4721
+ Effect.gen(function* () {
4722
+ const harness = yield* makeWakeHarnessWithOptions({
4723
+ close: (sdkMessages) => Queue.shutdown(sdkMessages),
4724
+ });
4725
+ const attemptId = RunAttemptId.make(`claude-compact-${outcome}`);
4726
+ yield* harness.runtime.startTurn(
4727
+ makeClaudeTestTurnInput({
4728
+ threadId: harness.threadId,
4729
+ providerThread: harness.providerThread,
4730
+ now: yield* DateTime.now,
4731
+ attemptId,
4732
+ text: "Continue.",
4733
+ attachments: [],
4734
+ }),
4735
+ );
4736
+ yield* harness.offerAndWait(
4737
+ claudeSdkFrame({
4738
+ type: "system",
4739
+ subtype: "status",
4740
+ status: "compacting",
4741
+ uuid: "00000000-0000-4000-8000-000000000221",
4742
+ session_id: WAKE_NATIVE_SESSION,
4743
+ }),
4744
+ );
4745
+ if (outcome === "query_exit") {
4746
+ yield* Queue.shutdown(harness.sdkMessages);
4747
+ } else if (outcome === "interrupt") {
4748
+ const idAllocator = yield* IdAllocator.IdAllocatorV2;
4749
+ yield* harness.runtime.interruptTurn({
4750
+ providerThread: harness.providerThread,
4751
+ providerTurnId: idAllocator.derive.providerTurn({
4752
+ driver: ClaudeAdapterV2.CLAUDE_PROVIDER,
4753
+ nativeTurnId: `turn:${attemptId}`,
4754
+ }),
4755
+ });
4756
+ } else {
4757
+ yield* Queue.offer(
4758
+ harness.sdkMessages,
4759
+ makeResultFrame({
4760
+ uuid: "00000000-0000-4000-8000-000000000222",
4761
+ result: "Stopped before the boundary.",
4762
+ }),
4763
+ );
4764
+ }
4765
+ const terminal = yield* Queue.take(harness.terminalReceipts);
4766
+ assert.equal(terminal.status, turnStatus);
4767
+ const updates = harness.events.flatMap((event) =>
4768
+ event.type === "turn_item.updated" && event.turnItem.type === "compaction"
4769
+ ? [event.turnItem]
4770
+ : [],
4771
+ );
4772
+ assert.lengthOf(updates, 2);
4773
+ const [running, settled] = updates;
4774
+ assert.equal(running?.status, "running");
4775
+ assert.equal(settled?.status, itemStatus);
4776
+ assert.equal(settled?.id, running?.id);
4777
+ assert.equal(settled?.ordinal, running?.ordinal);
4778
+ assert.deepEqual(settled?.startedAt, running?.startedAt);
4779
+ assert.isNotNull(settled?.completedAt);
4780
+ }).pipe(
4781
+ Effect.scoped,
4782
+ Effect.provide(
4783
+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
4784
+ ),
4785
+ ),
4786
+ );
4787
+
4788
it.effect("titles Claude reads, searches, and skills on tool completion", () =>
4789
Effect.gen(function* () {
4790
const harness = yield* makeWakeHarness;
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+98
-25
@@ -3044,6 +3044,8 @@ interface ActiveClaudeTurnContext {
3044
// compaction makes the usage stale (null) without forgetting the request.
3045
streamUsage: { readonly messageId: string; usage: ClaudeMessageUsage | null } | null;
3046
readonly toolCalls: Map<string, ActiveClaudeToolCall>;
3047
+ // A successful status can precede the boundary that supplies its token counts.
3048
+ compaction: Extract<OrchestrationV2TurnItem, { type: "compaction" }> | null;
3049
readonly ignoredTaskIds: Set<string>;
3050
readonly announcedUsageLimits: Set<string>;
3051
authenticationFailureMessage: string | undefined;
@@ -6050,6 +6052,23 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
6052
readonly result?: SDKResultMessage;
6053
}) {
6054
yield* reasoningDeltas.flushTurn(input.context.nativeTurnId);
6055
+ if (input.context.compaction?.status === "running") {
6056
+ yield* emitProviderEvent({
6057
+ type: "turn_item.updated",
6058
+ driver: CLAUDE_PROVIDER,
6059
+ turnItem: {
6060
+ ...input.context.compaction,
6061
+ status: input.status === "completed" ? "failed" : input.status,
6062
+ title:
6063
+ input.status === "completed" || input.status === "failed"
6064
+ ? "Context compaction failed"
6065
+ : "Context compaction stopped",
6066
+ completedAt: input.completedAt,
6067
+ updatedAt: input.completedAt,
6068
+ },
6069
+ });
6070
+ }
6071
+ input.context.compaction = null;
6072
if (input.status !== "completed") {
6073
const liveQuery = yield* Ref.get(queryContext);
6074
for (const [taskId, subagent] of yield* Ref.get(sessionSubagentsByTaskId)) {
@@ -7119,16 +7138,86 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
7138
if (
7139
message.type === "system" &&
7140
message.subtype === "status" &&
7122
- message.compact_result !== undefined
7141
+ (message.compact_result !== undefined ||
7142
+ (message.status === null && message.permissionMode === undefined))
7143
) {
7124
- context.compactionFailure =
7125
- message.compact_result === "failed" ? { message: message.compact_error } : null;
7144
+ if (message.compact_result !== undefined) {
7145
+ context.compactionFailure =
7146
+ message.compact_result === "failed" ? { message: message.compact_error } : null;
7147
+ }
7148
+ if (context.compaction?.status === "running") {
7149
+ const now = yield* DateTime.now;
7150
+ context.compaction = {
7151
+ ...context.compaction,
7152
+ status:
7153
+ message.compact_result === "success"
7154
+ ? "completed"
7155
+ : message.compact_result === "failed"
7156
+ ? "failed"
7157
+ : "interrupted",
7158
+ title:
7159
+ message.compact_result === "success"
7160
+ ? "Context compacted"
7161
+ : message.compact_result === "failed"
7162
+ ? "Context compaction failed"
7163
+ : "Context compaction stopped",
7164
+ completedAt: now,
7165
+ updatedAt: now,
7166
+ };
7167
+ yield* emitProviderEvent({
7168
+ type: "turn_item.updated",
7169
+ driver: CLAUDE_PROVIDER,
7170
+ turnItem: context.compaction,
7171
+ });
7172
+ if (message.compact_result !== "success") context.compaction = null;
7173
+ }
7174
}
7175
7128
- if (message.type === "system" && message.subtype === "compact_boundary") {
7129
- if (context.streamUsage !== null) context.streamUsage.usage = null;
7176
+ if (
7177
+ message.type === "system" &&
7178
+ (message.subtype === "compact_boundary" ||
7179
+ (message.subtype === "status" && message.status === "compacting"))
7180
+ ) {
7181
+ if (message.subtype === "status" && context.compaction?.status === "running") return;
7182
const now = yield* DateTime.now;
7183
const nativeItemId = message.uuid;
7184
+ const compaction =
7185
+ (message.subtype === "compact_boundary" ? context.compaction : null) ??
7186
+ ({
7187
+ id: idAllocator.derive.turnItemFromProviderItem({
7188
+ driver: CLAUDE_PROVIDER,
7189
+ nativeItemId,
7190
+ }),
7191
+ threadId: context.input.threadId,
7192
+ runId: context.input.runId,
7193
+ nodeId: context.input.rootNodeId,
7194
+ providerThreadId: context.input.providerThread.id,
7195
+ providerTurnId: context.providerTurnId,
7196
+ nativeItemRef: {
7197
+ driver: CLAUDE_PROVIDER,
7198
+ nativeId: nativeItemId,
7199
+ strength: "strong",
7200
+ },
7201
+ parentItemId: null,
7202
+ ordinal: yield* resolveItemOrdinal(context, nativeItemId),
7203
+ type: "compaction",
7204
+ driver: CLAUDE_PROVIDER,
7205
+ status: "running",
7206
+ title: "Compacting context",
7207
+ startedAt: now,
7208
+ completedAt: null,
7209
+ updatedAt: now,
7210
+ } satisfies OrchestrationV2TurnItem);
7211
+ if (message.subtype === "status") {
7212
+ context.compaction = compaction;
7213
+ yield* emitProviderEvent({
7214
+ type: "turn_item.updated",
7215
+ driver: CLAUDE_PROVIDER,
7216
+ turnItem: compaction,
7217
+ });
7218
+ return;
7219
+ }
7220
+ if (context.streamUsage !== null) context.streamUsage.usage = null;
7221
const postTokens = message.compact_metadata.post_tokens;
7222
const afterTokenCount =
7223
typeof postTokens === "number" && Number.isFinite(postTokens) && postTokens > 0
@@ -7165,28 +7254,10 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
7254
type: "turn_item.updated",
7255
driver: CLAUDE_PROVIDER,
7256
turnItem: {
7168
- id: idAllocator.derive.turnItemFromProviderItem({
7169
- driver: CLAUDE_PROVIDER,
7170
- nativeItemId,
7171
- }),
7172
- threadId: context.input.threadId,
7173
- runId: context.input.runId,
7174
- nodeId: context.input.rootNodeId,
7175
- providerThreadId: context.input.providerThread.id,
7176
- providerTurnId: context.providerTurnId,
7177
- nativeItemRef: {
7178
- driver: CLAUDE_PROVIDER,
7179
- nativeId: nativeItemId,
7180
- strength: "strong",
7181
- },
7182
- parentItemId: null,
7183
- ordinal: yield* resolveItemOrdinal(context, nativeItemId),
7184
- type: "compaction",
7185
- driver: CLAUDE_PROVIDER,
7257
+ ...compaction,
7258
status: "completed",
7259
title: "Context compacted",
7188
- startedAt: now,
7189
- completedAt: now,
7260
+ completedAt: compaction.completedAt ?? now,
7261
updatedAt: now,
7262
...(message.compact_metadata.pre_tokens === undefined
7263
? {}
@@ -7194,6 +7265,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
7265
...(afterTokenCount === undefined ? {} : { afterTokenCount }),
7266
},
7267
});
7268
+ context.compaction = null;
7269
return;
7270
}
7271
@@ -8727,6 +8799,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
8799
},
8800
streamUsage: null,
8801
toolCalls: new Map(),
8802
+ compaction: null,
8803
ignoredTaskIds: new Set(),
8804
announcedUsageLimits: new Set(),
8805
authenticationFailureMessage: undefined,
apps/web/src/components/ChatView.tsx
+12
-3
@@ -2518,12 +2518,21 @@ export default function ChatView(props: ChatViewProps) {
2518
({ item }) =>
2519
item.type === "compaction" &&
2520
item.runId === activeActivityRun?.runId &&
2521
- item.status === "completed",
2521
+ (item.status === "completed" ||
2522
+ item.status === "failed" ||
2523
+ item.status === "interrupted" ||
2524
+ item.status === "cancelled"),
2525
+ );
2526
+ const compactionRunning = serverVisibleTurnItems.some(
2527
+ ({ item }) =>
2528
+ item.type === "compaction" &&
2529
+ item.runId !== null &&
2530
+ item.runId === activeRuntime?.activeRunId &&
2531
+ item.status === "running",
2532
);
2533
const isCompacting =
2534
(isSendBusy || phase === "connecting" || phase === "running") &&
2525
- compactRequestIsActive &&
2526
- !compactionSettled;
2535
+ (compactionRunning || (compactRequestIsActive && !compactionSettled));
2536
const isWorking =
2537
phase === "running" ||
2538
isSendBusy ||
packages/client-runtime/src/work-log/presentation.ts
+3
@@ -67,6 +67,9 @@ export function contextCompactionTokenCounts(
67
}
68
69
export function contextCompactionLabel(item: CompactionLabelItem): string {
70
+ if (item.status === "failed") return "Context compaction failed";
71
+ if (item.status === "cancelled" || item.status === "interrupted")
72
+ return "Context compaction stopped";
73
if (item.status === "running") return "Compacting context";
74
const tokens = contextCompactionTokenCounts(item);
75
return tokens