start phase 1

This commit is contained in:
Julius Marminge authored and Julius Marminge committed 2026-02-26 13:20:36 -08:00
1 parent 6954d1b91c
commit fefea0bdf6
16 files changed
+625 -4904

No files matched your search

+6 -1
View File
@@ -1,5 +1,10 @@
# PR #89 Review Remediation Plan (Phased)
## How To Use These Files
- Working checklist with updateable status per item (single source of truth): `.plans/16c-pr89-remediation-checklist.md`
- This file (`16-pr89-review-remediation-phases.md`): phase strategy and grouping.
## Scope
- Source: GitHub review comments on PR #89 (`Add server-side orchestration engine with event sourcing`).
@@ -14,7 +19,7 @@
## Phase 0: Canonical Triage Lock
- Create a single tracking checklist for the 74 unique actionable findings.
- Create a single tracking checklist for the 53 currently actionable findings.
- Map every duplicate thread to its canonical item.
- Mark invalid/false-positive items with explicit rationale.
File diff suppressed because it is too large. Load diff
-201
View File
@@ -1,201 +0,0 @@
# Phase 0: PR #89 Canonical Triage Lock
- PR: https://github.com/pingdotgg/t3-code/pull/89
- Title: Add server-side orchestration engine with event sourcing
- Generated from latest GitHub data and deduplicated into canonical fix items.
## Summary
- Total threads: 185
- Actionable canonical: 53
- Actionable duplicates: 24
- Filtered outdated: 94
- Filtered resolved: 6
- Filtered invalid: 8
## Canonical Actionable Checklist
### Other (16)
- [ ] C011 [Medium] Template literal `${cause}` throws if `cause` is a `Symbol`. Consider using `String(cause)` instead. (apps/server/src/orchestration/Errors.ts:117)
- Threads: PRRT_kwDORLtfbc5wBFv4
- [ ] C024 [Medium] In `executeUnprepared`, preparing outside an effect and not closing the statement can cause uncaught errors and leaks. Suggest wrapping with `Effect.acquireUseRelease`: prepare in acquire (error-safe) and `finalize` in release. (apps/server/src/persistence/NodeSqliteClient.ts:145)
- Threads: PRRT_kwDORLtfbc5whxX9
- [ ] C028 [Medium] Branch sync dispatches both server and stale local update (apps/web/src/components/BranchToolbar.tsx:102)
- Threads: PRRT_kwDORLtfbc5v-XCu
- [ ] C032 [Low] Dummy workflow marker accidentally committed to docs (AGENTS.md:45) (+1 dup)
- Threads: PRRT_kwDORLtfbc5wlYgj, PRRT_kwDORLtfbc5w1C4H
- [ ] C037 [Low] `Effect.callback` should return a cleanup function to close the server(s) on fiber interruption. Without it, the `Net.Server` handles keep the process alive and leak the port if the effect is cancelled. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/config.ts:41)
- Threads: PRRT_kwDORLtfbc5wj4cO
- [ ] C041 [Low] Template literal interpolation throws `TypeError` if `cause` is a `Symbol`. Consider using `String(cause)` for safe coercion. (apps/server/src/orchestration/Errors.ts:126)
- Threads: PRRT_kwDORLtfbc5wBFWs
- [ ] C047 [Low] `SqlSchema.findOneOption` can produce both SQL errors and decode errors, but `mapError` wraps all as `PersistenceSqlError`. Consider distinguishing `ParseError` from SQL errors and mapping decode failures to `PersistenceDecodeError` instead. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/persistence/Layers/OrchestrationCommandReceipts.ts:75)
- Threads: PRRT_kwDORLtfbc5wiaR-
- [ ] C048 [Low] `statement.run()` returns a `RunResult` object, not an array. Casting it to `ReadonlyArray<any>` will cause runtime errors when consumers call array methods. Consider wrapping the result (e.g., `[result]`) or returning a properly typed object. (apps/server/src/persistence/NodeSqliteClient.ts:99)
- Threads: PRRT_kwDORLtfbc5wio-r
- [ ] C049 [Low] `JSON.stringify(cause)` returns `undefined` for `undefined`, functions, or symbols, violating the `string` return type. Consider coercing the result to a string (e.g., `String(JSON.stringify(cause))`) or adding a fallback. (apps/server/src/provider/Layers/ProviderService.ts:59)
- Threads: PRRT_kwDORLtfbc5wnVsI
- [ ] C050 [Low] The read-modify-write pattern (`getBySessionId` → merge → `upsert`) is susceptible to lost updates under concurrent writes. Consider wrapping in a transaction or adding optimistic concurrency control (e.g., version field) if concurrent session updates are expected. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/provider/Layers/ProviderSessionDirectory.ts:94)
- Threads: PRRT_kwDORLtfbc5wiLhY
- [ ] C051 [Low] Using `??` for `providerThreadId` and `adapterKey` makes it impossible to clear these fields by passing `null`, since `null ?? existing` evaluates to `existing`. Consider using explicit `undefined` checks (like `resumeCursor` does) if clearing should be supported. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/provider/Layers/ProviderSessionDirectory.ts:119)
- Threads: PRRT_kwDORLtfbc5wxvH9
- [ ] C052 [Low] Race condition: `processHandle` may be `null` when `data` callback fires, since it's assigned after `Bun.spawn` returns. Consider initializing `BunPtyProcess` first, then passing it to the callback to avoid losing initial output. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/terminal/Layers/BunPTY.ts:97)
- Threads: PRRT_kwDORLtfbc5w1CxE
- [ ] C056 [Low] When `onOpenChange` is provided without `open`, the internal `_open` state never updates because `setOpenProp` takes precedence. Consider calling `_setOpen` when `openProp === undefined`, regardless of whether `setOpenProp` exists. (apps/web/src/components/ui/sidebar.tsx:114)
- Threads: PRRT_kwDORLtfbc5wxvIq
- [ ] C057 [Low] The `resizable` object is recreated on every render, causing `SidebarRail`'s `useEffect` to repeatedly read localStorage and update the DOM. Consider memoizing the object with `useMemo`. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/web/src/routes/_chat.$threadId.tsx:105)
- Threads: PRRT_kwDORLtfbc5wyWz4
- [ ] C058 [Low] When `localStorage.getItem()` returns `null`, `Number(null)` evaluates to `0`, which passes `Number.isFinite(0)`. This causes the sidebar to clamp to `minWidth` on first load, overriding the `DIFF_INLINE_DEFAULT_WIDTH` CSS clamp. Consider checking for `null` or empty string before parsing, e.g. guard with `storedWidth === null || storedWidth === ''`. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/web/src/routes/_chat.$threadId.tsx:122)
- Threads: PRRT_kwDORLtfbc5wnVsX
- [ ] C060 [Low] `defaultModel` should be `Schema.optional(Schema.NullOr(Schema.String))` to allow clearing the value. Currently there's no way to reset it to `null` since omitting means "no change" in patch semantics. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (packages/contracts/src/orchestration.ts:253)
- Threads: PRRT_kwDORLtfbc5whxJC
### Runtime resilience and failure handling (10)
- [x] C002 [High] A dispatch error in `processEvent` will terminate the `Effect.forever` loop, permanently halting event ingestion. Consider adding error recovery (e.g., `Effect.catchAll` with logging) around `processEvent` so failures don't kill the fiber. (apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts:333) (+5 dup)
- Threads: PRRT_kwDORLtfbc5wj4cH, PRRT_kwDORLtfbc5wnWwF, PRRT_kwDORLtfbc5wyTaP, PRRT_kwDORLtfbc5wzliw, PRRT_kwDORLtfbc5w0_g3, PRRT_kwDORLtfbc5w1HGT
- [x] C012 [Medium] Forked revert dispatch risks read model inconsistency (apps/server/src/orchestration/Layers/CheckpointReactor.ts:542) (+4 dup)
- Threads: PRRT_kwDORLtfbc5whszW, PRRT_kwDORLtfbc5wyTaS, PRRT_kwDORLtfbc5wzli0, PRRT_kwDORLtfbc5w0_g4, PRRT_kwDORLtfbc5w1HGX
- [ ] C019 [Medium] ProviderRuntimeIngestion processes events for wrong thread on race (apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts:178)
- Threads: PRRT_kwDORLtfbc5wkPaL
- [ ] C020 [Medium] On `message.completed`, the message ID is added to the set and `thread.message.assistant.complete` is dispatched. On `turn.completed`, the same set is iterated and `thread.message.assistant.complete` is dispatched again for each ID—including already-completed ones. Consider removing message IDs from the set after dispatching on `message.completed`, or filtering out already-completed IDs before the `turn.completed` loop. (apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts:266)
- Threads: PRRT_kwDORLtfbc5w1GPr
- [x] C027 [Medium] WS message handler can cause unhandled promise rejection (apps/server/src/wsServer.ts:545) (+1 dup)
- Threads: PRRT_kwDORLtfbc5wyTaW, PRRT_kwDORLtfbc5wzli3
- [ ] C042 [Low] Duplicated `resolveThreadWorkspaceCwd` across three files (apps/server/src/orchestration/Layers/CheckpointReactor.ts:62)
- Threads: PRRT_kwDORLtfbc5wzli2
- [ ] C043 [Low] Duplicated workspace CWD resolution logic across reactor modules (apps/server/src/orchestration/Layers/CheckpointReactor.ts:62) (+2 dup)
- Threads: PRRT_kwDORLtfbc5wnWwM, PRRT_kwDORLtfbc5w1C3-, PRRT_kwDORLtfbc5w1HGZ
- [ ] C044 [Low] Checkpoint reactor swallows diff errors silently for `turn.completed` (apps/server/src/orchestration/Layers/CheckpointReactor.ts:274)
- Threads: PRRT_kwDORLtfbc5wkPaO
- [ ] C045 [Low] `truncateDetail` slices to `limit - 1` then appends `"..."` (3 chars), producing strings of length `limit + 2`. Consider slicing to `limit - 3` instead. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts:29)
- Threads: PRRT_kwDORLtfbc5wzp4R
- [ ] C046 [Low] `latestMessageIdByTurnKey` is written to but never read, and `clearAssistantMessageIdsForTurn` doesn't clear its entries—only `clearTurnStateForSession` does. Consider removing this map entirely if unused, or clearing it alongside `turnMessageIdsByTurnKey` in `clearAssistantMessageIdsForTurn`. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts:133)
- Threads: PRRT_kwDORLtfbc5wxvIQ
### Edge-case parsing/platform behavior (9)
- [ ] C009 [Medium] Git's braced rename syntax (e.g., `src/{old => new}/file.ts`) isn't handled correctly. The current slice after ` => ` produces invalid paths like `new}/file.ts`. Consider expanding the braces to construct the full destination path. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/git/Layers/GitCore.ts:41)
- Threads: PRRT_kwDORLtfbc5w1CxT
- [ ] C010 [Medium] `loadCustomKeybindingsConfig` fails when the config file doesn't exist, which is expected for new users. Consider catching `ENOENT` and returning an empty array instead. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/keybindings.ts:418)
- Threads: PRRT_kwDORLtfbc5wxvIJ
- [ ] C022 [Medium] Fish shell outputs `$PATH` as space-separated, not colon-separated. Consider checking if the shell is fish and using `string join : $PATH` instead, or validating the result contains colons before assigning. (apps/server/src/os-jank.ts:10)
- Threads: PRRT_kwDORLtfbc5wkRZM
- [ ] C023 [Medium] Using `-il` flags causes the shell to source profile scripts that may print banners or other text, polluting the captured `PATH`. Consider using `-lc` (login only, non-interactive) to reduce unwanted output. (apps/server/src/os-jank.ts:10)
- Threads: PRRT_kwDORLtfbc5wj4cM
- [ ] C029 [Medium] `parseFileUrlHref` already decodes the path (line 46), but `safeDecode` is called again here, corrupting filenames containing `%` sequences. Consider skipping the decode when `fileUrlTarget` is non-null. (apps/web/src/markdown-links.ts:105)
- Threads: PRRT_kwDORLtfbc5wnVsU
- [ ] C030 [Medium] `EXTERNAL_SCHEME_PATTERN` matches `script.ts:10` as a scheme because `.ts:` looks like `scheme:`. Consider requiring `://` after the colon, or checking that what follows the colon is not just digits. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/web/src/markdown-links.ts:111)
- Threads: PRRT_kwDORLtfbc5wnVsK
- [ ] C038 [Low] Multi-byte UTF-8 characters split across chunks will be corrupted when decoding each chunk separately. Consider accumulating all chunks first, then decoding once, or use `TextDecoder` with `stream: true`. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/git/Layers/CodexTextGeneration.ts:136)
- Threads: PRRT_kwDORLtfbc5w1GPo
- [ ] C039 [Low] The `+` key can be parsed (via trailing `+` handling) but cannot be encoded because `shortcut.key.includes("+")` returns true for the literal `+` key. Consider checking `shortcut.key === "+"` separately and encoding it as `"space"` style (e.g., a special token), or adjusting the condition to allow the single `+` character. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/keybindings.ts:352)
- Threads: PRRT_kwDORLtfbc5wxvIB
- [ ] C040 [Low] `upsertKeybindingRule` has a race condition: concurrent calls read the same file state, then the last write overwrites earlier changes. Consider wrapping the read-modify-write sequence with `Effect.Semaphore` to serialize access. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/keybindings.ts:488)
- Threads: PRRT_kwDORLtfbc5wxvIA
### Event ordering and state consistency (5)
- [ ] C001 [High] Non-atomic event appending can corrupt state on retry. If an error occurs mid-loop (lines 96-102) after some events are persisted but before the receipt is written, the command appears to fail. A retry generates new UUIDs via `crypto.randomUUID()` in the decider, appending duplicate events. Consider wrapping the loop in a transaction or using deterministic event IDs derived from `commandId`. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/orchestration/Layers/OrchestrationEngine.ts:96)
- Threads: PRRT_kwDORLtfbc5wzp4T
- [ ] C013 [Medium] If `projectionPipeline.projectEvent` fails after `eventStore.append` succeeds, the event is persisted but `readModel` isn't updated, causing desync. Consider updating the in-memory `readModel` immediately after append (before the external projection), so local state stays consistent regardless of downstream failures. (apps/server/src/orchestration/Layers/OrchestrationEngine.ts:99)
- Threads: PRRT_kwDORLtfbc5whtrM
- [ ] C014 [Medium] Engine error handler catches all errors including non-invariant ones (apps/server/src/orchestration/Layers/OrchestrationEngine.ts:144)
- Threads: PRRT_kwDORLtfbc5wkPaJ
- [ ] C015 [Medium] The gap-filling fallback logic can retain messages from turns that are about to be deleted, causing foreign key violations. Consider removing the fallback logic entirely, or filtering `fallbackUserMessages` and `fallbackAssistantMessages` to only include messages whose `turnId` is in `retainedTurnIds`. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/orchestration/Layers/ProjectionPipeline.ts:99)
- Threads: PRRT_kwDORLtfbc5whxJO
- [ ] C016 [Medium] The in-memory `pendingTurnStartByThreadId` map isn't restored during bootstrap. If the service restarts after processing `thread.turn-start-requested` but before `thread.session-set`, the `userMessageId` and `startedAt` will be lost since bootstrap resumes *after* the committed sequence. Consider persisting this pending state or processing these two events atomically. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/orchestration/Layers/ProjectionPipeline.ts:490)
- Threads: PRRT_kwDORLtfbc5wxvH8
### WebSocket robustness (5)
- [ ] C003 [High] Consider attaching a no-op error listener before `socket.write` (e.g., `socket.on('error', () => {})`) to prevent an unhandled `EPIPE`/`ECONNRESET` from crashing the process if the client disconnects mid-handshake. (apps/server/src/wsServer.ts:75)
- Threads: PRRT_kwDORLtfbc5v-cf4
- [x] C026 [Medium] Consider adding `.catch(() => {})` after `Effect.runPromise(handleMessage(ws, raw))` to prevent unhandled rejections from crashing the server if `encodeResponse` or setup logic fails. (apps/server/src/wsServer.ts:545)
- Threads: PRRT_kwDORLtfbc5wj4cE
- [ ] C053 [Low] Consider using `socket.end(response)` instead of `socket.write(response)` + `socket.destroy()` to ensure the HTTP error response is fully flushed before closing the connection. (apps/server/src/wsServer.ts:83)
- Threads: PRRT_kwDORLtfbc5v-WPD
- [ ] C054 [Low] When array chunks contain a multi-byte UTF-8 character split across boundaries, decoding each chunk separately produces replacement characters. Consider using `Buffer.concat()` on all chunks before calling `.toString("utf8")`. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/wsServer.ts:104)
- Threads: PRRT_kwDORLtfbc5whtrR
- [ ] C059 [Low] Suggestion: don’t spread `params` into `body`; it can override `_tag` and mishandle non-object values. Keep `_tag` separate and nest `params` under a single key (e.g., `data`), or validate `params` is a plain object. (apps/web/src/wsTransport.ts:59)
- Threads: PRRT_kwDORLtfbc5whtrN
### Checkpointing correctness (5)
- [ ] C008 [Medium] Inconsistent input normalization across CheckpointStore methods (apps/server/src/checkpointing/Layers/CheckpointStore.ts:94) (+3 dup)
- Threads: PRRT_kwDORLtfbc5widJw, PRRT_kwDORLtfbc5wnWv_, PRRT_kwDORLtfbc5w0_g7, PRRT_kwDORLtfbc5w1C36
- [ ] C017 [Medium] `REQUIRED_SNAPSHOT_PROJECTORS` includes `pending-approvals` and `thread-turns`, but `getSnapshot` doesn't query their data. If these projectors lag behind, the returned `snapshotSequence` will be lower than what the included data actually reflects, causing clients to replay already-applied events. Consider filtering `REQUIRED_SNAPSHOT_PROJECTORS` to only include projectors whose data is actually fetched in the snapshot. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts:71)
- Threads: PRRT_kwDORLtfbc5wiLhQ
- [ ] C033 [Low] Three error classes defined but never instantiated anywhere (apps/server/src/checkpointing/Errors.ts:51)
- Threads: PRRT_kwDORLtfbc5wlYgo
- [ ] C034 [Low] Redundant `CheckpointInvariantError` in `CheckpointServiceError` union type (apps/server/src/checkpointing/Errors.ts:79)
- Threads: PRRT_kwDORLtfbc5wj5fn
- [ ] C035 [Low] Redundant error type in CheckpointServiceError union definition (apps/server/src/checkpointing/Errors.ts:79) (+2 dup)
- Threads: PRRT_kwDORLtfbc5wlYgs, PRRT_kwDORLtfbc5wxsO6, PRRT_kwDORLtfbc5w1C4B
### Build/runtime portability (2)
- [ ] C006 [Medium] Build script runs TypeScript file with bare node (apps/server/package.json:14)
- Threads: PRRT_kwDORLtfbc5wxsO-
- [ ] C007 [Medium] Build script uses `node` to run `.ts` file directly (apps/server/package.json:14) (+1 dup)
- Threads: PRRT_kwDORLtfbc5wiLNS, PRRT_kwDORLtfbc5wj5fl
### Memory/resource growth (1)
- [ ] C018 [Medium] Unbounded memory growth in turn start deduplication set (apps/server/src/orchestration/Layers/ProviderCommandReactor.ts:84) (+5 dup)
- Threads: PRRT_kwDORLtfbc5whszQ, PRRT_kwDORLtfbc5wl2A8, PRRT_kwDORLtfbc5wyTaT, PRRT_kwDORLtfbc5wzliz, PRRT_kwDORLtfbc5w0_g-, PRRT_kwDORLtfbc5w1HGW
## Invalid / False-Positive Threads
- PRRT_kwDORLtfbc5v9An7 | apps/web/src/routes/__root.tsx:140 | channel.** The web app currently does not consume provider event streams via the `providers.event` channel. While the orchestration API has `onReadModel()` and `onDomainEvent()` subscriptions, the providers event stream subscription is missing. Add a subscription to `ORCHESTRATION_WS_CHANNELS.event` (or the appropriate providers event channel from contracts) in `wsNativeApi.ts` and expose it via the `api.providers` object to comply with the guideline requirement. <details> <summary>🤖 Prompt for AI Agents</summary>
- Rationale: Invalid by design: provider runtime events are intentionally surfaced through orchestration domain events (`orchestration.domainEvent`), not a separate `providers.event` WebSocket channel in the current architecture.
- PRRT_kwDORLtfbc5v9An- | apps/web/src/wsNativeApi.ts:165 | push stream, and the callbacks rely on unchecked casts. Please reintroduce a `providers.onEvent` (or equivalent) that subscribes to the `providers.event` channel and decode read-model/domain-event payloads using the shared contracts schemas before invoking callbacks. As per coding guidelines: "Web app must consume provider event streams via WebSocket push on channel `providers.event`" and "Use Zod schemas from `packages/contracts` for shared type contracts covering provider events, WebSocket protocol, and model/session types". <details> <summary>🤖 Prompt for AI Agents</summary>
- Rationale: Invalid by design: provider runtime events are intentionally surfaced through orchestration domain events (`orchestration.domainEvent`), not a separate `providers.event` WebSocket channel in the current architecture.
- PRRT_kwDORLtfbc5v9SCp | apps/web/src/session-logic.ts:127 | Revert uses wrong turn count from positional inference
- Rationale: Invalid after post-rewrite audit: Revert now uses explicit checkpointTurnCount first; positional fallback is non-primary.
- PRRT_kwDORLtfbc5widJx | apps/server/package.json:14 | Build script requires implicit Node.js TypeScript support
- Rationale: Thread contains explicit false-positive determination in replies.
- PRRT_kwDORLtfbc5wiqFX | apps/server/src/checkpointing/Layers/CheckpointStore.ts:284 | Duplicate `checkpointRefForThreadTurn` function in two production files
- Rationale: Invalid after post-rewrite audit: No longer duplicated; single production source via Refs.ts.
- PRRT_kwDORLtfbc5wkPaA | apps/server/src/orchestration/decider.ts:27 | Shared mutable default metadata object causes stale eventId
- Rationale: Invalid after post-rewrite audit: Stale-eventId claim no longer applies; eventId is regenerated per event.
- PRRT_kwDORLtfbc5wkPaG | apps/server/src/wsServer.ts:128 | Duplicate `checkpointRefForThreadTurn` function across files
- Rationale: Invalid after post-rewrite audit: No longer duplicated; helper is centralized.
- PRRT_kwDORLtfbc5wvwag | apps/server/src/wsServer.ts:128 | Duplicated checkpoint ref computation across two files
- Rationale: Invalid after post-rewrite audit: No longer duplicated; checkpoint ref helper now centralized.
## Duplicate Mapping
- Each duplicate thread is mapped to one canonical fix item.
- PRRT_kwDORLtfbc5wj5fl | apps/server/package.json:14 -> C007
- PRRT_kwDORLtfbc5wl2A8 | apps/server/src/orchestration/Layers/ProviderCommandReactor.ts:84 -> C018
- PRRT_kwDORLtfbc5wnWv_ | apps/server/src/checkpointing/Layers/CheckpointStore.ts:94 -> C008
- PRRT_kwDORLtfbc5wnWwF | apps/server/src/orchestration/Layers/CheckpointReactor.ts:584 -> C002
- PRRT_kwDORLtfbc5wxsO6 | apps/server/src/checkpointing/Errors.ts:79 -> C035
- PRRT_kwDORLtfbc5wyTaP | apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts:334 -> C002
- PRRT_kwDORLtfbc5wyTaS | apps/server/src/orchestration/Layers/CheckpointReactor.ts:542 -> C012
- PRRT_kwDORLtfbc5wyTaT | apps/server/src/orchestration/Layers/ProviderCommandReactor.ts:84 -> C018
- PRRT_kwDORLtfbc5wzliw | apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts:334 -> C002
- PRRT_kwDORLtfbc5wzliz | apps/server/src/orchestration/Layers/ProviderCommandReactor.ts:84 -> C018
- PRRT_kwDORLtfbc5wzli0 | apps/server/src/orchestration/Layers/CheckpointReactor.ts:542 -> C012
- PRRT_kwDORLtfbc5wzli3 | apps/server/src/wsServer.ts:545 -> C027
- PRRT_kwDORLtfbc5w0_g3 | apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts:334 -> C002
- PRRT_kwDORLtfbc5w0_g4 | apps/server/src/orchestration/Layers/CheckpointReactor.ts:542 -> C012
- PRRT_kwDORLtfbc5w0_g7 | apps/server/src/checkpointing/Layers/CheckpointStore.ts:95 -> C008
- PRRT_kwDORLtfbc5w0_g- | apps/server/src/orchestration/Layers/ProviderCommandReactor.ts:84 -> C018
- PRRT_kwDORLtfbc5w1C36 | apps/server/src/checkpointing/Layers/CheckpointStore.ts:94 -> C008
- PRRT_kwDORLtfbc5w1C3- | apps/server/src/checkpointing/Layers/CheckpointDiffQuery.ts:40 -> C043
- PRRT_kwDORLtfbc5w1C4B | apps/server/src/checkpointing/Errors.ts:79 -> C035
- PRRT_kwDORLtfbc5w1C4H | AGENTS.md:45 -> C032
- PRRT_kwDORLtfbc5w1HGT | apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts:334 -> C002
- PRRT_kwDORLtfbc5w1HGW | apps/server/src/orchestration/Layers/ProviderCommandReactor.ts:84 -> C018
- PRRT_kwDORLtfbc5w1HGX | apps/server/src/orchestration/Layers/CheckpointReactor.ts:542 -> C012
- PRRT_kwDORLtfbc5w1HGZ | apps/server/src/checkpointing/Layers/CheckpointDiffQuery.ts:40 -> C043
## Outdated / Resolved Buckets
- Outdated threads: 94
- Resolved threads: 6
Per-thread mapping source of truth: `.plans/16a-pr89-phase0-canonical-triage.json`.
@@ -1,790 +0,0 @@
{
"source": ".plans/16a-pr89-phase0-canonical-triage.json",
"architecture_assumption": "Provider runtime activity is projected and consumed via orchestration.domainEvent; no separate providers.event push channel is expected.",
"summary": {
"total_canonical_reviewed": 58,
"valid": 34,
"partially_valid": 19,
"invalid": 5
},
"records": [
{
"canonical_id": "C001",
"verdict": "valid",
"rationale": "Append/project/receipt are non-atomic; retry can duplicate events.",
"severity": "High",
"area": "Event ordering and state consistency",
"path": "apps/server/src/orchestration/Layers/OrchestrationEngine.ts",
"line": 96,
"title": "Non-atomic event appending can corrupt state on retry. If an error occurs mid-loop (lines 96-102) after some events are persisted but before the receipt is written, the command appears to fail. A retry generates new UUIDs via `crypto.randomUUID()` in the decider, appending duplicate events. Consider wrapping the loop in a transaction or using deterministic event IDs derived from `commandId`. <details> <summary>\ud83d\ude80 Reply \"<strong>fix it for me</strong>\" or copy this <strong>AI Prompt</strong> for your agent:</summary>",
"thread_ids": [
"PRRT_kwDORLtfbc5wzp4T"
]
},
{
"canonical_id": "C002",
"verdict": "valid",
"rationale": "Ingestion worker loop can terminate on unhandled processEvent failure.",
"severity": "High",
"area": "Runtime resilience and failure handling",
"path": "apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts",
"line": 333,
"title": "A dispatch error in `processEvent` will terminate the `Effect.forever` loop, permanently halting event ingestion. Consider adding error recovery (e.g., `Effect.catchAll` with logging) around `processEvent` so failures don't kill the fiber.",
"thread_ids": [
"PRRT_kwDORLtfbc5wj4cH",
"PRRT_kwDORLtfbc5wnWwF",
"PRRT_kwDORLtfbc5wyTaP",
"PRRT_kwDORLtfbc5wzliw",
"PRRT_kwDORLtfbc5w0_g3",
"PRRT_kwDORLtfbc5w1HGT"
]
},
{
"canonical_id": "C003",
"verdict": "valid",
"rationale": "Upgrade reject writes then destroys socket without defensive error listener.",
"severity": "High",
"area": "WebSocket robustness",
"path": "apps/server/src/wsServer.ts",
"line": 75,
"title": "Consider attaching a no-op error listener before `socket.write` (e.g., `socket.on('error', () => {})`) to prevent an unhandled `EPIPE`/`ECONNRESET` from crashing the process if the client disconnects mid-handshake.",
"thread_ids": [
"PRRT_kwDORLtfbc5v-cf4"
]
},
{
"canonical_id": "C006",
"verdict": "partially-valid",
"rationale": "Node 24 makes this work, but script still relies on runtime-specific TS execution.",
"severity": "Medium",
"area": "Build/runtime portability",
"path": "apps/server/package.json",
"line": 14,
"title": "Build script runs TypeScript file with bare node",
"thread_ids": [
"PRRT_kwDORLtfbc5wxsO-"
]
},
{
"canonical_id": "C007",
"verdict": "partially-valid",
"rationale": "Same as C006 (duplicate concern).",
"severity": "Medium",
"area": "Build/runtime portability",
"path": "apps/server/package.json",
"line": 14,
"title": "Build script uses `node` to run `.ts` file directly",
"thread_ids": [
"PRRT_kwDORLtfbc5wiLNS",
"PRRT_kwDORLtfbc5wj5fl"
]
},
{
"canonical_id": "C008",
"verdict": "partially-valid",
"rationale": "Normalization inconsistency remains, but upstream callsites now mostly canonicalize inputs.",
"severity": "Medium",
"area": "Checkpointing correctness",
"path": "apps/server/src/checkpointing/Layers/CheckpointStore.ts",
"line": 94,
"title": "Inconsistent input normalization across CheckpointStore methods",
"thread_ids": [
"PRRT_kwDORLtfbc5widJw",
"PRRT_kwDORLtfbc5wnWv_",
"PRRT_kwDORLtfbc5w0_g7",
"PRRT_kwDORLtfbc5w1C36"
]
},
{
"canonical_id": "C009",
"verdict": "valid",
"rationale": "Braced rename parsing still breaks paths like src/{old => new}/file.ts.",
"severity": "Medium",
"area": "Edge-case parsing/platform behavior",
"path": "apps/server/src/git/Layers/GitCore.ts",
"line": 41,
"title": "Git's braced rename syntax (e.g., `src/{old => new}/file.ts`) isn't handled correctly. The current slice after ` => ` produces invalid paths like `new}/file.ts`. Consider expanding the braces to construct the full destination path. <details> <summary>\ud83d\ude80 Reply \"<strong>fix it for me</strong>\" or copy this <strong>AI Prompt</strong> for your agent:</summary>",
"thread_ids": [
"PRRT_kwDORLtfbc5w1CxT"
]
},
{
"canonical_id": "C010",
"verdict": "valid",
"rationale": "ENOENT for missing keybindings config still not handled as empty/default.",
"severity": "Medium",
"area": "Edge-case parsing/platform behavior",
"path": "apps/server/src/keybindings.ts",
"line": 418,
"title": "`loadCustomKeybindingsConfig` fails when the config file doesn't exist, which is expected for new users. Consider catching `ENOENT` and returning an empty array instead. <details> <summary>\ud83d\ude80 Reply \"<strong>fix it for me</strong>\" or copy this <strong>AI Prompt</strong> for your agent:</summary>",
"thread_ids": [
"PRRT_kwDORLtfbc5wxvIJ"
]
},
{
"canonical_id": "C011",
"verdict": "valid",
"rationale": "Template-literal interpolation of Symbol still throws.",
"severity": "Medium",
"area": "Other",
"path": "apps/server/src/orchestration/Errors.ts",
"line": 117,
"title": "Template literal `${cause}` throws if `cause` is a `Symbol`. Consider using `String(cause)` instead.",
"thread_ids": [
"PRRT_kwDORLtfbc5wBFv4"
]
},
{
"canonical_id": "C012",
"verdict": "valid",
"rationale": "Revert completion dispatch remains forked; state consistency window remains.",
"severity": "Medium",
"area": "Runtime resilience and failure handling",
"path": "apps/server/src/orchestration/Layers/CheckpointReactor.ts",
"line": 542,
"title": "Forked revert dispatch risks read model inconsistency",
"thread_ids": [
"PRRT_kwDORLtfbc5whszW",
"PRRT_kwDORLtfbc5wyTaS",
"PRRT_kwDORLtfbc5wzli0",
"PRRT_kwDORLtfbc5w0_g4",
"PRRT_kwDORLtfbc5w1HGX"
]
},
{
"canonical_id": "C013",
"verdict": "valid",
"rationale": "Persisted event can outpace in-memory projection on mid-flight failure.",
"severity": "Medium",
"area": "Event ordering and state consistency",
"path": "apps/server/src/orchestration/Layers/OrchestrationEngine.ts",
"line": 99,
"title": "If `projectionPipeline.projectEvent` fails after `eventStore.append` succeeds, the event is persisted but `readModel` isn't updated, causing desync. Consider updating the in-memory `readModel` immediately after append (before the external projection), so local state stays consistent regardless of downstream failures.",
"thread_ids": [
"PRRT_kwDORLtfbc5whtrM"
]
},
{
"canonical_id": "C014",
"verdict": "partially-valid",
"rationale": "Broad catch may be intentional for liveness; correctness concern is contextual.",
"severity": "Medium",
"area": "Event ordering and state consistency",
"path": "apps/server/src/orchestration/Layers/OrchestrationEngine.ts",
"line": 144,
"title": "Engine error handler catches all errors including non-invariant ones",
"thread_ids": [
"PRRT_kwDORLtfbc5wkPaJ"
]
},
{
"canonical_id": "C015",
"verdict": "partially-valid",
"rationale": "Message fallback retention issue is real, but prior FK-violation claim is overstated.",
"severity": "Medium",
"area": "Event ordering and state consistency",
"path": "apps/server/src/orchestration/Layers/ProjectionPipeline.ts",
"line": 99,
"title": "The gap-filling fallback logic can retain messages from turns that are about to be deleted, causing foreign key violations. Consider removing the fallback logic entirely, or filtering `fallbackUserMessages` and `fallbackAssistantMessages` to only include messages whose `turnId` is in `retainedTurnIds`. <details> <summary>\ud83d\ude80 Reply \"<strong>fix it for me</strong>\" or copy this <strong>AI Prompt</strong> for your agent:</summary>",
"thread_ids": [
"PRRT_kwDORLtfbc5whxJO"
]
},
{
"canonical_id": "C016",
"verdict": "valid",
"rationale": "Pending turn-start map is in-memory only and not rebuilt on bootstrap.",
"severity": "Medium",
"area": "Event ordering and state consistency",
"path": "apps/server/src/orchestration/Layers/ProjectionPipeline.ts",
"line": 490,
"title": "The in-memory `pendingTurnStartByThreadId` map isn't restored during bootstrap. If the service restarts after processing `thread.turn-start-requested` but before `thread.session-set`, the `userMessageId` and `startedAt` will be lost since bootstrap resumes *after* the committed sequence. Consider persisting this pending state or processing these two events atomically. <details> <summary>\ud83d\ude80 Reply \"<strong>fix it for me</strong>\" or copy this <strong>AI Prompt</strong> for your agent:</summary>",
"thread_ids": [
"PRRT_kwDORLtfbc5wxvH8"
]
},
{
"canonical_id": "C017",
"verdict": "partially-valid",
"rationale": "Snapshot sequence can under-report due to extra projectors, but replay impact is lower now.",
"severity": "Medium",
"area": "Checkpointing correctness",
"path": "apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts",
"line": 71,
"title": "`REQUIRED_SNAPSHOT_PROJECTORS` includes `pending-approvals` and `thread-turns`, but `getSnapshot` doesn't query their data. If these projectors lag behind, the returned `snapshotSequence` will be lower than what the included data actually reflects, causing clients to replay already-applied events. Consider filtering `REQUIRED_SNAPSHOT_PROJECTORS` to only include projectors whose data is actually fetched in the snapshot. <details> <summary>\ud83d\ude80 Reply \"<strong>fix it for me</strong>\" or copy this <strong>AI Prompt</strong> for your agent:</summary>",
"thread_ids": [
"PRRT_kwDORLtfbc5wiLhQ"
]
},
{
"canonical_id": "C018",
"verdict": "valid",
"rationale": "handledTurnStartKeys still grows without pruning.",
"severity": "Medium",
"area": "Memory/resource growth",
"path": "apps/server/src/orchestration/Layers/ProviderCommandReactor.ts",
"line": 84,
"title": "Unbounded memory growth in turn start deduplication set",
"thread_ids": [
"PRRT_kwDORLtfbc5whszQ",
"PRRT_kwDORLtfbc5wl2A8",
"PRRT_kwDORLtfbc5wyTaT",
"PRRT_kwDORLtfbc5wzliz",
"PRRT_kwDORLtfbc5w0_g-",
"PRRT_kwDORLtfbc5w1HGW"
]
},
{
"canonical_id": "C019",
"verdict": "partially-valid",
"rationale": "SessionId-only routing can misassociate events under races/rebinds.",
"severity": "Medium",
"area": "Runtime resilience and failure handling",
"path": "apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts",
"line": 178,
"title": "ProviderRuntimeIngestion processes events for wrong thread on race",
"thread_ids": [
"PRRT_kwDORLtfbc5wkPaL"
]
},
{
"canonical_id": "C020",
"verdict": "partially-valid",
"rationale": "Duplicate complete dispatch exists; downstream impact often idempotent.",
"severity": "Medium",
"area": "Runtime resilience and failure handling",
"path": "apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts",
"line": 266,
"title": "On `message.completed`, the message ID is added to the set and `thread.message.assistant.complete` is dispatched. On `turn.completed`, the same set is iterated and `thread.message.assistant.complete` is dispatched again for each ID\u2014including already-completed ones. Consider removing message IDs from the set after dispatching on `message.completed`, or filtering out already-completed IDs before the `turn.completed` loop.",
"thread_ids": [
"PRRT_kwDORLtfbc5w1GPr"
]
},
{
"canonical_id": "C021",
"verdict": "invalid",
"rationale": "Stale-eventId claim no longer applies; eventId is regenerated per event.",
"severity": "Medium",
"area": "Other",
"path": "apps/server/src/orchestration/decider.ts",
"line": 27,
"title": "Shared mutable default metadata object causes stale eventId",
"thread_ids": [
"PRRT_kwDORLtfbc5wkPaA"
]
},
{
"canonical_id": "C022",
"verdict": "valid",
"rationale": "fish PATH formatting risk still exists in os-jank path recovery.",
"severity": "Medium",
"area": "Edge-case parsing/platform behavior",
"path": "apps/server/src/os-jank.ts",
"line": 10,
"title": "Fish shell outputs `$PATH` as space-separated, not colon-separated. Consider checking if the shell is fish and using `string join : $PATH` instead, or validating the result contains colons before assigning.",
"thread_ids": [
"PRRT_kwDORLtfbc5wkRZM"
]
},
{
"canonical_id": "C023",
"verdict": "valid",
"rationale": "-ilc shell invocation can pollute captured PATH output.",
"severity": "Medium",
"area": "Edge-case parsing/platform behavior",
"path": "apps/server/src/os-jank.ts",
"line": 10,
"title": "Using `-il` flags causes the shell to source profile scripts that may print banners or other text, polluting the captured `PATH`. Consider using `-lc` (login only, non-interactive) to reduce unwanted output.",
"thread_ids": [
"PRRT_kwDORLtfbc5wj4cM"
]
},
{
"canonical_id": "C024",
"verdict": "partially-valid",
"rationale": "prepare() still outside managed effect boundary; failure handling risk remains.",
"severity": "Medium",
"area": "Other",
"path": "apps/server/src/persistence/NodeSqliteClient.ts",
"line": 145,
"title": "In `executeUnprepared`, preparing outside an effect and not closing the statement can cause uncaught errors and leaks. Suggest wrapping with `Effect.acquireUseRelease`: prepare in acquire (error-safe) and `finalize` in release.",
"thread_ids": [
"PRRT_kwDORLtfbc5whxX9"
]
},
{
"canonical_id": "C025",
"verdict": "invalid",
"rationale": "No longer duplicated; checkpoint ref helper now centralized.",
"severity": "Medium",
"area": "Checkpointing correctness",
"path": "apps/server/src/wsServer.ts",
"line": 128,
"title": "Duplicated checkpoint ref computation across two files",
"thread_ids": [
"PRRT_kwDORLtfbc5wvwag"
]
},
{
"canonical_id": "C026",
"verdict": "valid",
"rationale": "runPromise result still not caught; rejection can surface unhandled.",
"severity": "Medium",
"area": "WebSocket robustness",
"path": "apps/server/src/wsServer.ts",
"line": 545,
"title": "Consider adding `.catch(() => {})` after `Effect.runPromise(handleMessage(ws, raw))` to prevent unhandled rejections from crashing the server if `encodeResponse` or setup logic fails.",
"thread_ids": [
"PRRT_kwDORLtfbc5wj4cE"
]
},
{
"canonical_id": "C027",
"verdict": "valid",
"rationale": "Same unhandled rejection path remains in WS message handler.",
"severity": "Medium",
"area": "Runtime resilience and failure handling",
"path": "apps/server/src/wsServer.ts",
"line": 545,
"title": "WS message handler can cause unhandled promise rejection",
"thread_ids": [
"PRRT_kwDORLtfbc5wyTaW",
"PRRT_kwDORLtfbc5wzli3"
]
},
{
"canonical_id": "C028",
"verdict": "partially-valid",
"rationale": "Optimistic local+server dual update is intentional but can temporarily diverge.",
"severity": "Medium",
"area": "Other",
"path": "apps/web/src/components/BranchToolbar.tsx",
"line": 102,
"title": "Branch sync dispatches both server and stale local update",
"thread_ids": [
"PRRT_kwDORLtfbc5v-XCu"
]
},
{
"canonical_id": "C029",
"verdict": "valid",
"rationale": "file URL decoding still double-decodes in one path.",
"severity": "Medium",
"area": "Edge-case parsing/platform behavior",
"path": "apps/web/src/markdown-links.ts",
"line": 105,
"title": "`parseFileUrlHref` already decodes the path (line 46), but `safeDecode` is called again here, corrupting filenames containing `%` sequences. Consider skipping the decode when `fileUrlTarget` is non-null.",
"thread_ids": [
"PRRT_kwDORLtfbc5wnVsU"
]
},
{
"canonical_id": "C030",
"verdict": "valid",
"rationale": "Scheme regex still misclassifies script.ts:10 as external scheme.",
"severity": "Medium",
"area": "Edge-case parsing/platform behavior",
"path": "apps/web/src/markdown-links.ts",
"line": 111,
"title": "`EXTERNAL_SCHEME_PATTERN` matches `script.ts:10` as a scheme because `.ts:` looks like `scheme:`. Consider requiring `://` after the colon, or checking that what follows the colon is not just digits. <details> <summary>\ud83d\ude80 Reply \"<strong>fix it for me</strong>\" or copy this <strong>AI Prompt</strong> for your agent:</summary>",
"thread_ids": [
"PRRT_kwDORLtfbc5wnVsK"
]
},
{
"canonical_id": "C031",
"verdict": "invalid",
"rationale": "Revert now uses explicit checkpointTurnCount first; positional fallback is non-primary.",
"severity": "Medium",
"area": "Event ordering and state consistency",
"path": "apps/web/src/session-logic.ts",
"line": 127,
"title": "Revert uses wrong turn count from positional inference",
"thread_ids": [
"PRRT_kwDORLtfbc5v9SCp"
]
},
{
"canonical_id": "C032",
"verdict": "valid",
"rationale": "Dummy workflow marker comment is still present in docs.",
"severity": "Low",
"area": "Other",
"path": "AGENTS.md",
"line": 45,
"title": "Dummy workflow marker accidentally committed to docs",
"thread_ids": [
"PRRT_kwDORLtfbc5wlYgj",
"PRRT_kwDORLtfbc5w1C4H"
]
},
{
"canonical_id": "C033",
"verdict": "partially-valid",
"rationale": "Original claim overstated; some errors used, others appear unused.",
"severity": "Low",
"area": "Checkpointing correctness",
"path": "apps/server/src/checkpointing/Errors.ts",
"line": 51,
"title": "Three error classes defined but never instantiated anywhere",
"thread_ids": [
"PRRT_kwDORLtfbc5wlYgo"
]
},
{
"canonical_id": "C034",
"verdict": "valid",
"rationale": "CheckpointInvariantError remains redundantly included in service union.",
"severity": "Low",
"area": "Checkpointing correctness",
"path": "apps/server/src/checkpointing/Errors.ts",
"line": 79,
"title": "Redundant `CheckpointInvariantError` in `CheckpointServiceError` union type",
"thread_ids": [
"PRRT_kwDORLtfbc5wj5fn"
]
},
{
"canonical_id": "C035",
"verdict": "valid",
"rationale": "Same as C034.",
"severity": "Low",
"area": "Checkpointing correctness",
"path": "apps/server/src/checkpointing/Errors.ts",
"line": 79,
"title": "Redundant error type in CheckpointServiceError union definition",
"thread_ids": [
"PRRT_kwDORLtfbc5wlYgs",
"PRRT_kwDORLtfbc5wxsO6",
"PRRT_kwDORLtfbc5w1C4B"
]
},
{
"canonical_id": "C036",
"verdict": "invalid",
"rationale": "No longer duplicated; single production source via Refs.ts.",
"severity": "Low",
"area": "Checkpointing correctness",
"path": "apps/server/src/checkpointing/Layers/CheckpointStore.ts",
"line": 284,
"title": "Duplicate `checkpointRefForThreadTurn` function in two production files",
"thread_ids": [
"PRRT_kwDORLtfbc5wiqFX"
]
},
{
"canonical_id": "C037",
"verdict": "partially-valid",
"rationale": "Callback cleanup missing, but practical exposure is low in one-shot startup path.",
"severity": "Low",
"area": "Other",
"path": "apps/server/src/config.ts",
"line": 41,
"title": "`Effect.callback` should return a cleanup function to close the server(s) on fiber interruption. Without it, the `Net.Server` handles keep the process alive and leak the port if the effect is cancelled. <details> <summary>\ud83d\ude80 Reply \"<strong>fix it for me</strong>\" or copy this <strong>AI Prompt</strong> for your agent:</summary>",
"thread_ids": [
"PRRT_kwDORLtfbc5wj4cO"
]
},
{
"canonical_id": "C038",
"verdict": "valid",
"rationale": "Chunk-by-chunk UTF-8 decode can still corrupt split multibyte characters.",
"severity": "Low",
"area": "Edge-case parsing/platform behavior",
"path": "apps/server/src/git/Layers/CodexTextGeneration.ts",
"line": 136,
"title": "Multi-byte UTF-8 characters split across chunks will be corrupted when decoding each chunk separately. Consider accumulating all chunks first, then decoding once, or use `TextDecoder` with `stream: true`. <details> <summary>\ud83d\ude80 Reply \"<strong>fix it for me</strong>\" or copy this <strong>AI Prompt</strong> for your agent:</summary>",
"thread_ids": [
"PRRT_kwDORLtfbc5w1GPo"
]
},
{
"canonical_id": "C039",
"verdict": "partially-valid",
"rationale": "Parser/encoder mismatch remains, but encoder path currently low-use.",
"severity": "Low",
"area": "Edge-case parsing/platform behavior",
"path": "apps/server/src/keybindings.ts",
"line": 352,
"title": "The `+` key can be parsed (via trailing `+` handling) but cannot be encoded because `shortcut.key.includes(\"+\")` returns true for the literal `+` key. Consider checking `shortcut.key === \"+\"` separately and encoding it as `\"space\"` style (e.g., a special token), or adjusting the condition to allow the single `+` character. <details> <summary>\ud83d\ude80 Reply \"<strong>fix it for me</strong>\" or copy this <strong>AI Prompt</strong> for your agent:</summary>",
"thread_ids": [
"PRRT_kwDORLtfbc5wxvIB"
]
},
{
"canonical_id": "C040",
"verdict": "valid",
"rationale": "upsertKeybindingRule read-modify-write remains race-prone.",
"severity": "Low",
"area": "Edge-case parsing/platform behavior",
"path": "apps/server/src/keybindings.ts",
"line": 488,
"title": "`upsertKeybindingRule` has a race condition: concurrent calls read the same file state, then the last write overwrites earlier changes. Consider wrapping the read-modify-write sequence with `Effect.Semaphore` to serialize access. <details> <summary>\ud83d\ude80 Reply \"<strong>fix it for me</strong>\" or copy this <strong>AI Prompt</strong> for your agent:</summary>",
"thread_ids": [
"PRRT_kwDORLtfbc5wxvIA"
]
},
{
"canonical_id": "C041",
"verdict": "valid",
"rationale": "Same Symbol interpolation hazard as C011 remains.",
"severity": "Low",
"area": "Other",
"path": "apps/server/src/orchestration/Errors.ts",
"line": 126,
"title": "Template literal interpolation throws `TypeError` if `cause` is a `Symbol`. Consider using `String(cause)` for safe coercion.",
"thread_ids": [
"PRRT_kwDORLtfbc5wBFWs"
]
},
{
"canonical_id": "C042",
"verdict": "partially-valid",
"rationale": "Duplication exists but one instance is variant logic, so impact is moderate.",
"severity": "Low",
"area": "Runtime resilience and failure handling",
"path": "apps/server/src/orchestration/Layers/CheckpointReactor.ts",
"line": 62,
"title": "Duplicated `resolveThreadWorkspaceCwd` across three files",
"thread_ids": [
"PRRT_kwDORLtfbc5wzli2"
]
},
{
"canonical_id": "C043",
"verdict": "valid",
"rationale": "Workspace CWD resolution duplication still present across modules.",
"severity": "Low",
"area": "Runtime resilience and failure handling",
"path": "apps/server/src/orchestration/Layers/CheckpointReactor.ts",
"line": 62,
"title": "Duplicated workspace CWD resolution logic across reactor modules",
"thread_ids": [
"PRRT_kwDORLtfbc5wnWwM",
"PRRT_kwDORLtfbc5w1C3-",
"PRRT_kwDORLtfbc5w1HGZ"
]
},
{
"canonical_id": "C044",
"verdict": "partially-valid",
"rationale": "Errors are swallowed to empty diff with warning; not fully silent but still lossy.",
"severity": "Low",
"area": "Runtime resilience and failure handling",
"path": "apps/server/src/orchestration/Layers/CheckpointReactor.ts",
"line": 274,
"title": "Checkpoint reactor swallows diff errors silently for `turn.completed`",
"thread_ids": [
"PRRT_kwDORLtfbc5wkPaO"
]
},
{
"canonical_id": "C045",
"verdict": "valid",
"rationale": "truncateDetail still overshoots limit.",
"severity": "Low",
"area": "Runtime resilience and failure handling",
"path": "apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts",
"line": 29,
"title": "`truncateDetail` slices to `limit - 1` then appends `\"...\"` (3 chars), producing strings of length `limit + 2`. Consider slicing to `limit - 3` instead. <details> <summary>\ud83d\ude80 Reply \"<strong>fix it for me</strong>\" or copy this <strong>AI Prompt</strong> for your agent:</summary>",
"thread_ids": [
"PRRT_kwDORLtfbc5wzp4R"
]
},
{
"canonical_id": "C046",
"verdict": "valid",
"rationale": "latestMessageIdByTurnKey still unused/unpruned in per-turn clear path.",
"severity": "Low",
"area": "Runtime resilience and failure handling",
"path": "apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts",
"line": 133,
"title": "`latestMessageIdByTurnKey` is written to but never read, and `clearAssistantMessageIdsForTurn` doesn't clear its entries\u2014only `clearTurnStateForSession` does. Consider removing this map entirely if unused, or clearing it alongside `turnMessageIdsByTurnKey` in `clearAssistantMessageIdsForTurn`. <details> <summary>\ud83d\ude80 Reply \"<strong>fix it for me</strong>\" or copy this <strong>AI Prompt</strong> for your agent:</summary>",
"thread_ids": [
"PRRT_kwDORLtfbc5wxvIQ"
]
},
{
"canonical_id": "C047",
"verdict": "valid",
"rationale": "Decode and SQL errors still collapsed into one persistence error kind.",
"severity": "Low",
"area": "Other",
"path": "apps/server/src/persistence/Layers/OrchestrationCommandReceipts.ts",
"line": 75,
"title": "`SqlSchema.findOneOption` can produce both SQL errors and decode errors, but `mapError` wraps all as `PersistenceSqlError`. Consider distinguishing `ParseError` from SQL errors and mapping decode failures to `PersistenceDecodeError` instead. <details> <summary>\ud83d\ude80 Reply \"<strong>fix it for me</strong>\" or copy this <strong>AI Prompt</strong> for your agent:</summary>",
"thread_ids": [
"PRRT_kwDORLtfbc5wiaR-"
]
},
{
"canonical_id": "C048",
"verdict": "partially-valid",
"rationale": "Unsafe run() result cast remains; runtime risk depends on raw-result consumers.",
"severity": "Low",
"area": "Other",
"path": "apps/server/src/persistence/NodeSqliteClient.ts",
"line": 99,
"title": "`statement.run()` returns a `RunResult` object, not an array. Casting it to `ReadonlyArray<any>` will cause runtime errors when consumers call array methods. Consider wrapping the result (e.g., `[result]`) or returning a properly typed object.",
"thread_ids": [
"PRRT_kwDORLtfbc5wio-r"
]
},
{
"canonical_id": "C049",
"verdict": "valid",
"rationale": "JSON.stringify(cause) may return undefined despite string expectations.",
"severity": "Low",
"area": "Other",
"path": "apps/server/src/provider/Layers/ProviderService.ts",
"line": 59,
"title": "`JSON.stringify(cause)` returns `undefined` for `undefined`, functions, or symbols, violating the `string` return type. Consider coercing the result to a string (e.g., `String(JSON.stringify(cause))`) or adding a fallback.",
"thread_ids": [
"PRRT_kwDORLtfbc5wnVsI"
]
},
{
"canonical_id": "C050",
"verdict": "valid",
"rationale": "ProviderSessionDirectory upsert remains read-merge-write without concurrency control.",
"severity": "Low",
"area": "Other",
"path": "apps/server/src/provider/Layers/ProviderSessionDirectory.ts",
"line": 94,
"title": "The read-modify-write pattern (`getBySessionId` \u2192 merge \u2192 `upsert`) is susceptible to lost updates under concurrent writes. Consider wrapping in a transaction or adding optimistic concurrency control (e.g., version field) if concurrent session updates are expected. <details> <summary>\ud83d\ude80 Reply \"<strong>fix it for me</strong>\" or copy this <strong>AI Prompt</strong> for your agent:</summary>",
"thread_ids": [
"PRRT_kwDORLtfbc5wiLhY"
]
},
{
"canonical_id": "C051",
"verdict": "partially-valid",
"rationale": "Null-clearing issue is real for providerThreadId; adapterKey part overstated.",
"severity": "Low",
"area": "Other",
"path": "apps/server/src/provider/Layers/ProviderSessionDirectory.ts",
"line": 119,
"title": "Using `??` for `providerThreadId` and `adapterKey` makes it impossible to clear these fields by passing `null`, since `null ?? existing` evaluates to `existing`. Consider using explicit `undefined` checks (like `resumeCursor` does) if clearing should be supported. <details> <summary>\ud83d\ude80 Reply \"<strong>fix it for me</strong>\" or copy this <strong>AI Prompt</strong> for your agent:</summary>",
"thread_ids": [
"PRRT_kwDORLtfbc5wxvH9"
]
},
{
"canonical_id": "C052",
"verdict": "valid",
"rationale": "Data callback may race before processHandle assignment.",
"severity": "Low",
"area": "Other",
"path": "apps/server/src/terminal/Layers/BunPTY.ts",
"line": 97,
"title": "Race condition: `processHandle` may be `null` when `data` callback fires, since it's assigned after `Bun.spawn` returns. Consider initializing `BunPtyProcess` first, then passing it to the callback to avoid losing initial output. <details> <summary>\ud83d\ude80 Reply \"<strong>fix it for me</strong>\" or copy this <strong>AI Prompt</strong> for your agent:</summary>",
"thread_ids": [
"PRRT_kwDORLtfbc5w1CxE"
]
},
{
"canonical_id": "C053",
"verdict": "valid",
"rationale": "Still uses write+destroy rather than end() for rejection response.",
"severity": "Low",
"area": "WebSocket robustness",
"path": "apps/server/src/wsServer.ts",
"line": 83,
"title": "Consider using `socket.end(response)` instead of `socket.write(response)` + `socket.destroy()` to ensure the HTTP error response is fully flushed before closing the connection.",
"thread_ids": [
"PRRT_kwDORLtfbc5v-WPD"
]
},
{
"canonical_id": "C054",
"verdict": "valid",
"rationale": "Array chunk UTF-8 decode remains vulnerable to split multibyte corruption.",
"severity": "Low",
"area": "WebSocket robustness",
"path": "apps/server/src/wsServer.ts",
"line": 104,
"title": "When array chunks contain a multi-byte UTF-8 character split across boundaries, decoding each chunk separately produces replacement characters. Consider using `Buffer.concat()` on all chunks before calling `.toString(\"utf8\")`. <details> <summary>\ud83d\ude80 Reply \"<strong>fix it for me</strong>\" or copy this <strong>AI Prompt</strong> for your agent:</summary>",
"thread_ids": [
"PRRT_kwDORLtfbc5whtrR"
]
},
{
"canonical_id": "C055",
"verdict": "invalid",
"rationale": "No longer duplicated; helper is centralized.",
"severity": "Low",
"area": "Checkpointing correctness",
"path": "apps/server/src/wsServer.ts",
"line": 128,
"title": "Duplicate `checkpointRefForThreadTurn` function across files",
"thread_ids": [
"PRRT_kwDORLtfbc5wkPaG"
]
},
{
"canonical_id": "C056",
"verdict": "partially-valid",
"rationale": "Bug pattern exists, but current callsites mostly avoid triggering it.",
"severity": "Low",
"area": "Other",
"path": "apps/web/src/components/ui/sidebar.tsx",
"line": 114,
"title": "When `onOpenChange` is provided without `open`, the internal `_open` state never updates because `setOpenProp` takes precedence. Consider calling `_setOpen` when `openProp === undefined`, regardless of whether `setOpenProp` exists.",
"thread_ids": [
"PRRT_kwDORLtfbc5wxvIq"
]
},
{
"canonical_id": "C057",
"verdict": "valid",
"rationale": "Resizable object recreation still retriggers effect/storage reads.",
"severity": "Low",
"area": "Other",
"path": "apps/web/src/routes/_chat.$threadId.tsx",
"line": 105,
"title": "The `resizable` object is recreated on every render, causing `SidebarRail`'s `useEffect` to repeatedly read localStorage and update the DOM. Consider memoizing the object with `useMemo`. <details> <summary>\ud83d\ude80 Reply \"<strong>fix it for me</strong>\" or copy this <strong>AI Prompt</strong> for your agent:</summary>",
"thread_ids": [
"PRRT_kwDORLtfbc5wyWz4"
]
},
{
"canonical_id": "C058",
"verdict": "valid",
"rationale": "Number(null) -> 0 path still forces min width on initial load.",
"severity": "Low",
"area": "Other",
"path": "apps/web/src/routes/_chat.$threadId.tsx",
"line": 122,
"title": "When `localStorage.getItem()` returns `null`, `Number(null)` evaluates to `0`, which passes `Number.isFinite(0)`. This causes the sidebar to clamp to `minWidth` on first load, overriding the `DIFF_INLINE_DEFAULT_WIDTH` CSS clamp. Consider checking for `null` or empty string before parsing, e.g. guard with `storedWidth === null || storedWidth === ''`. <details> <summary>\ud83d\ude80 Reply \"<strong>fix it for me</strong>\" or copy this <strong>AI Prompt</strong> for your agent:</summary>",
"thread_ids": [
"PRRT_kwDORLtfbc5wnVsX"
]
},
{
"canonical_id": "C059",
"verdict": "partially-valid",
"rationale": "Transport _tag override risk exists but current callsites are constrained.",
"severity": "Low",
"area": "WebSocket robustness",
"path": "apps/web/src/wsTransport.ts",
"line": 59,
"title": "Suggestion: don\u2019t spread `params` into `body`; it can override `_tag` and mishandle non-object values. Keep `_tag` separate and nest `params` under a single key (e.g., `data`), or validate `params` is a plain object.",
"thread_ids": [
"PRRT_kwDORLtfbc5whtrN"
]
},
{
"canonical_id": "C060",
"verdict": "valid",
"rationale": "Schema still cannot express null clear for defaultModel patch.",
"severity": "Low",
"area": "Other",
"path": "packages/contracts/src/orchestration.ts",
"line": 253,
"title": "`defaultModel` should be `Schema.optional(Schema.NullOr(Schema.String))` to allow clearing the value. Currently there's no way to reset it to `null` since omitting means \"no change\" in patch semantics. <details> <summary>\ud83d\ude80 Reply \"<strong>fix it for me</strong>\" or copy this <strong>AI Prompt</strong> for your agent:</summary>",
"thread_ids": [
"PRRT_kwDORLtfbc5whxJC"
]
}
]
}
@@ -1,125 +0,0 @@
# PR #89 Post-Rewrite Validity Audit
Architecture baseline used for this audit:
- Provider runtime activity is projected into orchestration domain events.
- Web client consumes `orchestration.domainEvent`; no separate `providers.event` channel is expected.
## Summary
- Canonical items reviewed: 58
- Valid: 34
- Partially valid: 19
- Invalid (stale/no longer applicable): 5
## Invalid Items To Close
- C021 [Medium] Shared mutable default metadata object causes stale eventId (apps/server/src/orchestration/decider.ts:27)
- Reason: Stale-eventId claim no longer applies; eventId is regenerated per event.
- Threads: PRRT_kwDORLtfbc5wkPaA
- C025 [Medium] Duplicated checkpoint ref computation across two files (apps/server/src/wsServer.ts:128)
- Reason: No longer duplicated; checkpoint ref helper now centralized.
- Threads: PRRT_kwDORLtfbc5wvwag
- C031 [Medium] Revert uses wrong turn count from positional inference (apps/web/src/session-logic.ts:127)
- Reason: Revert now uses explicit checkpointTurnCount first; positional fallback is non-primary.
- Threads: PRRT_kwDORLtfbc5v9SCp
- C036 [Low] Duplicate `checkpointRefForThreadTurn` function in two production files (apps/server/src/checkpointing/Layers/CheckpointStore.ts:284)
- Reason: No longer duplicated; single production source via Refs.ts.
- Threads: PRRT_kwDORLtfbc5wiqFX
- C055 [Low] Duplicate `checkpointRefForThreadTurn` function across files (apps/server/src/wsServer.ts:128)
- Reason: No longer duplicated; helper is centralized.
- Threads: PRRT_kwDORLtfbc5wkPaG
## Partially Valid Items (de-scope or lower priority)
- C006 [Medium] Build script runs TypeScript file with bare node (apps/server/package.json:14)
- Note: Node 24 makes this work, but script still relies on runtime-specific TS execution.
- C007 [Medium] Build script uses `node` to run `.ts` file directly (apps/server/package.json:14)
- Note: Same as C006 (duplicate concern).
- C008 [Medium] Inconsistent input normalization across CheckpointStore methods (apps/server/src/checkpointing/Layers/CheckpointStore.ts:94)
- Note: Normalization inconsistency remains, but upstream callsites now mostly canonicalize inputs.
- C014 [Medium] Engine error handler catches all errors including non-invariant ones (apps/server/src/orchestration/Layers/OrchestrationEngine.ts:144)
- Note: Broad catch may be intentional for liveness; correctness concern is contextual.
- C015 [Medium] The gap-filling fallback logic can retain messages from turns that are about to be deleted, causing foreign key violations. Consider removing the fallback logic entirely, or filtering `fallbackUserMessages` and `fallbackAssistantMessages` to only include messages whose `turnId` is in `retainedTurnIds`. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/orchestration/Layers/ProjectionPipeline.ts:99)
- Note: Message fallback retention issue is real, but prior FK-violation claim is overstated.
- C017 [Medium] `REQUIRED_SNAPSHOT_PROJECTORS` includes `pending-approvals` and `thread-turns`, but `getSnapshot` doesn't query their data. If these projectors lag behind, the returned `snapshotSequence` will be lower than what the included data actually reflects, causing clients to replay already-applied events. Consider filtering `REQUIRED_SNAPSHOT_PROJECTORS` to only include projectors whose data is actually fetched in the snapshot. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts:71)
- Note: Snapshot sequence can under-report due to extra projectors, but replay impact is lower now.
- C019 [Medium] ProviderRuntimeIngestion processes events for wrong thread on race (apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts:178)
- Note: SessionId-only routing can misassociate events under races/rebinds.
- C020 [Medium] On `message.completed`, the message ID is added to the set and `thread.message.assistant.complete` is dispatched. On `turn.completed`, the same set is iterated and `thread.message.assistant.complete` is dispatched again for each ID—including already-completed ones. Consider removing message IDs from the set after dispatching on `message.completed`, or filtering out already-completed IDs before the `turn.completed` loop. (apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts:266)
- Note: Duplicate complete dispatch exists; downstream impact often idempotent.
- C024 [Medium] In `executeUnprepared`, preparing outside an effect and not closing the statement can cause uncaught errors and leaks. Suggest wrapping with `Effect.acquireUseRelease`: prepare in acquire (error-safe) and `finalize` in release. (apps/server/src/persistence/NodeSqliteClient.ts:145)
- Note: prepare() still outside managed effect boundary; failure handling risk remains.
- C028 [Medium] Branch sync dispatches both server and stale local update (apps/web/src/components/BranchToolbar.tsx:102)
- Note: Optimistic local+server dual update is intentional but can temporarily diverge.
- C033 [Low] Three error classes defined but never instantiated anywhere (apps/server/src/checkpointing/Errors.ts:51)
- Note: Original claim overstated; some errors used, others appear unused.
- C037 [Low] `Effect.callback` should return a cleanup function to close the server(s) on fiber interruption. Without it, the `Net.Server` handles keep the process alive and leak the port if the effect is cancelled. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/config.ts:41)
- Note: Callback cleanup missing, but practical exposure is low in one-shot startup path.
- C039 [Low] The `+` key can be parsed (via trailing `+` handling) but cannot be encoded because `shortcut.key.includes("+")` returns true for the literal `+` key. Consider checking `shortcut.key === "+"` separately and encoding it as `"space"` style (e.g., a special token), or adjusting the condition to allow the single `+` character. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/keybindings.ts:352)
- Note: Parser/encoder mismatch remains, but encoder path currently low-use.
- C042 [Low] Duplicated `resolveThreadWorkspaceCwd` across three files (apps/server/src/orchestration/Layers/CheckpointReactor.ts:62)
- Note: Duplication exists but one instance is variant logic, so impact is moderate.
- C044 [Low] Checkpoint reactor swallows diff errors silently for `turn.completed` (apps/server/src/orchestration/Layers/CheckpointReactor.ts:274)
- Note: Errors are swallowed to empty diff with warning; not fully silent but still lossy.
- C048 [Low] `statement.run()` returns a `RunResult` object, not an array. Casting it to `ReadonlyArray<any>` will cause runtime errors when consumers call array methods. Consider wrapping the result (e.g., `[result]`) or returning a properly typed object. (apps/server/src/persistence/NodeSqliteClient.ts:99)
- Note: Unsafe run() result cast remains; runtime risk depends on raw-result consumers.
- C051 [Low] Using `??` for `providerThreadId` and `adapterKey` makes it impossible to clear these fields by passing `null`, since `null ?? existing` evaluates to `existing`. Consider using explicit `undefined` checks (like `resumeCursor` does) if clearing should be supported. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/provider/Layers/ProviderSessionDirectory.ts:119)
- Note: Null-clearing issue is real for providerThreadId; adapterKey part overstated.
- C056 [Low] When `onOpenChange` is provided without `open`, the internal `_open` state never updates because `setOpenProp` takes precedence. Consider calling `_setOpen` when `openProp === undefined`, regardless of whether `setOpenProp` exists. (apps/web/src/components/ui/sidebar.tsx:114)
- Note: Bug pattern exists, but current callsites mostly avoid triggering it.
- C059 [Low] Suggestion: don’t spread `params` into `body`; it can override `_tag` and mishandle non-object values. Keep `_tag` separate and nest `params` under a single key (e.g., `data`), or validate `params` is a plain object. (apps/web/src/wsTransport.ts:59)
- Note: Transport _tag override risk exists but current callsites are constrained.
## Valid Items (actionable unless marked completed)
- C001 [High] Non-atomic event appending can corrupt state on retry. If an error occurs mid-loop (lines 96-102) after some events are persisted but before the receipt is written, the command appears to fail. A retry generates new UUIDs via `crypto.randomUUID()` in the decider, appending duplicate events. Consider wrapping the loop in a transaction or using deterministic event IDs derived from `commandId`. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/orchestration/Layers/OrchestrationEngine.ts:96)
- C002 [High] A dispatch error in `processEvent` will terminate the `Effect.forever` loop, permanently halting event ingestion. Consider adding error recovery (e.g., `Effect.catchAll` with logging) around `processEvent` so failures don't kill the fiber. (apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts:333)
- Status: Completed in Phase 1.
- C003 [High] Consider attaching a no-op error listener before `socket.write` (e.g., `socket.on('error', () => {})`) to prevent an unhandled `EPIPE`/`ECONNRESET` from crashing the process if the client disconnects mid-handshake. (apps/server/src/wsServer.ts:75)
- C009 [Medium] Git's braced rename syntax (e.g., `src/{old => new}/file.ts`) isn't handled correctly. The current slice after ` => ` produces invalid paths like `new}/file.ts`. Consider expanding the braces to construct the full destination path. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/git/Layers/GitCore.ts:41)
- C010 [Medium] `loadCustomKeybindingsConfig` fails when the config file doesn't exist, which is expected for new users. Consider catching `ENOENT` and returning an empty array instead. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/keybindings.ts:418)
- C011 [Medium] Template literal `${cause}` throws if `cause` is a `Symbol`. Consider using `String(cause)` instead. (apps/server/src/orchestration/Errors.ts:117)
- C012 [Medium] Forked revert dispatch risks read model inconsistency (apps/server/src/orchestration/Layers/CheckpointReactor.ts:542)
- Status: Completed in Phase 1.
- C013 [Medium] If `projectionPipeline.projectEvent` fails after `eventStore.append` succeeds, the event is persisted but `readModel` isn't updated, causing desync. Consider updating the in-memory `readModel` immediately after append (before the external projection), so local state stays consistent regardless of downstream failures. (apps/server/src/orchestration/Layers/OrchestrationEngine.ts:99)
- C016 [Medium] The in-memory `pendingTurnStartByThreadId` map isn't restored during bootstrap. If the service restarts after processing `thread.turn-start-requested` but before `thread.session-set`, the `userMessageId` and `startedAt` will be lost since bootstrap resumes *after* the committed sequence. Consider persisting this pending state or processing these two events atomically. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/orchestration/Layers/ProjectionPipeline.ts:490)
- C018 [Medium] Unbounded memory growth in turn start deduplication set (apps/server/src/orchestration/Layers/ProviderCommandReactor.ts:84)
- C022 [Medium] Fish shell outputs `$PATH` as space-separated, not colon-separated. Consider checking if the shell is fish and using `string join : $PATH` instead, or validating the result contains colons before assigning. (apps/server/src/os-jank.ts:10)
- C023 [Medium] Using `-il` flags causes the shell to source profile scripts that may print banners or other text, polluting the captured `PATH`. Consider using `-lc` (login only, non-interactive) to reduce unwanted output. (apps/server/src/os-jank.ts:10)
- C026 [Medium] Consider adding `.catch(() => {})` after `Effect.runPromise(handleMessage(ws, raw))` to prevent unhandled rejections from crashing the server if `encodeResponse` or setup logic fails. (apps/server/src/wsServer.ts:545)
- Status: Completed in Phase 1.
- C027 [Medium] WS message handler can cause unhandled promise rejection (apps/server/src/wsServer.ts:545)
- Status: Completed in Phase 1.
- C029 [Medium] `parseFileUrlHref` already decodes the path (line 46), but `safeDecode` is called again here, corrupting filenames containing `%` sequences. Consider skipping the decode when `fileUrlTarget` is non-null. (apps/web/src/markdown-links.ts:105)
- C030 [Medium] `EXTERNAL_SCHEME_PATTERN` matches `script.ts:10` as a scheme because `.ts:` looks like `scheme:`. Consider requiring `://` after the colon, or checking that what follows the colon is not just digits. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/web/src/markdown-links.ts:111)
- C032 [Low] Dummy workflow marker accidentally committed to docs (AGENTS.md:45)
- C034 [Low] Redundant `CheckpointInvariantError` in `CheckpointServiceError` union type (apps/server/src/checkpointing/Errors.ts:79)
- C035 [Low] Redundant error type in CheckpointServiceError union definition (apps/server/src/checkpointing/Errors.ts:79)
- C038 [Low] Multi-byte UTF-8 characters split across chunks will be corrupted when decoding each chunk separately. Consider accumulating all chunks first, then decoding once, or use `TextDecoder` with `stream: true`. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/git/Layers/CodexTextGeneration.ts:136)
- C040 [Low] `upsertKeybindingRule` has a race condition: concurrent calls read the same file state, then the last write overwrites earlier changes. Consider wrapping the read-modify-write sequence with `Effect.Semaphore` to serialize access. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/keybindings.ts:488)
- C041 [Low] Template literal interpolation throws `TypeError` if `cause` is a `Symbol`. Consider using `String(cause)` for safe coercion. (apps/server/src/orchestration/Errors.ts:126)
- C043 [Low] Duplicated workspace CWD resolution logic across reactor modules (apps/server/src/orchestration/Layers/CheckpointReactor.ts:62)
- C045 [Low] `truncateDetail` slices to `limit - 1` then appends `"..."` (3 chars), producing strings of length `limit + 2`. Consider slicing to `limit - 3` instead. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts:29)
- C046 [Low] `latestMessageIdByTurnKey` is written to but never read, and `clearAssistantMessageIdsForTurn` doesn't clear its entries—only `clearTurnStateForSession` does. Consider removing this map entirely if unused, or clearing it alongside `turnMessageIdsByTurnKey` in `clearAssistantMessageIdsForTurn`. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts:133)
- C047 [Low] `SqlSchema.findOneOption` can produce both SQL errors and decode errors, but `mapError` wraps all as `PersistenceSqlError`. Consider distinguishing `ParseError` from SQL errors and mapping decode failures to `PersistenceDecodeError` instead. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/persistence/Layers/OrchestrationCommandReceipts.ts:75)
- C049 [Low] `JSON.stringify(cause)` returns `undefined` for `undefined`, functions, or symbols, violating the `string` return type. Consider coercing the result to a string (e.g., `String(JSON.stringify(cause))`) or adding a fallback. (apps/server/src/provider/Layers/ProviderService.ts:59)
- C050 [Low] The read-modify-write pattern (`getBySessionId` → merge → `upsert`) is susceptible to lost updates under concurrent writes. Consider wrapping in a transaction or adding optimistic concurrency control (e.g., version field) if concurrent session updates are expected. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/provider/Layers/ProviderSessionDirectory.ts:94)
- C052 [Low] Race condition: `processHandle` may be `null` when `data` callback fires, since it's assigned after `Bun.spawn` returns. Consider initializing `BunPtyProcess` first, then passing it to the callback to avoid losing initial output. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/terminal/Layers/BunPTY.ts:97)
- C053 [Low] Consider using `socket.end(response)` instead of `socket.write(response)` + `socket.destroy()` to ensure the HTTP error response is fully flushed before closing the connection. (apps/server/src/wsServer.ts:83)
- C054 [Low] When array chunks contain a multi-byte UTF-8 character split across boundaries, decoding each chunk separately produces replacement characters. Consider using `Buffer.concat()` on all chunks before calling `.toString("utf8")`. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/server/src/wsServer.ts:104)
- C057 [Low] The `resizable` object is recreated on every render, causing `SidebarRail`'s `useEffect` to repeatedly read localStorage and update the DOM. Consider memoizing the object with `useMemo`. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/web/src/routes/_chat.$threadId.tsx:105)
- C058 [Low] When `localStorage.getItem()` returns `null`, `Number(null)` evaluates to `0`, which passes `Number.isFinite(0)`. This causes the sidebar to clamp to `minWidth` on first load, overriding the `DIFF_INLINE_DEFAULT_WIDTH` CSS clamp. Consider checking for `null` or empty string before parsing, e.g. guard with `storedWidth === null || storedWidth === ''`. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (apps/web/src/routes/_chat.$threadId.tsx:122)
- C060 [Low] `defaultModel` should be `Schema.optional(Schema.NullOr(Schema.String))` to allow clearing the value. Currently there's no way to reset it to `null` since omitting means "no change" in patch semantics. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary> (packages/contracts/src/orchestration.ts:253)
## By Area
- Build/runtime portability: valid=0, partially-valid=2, invalid=0
- Checkpointing correctness: valid=2, partially-valid=3, invalid=3
- Edge-case parsing/platform behavior: valid=8, partially-valid=1, invalid=0
- Event ordering and state consistency: valid=3, partially-valid=2, invalid=1
- Memory/resource growth: valid=1, partially-valid=0, invalid=0
- Other: valid=10, partially-valid=6, invalid=1
- Runtime resilience and failure handling: valid=6, partially-valid=4, invalid=0
- WebSocket robustness: valid=4, partially-valid=1, invalid=0
Machine-readable mapping: `.plans/16b-pr89-architecture-validity-audit.json`.
+542
View File
@@ -0,0 +1,542 @@
# PR #89 Remediation Checklist (Consolidated)
_Last updated: 2026-02-26_
This is the working checklist for remediation execution.
Status values:
- `TODO`: Not started
- `IN_PROGRESS`: Currently being worked
- `BLOCKED`: Waiting on decision/dependency
- `DONE`: Implemented and verified
- `CLOSED_INVALID`: Stale/invalid review finding
Counts: active `53` (`valid=34`, `partially-valid=19`), closed-invalid `5`
## Active Checklist
### Phase 1
- [x] `C002` A dispatch error in `processEvent` will terminate the `Effect.forever` loop, permanently halting event ingestion. Consider adding error recovery (e.g., `Effect.catchAll` with logging) around `processEvent` so failures don't kill the fiber.
- Status: `DONE`
- Verdict: `valid`
- Severity: `High`
- Area: `Runtime resilience and failure handling`
- File: `apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts:333`
- Threads: PRRT_kwDORLtfbc5wj4cH, PRRT_kwDORLtfbc5wnWwF, PRRT_kwDORLtfbc5wyTaP, PRRT_kwDORLtfbc5wzliw, PRRT_kwDORLtfbc5w0_g3, PRRT_kwDORLtfbc5w1HGT (+5 duplicate thread(s))
- Audit note: Ingestion worker loop can terminate on unhandled processEvent failure.
- [x] `C003` Consider attaching a no-op error listener before `socket.write` (e.g., `socket.on('error', () => {})`) to prevent an unhandled `EPIPE`/`ECONNRESET` from crashing the process if the client disconnects mid-handshake.
- Status: `DONE`
- Verdict: `valid`
- Severity: `High`
- Area: `WebSocket robustness`
- File: `apps/server/src/wsServer.ts:75`
- Threads: PRRT_kwDORLtfbc5v-cf4
- Audit note: Upgrade reject writes then destroys socket without defensive error listener.
- [x] `C012` Forked revert dispatch risks read model inconsistency
- Status: `DONE`
- Verdict: `valid`
- Severity: `Medium`
- Area: `Runtime resilience and failure handling`
- File: `apps/server/src/orchestration/Layers/CheckpointReactor.ts:542`
- Threads: PRRT_kwDORLtfbc5whszW, PRRT_kwDORLtfbc5wyTaS, PRRT_kwDORLtfbc5wzli0, PRRT_kwDORLtfbc5w0_g4, PRRT_kwDORLtfbc5w1HGX (+4 duplicate thread(s))
- Audit note: Revert completion dispatch remains forked; state consistency window remains.
- [ ] `C019` ProviderRuntimeIngestion processes events for wrong thread on race
- Status: `TODO`
- Verdict: `partially-valid`
- Severity: `Medium`
- Area: `Runtime resilience and failure handling`
- File: `apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts:178`
- Threads: PRRT_kwDORLtfbc5wkPaL
- Audit note: SessionId-only routing can misassociate events under races/rebinds.
- [ ] `C020` On `message.completed`, the message ID is added to the set and `thread.message.assistant.complete` is dispatched. On `turn.completed`, the same set is iterated and `thread.message.assistant.complete` is dispatched again for each ID—including already-completed ones. Consider removing message IDs from the set after dispatching on `message.completed`, or filtering out already-completed IDs before the `turn.completed` loop.
- Status: `TODO`
- Verdict: `partially-valid`
- Severity: `Medium`
- Area: `Runtime resilience and failure handling`
- File: `apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts:266`
- Threads: PRRT_kwDORLtfbc5w1GPr
- Audit note: Duplicate complete dispatch exists; downstream impact often idempotent.
- [x] `C026` Consider adding `.catch(() => {})` after `Effect.runPromise(handleMessage(ws, raw))` to prevent unhandled rejections from crashing the server if `encodeResponse` or setup logic fails.
- Status: `DONE`
- Verdict: `valid`
- Severity: `Medium`
- Area: `WebSocket robustness`
- File: `apps/server/src/wsServer.ts:545`
- Threads: PRRT_kwDORLtfbc5wj4cE
- Audit note: runPromise result still not caught; rejection can surface unhandled.
- [x] `C027` WS message handler can cause unhandled promise rejection
- Status: `DONE`
- Verdict: `valid`
- Severity: `Medium`
- Area: `Runtime resilience and failure handling`
- File: `apps/server/src/wsServer.ts:545`
- Threads: PRRT_kwDORLtfbc5wyTaW, PRRT_kwDORLtfbc5wzli3 (+1 duplicate thread(s))
- Audit note: Same unhandled rejection path remains in WS message handler.
- [ ] `C042` Duplicated `resolveThreadWorkspaceCwd` across three files
- Status: `TODO`
- Verdict: `partially-valid`
- Severity: `Low`
- Area: `Runtime resilience and failure handling`
- File: `apps/server/src/orchestration/Layers/CheckpointReactor.ts:62`
- Threads: PRRT_kwDORLtfbc5wzli2
- Audit note: Duplication exists but one instance is variant logic, so impact is moderate.
- [x] `C043` Duplicated workspace CWD resolution logic across reactor modules
- Status: `DONE`
- Verdict: `valid`
- Severity: `Low`
- Area: `Runtime resilience and failure handling`
- File: `apps/server/src/orchestration/Layers/CheckpointReactor.ts:62`
- Threads: PRRT_kwDORLtfbc5wnWwM, PRRT_kwDORLtfbc5w1C3-, PRRT_kwDORLtfbc5w1HGZ (+2 duplicate thread(s))
- Audit note: Workspace CWD resolution duplication still present across modules.
- [ ] `C044` Checkpoint reactor swallows diff errors silently for `turn.completed`
- Status: `TODO`
- Verdict: `partially-valid`
- Severity: `Low`
- Area: `Runtime resilience and failure handling`
- File: `apps/server/src/orchestration/Layers/CheckpointReactor.ts:274`
- Threads: PRRT_kwDORLtfbc5wkPaO
- Audit note: Errors are swallowed to empty diff with warning; not fully silent but still lossy.
- [x] `C045` `truncateDetail` slices to `limit - 1` then appends `"..."` (3 chars), producing strings of length `limit + 2`. Consider slicing to `limit - 3` instead. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary>
- Status: `DONE`
- Verdict: `valid`
- Severity: `Low`
- Area: `Runtime resilience and failure handling`
- File: `apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts:29`
- Threads: PRRT_kwDORLtfbc5wzp4R
- Audit note: truncateDetail still overshoots limit.
- [x] `C046` `latestMessageIdByTurnKey` is written to but never read, and `clearAssistantMessageIdsForTurn` doesn't clear its entries—only `clearTurnStateForSession` does. Consider removing this map entirely if unused, or clearing it alongside `turnMessageIdsByTurnKey` in `clearAssistantMessageIdsForTurn`. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary>
- Status: `DONE`
- Verdict: `valid`
- Severity: `Low`
- Area: `Runtime resilience and failure handling`
- File: `apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts:133`
- Threads: PRRT_kwDORLtfbc5wxvIQ
- Audit note: latestMessageIdByTurnKey still unused/unpruned in per-turn clear path.
- [x] `C053` Consider using `socket.end(response)` instead of `socket.write(response)` + `socket.destroy()` to ensure the HTTP error response is fully flushed before closing the connection.
- Status: `DONE`
- Verdict: `valid`
- Severity: `Low`
- Area: `WebSocket robustness`
- File: `apps/server/src/wsServer.ts:83`
- Threads: PRRT_kwDORLtfbc5v-WPD
- Audit note: Still uses write+destroy rather than end() for rejection response.
- [ ] `C054` When array chunks contain a multi-byte UTF-8 character split across boundaries, decoding each chunk separately produces replacement characters. Consider using `Buffer.concat()` on all chunks before calling `.toString("utf8")`. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary>
- Status: `TODO`
- Verdict: `valid`
- Severity: `Low`
- Area: `WebSocket robustness`
- File: `apps/server/src/wsServer.ts:104`
- Threads: PRRT_kwDORLtfbc5whtrR
- Audit note: Array chunk UTF-8 decode remains vulnerable to split multibyte corruption.
- [x] `C059` Suggestion: don’t spread `params` into `body`; it can override `_tag` and mishandle non-object values. Keep `_tag` separate and nest `params` under a single key (e.g., `data`), or validate `params` is a plain object.
- Status: `DONE`
- Verdict: `partially-valid`
- Severity: `Low`
- Area: `WebSocket robustness`
- File: `apps/web/src/wsTransport.ts:59`
- Threads: PRRT_kwDORLtfbc5whtrN
- Audit note: Transport _tag override risk exists but current callsites are constrained.
### Phase 2
- [ ] `C001` Non-atomic event appending can corrupt state on retry. If an error occurs mid-loop (lines 96-102) after some events are persisted but before the receipt is written, the command appears to fail. A retry generates new UUIDs via `crypto.randomUUID()` in the decider, appending duplicate events. Consider wrapping the loop in a transaction or using deterministic event IDs derived from `commandId`. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary>
- Status: `TODO`
- Verdict: `valid`
- Severity: `High`
- Area: `Event ordering and state consistency`
- File: `apps/server/src/orchestration/Layers/OrchestrationEngine.ts:96`
- Threads: PRRT_kwDORLtfbc5wzp4T
- Audit note: Append/project/receipt are non-atomic; retry can duplicate events.
- [ ] `C013` If `projectionPipeline.projectEvent` fails after `eventStore.append` succeeds, the event is persisted but `readModel` isn't updated, causing desync. Consider updating the in-memory `readModel` immediately after append (before the external projection), so local state stays consistent regardless of downstream failures.
- Status: `TODO`
- Verdict: `valid`
- Severity: `Medium`
- Area: `Event ordering and state consistency`
- File: `apps/server/src/orchestration/Layers/OrchestrationEngine.ts:99`
- Threads: PRRT_kwDORLtfbc5whtrM
- Audit note: Persisted event can outpace in-memory projection on mid-flight failure.
- [ ] `C014` Engine error handler catches all errors including non-invariant ones
- Status: `TODO`
- Verdict: `partially-valid`
- Severity: `Medium`
- Area: `Event ordering and state consistency`
- File: `apps/server/src/orchestration/Layers/OrchestrationEngine.ts:144`
- Threads: PRRT_kwDORLtfbc5wkPaJ
- Audit note: Broad catch may be intentional for liveness; correctness concern is contextual.
- [ ] `C015` The gap-filling fallback logic can retain messages from turns that are about to be deleted, causing foreign key violations. Consider removing the fallback logic entirely, or filtering `fallbackUserMessages` and `fallbackAssistantMessages` to only include messages whose `turnId` is in `retainedTurnIds`. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary>
- Status: `TODO`
- Verdict: `partially-valid`
- Severity: `Medium`
- Area: `Event ordering and state consistency`
- File: `apps/server/src/orchestration/Layers/ProjectionPipeline.ts:99`
- Threads: PRRT_kwDORLtfbc5whxJO
- Audit note: Message fallback retention issue is real, but prior FK-violation claim is overstated.
- [ ] `C016` The in-memory `pendingTurnStartByThreadId` map isn't restored during bootstrap. If the service restarts after processing `thread.turn-start-requested` but before `thread.session-set`, the `userMessageId` and `startedAt` will be lost since bootstrap resumes *after* the committed sequence. Consider persisting this pending state or processing these two events atomically. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary>
- Status: `TODO`
- Verdict: `valid`
- Severity: `Medium`
- Area: `Event ordering and state consistency`
- File: `apps/server/src/orchestration/Layers/ProjectionPipeline.ts:490`
- Threads: PRRT_kwDORLtfbc5wxvH8
- Audit note: Pending turn-start map is in-memory only and not rebuilt on bootstrap.
### Phase 3
- [ ] `C008` Inconsistent input normalization across CheckpointStore methods
- Status: `TODO`
- Verdict: `partially-valid`
- Severity: `Medium`
- Area: `Checkpointing correctness`
- File: `apps/server/src/checkpointing/Layers/CheckpointStore.ts:94`
- Threads: PRRT_kwDORLtfbc5widJw, PRRT_kwDORLtfbc5wnWv_, PRRT_kwDORLtfbc5w0_g7, PRRT_kwDORLtfbc5w1C36 (+3 duplicate thread(s))
- Audit note: Normalization inconsistency remains, but upstream callsites now mostly canonicalize inputs.
- [ ] `C017` `REQUIRED_SNAPSHOT_PROJECTORS` includes `pending-approvals` and `thread-turns`, but `getSnapshot` doesn't query their data. If these projectors lag behind, the returned `snapshotSequence` will be lower than what the included data actually reflects, causing clients to replay already-applied events. Consider filtering `REQUIRED_SNAPSHOT_PROJECTORS` to only include projectors whose data is actually fetched in the snapshot. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary>
- Status: `TODO`
- Verdict: `partially-valid`
- Severity: `Medium`
- Area: `Checkpointing correctness`
- File: `apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts:71`
- Threads: PRRT_kwDORLtfbc5wiLhQ
- Audit note: Snapshot sequence can under-report due to extra projectors, but replay impact is lower now.
- [ ] `C033` Three error classes defined but never instantiated anywhere
- Status: `TODO`
- Verdict: `partially-valid`
- Severity: `Low`
- Area: `Checkpointing correctness`
- File: `apps/server/src/checkpointing/Errors.ts:51`
- Threads: PRRT_kwDORLtfbc5wlYgo
- Audit note: Original claim overstated; some errors used, others appear unused.
- [ ] `C034` Redundant `CheckpointInvariantError` in `CheckpointServiceError` union type
- Status: `TODO`
- Verdict: `valid`
- Severity: `Low`
- Area: `Checkpointing correctness`
- File: `apps/server/src/checkpointing/Errors.ts:79`
- Threads: PRRT_kwDORLtfbc5wj5fn
- Audit note: CheckpointInvariantError remains redundantly included in service union.
- [ ] `C035` Redundant error type in CheckpointServiceError union definition
- Status: `TODO`
- Verdict: `valid`
- Severity: `Low`
- Area: `Checkpointing correctness`
- File: `apps/server/src/checkpointing/Errors.ts:79`
- Threads: PRRT_kwDORLtfbc5wlYgs, PRRT_kwDORLtfbc5wxsO6, PRRT_kwDORLtfbc5w1C4B (+2 duplicate thread(s))
- Audit note: Same as C034.
### Phase 4
- [ ] `C018` Unbounded memory growth in turn start deduplication set
- Status: `TODO`
- Verdict: `valid`
- Severity: `Medium`
- Area: `Memory/resource growth`
- File: `apps/server/src/orchestration/Layers/ProviderCommandReactor.ts:84`
- Threads: PRRT_kwDORLtfbc5whszQ, PRRT_kwDORLtfbc5wl2A8, PRRT_kwDORLtfbc5wyTaT, PRRT_kwDORLtfbc5wzliz, PRRT_kwDORLtfbc5w0_g-, PRRT_kwDORLtfbc5w1HGW (+5 duplicate thread(s))
- Audit note: handledTurnStartKeys still grows without pruning.
### Phase 5
- [ ] `C009` Git's braced rename syntax (e.g., `src/{old => new}/file.ts`) isn't handled correctly. The current slice after ` => ` produces invalid paths like `new}/file.ts`. Consider expanding the braces to construct the full destination path. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary>
- Status: `TODO`
- Verdict: `valid`
- Severity: `Medium`
- Area: `Edge-case parsing/platform behavior`
- File: `apps/server/src/git/Layers/GitCore.ts:41`
- Threads: PRRT_kwDORLtfbc5w1CxT
- Audit note: Braced rename parsing still breaks paths like src/{old => new}/file.ts.
- [ ] `C010` `loadCustomKeybindingsConfig` fails when the config file doesn't exist, which is expected for new users. Consider catching `ENOENT` and returning an empty array instead. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary>
- Status: `TODO`
- Verdict: `valid`
- Severity: `Medium`
- Area: `Edge-case parsing/platform behavior`
- File: `apps/server/src/keybindings.ts:418`
- Threads: PRRT_kwDORLtfbc5wxvIJ
- Audit note: ENOENT for missing keybindings config still not handled as empty/default.
- [ ] `C022` Fish shell outputs `$PATH` as space-separated, not colon-separated. Consider checking if the shell is fish and using `string join : $PATH` instead, or validating the result contains colons before assigning.
- Status: `TODO`
- Verdict: `valid`
- Severity: `Medium`
- Area: `Edge-case parsing/platform behavior`
- File: `apps/server/src/os-jank.ts:10`
- Threads: PRRT_kwDORLtfbc5wkRZM
- Audit note: fish PATH formatting risk still exists in os-jank path recovery.
- [ ] `C023` Using `-il` flags causes the shell to source profile scripts that may print banners or other text, polluting the captured `PATH`. Consider using `-lc` (login only, non-interactive) to reduce unwanted output.
- Status: `TODO`
- Verdict: `valid`
- Severity: `Medium`
- Area: `Edge-case parsing/platform behavior`
- File: `apps/server/src/os-jank.ts:10`
- Threads: PRRT_kwDORLtfbc5wj4cM
- Audit note: -ilc shell invocation can pollute captured PATH output.
- [ ] `C029` `parseFileUrlHref` already decodes the path (line 46), but `safeDecode` is called again here, corrupting filenames containing `%` sequences. Consider skipping the decode when `fileUrlTarget` is non-null.
- Status: `TODO`
- Verdict: `valid`
- Severity: `Medium`
- Area: `Edge-case parsing/platform behavior`
- File: `apps/web/src/markdown-links.ts:105`
- Threads: PRRT_kwDORLtfbc5wnVsU
- Audit note: file URL decoding still double-decodes in one path.
- [ ] `C030` `EXTERNAL_SCHEME_PATTERN` matches `script.ts:10` as a scheme because `.ts:` looks like `scheme:`. Consider requiring `://` after the colon, or checking that what follows the colon is not just digits. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary>
- Status: `TODO`
- Verdict: `valid`
- Severity: `Medium`
- Area: `Edge-case parsing/platform behavior`
- File: `apps/web/src/markdown-links.ts:111`
- Threads: PRRT_kwDORLtfbc5wnVsK
- Audit note: Scheme regex still misclassifies script.ts:10 as external scheme.
- [ ] `C038` Multi-byte UTF-8 characters split across chunks will be corrupted when decoding each chunk separately. Consider accumulating all chunks first, then decoding once, or use `TextDecoder` with `stream: true`. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary>
- Status: `TODO`
- Verdict: `valid`
- Severity: `Low`
- Area: `Edge-case parsing/platform behavior`
- File: `apps/server/src/git/Layers/CodexTextGeneration.ts:136`
- Threads: PRRT_kwDORLtfbc5w1GPo
- Audit note: Chunk-by-chunk UTF-8 decode can still corrupt split multibyte characters.
- [ ] `C039` The `+` key can be parsed (via trailing `+` handling) but cannot be encoded because `shortcut.key.includes("+")` returns true for the literal `+` key. Consider checking `shortcut.key === "+"` separately and encoding it as `"space"` style (e.g., a special token), or adjusting the condition to allow the single `+` character. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary>
- Status: `TODO`
- Verdict: `partially-valid`
- Severity: `Low`
- Area: `Edge-case parsing/platform behavior`
- File: `apps/server/src/keybindings.ts:352`
- Threads: PRRT_kwDORLtfbc5wxvIB
- Audit note: Parser/encoder mismatch remains, but encoder path currently low-use.
- [ ] `C040` `upsertKeybindingRule` has a race condition: concurrent calls read the same file state, then the last write overwrites earlier changes. Consider wrapping the read-modify-write sequence with `Effect.Semaphore` to serialize access. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary>
- Status: `TODO`
- Verdict: `valid`
- Severity: `Low`
- Area: `Edge-case parsing/platform behavior`
- File: `apps/server/src/keybindings.ts:488`
- Threads: PRRT_kwDORLtfbc5wxvIA
- Audit note: upsertKeybindingRule read-modify-write remains race-prone.
### Phase 6
- [ ] `C006` Build script runs TypeScript file with bare node
- Status: `TODO`
- Verdict: `partially-valid`
- Severity: `Medium`
- Area: `Build/runtime portability`
- File: `apps/server/package.json:14`
- Threads: PRRT_kwDORLtfbc5wxsO-
- Audit note: Node 24 makes this work, but script still relies on runtime-specific TS execution.
- [ ] `C007` Build script uses `node` to run `.ts` file directly
- Status: `TODO`
- Verdict: `partially-valid`
- Severity: `Medium`
- Area: `Build/runtime portability`
- File: `apps/server/package.json:14`
- Threads: PRRT_kwDORLtfbc5wiLNS, PRRT_kwDORLtfbc5wj5fl (+1 duplicate thread(s))
- Audit note: Same as C006 (duplicate concern).
- [ ] `C011` Template literal `${cause}` throws if `cause` is a `Symbol`. Consider using `String(cause)` instead.
- Status: `TODO`
- Verdict: `valid`
- Severity: `Medium`
- Area: `Other`
- File: `apps/server/src/orchestration/Errors.ts:117`
- Threads: PRRT_kwDORLtfbc5wBFv4
- Audit note: Template-literal interpolation of Symbol still throws.
- [ ] `C024` In `executeUnprepared`, preparing outside an effect and not closing the statement can cause uncaught errors and leaks. Suggest wrapping with `Effect.acquireUseRelease`: prepare in acquire (error-safe) and `finalize` in release.
- Status: `TODO`
- Verdict: `partially-valid`
- Severity: `Medium`
- Area: `Other`
- File: `apps/server/src/persistence/NodeSqliteClient.ts:145`
- Threads: PRRT_kwDORLtfbc5whxX9
- Audit note: prepare() still outside managed effect boundary; failure handling risk remains.
- [ ] `C028` Branch sync dispatches both server and stale local update
- Status: `TODO`
- Verdict: `partially-valid`
- Severity: `Medium`
- Area: `Other`
- File: `apps/web/src/components/BranchToolbar.tsx:102`
- Threads: PRRT_kwDORLtfbc5v-XCu
- Audit note: Optimistic local+server dual update is intentional but can temporarily diverge.
- [ ] `C032` Dummy workflow marker accidentally committed to docs
- Status: `TODO`
- Verdict: `valid`
- Severity: `Low`
- Area: `Other`
- File: `AGENTS.md:45`
- Threads: PRRT_kwDORLtfbc5wlYgj, PRRT_kwDORLtfbc5w1C4H (+1 duplicate thread(s))
- Audit note: Dummy workflow marker comment is still present in docs.
- [ ] `C037` `Effect.callback` should return a cleanup function to close the server(s) on fiber interruption. Without it, the `Net.Server` handles keep the process alive and leak the port if the effect is cancelled. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary>
- Status: `TODO`
- Verdict: `partially-valid`
- Severity: `Low`
- Area: `Other`
- File: `apps/server/src/config.ts:41`
- Threads: PRRT_kwDORLtfbc5wj4cO
- Audit note: Callback cleanup missing, but practical exposure is low in one-shot startup path.
- [ ] `C041` Template literal interpolation throws `TypeError` if `cause` is a `Symbol`. Consider using `String(cause)` for safe coercion.
- Status: `TODO`
- Verdict: `valid`
- Severity: `Low`
- Area: `Other`
- File: `apps/server/src/orchestration/Errors.ts:126`
- Threads: PRRT_kwDORLtfbc5wBFWs
- Audit note: Same Symbol interpolation hazard as C011 remains.
- [ ] `C047` `SqlSchema.findOneOption` can produce both SQL errors and decode errors, but `mapError` wraps all as `PersistenceSqlError`. Consider distinguishing `ParseError` from SQL errors and mapping decode failures to `PersistenceDecodeError` instead. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary>
- Status: `TODO`
- Verdict: `valid`
- Severity: `Low`
- Area: `Other`
- File: `apps/server/src/persistence/Layers/OrchestrationCommandReceipts.ts:75`
- Threads: PRRT_kwDORLtfbc5wiaR-
- Audit note: Decode and SQL errors still collapsed into one persistence error kind.
- [ ] `C048` `statement.run()` returns a `RunResult` object, not an array. Casting it to `ReadonlyArray<any>` will cause runtime errors when consumers call array methods. Consider wrapping the result (e.g., `[result]`) or returning a properly typed object.
- Status: `TODO`
- Verdict: `partially-valid`
- Severity: `Low`
- Area: `Other`
- File: `apps/server/src/persistence/NodeSqliteClient.ts:99`
- Threads: PRRT_kwDORLtfbc5wio-r
- Audit note: Unsafe run() result cast remains; runtime risk depends on raw-result consumers.
- [ ] `C049` `JSON.stringify(cause)` returns `undefined` for `undefined`, functions, or symbols, violating the `string` return type. Consider coercing the result to a string (e.g., `String(JSON.stringify(cause))`) or adding a fallback.
- Status: `TODO`
- Verdict: `valid`
- Severity: `Low`
- Area: `Other`
- File: `apps/server/src/provider/Layers/ProviderService.ts:59`
- Threads: PRRT_kwDORLtfbc5wnVsI
- Audit note: JSON.stringify(cause) may return undefined despite string expectations.
- [ ] `C050` The read-modify-write pattern (`getBySessionId` → merge → `upsert`) is susceptible to lost updates under concurrent writes. Consider wrapping in a transaction or adding optimistic concurrency control (e.g., version field) if concurrent session updates are expected. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary>
- Status: `TODO`
- Verdict: `valid`
- Severity: `Low`
- Area: `Other`
- File: `apps/server/src/provider/Layers/ProviderSessionDirectory.ts:94`
- Threads: PRRT_kwDORLtfbc5wiLhY
- Audit note: ProviderSessionDirectory upsert remains read-merge-write without concurrency control.
- [ ] `C051` Using `??` for `providerThreadId` and `adapterKey` makes it impossible to clear these fields by passing `null`, since `null ?? existing` evaluates to `existing`. Consider using explicit `undefined` checks (like `resumeCursor` does) if clearing should be supported. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary>
- Status: `TODO`
- Verdict: `partially-valid`
- Severity: `Low`
- Area: `Other`
- File: `apps/server/src/provider/Layers/ProviderSessionDirectory.ts:119`
- Threads: PRRT_kwDORLtfbc5wxvH9
- Audit note: Null-clearing issue is real for providerThreadId; adapterKey part overstated.
- [ ] `C052` Race condition: `processHandle` may be `null` when `data` callback fires, since it's assigned after `Bun.spawn` returns. Consider initializing `BunPtyProcess` first, then passing it to the callback to avoid losing initial output. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary>
- Status: `TODO`
- Verdict: `valid`
- Severity: `Low`
- Area: `Other`
- File: `apps/server/src/terminal/Layers/BunPTY.ts:97`
- Threads: PRRT_kwDORLtfbc5w1CxE
- Audit note: Data callback may race before processHandle assignment.
- [ ] `C056` When `onOpenChange` is provided without `open`, the internal `_open` state never updates because `setOpenProp` takes precedence. Consider calling `_setOpen` when `openProp === undefined`, regardless of whether `setOpenProp` exists.
- Status: `TODO`
- Verdict: `partially-valid`
- Severity: `Low`
- Area: `Other`
- File: `apps/web/src/components/ui/sidebar.tsx:114`
- Threads: PRRT_kwDORLtfbc5wxvIq
- Audit note: Bug pattern exists, but current callsites mostly avoid triggering it.
- [ ] `C057` The `resizable` object is recreated on every render, causing `SidebarRail`'s `useEffect` to repeatedly read localStorage and update the DOM. Consider memoizing the object with `useMemo`. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary>
- Status: `TODO`
- Verdict: `valid`
- Severity: `Low`
- Area: `Other`
- File: `apps/web/src/routes/_chat.$threadId.tsx:105`
- Threads: PRRT_kwDORLtfbc5wyWz4
- Audit note: Resizable object recreation still retriggers effect/storage reads.
- [ ] `C058` When `localStorage.getItem()` returns `null`, `Number(null)` evaluates to `0`, which passes `Number.isFinite(0)`. This causes the sidebar to clamp to `minWidth` on first load, overriding the `DIFF_INLINE_DEFAULT_WIDTH` CSS clamp. Consider checking for `null` or empty string before parsing, e.g. guard with `storedWidth === null || storedWidth === ''`. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary>
- Status: `TODO`
- Verdict: `valid`
- Severity: `Low`
- Area: `Other`
- File: `apps/web/src/routes/_chat.$threadId.tsx:122`
- Threads: PRRT_kwDORLtfbc5wnVsX
- Audit note: Number(null) -> 0 path still forces min width on initial load.
- [ ] `C060` `defaultModel` should be `Schema.optional(Schema.NullOr(Schema.String))` to allow clearing the value. Currently there's no way to reset it to `null` since omitting means "no change" in patch semantics. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary>
- Status: `TODO`
- Verdict: `valid`
- Severity: `Low`
- Area: `Other`
- File: `packages/contracts/src/orchestration.ts:253`
- Threads: PRRT_kwDORLtfbc5whxJC
- Audit note: Schema still cannot express null clear for defaultModel patch.
## Closed Invalid Items
- [x] `C021` Shared mutable default metadata object causes stale eventId
- Status: `CLOSED_INVALID`
- Severity: `Medium`
- File: `apps/server/src/orchestration/decider.ts:27`
- Threads: PRRT_kwDORLtfbc5wkPaA
- Rationale: Stale-eventId claim no longer applies; eventId is regenerated per event.
- [x] `C025` Duplicated checkpoint ref computation across two files
- Status: `CLOSED_INVALID`
- Severity: `Medium`
- File: `apps/server/src/wsServer.ts:128`
- Threads: PRRT_kwDORLtfbc5wvwag
- Rationale: No longer duplicated; checkpoint ref helper now centralized.
- [x] `C031` Revert uses wrong turn count from positional inference
- Status: `CLOSED_INVALID`
- Severity: `Medium`
- File: `apps/web/src/session-logic.ts:127`
- Threads: PRRT_kwDORLtfbc5v9SCp
- Rationale: Revert now uses explicit checkpointTurnCount first; positional fallback is non-primary.
- [x] `C036` Duplicate `checkpointRefForThreadTurn` function in two production files
- Status: `CLOSED_INVALID`
- Severity: `Low`
- File: `apps/server/src/checkpointing/Layers/CheckpointStore.ts:284`
- Threads: PRRT_kwDORLtfbc5wiqFX
- Rationale: No longer duplicated; single production source via Refs.ts.
- [x] `C055` Duplicate `checkpointRefForThreadTurn` function across files
- Status: `CLOSED_INVALID`
- Severity: `Low`
- File: `apps/server/src/wsServer.ts:128`
- Threads: PRRT_kwDORLtfbc5wkPaG
- Rationale: No longer duplicated; helper is centralized.
@@ -22,7 +22,7 @@ import {
makeOrchestrationIntegrationHarness,
type OrchestrationIntegrationHarness,
} from "./OrchestrationEngineHarness.integration.ts";
import { checkpointRefForThreadTurn } from "../src/checkpointing/Refs.ts";
import { checkpointRefForThreadTurn } from "../src/checkpointing/Utils.ts";
const asMessageId = (value: string): MessageId => MessageId.makeUnsafe(value);
const asProjectId = (value: string): ProjectId => ProjectId.makeUnsafe(value);
@@ -9,7 +9,7 @@ import { Effect, Layer } from "effect";
import { describe, expect, it } from "vitest";
import { ProjectionSnapshotQuery } from "../../orchestration/Services/ProjectionSnapshotQuery.ts";
import { checkpointRefForThreadTurn } from "../Refs.ts";
import { checkpointRefForThreadTurn } from "../Utils.ts";
import { CheckpointDiffQueryLive } from "./CheckpointDiffQuery.ts";
import { CheckpointStore, type CheckpointStoreShape } from "../Services/CheckpointStore.ts";
import { CheckpointDiffQuery } from "../Services/CheckpointDiffQuery.ts";
@@ -9,35 +9,12 @@ import { Effect, Layer, Schema } from "effect";
import { ProjectionSnapshotQuery } from "../../orchestration/Services/ProjectionSnapshotQuery.ts";
import { CheckpointInvariantError, CheckpointUnavailableError } from "../Errors.ts";
import { checkpointRefForThreadTurn } from "../Refs.ts";
import { checkpointRefForThreadTurn, resolveThreadWorkspaceCwd } from "../Utils.ts";
import { CheckpointStore } from "../Services/CheckpointStore.ts";
import { CheckpointDiffQuery, type CheckpointDiffQueryShape } from "../Services/CheckpointDiffQuery.ts";
function trimToNonEmpty(value: string | null | undefined): string | undefined {
const normalized = value?.trim();
return normalized && normalized.length > 0 ? normalized : undefined;
}
function resolveThreadWorkspaceCwd(input: {
readonly thread: {
readonly projectId: ProjectId;
readonly worktreePath: string | null;
};
readonly projects: ReadonlyArray<{
readonly id: ProjectId;
readonly workspaceRoot: string;
}>;
}): string | undefined {
const worktreeCwd = trimToNonEmpty(input.thread.worktreePath);
if (worktreeCwd) {
return worktreeCwd;
}
const workspaceRoot = input.projects.find(
(project) => project.id === input.thread.projectId,
)?.workspaceRoot;
return trimToNonEmpty(workspaceRoot);
}
import {
CheckpointDiffQuery,
type CheckpointDiffQueryShape,
} from "../Services/CheckpointDiffQuery.ts";
const isTurnDiffResult = Schema.is(OrchestrationGetTurnDiffResult);
-10
View File
@@ -1,10 +0,0 @@
import { Encoding } from "effect";
import { CheckpointRef, type ThreadId } from "@t3tools/contracts";
export const CHECKPOINT_REFS_PREFIX = "refs/t3/checkpoints";
export function checkpointRefForThreadTurn(threadId: ThreadId, turnCount: number): CheckpointRef {
return CheckpointRef.makeUnsafe(
`${CHECKPOINT_REFS_PREFIX}/${Encoding.encodeBase64Url(threadId)}/turn/${turnCount}`,
);
}
+36
View File
@@ -0,0 +1,36 @@
import { Encoding } from "effect";
import { CheckpointRef, ProjectId, type ThreadId } from "@t3tools/contracts";
export const CHECKPOINT_REFS_PREFIX = "refs/t3/checkpoints";
export function checkpointRefForThreadTurn(threadId: ThreadId, turnCount: number): CheckpointRef {
return CheckpointRef.makeUnsafe(
`${CHECKPOINT_REFS_PREFIX}/${Encoding.encodeBase64Url(threadId)}/turn/${turnCount}`,
);
}
function trimToNonEmpty(value: string | null | undefined): string | undefined {
const normalized = value?.trim();
return normalized && normalized.length > 0 ? normalized : undefined;
}
export function resolveThreadWorkspaceCwd(input: {
readonly thread: {
readonly projectId: ProjectId;
readonly worktreePath: string | null;
};
readonly projects: ReadonlyArray<{
readonly id: ProjectId;
readonly workspaceRoot: string;
}>;
}): string | undefined {
const worktreeCwd = trimToNonEmpty(input.thread.worktreePath);
if (worktreeCwd) {
return worktreeCwd;
}
const workspaceRoot = input.projects.find(
(project) => project.id === input.thread.projectId,
)?.workspaceRoot;
return trimToNonEmpty(workspaceRoot);
}
@@ -35,7 +35,7 @@ import {
ProviderService,
type ProviderServiceShape,
} from "../../provider/Services/ProviderService.ts";
import { checkpointRefForThreadTurn } from "../../checkpointing/Refs.ts";
import { checkpointRefForThreadTurn } from "../../checkpointing/Utils.ts";
const asProjectId = (value: string): ProjectId => ProjectId.makeUnsafe(value);
const asSessionId = (value: string): ProviderSessionId => ProviderSessionId.makeUnsafe(value);
@@ -334,7 +334,10 @@ describe("CheckpointReactor", () => {
threadId: ProviderThreadId.makeUnsafe("provider-thread-1"),
turnId: asTurnId("turn-1"),
});
await waitForGitRefExists(harness.cwd, checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 0));
await waitForGitRefExists(
harness.cwd,
checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 0),
);
fs.writeFileSync(path.join(harness.cwd, "README.md"), "v2\n", "utf8");
harness.provider.emit({
@@ -354,12 +357,12 @@ describe("CheckpointReactor", () => {
(entry) => entry.latestTurnId === "turn-1" && entry.checkpoints.length === 1,
);
expect(thread.checkpoints[0]?.checkpointTurnCount).toBe(1);
expect(gitRefExists(harness.cwd, checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 0))).toBe(
true,
);
expect(gitRefExists(harness.cwd, checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 1))).toBe(
true,
);
expect(
gitRefExists(harness.cwd, checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 0)),
).toBe(true);
expect(
gitRefExists(harness.cwd, checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 1)),
).toBe(true);
expect(
gitShowFileAtRef(
harness.cwd,
@@ -398,7 +401,10 @@ describe("CheckpointReactor", () => {
}),
);
await waitForGitRefExists(harness.cwd, checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 0));
await waitForGitRefExists(
harness.cwd,
checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 0),
);
expect(
gitShowFileAtRef(
harness.cwd,
@@ -448,9 +454,9 @@ describe("CheckpointReactor", () => {
});
await waitForEvent(harness.engine, (event) => event.type === "thread.turn-diff-completed");
expect(gitRefExists(harness.cwd, checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 1))).toBe(
true,
);
expect(
gitRefExists(harness.cwd, checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 1)),
).toBe(true);
expect(
gitShowFileAtRef(
harness.cwd,
@@ -556,7 +562,10 @@ describe("CheckpointReactor", () => {
turnId: asTurnId("turn-after-runtime-failure"),
});
await waitForGitRefExists(harness.cwd, checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 0));
await waitForGitRefExists(
harness.cwd,
checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 0),
);
expect(
gitRefExists(harness.cwd, checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 0)),
).toBe(true);
@@ -636,9 +645,9 @@ describe("CheckpointReactor", () => {
numTurns: 1,
});
expect(fs.readFileSync(path.join(harness.cwd, "README.md"), "utf8")).toBe("v2\n");
expect(gitRefExists(harness.cwd, checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 2))).toBe(
false,
);
expect(
gitRefExists(harness.cwd, checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 2)),
).toBe(false);
});
it("processes consecutive revert requests with deterministic rollback sequencing", async () => {
@@ -5,14 +5,16 @@ import {
ProviderSessionId,
ThreadId,
TurnId,
type ProjectId,
type OrchestrationEvent,
type ProviderRuntimeEvent,
} from "@t3tools/contracts";
import { Cause, Effect, Layer, Option, Queue, Stream } from "effect";
import { parseTurnDiffFilesFromUnifiedDiff } from "../../checkpointing/Diffs.ts";
import { checkpointRefForThreadTurn } from "../../checkpointing/Refs.ts";
import {
checkpointRefForThreadTurn,
resolveThreadWorkspaceCwd,
} from "../../checkpointing/Utils.ts";
import { CheckpointStore } from "../../checkpointing/Services/CheckpointStore.ts";
import { ProviderService } from "../../provider/Services/ProviderService.ts";
import { CheckpointReactor, type CheckpointReactorShape } from "../Services/CheckpointReactor.ts";
@@ -40,27 +42,6 @@ function trimToNonEmpty(value: string | null | undefined): string | undefined {
return normalized && normalized.length > 0 ? normalized : undefined;
}
function resolveThreadWorkspaceCwd(input: {
readonly thread: {
readonly projectId: ProjectId;
readonly worktreePath: string | null;
};
readonly projects: ReadonlyArray<{
readonly id: ProjectId;
readonly workspaceRoot: string;
}>;
}): string | undefined {
const worktreeCwd = trimToNonEmpty(input.thread.worktreePath);
if (worktreeCwd) {
return worktreeCwd;
}
const workspaceRoot = input.projects.find(
(project) => project.id === input.thread.projectId,
)?.workspaceRoot;
return trimToNonEmpty(workspaceRoot);
}
function checkpointStatusFromRuntime(status: string | undefined): "ready" | "missing" | "error" {
switch (status) {
case "failed":
@@ -26,7 +26,7 @@ function toTurnId(value: string | undefined): TurnId | undefined {
}
function truncateDetail(value: string, limit = 180): string {
return value.length > limit ? `${value.slice(0, limit - 1)}...` : value;
return value.length > limit ? `${value.slice(0, limit - 3)}...` : value;
}
function runtimeEventToActivities(
@@ -130,7 +130,6 @@ const make = Effect.gen(function* () {
const providerService = yield* ProviderService;
const turnMessageIdsByTurnKey = new Map<string, Set<MessageId>>();
const latestMessageIdByTurnKey = new Map<string, MessageId>();
const rememberAssistantMessageId = (
sessionId: ProviderSessionId,
@@ -144,7 +143,6 @@ const make = Effect.gen(function* () {
} else {
turnMessageIdsByTurnKey.set(key, new Set([messageId]));
}
latestMessageIdByTurnKey.set(key, messageId);
};
const getAssistantMessageIdsForTurn = (sessionId: ProviderSessionId, turnId: TurnId) => {
@@ -162,11 +160,6 @@ const make = Effect.gen(function* () {
turnMessageIdsByTurnKey.delete(key);
}
}
for (const key of latestMessageIdByTurnKey.keys()) {
if (key.startsWith(prefix)) {
latestMessageIdByTurnKey.delete(key);
}
}
};
const processEvent = (event: ProviderRuntimeEvent) =>
+3 -2
View File
@@ -72,7 +72,7 @@ const isServerNotRunningError = (error: unknown): boolean => {
};
function rejectUpgrade(socket: Duplex, statusCode: number, message: string): void {
socket.write(
socket.end(
`HTTP/1.1 ${statusCode} ${statusCode === 401 ? "Unauthorized" : "Bad Request"}\r\n` +
"Connection: close\r\n" +
"Content-Type: text/plain\r\n" +
@@ -80,7 +80,6 @@ function rejectUpgrade(socket: Duplex, statusCode: number, message: string): voi
"\r\n" +
message,
);
socket.destroy();
}
function parseBooleanEnv(value: string | undefined): boolean | undefined {
@@ -506,6 +505,8 @@ export const createServer = Effect.fn(function* (options: ServerOptions = {}): E
});
httpServer.on("upgrade", (request, socket, head) => {
socket.on("error", () => {}); // Prevent unhandled `EPIPE`/`ECONNRESET` from crashing the process if the client disconnects mid-handshake
if (authToken) {
let providedToken: string | null = null;
try {
+1 -4
View File
@@ -53,10 +53,7 @@ export class WsTransport {
throw new Error("Request method is required");
}
const id = String(this.nextId++);
const body =
params !== undefined
? { _tag: method, ...(params as Record<string, unknown>) }
: { _tag: method };
const body = params != null ? { ...params, _tag: method } : { _tag: method };
const message: WsRequestEnvelope = { id, body };
return new Promise<T>((resolve, reject) => {