fix: show external Codex usage without inflating OpenCode Zen#2
fix: show external Codex usage without inflating OpenCode Zen#2Daltonganger wants to merge 3 commits intomainfrom
Conversation
|
@copilot Review this critical! |
| let currentPath = components.path | ||
| if currentPath.hasSuffix("/api/codex/usage") { | ||
| components.path = String(currentPath.dropLast("/api/codex/usage".count)) + "/v1/usage" | ||
| } else if currentPath.hasSuffix("/usage") { |
There was a problem hiding this comment.
🔥 The Roast: This hasSuffix("/usage") check is about as precise as a blindfolded surgeon. If someone passes a URL that already ends with /v1/usage, the second condition catches it (because /v1/usage does end with /usage), drops the last 7 characters, and slaps /v1/usage back on — giving you the majestic /v1/v1/usage. Your URL just got a stutter.
🩹 The Fix: Add an explicit guard for /v1/usage before the broader /usage check:
| } else if currentPath.hasSuffix("/usage") { | |
| } else if currentPath.hasSuffix("/v1/usage") { | |
| // Already a self-service endpoint; keep as-is | |
| } else if currentPath.hasSuffix("/usage") { |
📏 Severity: warning
Code Review Roast 🔥Verdict: No Issues Found | Recommendation: Merge The previous review's warning about the URL double-injection ( Overview
Resolved Issues
🏆 Best part: The fix is surgical — one 💀 Worst part: Line 525 ( 📊 Overall: Like someone actually reading the code review and doing exactly what was asked. I'm not used to this. Files Reviewed (2 files incremental)
Reviewed by mimo-v2-pro-20260318 · 156,021 tokens |
…le /v1 URL injection Agent-Logs-Url: https://github.com/Daltonganger/opencode-bar/sessions/2672ff4d-23d5-4e27-9d06-5c3ec83b03b4 Co-authored-by: Daltonganger <17501732+Daltonganger@users.noreply.github.com>
Critical review complete. Two bugs were found and fixed in commit 1. limits = (try? container.decodeIfPresent([SelfServiceLimit].self, forKey: .limits)) ?? []2. URL path rewrite could produce double Three regression tests were added to cover both fixes. Other observations (no code changes needed):
|
Summary
/v1/usagesupport for external OpenAI API-key Codex accounts and map the returned limits into Codex quota dataopenai/*spend as pay-as-you-go when OpenCode routes OpenAI throughprovider.openai.options.baseURLTesting
make lint-swiftxcodebuild -project "CopilotMonitor.xcodeproj" -scheme "CopilotMonitor" -configuration Debug build -quiet