Skip to content

Commit ffde3a2

Browse files
chore: merge upstream main into fork
2 parents cfc63dc + dd5b540 commit ffde3a2

413 files changed

Lines changed: 18408 additions & 9236 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/app/DesktopAppActivation.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,10 @@ export const make = Effect.gen(function* () {
382382
webContents.send(DESKTOP_APP_ACTIVATION_REQUEST_CHANNEL, request);
383383
});
384384
}),
385-
complete: (response) => Effect.sync(() => broker.complete(response)),
385+
// The IPC handler owns the activation-completion span.
386+
complete: Effect.fnUntraced(function* (response) {
387+
return yield* Effect.sync(() => broker.complete(response));
388+
}),
386389
});
387390
});
388391

‎apps/desktop/src/app/DesktopObservability.ts‎

Lines changed: 86 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -459,90 +459,91 @@ const makeBackendOutputLogShape = (
459459
): Effect.Effect<DesktopBackendOutputLogShape> =>
460460
Option.match(sink, {
461461
onNone: () => Effect.succeed(DesktopBackendOutputLogNoop),
462-
onSome: (logFile) =>
463-
Effect.gen(function* () {
464-
const sessionRef = yield* Ref.make(Option.none<BackendOutputSession>());
465-
const writeFailure = Effect.fn("desktop.observability.backendOutput.writeFailure")(
466-
function* (session: BackendOutputSession, details: string) {
467-
yield* writeBackendChildLogRecord(logFile, {
468-
message: "backend child process failure output start",
469-
level: "ERROR",
470-
annotations: {
471-
component: "desktop-backend-child",
472-
runId: session.runId,
473-
instanceId: id,
474-
phase: "START",
475-
details: session.startDetails,
476-
},
477-
});
478-
for (const output of session.chunks) {
479-
yield* writeBackendChildLogRecord(logFile, {
480-
message: "backend child process output",
481-
level: output.streamName === "stderr" ? "ERROR" : "INFO",
482-
annotations: {
483-
component: "desktop-backend-child",
484-
runId: session.runId,
485-
instanceId: id,
486-
stream: output.streamName,
487-
text: textDecoder.decode(output.chunk.subarray(output.offset)),
488-
},
489-
});
490-
}
491-
yield* writeBackendChildLogRecord(logFile, {
492-
message: "backend child process failure output end",
493-
level: "ERROR",
494-
annotations: {
495-
component: "desktop-backend-child",
496-
runId: session.runId,
497-
instanceId: id,
498-
phase: "END",
499-
details: sanitizeLogValue(details),
500-
},
501-
});
462+
// The enclosing operation owns the span for this inline handler.
463+
onSome: Effect.fnUntraced(function* (logFile) {
464+
const sessionRef = yield* Ref.make(Option.none<BackendOutputSession>());
465+
const writeFailure = Effect.fn("desktop.observability.backendOutput.writeFailure")(function* (
466+
session: BackendOutputSession,
467+
details: string,
468+
) {
469+
yield* writeBackendChildLogRecord(logFile, {
470+
message: "backend child process failure output start",
471+
level: "ERROR",
472+
annotations: {
473+
component: "desktop-backend-child",
474+
runId: session.runId,
475+
instanceId: id,
476+
phase: "START",
477+
details: session.startDetails,
502478
},
503-
);
504-
return {
505-
beginSession: Effect.fn("desktop.observability.backendOutput.beginSession")(function* ({
506-
details,
507-
}) {
508-
const runId = yield* currentDesktopRunId;
509-
yield* Ref.set(
510-
sessionRef,
511-
Option.some({
512-
runId,
513-
startDetails: sanitizeLogValue(details),
514-
chunks: [],
515-
byteLength: 0,
516-
}),
517-
);
518-
}),
519-
writeOutputChunk: Effect.fnUntraced(function* (streamName, chunk) {
520-
if (environment.isDevelopment) {
521-
yield* writeDevelopmentConsoleOutput(streamName, chunk);
522-
}
523-
yield* Ref.update(
524-
sessionRef,
525-
Option.map((session) => appendBoundedOutputChunk(session, streamName, chunk)),
526-
);
527-
}),
528-
persistFailureSnapshot: Effect.fn(
529-
"desktop.observability.backendOutput.persistFailureSnapshot",
530-
)(function* ({ details }) {
531-
const session = yield* Ref.get(sessionRef);
532-
if (Option.isSome(session)) {
533-
yield* writeFailure(session.value, details);
534-
}
535-
}),
536-
persistFailure: Effect.fn("desktop.observability.backendOutput.persistFailure")(
537-
function* ({ details }) {
538-
const session = yield* Ref.modify(sessionRef, (current) => [current, Option.none()]);
539-
if (Option.isNone(session)) return;
540-
yield* writeFailure(session.value, details);
479+
});
480+
for (const output of session.chunks) {
481+
yield* writeBackendChildLogRecord(logFile, {
482+
message: "backend child process output",
483+
level: output.streamName === "stderr" ? "ERROR" : "INFO",
484+
annotations: {
485+
component: "desktop-backend-child",
486+
runId: session.runId,
487+
instanceId: id,
488+
stream: output.streamName,
489+
text: textDecoder.decode(output.chunk.subarray(output.offset)),
541490
},
542-
),
543-
discardSession: Ref.set(sessionRef, Option.none()),
544-
} satisfies DesktopBackendOutputLogShape;
545-
}),
491+
});
492+
}
493+
yield* writeBackendChildLogRecord(logFile, {
494+
message: "backend child process failure output end",
495+
level: "ERROR",
496+
annotations: {
497+
component: "desktop-backend-child",
498+
runId: session.runId,
499+
instanceId: id,
500+
phase: "END",
501+
details: sanitizeLogValue(details),
502+
},
503+
});
504+
});
505+
return {
506+
beginSession: Effect.fn("desktop.observability.backendOutput.beginSession")(function* ({
507+
details,
508+
}) {
509+
const runId = yield* currentDesktopRunId;
510+
yield* Ref.set(
511+
sessionRef,
512+
Option.some({
513+
runId,
514+
startDetails: sanitizeLogValue(details),
515+
chunks: [],
516+
byteLength: 0,
517+
}),
518+
);
519+
}),
520+
writeOutputChunk: Effect.fnUntraced(function* (streamName, chunk) {
521+
if (environment.isDevelopment) {
522+
yield* writeDevelopmentConsoleOutput(streamName, chunk);
523+
}
524+
yield* Ref.update(
525+
sessionRef,
526+
Option.map((session) => appendBoundedOutputChunk(session, streamName, chunk)),
527+
);
528+
}),
529+
persistFailureSnapshot: Effect.fn(
530+
"desktop.observability.backendOutput.persistFailureSnapshot",
531+
)(function* ({ details }) {
532+
const session = yield* Ref.get(sessionRef);
533+
if (Option.isSome(session)) {
534+
yield* writeFailure(session.value, details);
535+
}
536+
}),
537+
persistFailure: Effect.fn("desktop.observability.backendOutput.persistFailure")(function* ({
538+
details,
539+
}) {
540+
const session = yield* Ref.modify(sessionRef, (current) => [current, Option.none()]);
541+
if (Option.isNone(session)) return;
542+
yield* writeFailure(session.value, details);
543+
}),
544+
discardSession: Ref.set(sessionRef, Option.none()),
545+
} satisfies DesktopBackendOutputLogShape;
546+
}),
546547
});
547548

548549
const layerBackendOutputLogFactory = Layer.effect(
@@ -589,7 +590,9 @@ const layerBackendOutputLogFactory = Layer.effect(
589590
});
590591

591592
return DesktopBackendOutputLogFactory.of({
592-
forInstance: (id) => makeForId(id),
593+
forInstance: Effect.fn("DesktopBackendOutputLogFactory.forInstance")(function (id) {
594+
return makeForId(id);
595+
}),
593596
});
594597
}),
595598
);

‎apps/desktop/src/app/DesktopWebLinks.ts‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,15 @@ const make = Effect.gen(function* () {
6969
});
7070

7171
return DesktopWebLinks.of({
72-
receive: (url) =>
73-
Effect.suspend(() => {
72+
receive: Effect.fn("DesktopWebLinks.receive")(function (url) {
73+
return Effect.suspend(() => {
7474
pending.push(url);
7575
return flush;
76-
}).pipe(Effect.withSpan("DesktopWebLinks.receive")),
77-
setRendererReady: (ready) =>
78-
(ready ? startListening : Effect.sync(stopListening)).pipe(
79-
Effect.andThen(flush),
80-
Effect.withSpan("DesktopWebLinks.setRendererReady"),
81-
),
76+
});
77+
}),
78+
setRendererReady: Effect.fn("DesktopWebLinks.setRendererReady")(function (ready) {
79+
return ready ? startListening : Effect.sync(stopListening);
80+
}, Effect.andThen(flush)),
8281
});
8382
});
8483

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

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,58 +1043,58 @@ export const makeBackendInstance = Effect.fn("makeBackendInstance")(function* (
10431043
});
10441044
yield* Option.match(active, {
10451045
onNone: () => Effect.void,
1046-
onSome: (run) =>
1047-
Effect.gen(function* () {
1048-
const closed = yield* closeRun(run, parentScope, options);
1049-
if (!closed) {
1050-
return;
1051-
}
1052-
const cleanup = yield* mutex.withPermits(1)(
1053-
Ref.modify(
1054-
state,
1055-
(
1056-
latest,
1057-
): readonly [
1058-
{
1059-
readonly needsCleanup: boolean;
1060-
readonly shouldStart: boolean;
1061-
},
1062-
BackendManagerState,
1063-
] => {
1064-
const current = Option.getOrUndefined(latest.active);
1065-
if (current?.id !== run.id) {
1066-
return [
1067-
{
1068-
needsCleanup: false,
1069-
shouldStart:
1070-
latest.desiredRunning &&
1071-
Option.isNone(latest.active) &&
1072-
Option.isNone(latest.restartFiber),
1073-
},
1074-
latest,
1075-
];
1076-
}
1046+
// The enclosing operation owns the span for this inline handler.
1047+
onSome: Effect.fnUntraced(function* (run) {
1048+
const closed = yield* closeRun(run, parentScope, options);
1049+
if (!closed) {
1050+
return;
1051+
}
1052+
const cleanup = yield* mutex.withPermits(1)(
1053+
Ref.modify(
1054+
state,
1055+
(
1056+
latest,
1057+
): readonly [
1058+
{
1059+
readonly needsCleanup: boolean;
1060+
readonly shouldStart: boolean;
1061+
},
1062+
BackendManagerState,
1063+
] => {
1064+
const current = Option.getOrUndefined(latest.active);
1065+
if (current?.id !== run.id) {
10771066
return [
10781067
{
1079-
needsCleanup: true,
1080-
shouldStart: latest.desiredRunning,
1081-
},
1082-
{
1083-
...latest,
1084-
active: Option.none<ActiveBackendRun>(),
1068+
needsCleanup: false,
1069+
shouldStart:
1070+
latest.desiredRunning &&
1071+
Option.isNone(latest.active) &&
1072+
Option.isNone(latest.restartFiber),
10851073
},
1074+
latest,
10861075
];
1087-
},
1088-
),
1089-
);
1090-
if (cleanup.needsCleanup) {
1091-
yield* desktopTelemetryPublisher.removeControlSource(spec.id);
1092-
yield* backendOutputLog.discardSession;
1093-
}
1094-
if (cleanup.shouldStart) {
1095-
yield* start;
1096-
}
1097-
}),
1076+
}
1077+
return [
1078+
{
1079+
needsCleanup: true,
1080+
shouldStart: latest.desiredRunning,
1081+
},
1082+
{
1083+
...latest,
1084+
active: Option.none<ActiveBackendRun>(),
1085+
},
1086+
];
1087+
},
1088+
),
1089+
);
1090+
if (cleanup.needsCleanup) {
1091+
yield* desktopTelemetryPublisher.removeControlSource(spec.id);
1092+
yield* backendOutputLog.discardSession;
1093+
}
1094+
if (cleanup.shouldStart) {
1095+
yield* start;
1096+
}
1097+
}),
10981098
});
10991099
});
11001100

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,14 @@ export const layer = Layer.effect(
291291
});
292292

293293
return DesktopBackendPool.of({
294-
get: (id) =>
295-
SynchronizedRef.get(instancesRef).pipe(
294+
get: Effect.fn("DesktopBackendPool.get")(function (id) {
295+
return SynchronizedRef.get(instancesRef).pipe(
296296
Effect.map((instances) => {
297297
const entry = instances.get(id);
298298
return entry?._tag === "Active" ? Option.some(entry.instance) : Option.none();
299299
}),
300-
),
300+
);
301+
}),
301302
list: SynchronizedRef.get(instancesRef).pipe(
302303
Effect.map((instances) =>
303304
Array.from(instances.values()).flatMap((entry) =>
@@ -326,11 +327,17 @@ export const layerTest = (
326327
);
327328
const primary = instances[0]!;
328329
return DesktopBackendPool.of({
329-
get: (id) => Effect.succeed(Option.fromNullishOr(byId.get(id))),
330+
get: Effect.fn("DesktopBackendPool.get")(function (id) {
331+
return Effect.succeed(Option.fromNullishOr(byId.get(id)));
332+
}),
330333
list: Effect.succeed(Array.from(byId.values())),
331334
primary: Effect.succeed(primary),
332-
register: () => Effect.die("DesktopBackendPool.layerTest does not support register"),
333-
unregister: () => Effect.die("DesktopBackendPool.layerTest does not support unregister"),
335+
register: Effect.fn("DesktopBackendPool.register")(function () {
336+
return Effect.die("DesktopBackendPool.layerTest does not support register");
337+
}),
338+
unregister: Effect.fn("DesktopBackendPool.unregister")(function () {
339+
return Effect.die("DesktopBackendPool.layerTest does not support unregister");
340+
}),
334341
});
335342
}),
336343
);

0 commit comments

Comments
 (0)