Skip to content

Commit 0c8b5f1

Browse files
fix(usage): retain project attribution through session recovery
2 parents 3ed432f + 7bf2a43 commit 0c8b5f1

271 files changed

Lines changed: 7442 additions & 1209 deletions

File tree

Some content is hidden

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

‎apps/desktop/src/backend/DesktopBackendManager.test.ts‎

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import {
55
type DesktopBackendBootstrap as DesktopBackendBootstrapValue,
66
DesktopTelemetryControlMessage,
77
} from "@t3tools/contracts";
8+
import {
9+
DATABASE_MIGRATION_PROGRESS_MESSAGE,
10+
DATABASE_MIGRATIONS_FINISHED_MESSAGE,
11+
DATABASE_MIGRATIONS_STARTED_MESSAGE,
12+
} from "@t3tools/shared/databaseMigrationLog";
813
import { assert, describe, it } from "@effect/vitest";
914
import * as Deferred from "effect/Deferred";
1015
import * as Duration from "effect/Duration";
@@ -688,12 +693,21 @@ describe("DesktopBackendManager", () => {
688693
Effect.scoped(
689694
Effect.gen(function* () {
690695
const reports = yield* Queue.unbounded<DesktopBackendManager.BackendStartupFailure>();
691-
const startInstance = (status: Ref.Ref<number>, onReady?: Effect.Effect<void>) =>
696+
const startInstance = (
697+
status: Ref.Ref<number>,
698+
onReady?: Effect.Effect<void>,
699+
stdout = "",
700+
) =>
692701
makeTestInstance({
693702
spawnerLayer: Layer.succeed(
694703
ChildProcessSpawner.ChildProcessSpawner,
695704
ChildProcessSpawner.make(() =>
696-
Effect.succeed(makeProcess({ exitCode: Effect.never })),
705+
Effect.succeed(
706+
makeProcess({
707+
exitCode: Effect.never,
708+
stdout: Stream.make(new TextEncoder().encode(stdout)),
709+
}),
710+
),
697711
),
698712
),
699713
httpClientLayer: layerHttpClient((request) =>
@@ -712,7 +726,30 @@ describe("DesktopBackendManager", () => {
712726
yield* Deferred.await(ready);
713727
assert.isTrue(Option.isNone(yield* Queue.poll(reports)));
714728

715-
yield* startInstance(yield* Ref.make(503));
729+
const migratingStatus = yield* Ref.make(503);
730+
const migrated = yield* Deferred.make<void>();
731+
yield* startInstance(
732+
migratingStatus,
733+
Deferred.succeed(migrated, undefined).pipe(Effect.asVoid),
734+
// Enough progress lines that the start line scrolls out of the output tail.
735+
`INFO ${DATABASE_MIGRATIONS_STARTED_MESSAGE}\n` +
736+
Array.from(
737+
{ length: 80 },
738+
(_, index) =>
739+
`INFO ${DATABASE_MIGRATION_PROGRESS_MESSAGE} migration=${index}_Migration progress="${index + 1} of 80"\n`,
740+
).join(""),
741+
);
742+
yield* TestClock.adjust(Duration.minutes(10));
743+
assert.isTrue(Option.isNone(yield* Queue.poll(reports)));
744+
yield* Ref.set(migratingStatus, 200);
745+
yield* TestClock.adjust(Duration.millis(100));
746+
yield* Deferred.await(migrated);
747+
748+
yield* startInstance(
749+
yield* Ref.make(503),
750+
undefined,
751+
`${DATABASE_MIGRATIONS_STARTED_MESSAGE}\n${DATABASE_MIGRATIONS_FINISHED_MESSAGE}\n`,
752+
);
716753
yield* TestClock.adjust(Duration.seconds(179));
717754
assert.isTrue(Option.isNone(yield* Queue.poll(reports)));
718755
yield* TestClock.adjust(Duration.seconds(1));

‎apps/desktop/src/backend/DesktopBackendManager.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
DesktopTelemetryControlMessage,
2626
type DesktopTelemetryControlMessage as DesktopTelemetryControlMessageValue,
2727
} from "@t3tools/contracts";
28+
import { isRunningDatabaseMigrations } from "@t3tools/shared/databaseMigrationLog";
2829
import { waitForHttpReady as waitForHttpReadyShared } from "@t3tools/shared/httpReadiness";
2930

3031
import * as DesktopObservability from "../app/DesktopObservability.ts";
@@ -971,6 +972,12 @@ export const makeBackendInstance = Effect.fn("makeBackendInstance")(function* (
971972
}),
972973
onReadinessFailure: Effect.fn("desktop.backendInstance.onReadinessFailure")(
973974
function* (error) {
975+
if (isRunningDatabaseMigrations(yield* Ref.get(outputTail))) {
976+
yield* logInstanceWarning("backend is still migrating its database; waiting", {
977+
error: error.message,
978+
});
979+
return;
980+
}
974981
yield* logInstanceWarning("backend readiness check failed during bootstrap", {
975982
error: error.message,
976983
});

‎apps/mobile/deps/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The Enriched Markdown tarball comes from Julius's [`fork/t3-mobile` branch](https://github.com/pingdotgg/enriched-markdown/tree/fork/t3-mobile). Its `t3-fork.json` records the exact source commit and upstream base. React block renderers, signed image sources, the `onLinksChange` link list (`renderers`, `resolveImageSource`, `onLinksChange`) and the iOS streaming memory bounds are upstream. The fork carries only changes with an open upstream PR: clipboard link metadata ([#962](https://github.com/software-mansion/enriched-markdown/pull/962)), development-host autolinks ([#961](https://github.com/software-mansion/enriched-markdown/pull/961)) and hash-route link fragments ([mity/md4c#454](https://github.com/mity/md4c/pull/454), arriving through [md4c#7](https://github.com/software-mansion-labs/md4c/pull/7)), `md4cFlags.preserveWindowsPaths`, which keeps backslashes in Windows drive paths in prose ([#1105](https://github.com/software-mansion/enriched-markdown/pull/1105), after [mity/md4c#477](https://github.com/mity/md4c/pull/477)), GitHub's strikethrough rules for `~` ([md4c#6](https://github.com/software-mansion-labs/md4c/pull/6)), `\(…\)` and `\[…\]` math delimiters ([#1043](https://github.com/software-mansion/enriched-markdown/pull/1043), [md4c#4](https://github.com/software-mansion-labs/md4c/pull/4)), iOS Copy as Markdown keeping bold spans whole ([#1143](https://github.com/software-mansion/enriched-markdown/pull/1143)), line breaks in copied table cells written as `<br>` ([#1144](https://github.com/software-mansion/enriched-markdown/pull/1144)), and Android measuring text in the span order its view draws it, so code blocks nested in list items no longer make a reply overlap the next message ([#1145](https://github.com/software-mansion/enriched-markdown/pull/1145)).
1+
The Enriched Markdown tarball comes from Julius's [`fork/t3-mobile` branch](https://github.com/pingdotgg/enriched-markdown/tree/fork/t3-mobile). Its `t3-fork.json` records the exact source commit and upstream base. React block renderers, signed image sources, the `onLinksChange` link list (`renderers`, `resolveImageSource`, `onLinksChange`) and the iOS streaming memory bounds are upstream. The fork carries only changes with an open upstream PR: clipboard link metadata ([#962](https://github.com/software-mansion/enriched-markdown/pull/962)), development-host autolinks ([#961](https://github.com/software-mansion/enriched-markdown/pull/961)) and hash-route link fragments ([mity/md4c#454](https://github.com/mity/md4c/pull/454), arriving through [md4c#7](https://github.com/software-mansion-labs/md4c/pull/7)), `md4cFlags.preserveWindowsPaths`, which keeps backslashes in Windows drive paths in prose ([#1105](https://github.com/software-mansion/enriched-markdown/pull/1105), after [mity/md4c#477](https://github.com/mity/md4c/pull/477)), GitHub's strikethrough rules for `~` ([md4c#6](https://github.com/software-mansion-labs/md4c/pull/6)), `\(…\)` and `\[…\]` math delimiters ([#1043](https://github.com/software-mansion/enriched-markdown/pull/1043), [md4c#4](https://github.com/software-mansion-labs/md4c/pull/4)), iOS Copy as Markdown keeping bold spans whole ([#1143](https://github.com/software-mansion/enriched-markdown/pull/1143)), line breaks in copied table cells written as `<br>` ([#1144](https://github.com/software-mansion/enriched-markdown/pull/1144)), and Android measuring text in the span order its view draws it, so code blocks nested in list items no longer make a reply overlap the next message ([#1145](https://github.com/software-mansion/enriched-markdown/pull/1145)). It also carries one fork-only change: iOS code blocks too big for one backing store draw through tiles, so a tall block with long lines no longer shows an empty pane ([pingdotgg/enriched-markdown#15](https://github.com/pingdotgg/enriched-markdown/pull/15)).
22

33
To replace it, commit the fork changes, run `yarn install --immutable` and `yarn workspace react-native-enriched-markdown prepare` in the fork checkout, then `node scripts/pack-t3.mjs /path/to/t3code/apps/mobile/deps`. Keep the package version aligned with Julius's `fork/t3-mobile` branch. Rename the archive to include the first eight characters of the source commit, such as `react-native-enriched-markdown-1.2.0-t3.18-4287c5d3.tgz`, so each build has a distinct dependency path without version bumps. Update the tarball path in `apps/mobile/package.json` and `pnpm-workspace.yaml`'s `allowBuilds`, and run `vp i` to update the lockfile. Native clients need rebuilding when this dependency changes.
44

Binary file not shown.
Binary file not shown.

‎apps/mobile/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
"react": "catalog:",
127127
"react-dom": "catalog:",
128128
"react-native": "0.88.1",
129-
"react-native-enriched-markdown": "file:deps/react-native-enriched-markdown-1.2.0-t3.18-497fbe63.tgz",
129+
"react-native-enriched-markdown": "file:deps/react-native-enriched-markdown-1.2.0-t3.18-0dc7ed81.tgz",
130130
"react-native-gesture-handler": "~3.5.0",
131131
"react-native-image-viewing": "^0.2.2",
132132
"react-native-keyboard-controller": "1.23.0",

‎apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ function FileSourceSurface(props: ComponentProps<typeof SourceFileSurface>) {
226226
<SourceFileSurface
227227
{...props}
228228
initialLine={selection?.line ?? props.initialLine}
229-
selectable={selection?.active === true}
229+
selectable={props.selectable === true || selection?.active === true}
230230
onLongPressLine={
231231
Platform.OS === "android" ? (line) => setSelection({ line, active: true }) : undefined
232232
}
@@ -250,6 +250,7 @@ function FileContent(props: {
250250
readonly threadId: ThreadId | null;
251251
readonly initialLine: number | null;
252252
readonly truncated: boolean;
253+
readonly selectable: boolean;
253254
readonly onRefresh?: () => Promise<void> | void;
254255
}) {
255256
// Reopening a mutable host file must not reuse a poster from an earlier visit.
@@ -351,6 +352,7 @@ function FileContent(props: {
351352
path={props.relativePath}
352353
initialLine={props.initialLine}
353354
headerInsetTop={props.truncated ? 0 : undefined}
355+
selectable={props.selectable}
354356
onRefresh={props.onRefresh}
355357
/>
356358
)}
@@ -650,6 +652,7 @@ export function ThreadFileScreen(props: ThreadFileRouteScreenProps) {
650652
readonly path: string;
651653
readonly mode: FileViewMode;
652654
} | null>(null);
655+
const [textSelectionPath, setTextSelectionPath] = useState<string | null>(null);
653656
const [previewRevision, setPreviewRevision] = useState(0);
654657
const previewKey = JSON.stringify([environmentId, cwd, relativePath, previewRevision]);
655658
const [fullScreenPreview, setFullScreenPreview] = useState<FilePreviewSource | null>(null);
@@ -749,6 +752,10 @@ export function ThreadFileScreen(props: ThreadFileRouteScreenProps) {
749752
: null,
750753
);
751754
const fileData = fileQuery.data as ProjectReadFileResult | null;
755+
// iOS only: Android lays out a whole-file selectable TextView on the UI thread, which stalls.
756+
const canSelectText =
757+
Platform.OS === "ios" && resolvedActiveMode === "source" && fileData?.contents != null;
758+
const selectingText = canSelectText && textSelectionPath === relativePath;
752759

753760
const handleSelectFile = (path: string) => {
754761
const targetPath =
@@ -837,6 +844,15 @@ export function ThreadFileScreen(props: ThreadFileRouteScreenProps) {
837844
onPress: () => setCodeWordBreak(!appearance.codeWordBreak),
838845
} as const)
839846
: null,
847+
canSelectText
848+
? ({
849+
id: "select-text",
850+
title: selectingText ? "Done selecting" : "Select text",
851+
icon: "character.cursor.ibeam",
852+
inline: false,
853+
onPress: () => setTextSelectionPath(selectingText ? null : relativePath),
854+
} as const)
855+
: null,
840856
...(mediaSource
841857
? mediaActions.actions
842858
.filter(({ id }) => id !== "open-file")
@@ -1046,6 +1062,7 @@ export function ThreadFileScreen(props: ThreadFileRouteScreenProps) {
10461062
relativePath={relativePath}
10471063
threadId={threadId}
10481064
truncated={fileData?.truncated ?? false}
1065+
selectable={selectingText}
10491066
onRefresh={() => fileQuery.refresh()}
10501067
/>
10511068
</ScreenContent>

‎apps/mobile/src/features/home/HomeScreen.tsx‎

Lines changed: 5 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ import { SwipeableScrollGateProvider, useSwipeableScrollGate } from "./thread-sw
9090
import { useFabScroll } from "./FabScrollContext";
9191
import { useWorkspaceTabs } from "../layout/workspace/WorkspaceTabsContext";
9292
import { ThreadListFilters } from "./ThreadListFilters";
93+
import { deriveHomeEmptyState } from "./home-empty-state";
9394

9495
interface HomeScreenProps {
9596
readonly projects: ReadonlyArray<EnvironmentProject>;
@@ -145,73 +146,6 @@ const ESTIMATED_THREAD_LIST_V2_ROW_HEIGHT = 72;
145146
// rows that are already built instead of rows still being rebuilt.
146147
const THREAD_LIST_V2_DRAW_DISTANCE = 1_000;
147148

148-
function deriveEmptyState(props: {
149-
readonly catalogState: WorkspaceState;
150-
readonly projectCount: number;
151-
}): { readonly title: string; readonly detail: string; readonly loading: boolean } {
152-
const { catalogState } = props;
153-
if (catalogState.isLoadingConnections) {
154-
return {
155-
title: "Loading environments",
156-
detail: "Checking saved environments on this device.",
157-
loading: true,
158-
};
159-
}
160-
161-
if (!catalogState.hasConnections) {
162-
return {
163-
title: "No environments connected",
164-
detail: "Add an environment to load projects and start coding sessions.",
165-
loading: false,
166-
};
167-
}
168-
169-
if (
170-
(catalogState.connectionState === "available" ||
171-
catalogState.connectionState === "offline" ||
172-
catalogState.connectionState === "error" ||
173-
catalogState.connectionState === "unsupported") &&
174-
!catalogState.hasLoadedShellSnapshot
175-
) {
176-
return {
177-
title:
178-
catalogState.connectionState === "unsupported"
179-
? "Client not supported"
180-
: "Environment unavailable",
181-
detail:
182-
catalogState.connectionError ??
183-
"The saved environment is offline. Check the URL or start the environment, then retry.",
184-
loading: false,
185-
};
186-
}
187-
188-
if (
189-
catalogState.hasConnectingEnvironment &&
190-
!catalogState.hasLoadedShellSnapshot &&
191-
catalogState.connectionError === null
192-
) {
193-
return {
194-
title: "Connecting to environment",
195-
detail: "Loading projects and threads from the saved environment.",
196-
loading: true,
197-
};
198-
}
199-
200-
if (props.projectCount === 0 && catalogState.hasLoadedShellSnapshot) {
201-
return {
202-
title: "No projects found",
203-
detail: "The connected environment did not report any projects.",
204-
loading: false,
205-
};
206-
}
207-
208-
return {
209-
title: "No threads yet",
210-
detail: "Create a task to start a new coding runtime in one of your connected projects.",
211-
loading: false,
212-
};
213-
}
214-
215149
function HomeTopContentSpacer() {
216150
return <View className="h-4" />;
217151
}
@@ -668,10 +602,7 @@ export function HomeScreen(props: HomeScreenProps) {
668602
? null
669603
: (props.savedConnectionsById[props.selectedEnvironmentId]?.environmentLabel ??
670604
"this environment");
671-
const emptyState = deriveEmptyState({
672-
catalogState: props.catalogState,
673-
projectCount: props.projects.length,
674-
});
605+
const emptyState = deriveHomeEmptyState(props.catalogState, props.projects.length);
675606

676607
if (!hasAnyThreads) {
677608
return (
@@ -694,14 +625,10 @@ export function HomeScreen(props: HomeScreenProps) {
694625
<EmptyState
695626
title={emptyState.title}
696627
detail={emptyState.detail}
697-
actionLabel={
698-
!props.catalogState.hasReadyEnvironment ? "Add environment" : undefined
699-
}
700-
onAction={
701-
!props.catalogState.hasReadyEnvironment ? props.onAddConnection : undefined
702-
}
628+
actionLabel={emptyState.showsAddEnvironment ? "Add environment" : undefined}
629+
onAction={emptyState.showsAddEnvironment ? props.onAddConnection : undefined}
703630
action={
704-
Platform.OS === "android" && !props.catalogState.hasReadyEnvironment ? (
631+
Platform.OS === "android" && emptyState.showsAddEnvironment ? (
705632
<FloatingActionButton
706633
label="Add environment"
707634
icon="plus"
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import { EnvironmentId } from "@t3tools/contracts";
2+
import { describe, expect, it } from "vite-plus/test";
3+
4+
import type { WorkspaceEnvironment, WorkspaceState } from "../../state/workspaceModel";
5+
import { deriveHomeEmptyState } from "./home-empty-state";
6+
7+
function connectingEnvironment(
8+
connectionState: "connecting" | "reconnecting",
9+
connectionError: string | null,
10+
): WorkspaceEnvironment {
11+
return {
12+
environmentId: EnvironmentId.make("environment-1"),
13+
environmentLabel: "corex",
14+
displayUrl: "",
15+
isRelayManaged: false,
16+
isEnabled: true,
17+
connectionState,
18+
connectionError,
19+
connectionErrorTraceId: null,
20+
};
21+
}
22+
23+
function workspaceState(overrides: Partial<WorkspaceState> = {}): WorkspaceState {
24+
return {
25+
isLoadingConnections: false,
26+
hasConnections: true,
27+
hasLoadedShellSnapshot: true,
28+
hasPendingShellSnapshot: false,
29+
hasSyncingConnectedEnvironment: false,
30+
hasReadyEnvironment: true,
31+
hasConnectingEnvironment: false,
32+
connectingEnvironments: [],
33+
connectionState: "connected",
34+
connectionError: null,
35+
shellSnapshotError: null,
36+
networkStatus: "online",
37+
...overrides,
38+
};
39+
}
40+
41+
const RETAINED_FAILURE = "Environment did not respond before the connection timeout.";
42+
const reconnecting = connectingEnvironment("reconnecting", RETAINED_FAILURE);
43+
44+
describe("home empty state", () => {
45+
it.each([
46+
[
47+
"waits while a saved environment retries after a retained failure",
48+
workspaceState({
49+
hasLoadedShellSnapshot: false,
50+
hasPendingShellSnapshot: true,
51+
hasReadyEnvironment: false,
52+
hasConnectingEnvironment: true,
53+
connectingEnvironments: [reconnecting],
54+
connectionState: "reconnecting",
55+
connectionError: RETAINED_FAILURE,
56+
}),
57+
1,
58+
{ title: "Connecting to environment", loading: true, showsAddEnvironment: false },
59+
],
60+
[
61+
"waits for a connected environment's first shell snapshot",
62+
workspaceState({
63+
hasLoadedShellSnapshot: false,
64+
hasPendingShellSnapshot: true,
65+
hasSyncingConnectedEnvironment: true,
66+
}),
67+
0,
68+
{ title: "Loading threads", loading: true, showsAddEnvironment: false },
69+
],
70+
[
71+
"waits while another environment is still connecting after one loaded empty",
72+
workspaceState({
73+
hasPendingShellSnapshot: true,
74+
hasConnectingEnvironment: true,
75+
connectingEnvironments: [reconnecting],
76+
connectionError: RETAINED_FAILURE,
77+
}),
78+
0,
79+
{ title: "Loading threads", loading: true, showsAddEnvironment: false },
80+
],
81+
[
82+
"reports no threads once every environment has resolved",
83+
workspaceState(),
84+
1,
85+
{ title: "No threads yet", loading: false, showsAddEnvironment: false },
86+
],
87+
[
88+
"does not wait on retries while the device is offline",
89+
workspaceState({
90+
hasPendingShellSnapshot: true,
91+
hasReadyEnvironment: false,
92+
hasConnectingEnvironment: true,
93+
connectingEnvironments: [reconnecting],
94+
connectionState: "offline",
95+
networkStatus: "offline",
96+
}),
97+
1,
98+
{ title: "No threads yet", loading: false, showsAddEnvironment: true },
99+
],
100+
] as const)("%s", (_name, state, projectCount, expected) => {
101+
const { title, loading, showsAddEnvironment } = deriveHomeEmptyState(state, projectCount);
102+
expect({ title, loading, showsAddEnvironment }).toEqual(expected);
103+
});
104+
});

0 commit comments

Comments
 (0)