fix(desktop): TODO新規worktree作成時のgit worktree add競合を解消#193
Conversation
workspaces.createはgit worktree addをバックグラウンドで実行するため、 直後にtodoAgent.createを呼ぶと未作成のworktreeパスに .superset/todo/<id>/goal.mdを先に書き込んでしまい、その後の git worktree addが「空でない」エラーで失敗していた。 todoAgent.createの先頭でworkspaceInitManager.waitForInitを awaitしてからartifactを準備するようにした。初期化失敗時は 明示的にエラーを返す。 Closes #188
|
Warning Rate limit exceeded
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 42 minutes and 40 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 126b830405
ℹ️ 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".
| // see as the sidebar error + "ブランチ取得中…" that never | ||
| // resolves. Block until init is done (or already no-op) so | ||
| // prepareArtifacts runs against a real worktree. | ||
| await workspaceInitManager.waitForInit(input.workspaceId); |
There was a problem hiding this comment.
Block TODO creation when workspace init times out
todoAgent.create awaits workspaceInitManager.waitForInit(input.workspaceId) but does not verify that initialization actually finished. In workspace-init-manager.waitForInit, the wait resolves after 30s even if init is still running, so on slower fetch/worktree setup paths this code can still proceed to prepareArtifacts and recreate the same git worktree add “path is not empty” race this change is meant to prevent. After waiting, reject if the workspace is still initializing (or wait without timeout) before touching the worktree path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/desktop/src/main/todo-agent/trpc-router.ts (1)
52-55: 初期化失敗はTRPCErrorで返すとクライアント制御が一貫します。Line 52〜55 は現在
Errorを投げていますが、このルーター内の他ハンドラと同様にTRPCError(例:PRECONDITION_FAILED)へ統一すると、UI側でのエラー分岐が安定します。差分案
if (workspaceInitManager.hasFailed(input.workspaceId)) { - throw new Error( - `todo-agent: workspace ${input.workspaceId} の初期化に失敗しました`, - ); + throw new TRPCError({ + code: "PRECONDITION_FAILED", + message: `todo-agent: workspace ${input.workspaceId} の初期化に失敗しました`, + }); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/desktop/src/main/todo-agent/trpc-router.ts` around lines 52 - 55, Replace the plain Error thrown in the branch that checks workspaceInitManager.hasFailed(input.workspaceId) with a TRPCError so client-side error handling is consistent; import TRPCError from '@trpc/server' (or use the existing import) and throw new TRPCError({ code: 'PRECONDITION_FAILED', message: `todo-agent: workspace ${input.workspaceId} の初期化に失敗しました` }) instead of throw new Error(...).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/desktop/src/main/todo-agent/trpc-router.ts`:
- Around line 52-55: Replace the plain Error thrown in the branch that checks
workspaceInitManager.hasFailed(input.workspaceId) with a TRPCError so
client-side error handling is consistent; import TRPCError from '@trpc/server'
(or use the existing import) and throw new TRPCError({ code:
'PRECONDITION_FAILED', message: `todo-agent: workspace ${input.workspaceId}
の初期化に失敗しました` }) instead of throw new Error(...).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e1fe58b6-8115-41ec-98e0-e492a6d7c12b
📒 Files selected for processing (1)
apps/desktop/src/main/todo-agent/trpc-router.ts
waitForInitは30s時点でresolveしてしまうため、遅いfetch/clone では初期化中のままprepareArtifactsに進んでしまい同じレース を再発させる可能性があった。 isInitializing()をポーリングで再確認し、10分上限で TIMEOUTを返すようにした。失敗判定もTRPCError/ PRECONDITION_FAILEDに統一。 Refs: CodeRabbit/Codex review on PR #193
概要
Issue #188 の対応。TodoModal で「新しい worktree を作成して実行」にチェックを付けて作成すると、
という症状が発生していた。
根本原因
`workspaces.create` mutation は DB 行を挿入したあと `initializeWorkspaceWorktree` を await せず(fire-and-forget で)返す。
TodoModal は戻り値を受け取ると即座に `todoAgent.create` を呼び、`supervisor.prepareArtifacts` が `/.superset/todo//goal.md` を mkdir + 書き込みしていた。
この時点では `git worktree add` がまだ走っておらず、ターゲットディレクトリを先に作ってしまうため、その後の `git worktree add` が「path is not empty」で失敗。結果として worktree はディスク上に実体を持たないまま DB 行だけが残り、選択時エラー、`gitSnapshot` の `git rev-parse` も空返答になり「ブランチ取得中…」で止まっていた。
修正
`todoAgent.create` mutation の先頭で `workspaceInitManager.waitForInit(workspaceId)` を await し、初期化完了後に `prepareArtifacts` を実行するように変更。初期化が failed だった場合は明示的にエラーを投げる。
`waitForInit` は対象 job が登録されていなければ即 resolve するため、既存 worktree を選んだ場合のパスには影響しない。
Test plan
Closes #188
Summary by CodeRabbit
バグ修正