refactor: gemini review final batch — MetaAgentSelector single-pass + rawq Duration constants#291
Conversation
…iew, T1) Gemini medium 지적: 기존 코드는 engineModels 를 두 번 순회 (recommended 한 번 + first fallback 한 번). filter 후 한 번 순회로 통일 — 동작 동등 (recommended → first → undefined 우선순위 보존), 가독성 + 한 번 순회만 수행. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
#287 review, T2) Gemini medium 지적: test 파일에 Detection 타입이 중복 정의돼 있었음. MetaAgentSelector 의 AgentDetection 을 export 하고 test 에서 import 로 교체. 타입 schema 는 동일 — 단순 중복 제거. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ini PR #288 review, T3+T4) Gemini medium 2건 (PR #288 review): - T3: u64 ms → std::time::Duration 직접 (MAX_WAIT / TICK_INTERVAL). Duration::from_millis 호출 중복 제거. - T4: std::thread::sleep(TICK_INTERVAL) 로 직접 사용. T3 의 상수 타입 변경이 T4 의 sleep 인자 형태를 강제하기 때문에 동일 hunk — 1 commit 으로 묶되 message 에 양쪽 review 항목 1:1 인용. 동작 변경 0. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request refactors time-related constants in the Rust backend to use std::time::Duration for improved type safety and updates the MetaAgentSelector component to export the AgentDetection interface for reuse in tests. Additionally, the model selection logic for CLI engines was refactored. Feedback was provided to optimize this selection logic by pre-processing engine models into a map to reduce time complexity from O(D * M) to O(M + D).
| const modelsForEngine = engineModels.filter((m) => m.engine === d.engine); | ||
| const recommendedId = modelsForEngine.find((m) => m.recommended)?.id; | ||
| const defaultId = modelsForEngine[0]?.id; | ||
| const modelToSelect = recommendedId ?? defaultId; | ||
| if (modelToSelect) next[d.engine] = modelToSelect; |
There was a problem hiding this comment.
This implementation iterates over engineModels for each detection inside the loop. While this is an improvement over the previous version, it has a time complexity of roughly O(D * M), where D is the number of detections and M is the number of engine models.
For better performance and scalability, especially if these lists could grow, consider processing engineModels once into a map and memoizing it (e.g., with useMemo). This would change the complexity to O(M + D).
Here's an example of how you could pre-process engineModels:
// Pre-process models once for efficient lookup
const modelsByEngine = useMemo(() => {
const map = new Map<string, { recommendedId?: string; firstId?: string }>();
for (const model of engineModels) {
if (!map.has(model.engine)) {
map.set(model.engine, {});
}
const entry = map.get(model.engine)!;
if (!entry.firstId) {
entry.firstId = model.id;
}
if (model.recommended && !entry.recommendedId) {
entry.recommendedId = model.id;
}
}
return map;
}, [engineModels]);
// Then, inside the `useEffect`'s loop over detections:
const modelsInfo = modelsByEngine.get(d.engine);
const modelToSelect = modelsInfo?.recommendedId ?? modelsInfo?.firstId;
if (modelToSelect) {
next[d.engine] = modelToSelect;
}This approach processes engineModels only once, making the default model selection more efficient as it avoids repeated iterations.
Summary
Gemini medium 지적 4건 묶음 처리 — PR #287 + PR #288 의 미처리 review 항목. 모두 refactor only, 동작 변경 0.
src/components/tunaflow/MetaAgentSelector.tsxengineModels두 번 순회 → filter 후 한 번 순회로 통일.recommended → first → undefined우선순위 동등src/tests/metaAgentSelector-modelDiscovery.test.tsxAgentDetectionexport 추가, test 의 중복Detection타입 제거 → import 로 교체src-tauri/src/agents/rawq.rsMAX_WAIT_MS: u64/TICK_INTERVAL_MS: u64→MAX_WAIT: Duration/TICK_INTERVAL: Duration.Duration::from_millis()호출 중복 제거sleep(Duration::from_millis(TICK_INTERVAL_MS))→sleep(TICK_INTERVAL)직접T3 의 상수 타입 변경이 T4 의
sleep인자 형태를 강제하므로 동일 hunk —c6ce007한 commit 으로 묶되 message 에서 양쪽 review 항목 1:1 인용.Review URLs
Verification
회귀 가드 grep
영역 외 변경 0 확인.
AgentDetectionimport 처는 MetaAgentSelector.tsx + test 두 곳뿐 (Rust 의 동명 struct 와 충돌 없음 — 별 언어).[CI 정책]
PR 직후
gh pr merge --squash --delete-branch --admin즉시 머지. CI watch 불필요 (refactor only, 동작 변경 0).🤖 Generated with Claude Code