GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Codex/add visualization tool for effect event lifecycle by jasonLaster · Pull Request #589 · pingdotgg/t3code Conversation
|
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| useEffect(() => { | ||
| const api = readNativeApi(); | ||
| if (!api) { | ||
| return; | ||
| } | ||
|
|
||
| let disposed = false; | ||
|
|
||
| void api.orchestration.replayEvents(0).then((replayed) => { | ||
| if (disposed) return; | ||
| setEvents(replayed); | ||
| }); | ||
|
|
||
| const unsubscribe = api.orchestration.onDomainEvent((event) => { | ||
| if (!isLive) return; | ||
| setEvents((current) => { | ||
| if (current.some((entry) => entry.sequence === event.sequence)) { | ||
| return current; | ||
| } | ||
| return [...current, event].toSorted((left, right) => left.sequence - right.sequence); | ||
| }); | ||
| }); | ||
|
|
||
| return () => { | ||
| disposed = true; | ||
| unsubscribe(); | ||
| }; | ||
| }, [isLive]); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium routes/_chat.$threadId.events.tsx:323
The useEffect in EventsRoutePage starts replayEvents(0) and onDomainEvent concurrently. Real-time events appended via setEvents((current) => [...current, event]) during the replay window are overwritten when replayEvents resolves and calls setEvents(replayed), causing those events to disappear from the UI until refresh. Consider buffering live events during replay and merging them once the history arrives.
let disposed = false; + const pendingLive: OrchestrationEvent[] = []; void api.orchestration.replayEvents(0).then((replayed) => { if (disposed) return; - setEvents(replayed); + const merged = [...replayed, ...pendingLive].toSorted((left, right) => left.sequence - right.sequence); + setEvents(merged); }); const unsubscribe = api.orchestration.onDomainEvent((event) => { if (!isLive) return; + pendingLive.push(event); setEvents((current) => { if (current.some((entry) => entry.sequence === event.sequence)) { return current;
In file apps/web/src/routes/_chat.$threadId.events.tsx around lines 323-350:
The `useEffect` in `EventsRoutePage` starts `replayEvents(0)` and `onDomainEvent` concurrently. Real-time events appended via `setEvents((current) => [...current, event])` during the replay window are overwritten when `replayEvents` resolves and calls `setEvents(replayed)`, causing those events to disappear from the UI until refresh. Consider buffering live events during replay and merging them once the history arrives.
Evidence trail:
apps/web/src/routes/_chat.$threadId.events.tsx lines 323-348 at REVIEWED_COMMIT - shows `replayEvents(0).then((replayed) => setEvents(replayed))` running concurrently with `onDomainEvent` subscription that calls `setEvents((current) => [...current, event])`. The `setEvents(replayed)` call completely replaces the array, overwriting any events appended by `onDomainEvent` during the replay window.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| this.state = this.reconnectAttempt > 0 ? "reconnecting" : "connecting"; | ||
| const ws = new WebSocket(this.url); | ||
|
|
||
| ws.addEventListener("open", () => { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium src/wsTransport.ts:244
When dispose() is called while connect() is in progress, this.ws is still null so the pending WebSocket is never closed. The open event handler then assigns this socket to this.ws and sets this.state = "open", resurrecting a zombie connection that persists indefinitely and consumes browser connection slots. The open handler should check this.disposed and close the socket immediately if the transport was disposed.
In file apps/web/src/wsTransport.ts around line 244:
When `dispose()` is called while `connect()` is in progress, `this.ws` is still `null` so the pending `WebSocket` is never closed. The `open` event handler then assigns this socket to `this.ws` and sets `this.state = "open"`, resurrecting a zombie connection that persists indefinitely and consumes browser connection slots. The `open` handler should check `this.disposed` and close the socket immediately if the transport was disposed.
Evidence trail:
apps/web/src/wsTransport.ts lines 220-234 (dispose method sets `this.disposed = true` and calls `this.ws?.close()` which does nothing if `this.ws` is null), lines 236-250 (connect method creates local `ws` variable at line 243, open handler at lines 245-250 assigns to `this.ws` and sets state to 'open' without checking `this.disposed`). Commit: REVIEWED_COMMIT
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } from "../Services/RuntimeReceiptBus.ts"; | ||
|
|
||
| const makeRuntimeReceiptBus = Effect.gen(function* () { | ||
| const pubSub = yield* PubSub.unbounded<OrchestrationRuntimeReceipt>(); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🟢 Low Layers/RuntimeReceiptBus.ts:10
PubSub.unbounded buffers messages indefinitely for slow or stalled consumers, so memory grows without limit until the process crashes with an Out of Memory error. Consider using PubSub.sliding or PubSub.dropping to enforce a bounded buffer size.
+ const pubSub = yield* PubSub.sliding<OrchestrationRuntimeReceipt>(1000);In file apps/server/src/orchestration/Layers/RuntimeReceiptBus.ts around line 10:
`PubSub.unbounded` buffers messages indefinitely for slow or stalled consumers, so memory grows without limit until the process crashes with an Out of Memory error. Consider using `PubSub.sliding` or `PubSub.dropping` to enforce a bounded buffer size.
Evidence trail:
apps/server/src/orchestration/Layers/RuntimeReceiptBus.ts line 10 shows `const pubSub = yield* PubSub.unbounded<OrchestrationRuntimeReceipt>();`. Effect library Stream.ts documentation at effect-ts.github.io confirms capacity options: `{ capacity: "unbounded" }` vs `{ capacity: number, strategy: "sliding" | "dropping" | "suspend" }`. The behavior claim (unbounded buffers indefinitely, alternatives exist with bounded strategies) is accurate per the Effect-TS API documentation.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| private state: TransportState = "connecting"; | ||
| private readonly url: string; | ||
|
|
||
| constructor(url?: string) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🟢 Low src/wsTransport.ts:140
The fallback URL construction at line 149 produces an invalid WebSocket URL when running on standard ports. When window.location.port is empty (ports 80 or 443), the result is ws://hostname: with a trailing colon, causing WebSocket constructor to throw SyntaxError. Also, hardcoding ws:// creates mixed-content errors when the page is served over HTTPS. Consider using window.location.protocol === 'https:' ? 'wss://' : 'ws://' and omitting the port when empty.
- url ?? - (bridgeUrl && bridgeUrl.length > 0 - ? bridgeUrl - : envUrl && envUrl.length > 0 - ? envUrl - : `ws://${window.location.hostname}:${window.location.port}`)
In file apps/web/src/wsTransport.ts around line 140:
The fallback URL construction at line 149 produces an invalid WebSocket URL when running on standard ports. When `window.location.port` is empty (ports 80 or 443), the result is `ws://hostname:` with a trailing colon, causing `WebSocket` constructor to throw `SyntaxError`. Also, hardcoding `ws://` creates mixed-content errors when the page is served over HTTPS. Consider using `window.location.protocol === 'https:' ? 'wss://' : 'ws://'` and omitting the port when empty.
Evidence trail:
apps/web/src/wsTransport.ts lines 144-149 (REVIEWED_COMMIT) - The fallback URL construction uses template literal `ws://${window.location.hostname}:${window.location.port}` which produces malformed URLs on standard ports and causes mixed-content issues on HTTPS.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| ); | ||
| } | ||
|
|
||
| export function classifyEvent(event: OrchestrationEvent): ReadonlyArray<string> { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🟢 Low lib/eventLifecycle.ts:371
classifyEvent falls back to matching event.type for non-diagnostic events, so every thread.activity-appended event is classified into all three traces that declare it: "session-startup", "turn-lifecycle", and "tool-execution". This floods the session-startup trace with unrelated tool activities, making it unusable for debugging startup. Consider inspecting the activity kind in the payload to discriminate startup handshake activities from tool activities.
In file apps/web/src/lib/eventLifecycle.ts around line 371:
`classifyEvent` falls back to matching `event.type` for non-diagnostic events, so every `thread.activity-appended` event is classified into all three traces that declare it: "session-startup", "turn-lifecycle", and "tool-execution". This floods the session-startup trace with unrelated tool activities, making it unusable for debugging startup. Consider inspecting the activity `kind` in the payload to discriminate startup handshake activities from tool activities.
Evidence trail:
apps/web/src/lib/eventLifecycle.ts lines 364-368 (`matchesTrace` function only checks `step.eventType === event.type`), lines 371-402 (`classifyEvent` function showing fallback to type-only matching), lines 120-248 (TRACE_DEFINITIONS showing `thread.activity-appended` in 'session-startup' at line 153, 'turn-lifecycle' at line 195, and 'tool-execution' at lines 224 and 245), lines 346-348 (showing `activity.kind` exists in payload but unused for classification)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Effect.forever( | ||
| Queue.take(queue).pipe( | ||
| Effect.flatMap((item) => | ||
| process(item).pipe( | ||
| Effect.ensuring(Ref.update(outstanding, (count) => Math.max(0, count - 1))), | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| ); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🟢 Low src/DrainableWorker.ts:51
Effect.forever stops repeating when process(item) fails, so a single failed item kills the worker permanently. Remaining queued items accumulate, outstanding never reaches zero, and drain() hangs forever. Consider catching and handling errors within the loop so the worker continues processing subsequent items.
- yield* Effect.forkScoped( - Effect.forever( - Queue.take(queue).pipe( - Effect.flatMap((item) => - process(item).pipe( - Effect.ensuring(Ref.update(outstanding, (count) => Math.max(0, count - 1))), - ), - ), - ), - ), - );
In file packages/shared/src/DrainableWorker.ts around lines 51-60:
`Effect.forever` stops repeating when `process(item)` fails, so a single failed item kills the worker permanently. Remaining queued items accumulate, `outstanding` never reaches zero, and `drain()` hangs forever. Consider catching and handling errors within the loop so the worker continues processing subsequent items.
Evidence trail:
packages/shared/src/DrainableWorker.ts lines 48-57 (REVIEWED_COMMIT): Effect.forever wraps the queue processing with no error handling around process(item). Effect.ensuring only guarantees the counter decrement runs but does not suppress errors. Standard Effect-ts semantics: errors propagate up and terminate Effect.forever.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| const alreadyStarted = yield* Ref.get(startedRef); | ||
| if (alreadyStarted) { | ||
| return yield* Deferred.await(startedDeferred); | ||
| } | ||
|
|
||
| yield* Ref.set(startedRef, true); | ||
| const startup = Effect.gen(function* () { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🟢 Low src/keybindings.ts:861
The start effect uses a non-atomic check-then-set pattern on startedRef: multiple concurrent fibers can read false before any sets true, causing startup to execute multiple times. This leaks duplicate file watchers and emits duplicate change events for the application's lifetime. Consider using Ref.getAndSet or Ref.modify to atomically claim the start token.
- const alreadyStarted = yield* Ref.get(startedRef); - if (alreadyStarted) { + const alreadyStarted = yield* Ref.getAndSet(startedRef, true); + if (alreadyStarted) { return yield* Deferred.await(startedDeferred); } - yield* Ref.set(startedRef, true); const startup = Effect.gen(function* () {
In file apps/server/src/keybindings.ts around lines 861-867:
The `start` effect uses a non-atomic check-then-set pattern on `startedRef`: multiple concurrent fibers can read `false` before any sets `true`, causing `startup` to execute multiple times. This leaks duplicate file watchers and emits duplicate change events for the application's lifetime. Consider using `Ref.getAndSet` or `Ref.modify` to atomically claim the start token.
Evidence trail:
apps/server/src/keybindings.ts lines 861-866 (REVIEWED_COMMIT): shows `Ref.get(startedRef)` followed by `Ref.set(startedRef, true)` as separate operations, confirming non-atomic check-then-set pattern. Line 547: `startedRef = yield* Ref.make(false)`. Lines 851-857: `startWatcher` creates file watchers via `watchFileWithStatPolling`. Lines 867-872: `startup` effect includes `startWatcher`.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.