Skip to content

feat(core): provider-aware errors + named-step logging in generate#41

Merged
hqhq1025 merged 2 commits intomainfrom
wt/fix-generate-logging
Apr 18, 2026
Merged

feat(core): provider-aware errors + named-step logging in generate#41
hqhq1025 merged 2 commits intomainfrom
wt/fix-generate-logging

Conversation

@hqhq1025
Copy link
Copy Markdown
Collaborator

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

  • Rewrite leaked openai.com URLs in upstream errors to the active provider's correct billing/key-help URL
  • Add named-step logging (load_config / validate_provider / resolve_model / build_request / send_request / parse_response) with timing + provider/model context
  • Strip URL when provider unknown

Test plan

  • vitest covering all 4 error-mapping cases
  • vitest verifying step log order
  • manual: trigger 401 with mismatched key/provider and confirm correct URL

…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.
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Findings

  • [Major] applyComment() drops injected logger (silent behavior regression) — ApplyCommentInput now advertises logger, but the value is not forwarded to runModel, 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 with generate(). 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 (only docs/research/* exists in this checkout), so project-principles verification was based on CLAUDE.md plus changed code.

Testing

  • Not run (automation): pnpm is not available in this runner environment.

open-codesign Bot

referenceUrl?: ReferenceUrlContext | null | undefined;
signal?: AbortSignal | undefined;
onRetry?: ((info: RetryReason) => void) | undefined;
logger?: CoreLogger | undefined;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 (only docs/research/* exists in this checkout), so principles verification was based on CLAUDE.md and 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): pnpm is not available in this runner environment.

open-codesign Bot

@hqhq1025 hqhq1025 merged commit 898556b into main Apr 18, 2026
5 of 6 checks passed
@hqhq1025 hqhq1025 deleted the wt/fix-generate-logging branch April 18, 2026 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant