GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Merge upstream pingdotgg/t3code main (v0.0.5 → v0.0.9) by aaditagrawal · Pull Request #668 · pingdotgg/t3code Conversation
|
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Opened against wrong repo — this should target the fork. Closing. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| state.currentTurnId = state.pendingTurnIds.shift() ?? state.currentTurnId ?? providerTurnId; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🟢 Low Layers/copilotTurnTracking.ts:30
When pendingTurnIds is empty, state.currentTurnId is set to itself instead of the new providerTurnId, causing all subsequent turns to reuse the first turn's ID. The expression state.pendingTurnIds.shift() ?? state.currentTurnId ?? providerTurnId prevents providerTurnId from ever being used once currentTurnId is populated. Consider removing ?? state.currentTurnId so the fallback chain correctly prefers the new providerTurnId when no client ID is pending.
| state.currentTurnId = state.pendingTurnIds.shift() ?? state.currentTurnId ?? providerTurnId; | |
| state.currentTurnId = state.pendingTurnIds.shift() ?? providerTurnId; |
In file apps/server/src/provider/Layers/copilotTurnTracking.ts around line 30:
When `pendingTurnIds` is empty, `state.currentTurnId` is set to itself instead of the new `providerTurnId`, causing all subsequent turns to reuse the first turn's ID. The expression `state.pendingTurnIds.shift() ?? state.currentTurnId ?? providerTurnId` prevents `providerTurnId` from ever being used once `currentTurnId` is populated. Consider removing `?? state.currentTurnId` so the fallback chain correctly prefers the new `providerTurnId` when no client ID is pending.
Evidence trail:
apps/server/src/provider/Layers/copilotTurnTracking.ts line 30: `state.currentTurnId = state.pendingTurnIds.shift() ?? state.currentTurnId ?? providerTurnId;` - line 29 shows `state.currentProviderTurnId = providerTurnId;` which IS updated each turn. apps/server/src/provider/Layers/CopilotAdapter.ts lines 1063-1091 shows `beginCopilotTurn` called on each `assistant.turn_start` event, and `clearTurnTracking` only called on `session.idle` or `abort`. Test file copilotTurnTracking.test.ts shows initial state has `pendingTurnIds: []` and `currentTurnId: undefined`.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| // ── Session teardown ────────────────────────────────────────────── | ||
|
|
||
| stopSession(threadId: ThreadId): void { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🟢 Low src/ampServerManager.ts:410
stopSession returns immediately after calling process.kill(), but the session entry is not removed from this.sessions until the asynchronous 'close' event fires. This creates a race where startSession immediately called after stopSession finds the stale entry and throws "AMP session already exists". Consider returning a promise that resolves after cleanup completes.
In file apps/server/src/ampServerManager.ts around line 410:
`stopSession` returns immediately after calling `process.kill()`, but the session entry is not removed from `this.sessions` until the asynchronous `'close'` event fires. This creates a race where `startSession` immediately called after `stopSession` finds the stale entry and throws "AMP session already exists". Consider returning a promise that resolves after cleanup completes.
Evidence trail:
apps/server/src/ampServerManager.ts lines 410-421 (stopSession returns void, calls process.kill() and returns immediately), lines 250-275 (close event handler where session.status is set to 'closed' at line 267 and this.sessions.delete(threadId) at line 275), lines 182-188 (startSession checks existing session and throws if status !== 'closed')
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| export function beginCopilotTurn( | ||
| state: CopilotTurnTrackingState, | ||
| providerTurnId: TurnId, | ||
| ): void { | ||
| state.pendingCompletionTurnId = undefined; | ||
| state.pendingCompletionProviderTurnId = undefined; | ||
| state.pendingTurnUsage = undefined; | ||
| state.currentProviderTurnId = providerTurnId; | ||
| state.currentTurnId = state.pendingTurnIds.shift() ?? state.currentTurnId ?? providerTurnId; | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Layers/copilotTurnTracking.ts:22
beginCopilotTurn clears pendingCompletionTurnId, pendingCompletionProviderTurnId, and pendingTurnUsage on lines 26–28. If a new turn starts before the previous turn's async completion logic finishes (e.g., usage event still pending), this wipes Turn A's buffered data and completion references. Any subsequent completionTurnRefs call falls back to state.currentTurnId (now Turn B), causing Turn A's metrics to be incorrectly attributed to Turn B. Consider preserving the pending completion state until it is explicitly consumed rather than clearing it on every new turn.
+export function beginCopilotTurn( + state: CopilotTurnTrackingState, + providerTurnId: TurnId, +): void { + state.currentProviderTurnId = providerTurnId; + state.currentTurnId = state.pendingTurnIds.shift() ?? state.currentTurnId ?? providerTurnId; +}
In file apps/server/src/provider/Layers/copilotTurnTracking.ts around lines 22-31:
`beginCopilotTurn` clears `pendingCompletionTurnId`, `pendingCompletionProviderTurnId`, and `pendingTurnUsage` on lines 26–28. If a new turn starts before the previous turn's async completion logic finishes (e.g., usage event still pending), this wipes Turn A's buffered data and completion references. Any subsequent `completionTurnRefs` call falls back to `state.currentTurnId` (now Turn B), causing Turn A's metrics to be incorrectly attributed to Turn B. Consider preserving the pending completion state until it is explicitly consumed rather than clearing it on every new turn.
Evidence trail:
apps/server/src/provider/Layers/copilotTurnTracking.ts:26-28 (beginCopilotTurn clears pending state), apps/server/src/provider/Layers/copilotTurnTracking.ts:15-19 (completionTurnRefs fallback logic), apps/server/src/provider/Layers/CopilotAdapter.ts:1063 (beginCopilotTurn called on turn_start), apps/server/src/provider/Layers/CopilotAdapter.ts:1090 (markTurnAwaitingCompletion called on turn_end), apps/server/src/provider/Layers/CopilotAdapter.ts:713 (completionTurnRefs used for usage event)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| private handleOutputLine(threadId: ThreadId, line: string): void { | ||
| const session = this.sessions.get(threadId); | ||
| if (!session) return; | ||
|
|
||
| const trimmed = line.trim(); | ||
| if (!trimmed) return; | ||
|
|
||
| let msg: AmpJsonlMessage; | ||
| try { | ||
| msg = JSON.parse(trimmed) as AmpJsonlMessage; | ||
| } catch { | ||
| // Non-JSON output — treat as raw assistant text. | ||
| this.logger.warn("Failed to parse JSONL line", { length: trimmed.length }); | ||
| this.emitEvent(threadId, session.activeTurnId, { | ||
| type: "content.delta", | ||
| payload: { | ||
| streamKind: "assistant_text", | ||
| delta: trimmed + "\n", | ||
| }, | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| switch (msg.type) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🟢 Low src/ampServerManager.ts:462
handleOutputLine parses untrusted input with JSON.parse and immediately accesses msg.type. If the external process sends the string "null", JSON.parse returns null, causing a TypeError: Cannot read property 'type' of null that crashes the Node.js process. Consider checking that msg is a non-null object before the switch statement.
- switch (msg.type) { + if (!msg || typeof msg !== "object") { + this.logger.warn("Invalid JSONL message", { line: trimmed.slice(0, 200) }); + return; + } + switch (msg.type) {
In file apps/server/src/ampServerManager.ts around lines 462-485:
`handleOutputLine` parses untrusted input with `JSON.parse` and immediately accesses `msg.type`. If the external process sends the string `"null"`, `JSON.parse` returns `null`, causing a `TypeError: Cannot read property 'type' of null` that crashes the Node.js process. Consider checking that `msg` is a non-null object before the switch statement.
Evidence trail:
apps/server/src/ampServerManager.ts lines 462-485 (at REVIEWED_COMMIT): `handleOutputLine` method parses JSON at line 470 with `msg = JSON.parse(trimmed) as AmpJsonlMessage`, catch block handles parse errors at lines 471-480, then line 485 has `switch (msg.type)` with no null check between parsing and access.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| commandId: event.commandId, | ||
| payloadJson: event.payload, | ||
| metadataJson: event.metadata, | ||
| const append: OrchestrationEventStoreShape["append"] = (event) => { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🟢 Low Layers/OrchestrationEventStore.ts:182
The append method stores a redacted event to disk and returns the redacted version to the caller. This strips username/password from providerOptions before the event is handed back, so any immediate downstream use of that event (e.g., calling an LLM provider) fails due to missing credentials. Return the original unredacted event augmented with the assigned sequence instead, keeping the redaction for persistence only.
In file apps/server/src/persistence/Layers/OrchestrationEventStore.ts around line 182:
The `append` method stores a redacted event to disk and returns the redacted version to the caller. This strips `username`/`password` from `providerOptions` before the event is handed back, so any immediate downstream use of that event (e.g., calling an LLM provider) fails due to missing credentials. Return the original unredacted event augmented with the assigned `sequence` instead, keeping the redaction for persistence only.
Evidence trail:
apps/server/src/persistence/Layers/OrchestrationEventStore.ts lines 182-195 (append method redacts then stores), apps/server/src/orchestration/redactEvent.ts lines 31-45 (redactEventForBoundary strips username/password), apps/server/src/orchestration/Layers/OrchestrationEngine.ts lines 124-165 (savedEvent pushed to eventPubSub), apps/server/src/orchestration/Layers/ProviderCommandReactor.ts lines 762-775 (subscribes to streamDomainEvents), lines 455-501 (processTurnStartRequested uses event.payload.providerOptions), lines 354-362 (sendTurnForThread passes providerOptions), lines 240-259 (effectiveProviderOptions passed to providerService.startSession)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| function readProviderListResponse( | ||
| value: | ||
| | ProviderListResponse | ||
| | { data: ProviderListResponse; error?: undefined } | ||
| | { data?: undefined; error: unknown }, | ||
| ): ProviderListResponse { | ||
| if ("all" in value && "connected" in value) { | ||
| return value; | ||
| } | ||
| if (value.data !== undefined) { | ||
| return value.data; | ||
| } | ||
| throw new Error("OpenCode SDK returned an empty provider list response"); | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🟢 Low src/opencodeServerManager.ts:728
When the SDK returns an error response like { error: "Unauthorized" }, readProviderListResponse falls through to the final throw with message "OpenCode SDK returned an empty provider list response", suppressing the actual error. Consider rethrowing or including value.error in the error message so callers can see the root cause.
- if (value.data !== undefined) { - return value.data; - } - throw new Error("OpenCode SDK returned an empty provider list response"); + if (value.data !== undefined) { + return value.data; + } + throw new Error(`OpenCode SDK returned an empty provider list response: ${value.error}`);
apps/server/src/kiloServerManager.ts:703
The function
readProviderListResponsefails to handle the error case of the input union type. Ifvalueis an error wrapper (e.g.{ error: "Access Denied", data: undefined }),value.datais undefined, causing the code to fall through to line 703. This throws a genericError("Kilo SDK returned an empty provider list response")instead of propagating the actual error. This swallows the underlying exception from the SDK, making debugging impossible. The function should check for and throwvalue.errorif present.
In file apps/server/src/opencodeServerManager.ts around lines 728-741:
When the SDK returns an error response like `{ error: "Unauthorized" }`, `readProviderListResponse` falls through to the final `throw` with message "OpenCode SDK returned an empty provider list response", suppressing the actual error. Consider rethrowing or including `value.error` in the error message so callers can see the root cause.
Evidence trail:
apps/server/src/opencodeServerManager.ts lines 728-743 at REVIEWED_COMMIT - The `readProviderListResponse` function accepts `{ data?: undefined; error: unknown }` as a valid input type, but the function body only checks for `"all" in value && "connected" in value` and `value.data !== undefined`. When an error response is passed, both conditions are false, and the function throws a generic error without using `value.error`.
Also found in 1 other location(s):
- apps/server/src/kiloServerManager.ts:703 -- The function `readProviderListResponse` fails to handle the error case of the input union type. If `value` is an error wrapper (e.g. `{ error: "Access Denied", data: undefined }`), `value.data` is undefined, causing the code to fall through to line 703. This throws a generic `Error("Kilo SDK returned an empty provider list response")` instead of propagating the actual error. This swallows the underlying exception from the SDK, making debugging impossible. The function should check for and throw `value.error` if present.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| export function fetchAmpUsage(): ProviderUsageResult { | ||
| const acc = _ampUsageAccumulator; | ||
| let sessionUsage: ProviderSessionUsage | undefined; | ||
| if (acc.turnCount > 0) { | ||
| sessionUsage = { | ||
| inputTokens: acc.inputTokens, | ||
| outputTokens: acc.outputTokens, | ||
| ...(acc.cachedTokens > 0 ? { cachedTokens: acc.cachedTokens } : {}), | ||
| totalTokens: acc.inputTokens + acc.outputTokens, | ||
| turnCount: acc.turnCount, | ||
| }; | ||
| } | ||
| return { | ||
| provider: PROVIDER, | ||
| ...(sessionUsage ? { sessionUsage } : {}), | ||
| }; | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
src/ampServerManager.ts:45
fetchAmpUsage returns sessionUsage only when turnCount > 0, but token usage is accumulated in _ampUsageAccumulator even when a session crashes or is interrupted before turnCount increments. This causes the function to return { provider: "amp" } with no usage data even when tokens were consumed, leading to silent under-reporting of costs for failed or interrupted sessions. Consider gating on total token presence rather than turn count, or ensure turnCount is incremented whenever usage is recorded.
+export function fetchAmpUsage(): ProviderUsageResult { + const acc = _ampUsageAccumulator; + let sessionUsage: ProviderSessionUsage | undefined; + if (acc.inputTokens > 0 || acc.outputTokens > 0) { + sessionUsage = { + inputTokens: acc.inputTokens, + outputTokens: acc.outputTokens, + ...(acc.cachedTokens > 0 ? { cachedTokens: acc.cachedTokens } : {}), + totalTokens: acc.inputTokens + acc.outputTokens, + turnCount: acc.turnCount, + }; + } + return { + provider: PROVIDER, + ...(sessionUsage ? { sessionUsage } : {}), + }; +}
In file apps/server/src/ampServerManager.ts around lines 45-61:
`fetchAmpUsage` returns `sessionUsage` only when `turnCount > 0`, but token usage is accumulated in `_ampUsageAccumulator` even when a session crashes or is interrupted before `turnCount` increments. This causes the function to return `{ provider: "amp" }` with no usage data even when tokens were consumed, leading to silent under-reporting of costs for failed or interrupted sessions. Consider gating on total token presence rather than turn count, or ensure `turnCount` is incremented whenever usage is recorded.
Evidence trail:
apps/server/src/ampServerManager.ts lines 45-57 (fetchAmpUsage returns sessionUsage only when turnCount > 0), lines 431-443 (token accumulation occurs whenever inner.usage is present), line 452 (turnCount++ only when stop_reason === 'end_turn'), lines 229-249 (close handler doesn't increment turnCount), lines 251-272 (error handler doesn't increment turnCount), lines 315-322 (interruptTurn doesn't increment turnCount). REVIEWED_COMMIT.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| const onChunk = (chunk: Buffer) => { | ||
| output += chunk.toString(); | ||
| const url = parseServerUrl(output); | ||
| if (!url) { | ||
| return; | ||
| } | ||
| clearTimeout(timeout); | ||
| resolve(url); | ||
| }; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium src/opencodeServerManager.ts:1267
The onChunk listener is never removed from child.stdout and child.stderr after the server URL is detected (line 1273). The listener keeps accumulating all server output into the output string for the lifetime of the child process, causing unbounded memory growth and repeated parseServerUrl calls on ever-growing data. Consider removing the listeners with child.stdout.off('data', onChunk) and child.stderr.off('data', onChunk) after resolving the promise.
const onChunk = (chunk: Buffer) => {
output += chunk.toString();
const url = parseServerUrl(output);
if (!url) {
return;
}
clearTimeout(timeout);
+ child.stdout.off("data", onChunk);
+ child.stderr.off("data", onChunk);
resolve(url);
};In file apps/server/src/opencodeServerManager.ts around lines 1267-1275:
The `onChunk` listener is never removed from `child.stdout` and `child.stderr` after the server URL is detected (line 1273). The listener keeps accumulating all server output into the `output` string for the lifetime of the child process, causing unbounded memory growth and repeated `parseServerUrl` calls on ever-growing data. Consider removing the listeners with `child.stdout.off('data', onChunk)` and `child.stderr.off('data', onChunk)` after resolving the promise.
Evidence trail:
apps/server/src/opencodeServerManager.ts lines 1250-1310 at REVIEWED_COMMIT: Line 1267 defines `onChunk` that appends to `output` and calls `parseServerUrl`. Lines 1276-1277 attach listeners with `.on('data', onChunk)`. Line 1273 calls `resolve(url)` without removing the listeners. The child process is stored in `this.server.child` (line 1303-1307) and kept alive, meaning listeners remain active indefinitely.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if (!trimmed || !trimmed.includes(" - ")) { | ||
| continue; | ||
| } | ||
| const match = /^(?<slug>[a-z0-9./-]+)\s+-\s+(?<name>.+?)(?:\s+\((?:current|default)\))*$/i.exec( |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🟢 Low Layers/CursorAdapter.ts:149
The regex [a-z0-9./-]+ on line 149 rejects model slugs containing colons or underscores, so identifiers like llama2:7b or my_model are silently discarded. Consider expanding the character class to include : and _.
- const match = /^(?<slug>[a-z0-9./-]+)\s+-\s+(?<name>.+?)(?:\s+\((?:current|default)\))*$/i.exec( + const match = /^(?<slug>[a-z0-9.:/_-]+)\s+-\s+(?<name>.+?)(?:\s+\((?:current|default)\))*$/i.exec(
In file apps/server/src/provider/Layers/CursorAdapter.ts around line 149:
The regex `[a-z0-9./-]+` on line 149 rejects model slugs containing colons or underscores, so identifiers like `llama2:7b` or `my_model` are silently discarded. Consider expanding the character class to include `:` and `_`.
Evidence trail:
apps/server/src/provider/Layers/CursorAdapter.ts lines 140-161 at REVIEWED_COMMIT. Line 149 shows regex `/^(?<slug>[a-z0-9./-]+)\s+-\s+(?<name>.+?)(?:\s+\((?:current|default)\))*$/i` where the character class `[a-z0-9./-]+` excludes colons and underscores. Lines 150-152 show `if (!match?.groups) { continue; }` which silently skips non-matching lines.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if (typeof value === "string" && value.length > 0) { | ||
| orderedAnswers[question.answerIndex] = [value]; | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🟢 Low src/kiloServerManager.ts:1054
In respondToUserInput, scalar answers that are not strings (numbers, booleans) are silently discarded because of typeof value === "string", leaving the answer slot as []. This contradicts the array branch which converts values with .map(String), implying non-strings should be converted rather than dropped. Consider converting scalar values with String(value) instead of filtering them out.
- if (typeof value === "string" && value.length > 0) { - orderedAnswers[question.answerIndex] = [value]; + if (value != null && value !== "" && value !== false) { + orderedAnswers[question.answerIndex] = [String(value)]; }
In file apps/server/src/kiloServerManager.ts around lines 1054-1056:
In `respondToUserInput`, scalar answers that are not strings (numbers, booleans) are silently discarded because of `typeof value === "string"`, leaving the answer slot as `[]`. This contradicts the array branch which converts values with `.map(String)`, implying non-strings should be converted rather than dropped. Consider converting scalar values with `String(value)` instead of filtering them out.
Evidence trail:
apps/server/src/kiloServerManager.ts lines 1048-1057 at REVIEWED_COMMIT: Line 1048 initializes orderedAnswers with empty arrays. Lines 1051-1053 handle arrays with `.map(String)` conversion. Lines 1055-1056 only accept strings with `typeof value === "string" && value.length > 0`, meaning numeric/boolean scalars are never assigned and the slot remains `[]`.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I really feel like you need to fix your workflow, because this isnt great that it keeps making PR's against the upstream repo |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.