feat(core): provider-aware errors + named-step logging in generate#41
Merged
feat(core): provider-aware errors + named-step logging in generate#41
Conversation
…erate Fixes runtime bug where 401/4xx errors leaked OpenAI URLs even when the active provider was Anthropic, OpenRouter, etc. Adds a CoreLogger contract and step-named events so the desktop log shows which generate stage failed. - packages/core/src/errors.ts: rewriteUpstreamMessage + remapProviderError; 4xx-only, with a per-provider key-help URL map and a generic fallback that strips the leaked URL for unknown providers. - packages/core/src/logger.ts: tiny CoreLogger interface, NOOP default. - packages/core/src/index.ts: instrument generate() with resolve_model, build_request, send_request, parse_response steps; wrap upstream errors. - apps/desktop/src/main/index.ts: log load_config + validate_provider before calling generate; pipe a scoped CoreLogger through. - Tests: 12 new error-mapping cases (openai keep, anthropic rewrite, openrouter, deepseek, unknown strip, 5xx passthrough) + step-log order test + send_request.fail test.
Contributor
There was a problem hiding this comment.
Findings
- [Major]
applyComment()drops injected logger (silent behavior regression) —ApplyCommentInputnow advertiseslogger, but the value is not forwarded torunModel, so callers get no step logs for comment revisions even when they pass a logger. This creates an implicit no-op API surface and makes observability inconsistent withgenerate(). Evidence:packages/core/src/index.ts:71,packages/core/src/index.ts:419.
Suggested fix:return runModel({ model: input.model, apiKey: input.apiKey, baseUrl: input.baseUrl, signal: input.signal, onRetry: input.onRetry, messages, logger: input.logger, });
Summary
- Review mode: initial
- 1 issue found in the latest diff.
- Not found in repo/docs:
docs/VISION.md,docs/PRINCIPLES.md(onlydocs/research/*exists in this checkout), so project-principles verification was based onCLAUDE.mdplus changed code.
Testing
- Not run (automation):
pnpmis not available in this runner environment.
open-codesign Bot
| referenceUrl?: ReferenceUrlContext | null | undefined; | ||
| signal?: AbortSignal | undefined; | ||
| onRetry?: ((info: RetryReason) => void) | undefined; | ||
| logger?: CoreLogger | undefined; |
Contributor
There was a problem hiding this comment.
[Major] logger is now part of ApplyCommentInput, but applyComment() still calls runModel() without passing it, so this new field becomes a silent no-op for revision flows.
Suggested fix:
return runModel({
model: input.model,
apiKey: input.apiKey,
baseUrl: input.baseUrl,
signal: input.signal,
onRetry: input.onRetry,
messages,
logger: input.logger,
});applyComment() advertised a logger param via ApplyCommentInput but dropped it before calling runModel — callers got no step logs for comment revisions even when supplying a logger. Plumb the logger through and emit named steps mirroring generate(): resolve_model / build_request / send_request / parse_response, scoped under [apply_comment] so observability is consistent across both flows. Adds a vitest case asserting the step log order.
Contributor
There was a problem hiding this comment.
Findings
- No new high-confidence issues found in the latest diff.
Summary
- Review mode: follow-up after new commits
- No blocking/major/minor findings on added/modified lines in this revision.
- Not found in repo/docs:
docs/VISION.md,docs/PRINCIPLES.md(onlydocs/research/*exists in this checkout), so principles verification was based onCLAUDE.mdand changed code only. - Residual risk/testing gap: end-to-end behavior for new IPC step logs was not validated in this runner.
Testing
- Not run (automation):
pnpmis not available in this runner environment.
open-codesign Bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes runtime bug where 401/4xx errors leak OpenAI URL for non-OpenAI providers, and adds step-named structured logging so users/devs can pinpoint which generate stage failed.
Summary
Test plan