Skip to content

Commit 4150b20

Browse files
committed
refactor(web): keep Synthos components within React Compiler support
reactCompilerCoverage.test requires every web source file to compile with no React Compiler bailouts. Twelve Synthos files bailed out on three unsupported constructs: try/finally, throw inside try, and a dynamic import() in a component. Rewrite them without changing behaviour: - try/catch/finally becomes try/catch followed by the same cleanup. No catch block rethrows. The two early returns inside try (ContextDeck, Knowledge open) happen only when the request is stale, where the old finally was already a no-op. KnowledgeGraph keeps its boolean result in a local. - Throws inside try move into small module-level helpers (assertSavedProfile, assertVaultConfigured, readBrainExport, readTokenMonitorExport) with the same checks and messages. - The night-riders scene import moves into loadSceneModule. Fails before (CI Test Web): 12 failed in reactCompilerCoverage.test. Passes after: 1288/1288, plus the Synthos unit tests. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01A1D6J2UMPo7YBWQFvbg1br
1 parent 585b7fa commit 4150b20

12 files changed

Lines changed: 65 additions & 61 deletions

‎apps/web/src/components/synthos/SynthosCockpit.tsx‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,8 @@ function CockpitEnvironment({
249249
? cause.message
250250
: "Command failed. Refresh to inspect the recorded state.",
251251
);
252-
} finally {
253-
setBusy(false);
254252
}
253+
setBusy(false);
255254
}
256255

257256
return (
@@ -900,9 +899,8 @@ function MissionComposer({
900899
setTask("");
901900
} catch (cause) {
902901
setError(cause instanceof Error ? cause.message : "The mission could not be saved.");
903-
} finally {
904-
setBusy(false);
905902
}
903+
setBusy(false);
906904
}
907905
return (
908906
<section className="sx-panel sx-mission">

‎apps/web/src/components/synthos/SynthosContextDeck.tsx‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,10 @@ function ContextProject({
239239
setError(
240240
`${messageOf(cause)} Your draft is retained; reload saved settings if another session changed them.`,
241241
);
242-
} finally {
243-
if (currentRequest.current === requestId) {
244-
pending.current = false;
245-
setBusy(false);
246-
}
242+
}
243+
if (currentRequest.current === requestId) {
244+
pending.current = false;
245+
setBusy(false);
247246
}
248247
}
249248

‎apps/web/src/components/synthos/SynthosCrewProfiles.tsx‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ import { randomUUID } from "../../lib/utils";
1212
import { synthosRequest } from "./synthosRequest";
1313
import { refreshCrewProfileMetadata } from "./synthosCrewProfileMetadata";
1414

15+
function assertSavedProfile(
16+
result: SynthosProfileResult,
17+
): asserts result is Extract<SynthosProfileResult, { type: "profile" }> {
18+
if (result.type !== "profile") throw new Error("The host did not return the saved profile.");
19+
}
20+
1521
export function SynthosCrewProfiles({
1622
environmentId,
1723
connected,
@@ -126,7 +132,7 @@ export function SynthosCrewProfiles({
126132
body: command,
127133
},
128134
);
129-
if (result.type !== "profile") throw new Error("The host did not return the saved profile.");
135+
assertSavedProfile(result);
130136
if (command.type === "get") {
131137
mergeLatest(result.profile);
132138
} else setSelected(result.profile);
@@ -148,10 +154,9 @@ export function SynthosCrewProfiles({
148154
setError(
149155
`${cause instanceof Error ? cause.message : "The profile could not be saved."} Your draft is preserved. Refresh profiles, then reselect the current version before retrying a conflict.`,
150156
);
151-
} finally {
152-
pending.current = false;
153-
setBusy(false);
154157
}
158+
pending.current = false;
159+
setBusy(false);
155160
}
156161

157162
return (

‎apps/web/src/components/synthos/SynthosGraphExplorer.tsx‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ import { useProjects } from "../../state/entities";
1313
import { synthosRequest } from "./synthosRequest";
1414

1515
const decodeBrain = Schema.decodeUnknownSync(Schema.fromJsonString(SynthosBrainExport));
16+
const readBrainExport = (file: File) => {
17+
if (file.size > 100_000)
18+
throw new Error("Export exceeds 100 KB; create a smaller approved graph export.");
19+
return file.text();
20+
};
1621
export function SynthosGraphExplorer({
1722
environmentId,
1823
activeWorkflow,
@@ -116,9 +121,8 @@ function Explorer({
116121
);
117122
} catch (cause) {
118123
setError(cause instanceof Error ? cause.message : "Graph request failed");
119-
} finally {
120-
setBusy(false);
121124
}
125+
setBusy(false);
122126
}
123127
const points = new Map(
124128
(graph?.nodes ?? []).map((n, i, all) => {
@@ -494,11 +498,7 @@ function Explorer({
494498
const file = event.target.files?.[0];
495499
if (!file) return;
496500
try {
497-
if (file.size > 100_000)
498-
throw new Error(
499-
"Export exceeds 100 KB; create a smaller approved graph export.",
500-
);
501-
const data = decodeBrain(await file.text());
501+
const data = decodeBrain(await readBrainExport(file));
502502
await run({
503503
type: "import_brain",
504504
projectId,

‎apps/web/src/components/synthos/SynthosKnowledge.tsx‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,8 @@ function KnowledgeSource({
128128
setSearched(true);
129129
} catch (cause) {
130130
setError(message(cause));
131-
} finally {
132-
setBusy(false);
133131
}
132+
setBusy(false);
134133
}
135134

136135
async function open(id: string) {
@@ -157,9 +156,8 @@ function KnowledgeSource({
157156
setPath(id);
158157
} catch (cause) {
159158
if (requestId === sequence.current) setError(message(cause));
160-
} finally {
161-
if (requestId === sequence.current) setBusy(false);
162159
}
160+
if (requestId === sequence.current) setBusy(false);
163161
}
164162

165163
async function save() {
@@ -202,9 +200,8 @@ function KnowledgeSource({
202200
setSaved(true);
203201
} catch (cause) {
204202
setError(message(cause));
205-
} finally {
206-
setBusy(false);
207203
}
204+
setBusy(false);
208205
}
209206

210207
return (

‎apps/web/src/components/synthos/SynthosKnowledgeGraph.tsx‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ export function SynthosKnowledgeGraph({ environmentId }: { environmentId: Enviro
106106
pending.current = true;
107107
setBusy(true);
108108
setError(null);
109+
let saved = false;
109110
try {
110111
const result = await run(command);
111112
if (result.type === "node") {
@@ -116,14 +117,13 @@ export function SynthosKnowledgeGraph({ environmentId }: { environmentId: Enviro
116117
setEditingNode(null);
117118
setEditingEdge(null);
118119
setRequestKey((value) => value + 1);
119-
return true;
120+
saved = true;
120121
} catch (cause) {
121122
setError(errorMessage(cause));
122-
return false;
123-
} finally {
124-
pending.current = false;
125-
setBusy(false);
126123
}
124+
pending.current = false;
125+
setBusy(false);
126+
return saved;
127127
}
128128
async function showHistory(entity: "node" | "edge", id: string) {
129129
const requestId = ++historyRequest.current;

‎apps/web/src/components/synthos/SynthosMemoryCapture.tsx‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ type Props = {
1212
type VaultNote = { path: string; content: string; version: string };
1313
type Capture = { sourceKey: string; provenance: string };
1414

15+
function assertVaultConfigured(connections: readonly SynthosConnectionStatus[]) {
16+
const status = connections.find((connection) => connection.id === "obsidian");
17+
if (status?.state !== "configured") {
18+
throw new Error(status?.reason ?? "Configure the Obsidian vault on this host first.");
19+
}
20+
}
21+
1522
function sourceKey(environmentId: EnvironmentId, workflow: SynthosWorkflow) {
1623
return JSON.stringify([environmentId, workflow.id, workflow.revision, workflow.policyHash]);
1724
}
@@ -99,10 +106,7 @@ function MemoryCaptureForm({ environmentId, connected, workflow }: Props) {
99106
"/api/synthos/connections",
100107
{ method: "POST", body: { type: "status" } },
101108
);
102-
const status = result.connections.find((connection) => connection.id === "obsidian");
103-
if (status?.state !== "configured") {
104-
throw new Error(status?.reason ?? "Configure the Obsidian vault on this host first.");
105-
}
109+
assertVaultConfigured(result.connections);
106110
setCapture({
107111
sourceKey: sourceKey(environmentId, workflow),
108112
provenance: provenance(environmentId, workflow),
@@ -114,10 +118,9 @@ function MemoryCaptureForm({ environmentId, connected, workflow }: Props) {
114118
clearReview();
115119
} catch (cause) {
116120
setError(cause instanceof Error ? cause.message : "The vault status could not be read.");
117-
} finally {
118-
inFlight.current = false;
119-
setBusy(false);
120121
}
122+
inFlight.current = false;
123+
setBusy(false);
121124
}
122125

123126
async function readDestination() {
@@ -134,10 +137,9 @@ function MemoryCaptureForm({ environmentId, connected, workflow }: Props) {
134137
setExisting(note);
135138
} catch (cause) {
136139
setError(cause instanceof Error ? cause.message : "The destination could not be read.");
137-
} finally {
138-
inFlight.current = false;
139-
setBusy(false);
140140
}
141+
inFlight.current = false;
142+
setBusy(false);
141143
}
142144

143145
async function save() {
@@ -173,10 +175,9 @@ function MemoryCaptureForm({ environmentId, connected, workflow }: Props) {
173175
setError(
174176
`${cause instanceof Error ? cause.message : "Save was not confirmed."} Read the destination before retrying; your draft is retained.`,
175177
);
176-
} finally {
177-
inFlight.current = false;
178-
setBusy(false);
179178
}
179+
inFlight.current = false;
180+
setBusy(false);
180181
}
181182

182183
return (

‎apps/web/src/components/synthos/SynthosSupplies.tsx‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,9 @@ export function SynthosSupplies({ environmentId }: { environmentId: EnvironmentI
5757
} catch (cause) {
5858
if (!controller.signal.aborted)
5959
setError(cause instanceof Error ? cause.message : "Tool inventory could not be loaded.");
60-
} finally {
61-
inFlight = false;
62-
if (!controller.signal.aborted) setBusy(false);
6360
}
61+
inFlight = false;
62+
if (!controller.signal.aborted) setBusy(false);
6463
};
6564
void load();
6665
const interval = window.setInterval(() => {
@@ -93,9 +92,8 @@ export function SynthosSupplies({ environmentId }: { environmentId: EnvironmentI
9392
);
9493
} catch (cause) {
9594
setError(cause instanceof Error ? cause.message : "The host could not complete this probe.");
96-
} finally {
97-
setProbingId(null);
9895
}
96+
setProbingId(null);
9997
}
10098

10199
return (

‎apps/web/src/components/synthos/SynthosTools.tsx‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,9 @@ function ToolsPanel({ environmentId, statuses }: SynthosToolsProps) {
7373
setError(
7474
cause instanceof Error ? cause.message : "AgentMail could not complete this request.",
7575
);
76-
} finally {
77-
pending.current = false;
78-
setBusy(null);
7976
}
77+
pending.current = false;
78+
setBusy(null);
8079
}
8180

8281
function invalidateDraft() {

‎apps/web/src/components/synthos/SynthosUsage.tsx‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ type UsageProps = {
2121
detailReady: boolean;
2222
};
2323

24+
function readTokenMonitorExport(file: File) {
25+
if (file.size > TOKEN_MONITOR_EXPORT_MAX_BYTES)
26+
throw new Error("Token Monitor exports must be at most 2 MiB.");
27+
return file.arrayBuffer();
28+
}
29+
2430
function count(value: number | null): string {
2531
return value === null ? "Unknown" : value.toLocaleString();
2632
}
@@ -59,18 +65,17 @@ function UsageStation({ environmentId, connected, workflow, detailReady }: Usage
5965
setError(null);
6066
setReport(null);
6167
try {
62-
if (file.size > TOKEN_MONITOR_EXPORT_MAX_BYTES)
63-
throw new Error("Token Monitor exports must be at most 2 MiB.");
64-
const text = new TextDecoder("utf-8", { fatal: true }).decode(await file.arrayBuffer());
68+
const text = new TextDecoder("utf-8", { fatal: true }).decode(
69+
await readTokenMonitorExport(file),
70+
);
6571
const parsed = parseTokenMonitorExport(text);
6672
if (sequence === importSequence.current) setReport(parsed);
6773
} catch (cause) {
6874
if (sequence === importSequence.current) {
6975
setError(cause instanceof Error ? cause.message : "Unable to read this export.");
7076
}
71-
} finally {
72-
if (sequence === importSequence.current) setReading(false);
7377
}
78+
if (sequence === importSequence.current) setReading(false);
7479
}
7580

7681
return (

0 commit comments

Comments
 (0)