Skip to content

upstream取り込み: mastracode 0.14 + small-model refactor (#3517)#313

Merged
MocA-Love merged 1 commit intomainfrom
upstream-merge/pr7-mastracode-upgrade
Apr 18, 2026
Merged

upstream取り込み: mastracode 0.14 + small-model refactor (#3517)#313
MocA-Love merged 1 commit intomainfrom
upstream-merge/pr7-mastracode-upgrade

Conversation

@MocA-Love
Copy link
Copy Markdown
Owner

概要

upstream 34c9049b6 refactor(desktop): upgrade mastracode + simplify small-model naming (#3517) を取り込む PR。behind 1 → 0。

パッケージ安全性調査(ユーザー承認の 7-day policy 3 日例外)

本取り込みは 2026-04-18 時点で 3 日経過の @mastra/core@1.25.0 / mastracode@0.14.0 を含むため通常なら AGENTS.md の 7-day policy 違反ですが、以下の安全性調査で問題なしを確認し、ユーザー承認の上で一回限りの例外として取り込み:

  • CVE / Malware 報告: なし(Snyk / GitHub Advisory / Socket / npm で確認)
  • Lifecycle スクリプト: mastracode@0.14.0 に install/postinstall/preinstall/prepare なし(fork ignore-scripts=true も効く)
  • 依存 pin: 26 deps すべて specific version pin("latest" 指定なし)
  • Maintainer / DL: @mastra/core は 11 maintainers / 週12-15万DL、@mastra/mcp は 9万DL、いずれも healthy
  • GitHub 活動: mastra-ai/mastra は 23.1k stars / 14,285 commits、継続的リリース
  • tarball 実体: npm view で mastracode@0.14.0 中身(26 deps、特定 pin、install スクリプト無)直接確認済

AGENTS.md の 7-day policy 行は本 PR で 復元(一回限り例外、policy 自体は将来のために維持)。

取り込み commit

SHA 内容
34c9049b6 refactor(desktop): upgrade mastracode + simplify small-model naming (superset-sh#3517) — 49 files, +2033/-2704

fork 適応修正

shim / credential resolution(最重要)

  1. apps/desktop/src/lib/ai/call-small-model.ts: upstream が削除したが fork の enhance-text.ts / git-operations.ts が使用中のため新規 shim として再実装。内部で getSmallModel() を呼び、従来の { result, attempts } shape を提供。OAuth-only ユーザーは missing-credentials になる(upstream 設計と同じトレードオフ)。
  2. packages/chat/src/server/shared/small-model/get-small-model.ts: fork の auth 全経路を見るよう拡張
    • Anthropic: process.env.ANTHROPIC_API_KEYapikey:anthropic in auth.json → fork の ~/.superset/chat-anthropic-env.json の env config(parseAnthropicEnvText で正式フォーマット解釈)
    • OpenAI: process.env.OPENAI_API_KEYapikey:openaiapikey:openai-codex (fork 独自 Codex CLI slot)
  3. runtime.ts (packages/chat): 旧 getDefaultSmallModelProviders + generateTitleFromMessageWithStreamingModel を新 getSmallModel + generateTitleFromMessage に書き換え。provider loop → single-model pattern。
  4. runtime.test.ts: mock を新 API に移植。
  5. git-operations.ts: generateTitleFromMessageWithStreamingModel import 削除、OAuth streaming fallback 分岐削除(shim が常に api_key credentials を返すため dead branch)。callSmallModel wrapper 経由で従来通り動作。
  6. enhance-text.ts: import 経路は callSmallModel shim 経由で維持(変更なし)。

その他 fork 維持

  • AGENTS.md 7-day policy 行: upstream 削除を巻き戻して復元
  • apps/desktop/package.json NODE_OPTIONS: fork の 12288 維持(upstream は 8192 に下げている)
  • ModelsSettings.tsx: clearProviderIssueMutation + clearProviderIssue helper 削除(modelProviders router が削除されたため dead code)、未使用 apiKeysOpen state 削除

検証

  • typecheck: 全 26 タスク pass
  • lint: 3件(main baseline と同じ pre-existing、regression なし)

Codex pre-review

3 ラウンドで承認:

  • Round 1: 3 件指摘(modelProviders router 削除の扱い、OAuth 挙動など)
  • Round 2: 2 件 High 指摘(openai-codex slot mismatch, Anthropic env config 経路)→ get-small-model.ts を fork auth 全経路対応に拡張して解消
  • Round 3: 1 件 High 指摘(env config parser が fork の正式パーサと不一致)→ parseAnthropicEnvText を直接 import(get-small-model.ts)+ shim 側は quote/export prefix 対応の簡易版

Deferred(upstream 意図挙動、PR7 起因ではない)

  • ModelsSettings の Logout 常時表示: 34c commit message 明記の意図挙動("Active providers now always show a Logout button. Clears OAuth or API key depending on authMethod")。実際の disconnect は managed OAuth のみ対応の可能性あり → fork 側で follow-up

テストチェックリスト

  • desktop 起動 + small-model タスク(branch naming / title generation)が Anthropic API key 保存経路で動作
  • OpenAI API key(openai-codex slot)経由でも small-model が動作
  • Anthropic managed env config(~/.superset/chat-anthropic-env.jsonANTHROPIC_API_KEY / ANTHROPIC_AUTH_TOKEN)経由でも small-model が動作
  • chat title 自動生成が動作
  • enhance-text(TODO description/goal 書き換え)が動作
  • git auto commit message 生成が動作
  • OAuth-only ユーザーは small-model が gracefully null(エラーではなく skip)

…uperset-sh#3517)

* remove 7 day rule

* Upgrade mastra

* upgrade ai

* Ad mastra

* refactor(desktop): remove dead provider-diagnostics plumbing

The provider-diagnostics store was fed by callSmallModel's per-attempt
reporting, which was removed when small-model tasks moved to direct AI-SDK
+ mastracode's AuthStorage. Nothing writes to the issue map anymore, so the
clearIssue mutation, getStatuses query, and diagnosticStatus plumbing in
ModelsSettings were all no-ops.

Settings still surfaces "Session expired / Reconnect" via auth-status alone.
ProviderIssue type collapsed from 8 codes to just "expired" to match.

* fix(auth): auto-refresh expired Anthropic OAuth tokens

Anthropic credentials were read via authStorage.get() everywhere, so
mastracode's built-in refresh flow never ran. Once the 1-hour access
token expired, status flipped to "Reconnect" and users had to do a
full PKCE re-auth, even though a valid refresh token was already
stored.

Resolvers now call authStorage.getApiKey() for oauth creds on expiry,
which triggers refreshToken() and persists the refreshed credential.
getAnthropicAuthStatus does the same before declaring issue: "expired".
Mirrors the pattern already used for OpenAI small-model auth.

* review: address PR feedback from cubic + coderabbit + greptile

- host-service ai-branch-name: run trailing-trim after slice so a
  100-char truncation can't re-introduce a bare "." or "-" that git
  rejects as an invalid ref (coderabbit / cubic #2, #7).
- host-service workspace-creation.generateBranchName: reuse the
  existing listBranchNames helper instead of the inline git walk,
  which classified off the short refname and could conflate a local
  "origin/foo" with refs/remotes/origin/foo (coderabbit #3).
- packages/chat shared/small-model: drop the unused
  hasSmallModelCredentials export; only a test mock consumed it
  (greptile #4).
- resolveAnthropicCredential: on refresh failure, return null instead
  of kind:"oauth" with a stale expiresAt so callers fall back cleanly
  (cubic #8).
- chat-service.getAnthropicAuthStatus: log context when refresh throws
  instead of silently swallowing (cubic #9).

* fix(chat): read auth.json directly instead of importing mastracode

Importing createAuthStorage from mastracode loads the entire CLI tree
(fastembed → onnxruntime-node's 208 MB native binary) via eager
top-level requires in mastracode's CJS entry. This crashed
electron-vite bundling and bloated the get-small-model chunk.

getSmallModel now reads mastracode's auth.json file directly using
the same path resolution logic (~/Library/Application Support/mastracode/
on macOS). Zero mastracode import, zero bundle impact. The chunk stays
at 1.2 MB (just @ai-sdk/anthropic + @ai-sdk/openai).

Production build verified: compile:app succeeds, Electron main process
boots with no onnxruntime error.

* docs(desktop): add manual testing plan for PR superset-sh#3517

* fix api key storage slot

* fix(auth): store API keys in dedicated slot so OAuth doesn't clobber them

setApiKeyForProvider and setStoredAnthropicApiKeyFromEnvVariables now
use authStorage.setStoredApiKey() (writes to "apikey:<provider>")
instead of authStorage.set() (writes to the main "<provider>" slot
shared with OAuth). This way connecting/disconnecting OAuth doesn't
overwrite or delete a stored API key.

resolveAuthMethodForProvider falls back to hasStoredApiKey() after
checking the main slot, so status correctly reports authenticated
when only an API key is stored.

* fix(auth): backup/restore API keys across OAuth connect/disconnect

mastracode's resolveModel only reads API keys from the main
authStorage slot (authStorage.get("anthropic")). OAuth login
overwrites this slot, and disconnect removes it — losing any
previously saved API key.

Fix: backup the API key to the dedicated apikey: slot before OAuth
connect, restore it after disconnect. setApiKeyForProvider now writes
to both slots (main for resolveModel compatibility, apikey: for
backup). resolveAuthMethodForProvider checks both.

Applies to both Anthropic and OpenAI providers.

* chore: add upstream PR reference to auth workaround

Point to mastra-ai/mastra#15483 so the backup/restore code can be
removed once upstream lands and we bump mastracode.

* refactor(desktop): derive settings provider action from status

Replace the cascade of if/else + canDisconnect flag with a single
getProviderAction(status) → connect | reconnect | logout | null.
Fixes "Active" badge + "Connect" button showing simultaneously
when authenticated via API key.

* fix(desktop): always show Logout when provider is active

Active providers now always show a Logout button. Clears OAuth or
API key depending on authMethod — no more "Active" badge with no
way to disconnect.

* fix(desktop): simplify OpenAI OAuth dialog + auto-open browser

Match Anthropic dialog's layout: remove the raw OAuth URL display
and "Tip" block, auto-open the browser on OAuth start. Change
"Back" to "Cancel" for consistency.

* refactor(desktop): unify OAuth dialogs into shared OAuthDialog

Extract shared OAuthDialog component with provider config object.
AnthropicOAuthDialog and OpenAIOAuthDialog become thin wrappers
that pass provider-specific labels and options.

* fix(desktop): show 'Copied!' feedback on Copy URL button

* refactor(desktop): merge provider account + API key into single card

Each provider section now renders AccountCard + ConfigRow inside
one rounded card with a divider, instead of two separate cards.
Removes the standalone "API Keys" collapsible section.

* refactor(desktop): compact OAuth row in provider settings card

OAuth row is now a single inline row (label + status + action)
instead of a stacked AccountCard. Both providers share the same
2-row card layout: OAuth row + API key row with divider.

* fix(desktop): contextual buttons in provider settings

Connect is now primary (filled). Save only shows when there's input.
Clear only shows when a key is saved. Removes visual noise from
empty-state provider cards.

* ui(desktop): add provider icons to settings section headers

* ui(desktop): show 'Not connected' badge instead of subtitle for disconnected providers

* ui: remove redundant disconnected subtitle

* ui: remove subtitle text from OAuth rows

* chore: remove dead AccountCard + getProviderSubtitle

* docs: update test plan to match current UI

* chore: move shipped plans to done/

---------

Co-authored-by: AviPeltz <aj.peltz@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 18, 2026

Warning

Rate limit exceeded

@MocA-Love has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes and 52 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 5 minutes and 52 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: eb0ee23e-5f21-4dbb-ade2-1046cf05ee87

📥 Commits

Reviewing files that changed from the base of the PR and between 9b9b194 and a05abe3.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (50)
  • apps/desktop/package.json
  • apps/desktop/plans/done/20260415-v2-host-service-ai-branch-naming-test-plan.md
  • apps/desktop/plans/done/20260415-v2-host-service-ai-branch-naming.md
  • apps/desktop/plans/done/20260417-fix-api-key-storage-slot.md
  • apps/desktop/runtime-dependencies.ts
  • apps/desktop/src/lib/ai/call-small-model.test.ts
  • apps/desktop/src/lib/ai/call-small-model.ts
  • apps/desktop/src/lib/ai/provider-diagnostics.ts
  • apps/desktop/src/lib/trpc/routers/changes/git-operations.ts
  • apps/desktop/src/lib/trpc/routers/index.ts
  • apps/desktop/src/lib/trpc/routers/model-providers/index.ts
  • apps/desktop/src/lib/trpc/routers/workspaces/utils/ai-branch-name.ts
  • apps/desktop/src/lib/trpc/routers/workspaces/utils/ai-name.test.ts
  • apps/desktop/src/lib/trpc/routers/workspaces/utils/ai-name.ts
  • apps/desktop/src/renderer/components/Chat/ChatInterface/components/ModelPicker/components/AnthropicOAuthDialog/AnthropicOAuthDialog.tsx
  • apps/desktop/src/renderer/components/Chat/ChatInterface/components/ModelPicker/components/OAuthDialog/OAuthDialog.tsx
  • apps/desktop/src/renderer/components/Chat/ChatInterface/components/ModelPicker/components/OAuthDialog/index.ts
  • apps/desktop/src/renderer/components/Chat/ChatInterface/components/ModelPicker/components/OpenAIOAuthDialog/OpenAIOAuthDialog.tsx
  • apps/desktop/src/renderer/components/Chat/ChatInterface/components/ModelPicker/hooks/useAnthropicOAuth/useAnthropicOAuth.ts
  • apps/desktop/src/renderer/components/Chat/ChatInterface/components/ModelPicker/hooks/useOpenAIOAuth/useOpenAIOAuth.ts
  • apps/desktop/src/renderer/routes/_authenticated/settings/models/components/ModelsSettings/ModelsSettings.tsx
  • apps/desktop/src/renderer/routes/_authenticated/settings/models/components/ModelsSettings/components/AccountCard/AccountCard.tsx
  • apps/desktop/src/renderer/routes/_authenticated/settings/models/components/ModelsSettings/components/AccountCard/index.ts
  • apps/desktop/src/renderer/routes/_authenticated/settings/models/components/ModelsSettings/components/ConfigRow/ConfigRow.tsx
  • apps/desktop/src/renderer/routes/_authenticated/settings/models/components/ModelsSettings/components/SettingsSection/SettingsSection.tsx
  • apps/desktop/src/renderer/routes/_authenticated/settings/models/components/ModelsSettings/utils.ts
  • apps/desktop/src/shared/ai/provider-status.test.ts
  • apps/desktop/src/shared/ai/provider-status.ts
  • packages/chat/package.json
  • packages/chat/src/server/desktop/auth/anthropic/anthropic.ts
  • packages/chat/src/server/desktop/chat-service/auth-storage-utils.ts
  • packages/chat/src/server/desktop/chat-service/chat-service.test.ts
  • packages/chat/src/server/desktop/chat-service/chat-service.ts
  • packages/chat/src/server/desktop/index.ts
  • packages/chat/src/server/desktop/small-model/index.ts
  • packages/chat/src/server/desktop/small-model/small-model.test.ts
  • packages/chat/src/server/desktop/small-model/small-model.ts
  • packages/chat/src/server/desktop/title-generation/index.ts
  • packages/chat/src/server/desktop/title-generation/title-generation.test.ts
  • packages/chat/src/server/desktop/title-generation/title-generation.ts
  • packages/chat/src/server/shared/index.ts
  • packages/chat/src/server/shared/small-model/get-small-model.ts
  • packages/chat/src/server/shared/small-model/index.ts
  • packages/chat/src/server/trpc/utils/runtime/runtime.test.ts
  • packages/chat/src/server/trpc/utils/runtime/runtime.ts
  • packages/host-service/package.json
  • packages/host-service/src/providers/model-providers/LocalModelProvider/LocalModelProvider.ts
  • packages/host-service/src/providers/model-providers/LocalModelProvider/utils/resolveAnthropicCredential.ts
  • packages/host-service/src/trpc/router/workspace-creation/utils/ai-branch-name.ts
  • packages/host-service/src/trpc/router/workspace-creation/workspace-creation.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch upstream-merge/pr7-mastracode-upgrade

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a05abe3db6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

providerId: string,
): string | null {
if (!authData) return null;
const entry = authData[`apikey:${providerId}`];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Read legacy API-key slots when resolving small-model creds

getStoredApiKey only reads apikey:<provider> entries from auth.json. Prior to this change, saved API keys were stored in the main provider slots (for example anthropic / openai-codex), so existing users upgrading with previously saved keys will now resolve no small-model credential until they re-save keys. That silently breaks small-model features (branch/workspace naming, title generation) even while provider auth may still appear connected.

Useful? React with 👍 / 👎.

Comment on lines +373 to +375
} else {
await clearAnthropicApiKeyMutation.mutateAsync();
setAnthropicApiKeyInput("");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Handle env-backed Anthropic logout explicitly

This non-OAuth branch clears only the Anthropic API-key slot. When the provider is connected via managed env credentials (authMethod === "env"), clicking Logout follows this path but does not clear the env config, so auth status stays connected and the Logout action is effectively a no-op for that mode.

Useful? React with 👍 / 👎.

@MocA-Love MocA-Love merged commit 0dc6040 into main Apr 18, 2026
14 checks passed
MocA-Love added a commit that referenced this pull request Apr 18, 2026
…regression)

PR #313 (mastracode 0.14 + small-model refactor) shipped three
take-home regressions for fork users:

1. Anthropic OAuth / AUTH_TOKEN broken. get-small-model routed the
   token through createAnthropic({ apiKey }), but fork's OAuth /
   managed-proxy credentials require authToken + anthropic-beta /
   user-agent / x-app headers (see getAnthropicProviderOptions).
   Users connected via Claude Code OAuth or a gateway that only
   emits ANTHROPIC_AUTH_TOKEN had all small-model tasks 401.

2. Provider fallback dropped. Old callSmallModel iterated Anthropic
   then OpenAI. The post-superset-sh#3517 shim collapsed to a single attempt,
   so a failing Anthropic account never fell through to OpenAI.

3. OAuth-only users saw 'Account not connected'. When getSmallModel
   returned null (because auth.json only had OAuth entries), the
   shim fabricated two 'missing-credentials' attempts regardless of
   what was actually connected.

Fix: replace the simple getSmallModel() with a fork-maintained
getSmallModelCandidates() that returns the full priority list
(Anthropic env -> keychain/config -> auth-storage -> managed env
config -> OpenAI env -> OpenAI auth-storage) with OAuth / API key /
AUTH_TOKEN each routed through the correct AI-SDK provider options
(getAnthropicProviderOptions for Anthropic, createOpenAICodexOAuthModel
for OpenAI Codex OAuth). getSmallModel() stays as an upstream-
compatible wrapper over the first viable candidate.

The callSmallModel shim now iterates candidates and surfaces
per-attempt outcomes so describeEnhanceFailure keeps its user
messages intact.

Restored behaviors:
- Anthropic OAuth / AUTH_TOKEN via fork-standard header set.
- Anthropic managed env config (~/.superset/chat-anthropic-env.json)
  with both ANTHROPIC_API_KEY (api-key path) and ANTHROPIC_AUTH_TOKEN
  (OAuth path).
- OpenAI Codex OAuth (rewrites to Codex backend, refreshes access
  token via mastracode authStorage).
- OpenAI stock / openai-codex API-key slot.
- Provider fallback: Anthropic failure now tries OpenAI.
MocA-Love added a commit that referenced this pull request Apr 18, 2026
fix(desktop): PR #313 small-model regression (OAuth + provider fallback)
MocA-Love added a commit that referenced this pull request Apr 18, 2026
…tracode-upgrade"

This reverts commit 0dc6040, reversing
changes made to 9b9b194.
MocA-Love added a commit that referenced this pull request Apr 18, 2026
#313 の revert で消えた mastracode externalize エントリを復元。
mastracode は @mastra/fastembed → onnxruntime-node を引き込み、
onnxruntime-node の native binding は dynamic require で読まれるため
Rollup が bundle 時に解決できず、main プロセスの起動が失敗する。
MocA-Love added a commit that referenced this pull request Apr 18, 2026
…iewer

revert: PR #313 + #318 (mastracode 0.14 アップグレードに伴う DiffViewer 表示崩れ)
MocA-Love added a commit that referenced this pull request Apr 18, 2026
MocA-Love added a commit that referenced this pull request Apr 18, 2026
restore: PR #313 + #318 を復活 (真犯人は node_modules 重複だった)
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.

2 participants