Skip to content

refactor(cli): fix timer leak, remove dead code, and consolidate error parsing#27

Merged
appleboy merged 1 commit intomainfrom
worktree-cli-refactor
Mar 31, 2026
Merged

refactor(cli): fix timer leak, remove dead code, and consolidate error parsing#27
appleboy merged 1 commit intomainfrom
worktree-cli-refactor

Conversation

@appleboy
Copy link
Copy Markdown
Member

Summary

  • Fix time.After timer leak in callback server — replaced with time.NewTimer + defer timer.Stop() to prevent 2-minute goroutine leaks on every successful OAuth callback
  • Remove unnecessary time.Sleep(100ms) in browser flow and device flow error paths — the buffered channel and consumer drain loops already ensure updates are processed
  • Remove 4 unused functions (GetFloat64, FlowUpdateType.String(), FormatDurationCompact, FormatInterval) and their associated test code
  • Extract parseOAuthError helper to consolidate triplicated OAuth error JSON unmarshaling across formatHTTPError, doTokenExchange, and handleDevicePollError
  • Delegate error formatting in doTokenExchange to formatHTTPError to eliminate duplicate formatting logic

Test plan

  • All existing tests pass (make test)
  • Linter passes with 0 issues (make lint)
  • Code formatted (make fmt)
  • Verify no regressions in OAuth browser flow (PKCE) end-to-end
  • Verify no regressions in device code flow end-to-end

🤖 Generated with Claude Code

…r parsing

- Replace time.After with time.NewTimer in callback server to prevent goroutine leak
- Remove unnecessary time.Sleep calls in browser and device flow error paths
- Remove unused functions: GetFloat64, FlowUpdateType.String, FormatDurationCompact, FormatInterval
- Extract parseOAuthError helper to consolidate triplicated error unmarshaling
- Delegate error formatting in doTokenExchange to formatHTTPError

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 37.50000% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
tokens.go 27.27% 7 Missing and 1 partial ⚠️
callback.go 66.66% 1 Missing ⚠️
device_flow.go 50.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@appleboy appleboy merged commit fd9b21e into main Mar 31, 2026
16 checks passed
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