Skip to content

Commit 8044ced

Browse files
committed
fix(provider): complete Muse session lifecycle integration
1 parent 587d0f9 commit 8044ced

44 files changed

Lines changed: 4004 additions & 337 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/mobile/src/components/ProviderIcon.tsx‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,13 @@ export function ProviderIcon(props: ProviderIconProps) {
6565
}
6666

6767
if (props.provider === "muse") {
68+
// Meta mark: https://research.meta.ai/navigation/meta-logo-primary-dark_standardsize.svg
6869
return (
69-
<Svg width={size} height={size} viewBox="0 0 24 24" fill="none">
70+
<Svg width={size} height={size} viewBox="0 0 150.4828 100" fill="none">
7071
<Path
71-
d="M4 19V5l8 10 8-10v14"
72-
stroke={mono}
73-
strokeWidth={2.5}
74-
strokeLinecap="round"
75-
strokeLinejoin="round"
72+
d="M107.9999847,0.0000013c-12.3391113,0-21.984787,9.2935991-30.7164001,21.0993118 C65.2847366,5.821527,55.2499847,0,43.2413788,0C18.7586193,0,0,31.8620682,0,65.5862122 C0,86.6896515,10.2095623,100,27.3103466,100c12.3080502,0,21.1600361-5.8025894,36.8965454-33.3103409 c0,0,6.5597382-11.5841255,11.0725021-19.563858c1.5813522,2.5531845,3.2431107,5.3001404,4.9964676,8.2535095 l7.379303,12.4137955C102.0298843,91.8478851,110.039032,100,124.5517273,100 c16.6595764,0,25.9310303-13.4923325,25.9310303-35.0344849 C150.4827576,29.6551723,131.301178,0.0000013,107.9999847,0.0000013z M52.2068977,59.2413788 c-12.7586212,20-17.1724167,24.4827576-24.2758656,24.4827576c-7.3103428,0-11.6551704-6.4178314-11.6551704-17.8620682 c0-24.4827576,12.2068977-49.5172424,26.7586231-49.5172424c7.880127,0,14.4653816,4.5510426,24.5522308,18.9913158 C58.0087967,50.0272293,52.2068977,59.2413788,52.2068977,59.2413788z M100.3597336,56.7235756L91.5367355,42.00877 c-2.3876724-3.8832092-4.6757278-7.451458-6.8838348-10.7230263 c7.951973-12.273531,14.5113449-18.3891907,22.3126144-18.3891907c16.2069016,0,29.1724243,23.8620682,29.1724243,53.1724091 c0,11.1724167-3.6593475,17.6551743-11.2413864,17.6551743 C117.6294937,83.7241364,114.1578674,78.924736,100.3597336,56.7235756z"
73+
fill={mono}
74+
fillRule="evenodd"
7675
/>
7776
</Svg>
7877
);

‎apps/mobile/src/connection/environment-cache-store.test.ts‎

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { EnvironmentId, type VcsListRefsResult } from "@t3tools/contracts";
1+
import {
2+
EnvironmentId,
3+
ProjectId,
4+
ProviderInstanceId,
5+
ThreadId,
6+
type OrchestrationThreadDetailSnapshot,
7+
type VcsListRefsResult,
8+
} from "@t3tools/contracts";
29
import { describe, expect, it } from "@effect/vitest";
310
import * as Effect from "effect/Effect";
411
import * as Option from "effect/Option";
@@ -7,6 +14,33 @@ import { type ClientCacheKind, MobileDatabase } from "../persistence/mobile-data
714
import { make } from "./environment-cache-store";
815

916
const ENVIRONMENT_ID = EnvironmentId.make("environment-1");
17+
const THREAD_ID = ThreadId.make("thread-1");
18+
const THREAD_SNAPSHOT: OrchestrationThreadDetailSnapshot = {
19+
snapshotSequence: 7,
20+
thread: {
21+
id: THREAD_ID,
22+
projectId: ProjectId.make("project-1"),
23+
title: "Cached thread",
24+
modelSelection: { instanceId: ProviderInstanceId.make("muse"), model: "muse-spark-1.3" },
25+
runtimeMode: "full-access",
26+
interactionMode: "default",
27+
branch: null,
28+
worktreePath: null,
29+
latestTurn: null,
30+
createdAt: "2026-09-11T00:00:00.000Z",
31+
updatedAt: "2026-09-11T00:00:00.000Z",
32+
archivedAt: null,
33+
settledOverride: null,
34+
settledAt: null,
35+
pullRequests: [],
36+
deletedAt: null,
37+
messages: [],
38+
proposedPlans: [],
39+
activities: [],
40+
checkpoints: [],
41+
session: null,
42+
},
43+
};
1044
const REFS: VcsListRefsResult = {
1145
refs: [
1246
{
@@ -69,6 +103,56 @@ function makeDatabase() {
69103
}
70104

71105
describe("mobile SQLite environment cache store", () => {
106+
it.effect("discards v3 thread snapshots so historical activities are refetched", () =>
107+
Effect.gen(function* () {
108+
const memory = makeDatabase();
109+
const store = yield* make().pipe(Effect.provideService(MobileDatabase, memory.database));
110+
const id = cacheId(ENVIRONMENT_ID, "thread", THREAD_ID);
111+
memory.values.set(
112+
id,
113+
JSON.stringify({
114+
schemaVersion: 3,
115+
environmentId: ENVIRONMENT_ID,
116+
threadId: THREAD_ID,
117+
snapshot: THREAD_SNAPSHOT,
118+
}),
119+
);
120+
121+
expect(yield* store.loadThread(ENVIRONMENT_ID, THREAD_ID)).toEqual(Option.none());
122+
expect(memory.removed).toEqual([id]);
123+
expect(memory.values.has(id)).toBe(false);
124+
}),
125+
);
126+
127+
it.effect("accepts v4 thread snapshots and round-trips refreshed history", () =>
128+
Effect.gen(function* () {
129+
const memory = makeDatabase();
130+
const store = yield* make().pipe(Effect.provideService(MobileDatabase, memory.database));
131+
memory.values.set(
132+
cacheId(ENVIRONMENT_ID, "thread", THREAD_ID),
133+
JSON.stringify({
134+
schemaVersion: 4,
135+
environmentId: ENVIRONMENT_ID,
136+
threadId: THREAD_ID,
137+
snapshot: THREAD_SNAPSHOT,
138+
}),
139+
);
140+
expect(yield* store.loadThread(ENVIRONMENT_ID, THREAD_ID)).toEqual(
141+
Option.some(THREAD_SNAPSHOT),
142+
);
143+
144+
const refreshed = {
145+
...THREAD_SNAPSHOT,
146+
snapshotSequence: 8,
147+
thread: { ...THREAD_SNAPSHOT.thread, title: "Refreshed thread" },
148+
};
149+
yield* store.saveThread(ENVIRONMENT_ID, refreshed);
150+
151+
expect(yield* store.loadThread(ENVIRONMENT_ID, THREAD_ID)).toEqual(Option.some(refreshed));
152+
expect(memory.removed).toEqual([]);
153+
}),
154+
);
155+
72156
it.effect("round-trips schema-validated VCS refs", () =>
73157
Effect.gen(function* () {
74158
const memory = makeDatabase();

‎apps/mobile/src/connection/environment-cache-store.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ const SHELL_SNAPSHOT_CACHE_SCHEMA_VERSION = 1;
2121
// v3 adds windowed (paginated) snapshots carrying `page` metadata; the bump
2222
// makes pre-pagination clients discard the record instead of decoding a
2323
// partial thread as complete (rollback safety).
24-
const THREAD_SNAPSHOT_CACHE_SCHEMA_VERSION = 3;
24+
// v4 refetches activities that previously lost Muse native item kinds during
25+
// projection. Cursor-based resume cannot repair already cached historical rows.
26+
const THREAD_SNAPSHOT_CACHE_SCHEMA_VERSION = 4;
2527
const SERVER_CONFIG_CACHE_SCHEMA_VERSION = 1;
2628
const VCS_REFS_CACHE_SCHEMA_VERSION = 1;
2729

‎apps/mobile/src/lib/threadActivity.test.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import { derivePendingRequests } from "@t3tools/client-runtime/pending-requests";
2+
import {
3+
summarizeToolGroup,
4+
workLogEntryIsToolLike,
5+
} from "@t3tools/client-runtime/work-log/presentation";
26
import { beforeEach, describe, expect, it } from "vite-plus/test";
37

48
import {
@@ -291,6 +295,44 @@ function makeThread(
291295
}
292296

293297
describe("buildThreadFeed", () => {
298+
it("renders projected Muse reminder children as updates instead of tool use", () => {
299+
const thread = makeThread({
300+
id: ThreadId.make("muse-reminders"),
301+
projectId: ProjectId.make("project-1"),
302+
title: "Muse reminders",
303+
activities: ["first", "second"].flatMap((itemId) =>
304+
["started", "completed"].map((phase) =>
305+
makeActivity({
306+
id: EventId.make(`${itemId}-${phase}`),
307+
kind: `tool.${phase}`,
308+
tone: "tool",
309+
summary: phase === "started" ? "reminderChild started" : "reminderChild",
310+
createdAt: "2026-09-11T00:00:00.000Z",
311+
payload: {
312+
itemType: "dynamic_tool_call",
313+
toolCallId: itemId,
314+
status: phase === "started" ? "inProgress" : "completed",
315+
title: "reminderChild",
316+
detail: "Reminder child session",
317+
data: { item: { kind: "reminderChild" } },
318+
},
319+
}),
320+
),
321+
),
322+
});
323+
const [group] = buildThreadFeed(thread);
324+
expect(group?.type).toBe("activity-group");
325+
if (group?.type !== "activity-group") return;
326+
const entries = group.activities.map((activity) => activity.workEntry);
327+
expect(entries).toHaveLength(2);
328+
expect(entries.map((entry) => entry.detail)).toEqual([
329+
"Reminder child session",
330+
"Reminder child session",
331+
]);
332+
expect(entries.every((entry) => !workLogEntryIsToolLike(entry))).toBe(true);
333+
expect(summarizeToolGroup(entries)).toBe("Received 2 updates");
334+
});
335+
294336
it("reuses unchanged feed and presentation rows during an assistant text update", () => {
295337
const completedTurnId = TurnId.make("completed-turn");
296338
const activeTurnId = TurnId.make("active-turn");

‎apps/mobile/src/lib/threadActivity.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ function toDerivedWorkLogEntry(activity: OrchestrationThreadActivity): DerivedWo
574574
if (toolPresentation.toolSource) {
575575
entry.toolSource = toolPresentation.toolSource;
576576
}
577-
if (itemType === "mcp_tool_call") {
577+
if (itemType === "mcp_tool_call" || itemType === "dynamic_tool_call") {
578578
const data = asRecord(payload?.data);
579579
const toolData = typeof data?.toolName === "string" ? (data.item ?? data) : data?.item;
580580
if (toolData !== undefined) {

‎apps/server/src/orchestration/ActivityPayloadProjection.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,31 @@ function activity(payload: Record<string, unknown>): OrchestrationThreadActivity
2121
* assertions are the tripwire.
2222
*/
2323
describe("projectActivityPayload", () => {
24+
it.each(["reminderChild", "toolCall", "futureWorkflow"])(
25+
"preserves the %s native kind without forwarding its full item",
26+
(kind) => {
27+
const projected = projectActivityPayload(
28+
activity({
29+
itemType: "dynamic_tool_call",
30+
detail: "Native activity detail",
31+
data: {
32+
item: {
33+
kind,
34+
childSessionId: "child-session",
35+
text: "x".repeat(10_000),
36+
},
37+
},
38+
}),
39+
);
40+
expect(projected.payload).toEqual({
41+
itemType: "dynamic_tool_call",
42+
detail: "Native activity detail",
43+
data: { item: { kind } },
44+
});
45+
expect(projectActivityPayload(projected)).toEqual(projected);
46+
},
47+
);
48+
2449
it("preserves tool attribution (agentId/parentToolUseId) through data slimming", () => {
2550
const projected = projectActivityPayload(
2651
activity({

‎apps/server/src/orchestration/ActivityPayloadProjection.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,12 @@ export function projectActivityPayload(
454454

455455
const projectedData: Record<string, unknown> = { ...questionInput };
456456
const item = projectCommandData(data);
457-
if (item) {
457+
const itemKind =
458+
payload.itemType === "dynamic_tool_call" ? asTrimmedString(asRecord(data.item)?.kind) : null;
459+
if (itemKind) {
460+
// Native kinds distinguish provider activity from model-invoked tools.
461+
projectedData.item = { ...item, kind: itemKind };
462+
} else if (item) {
458463
projectedData.item = item;
459464
}
460465
const command = projectCommandValue(data);

‎apps/server/src/project/AgentSessionImporter.test.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ const WORKSPACE_ROOT = "/tmp/project-from-server";
6666
const CLAUDE_SESSION_ID = "123e4567-e89b-42d3-a456-426614174000";
6767
const encodeTranscriptRecord = Schema.encodeUnknownSync(Schema.fromJsonString(Schema.Unknown));
6868

69-
const makeThread = (source: "codex" | "claudeAgent"): AgentSessionScanner.AgentSessionThread => ({
69+
const makeThread = (
70+
source: "codex" | "claudeAgent" | "muse",
71+
): AgentSessionScanner.AgentSessionThread => ({
7072
source,
7173
providerInstanceId: ProviderInstanceId.make(source),
7274
providerSessionId: source === "codex" ? "codex-session" : CLAUDE_SESSION_ID,
@@ -859,7 +861,7 @@ it.layer(integrationLayer)("AgentSessionImporter integration", (it) => {
859861
}),
860862
);
861863

862-
for (const source of ["codex", "claudeAgent"] as const) {
864+
for (const source of ["codex", "claudeAgent", "muse"] as const) {
863865
it.effect(`resumes imported ${source} history only after the first prompt`, () =>
864866
Effect.gen(function* () {
865867
const engine = yield* OrchestrationEngine.OrchestrationEngineService;
@@ -878,7 +880,9 @@ it.layer(integrationLayer)("AgentSessionImporter integration", (it) => {
878880
const resumeCursor =
879881
source === "codex"
880882
? { threadId: sourceThread.providerSessionId }
881-
: { threadId, resume: sourceThread.providerSessionId };
883+
: source === "muse"
884+
? { sessionId: sourceThread.providerSessionId }
885+
: { threadId, resume: sourceThread.providerSessionId };
882886
const provider = ProviderDriverKind.make(source);
883887
const harness = yield* makeTestProviderAdapterHarness({ provider });
884888
const importSettled = yield* Deferred.make<void>();

‎apps/server/src/project/AgentSessionImporter.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export const importRecentAgentThreads = Effect.fn("importRecentAgentThreads")(fu
174174
const existingBinding = yield* directory.getBinding(threadId);
175175

176176
if (
177-
thread.source === "claudeAgent" &&
177+
(thread.source === "claudeAgent" || thread.source === "muse") &&
178178
!CLAUDE_SESSION_ID_PATTERN.test(thread.providerSessionId)
179179
) {
180180
return yield* new AgentSessionUnresumableSessionError({
@@ -233,7 +233,9 @@ export const importRecentAgentThreads = Effect.fn("importRecentAgentThreads")(fu
233233
resumeCursor:
234234
thread.source === "codex"
235235
? { threadId: thread.providerSessionId }
236-
: { threadId, resume: thread.providerSessionId },
236+
: thread.source === "muse"
237+
? { sessionId: thread.providerSessionId }
238+
: { threadId, resume: thread.providerSessionId },
237239
runtimePayload: { cwd: workspaceRoot },
238240
},
239241
{ onConflict: "ignore" },

0 commit comments

Comments
 (0)