Skip to content

Conversation

@thurstonsand
Copy link
Contributor

@thurstonsand thurstonsand commented Dec 3, 2025

Problem

When using CLI Proxy API with AMP CLI, two features fail with 404 errors:

  1. amp login flow - Returns 404 for /auth/cli-login:
    amp login
    Logging in to localhost
    ...
    http://localhost:8317/auth/cli-login?authToken=...

Visiting the URL returns 404.

  1. Amp Tab (VS Code) - Returns 404 for /api/tab/llm-proxy:
    error getModelResponse Error calling Amp Tab Proxy API: HTTP error! status: 404

Root Cause

  • /auth/* routes are only registered under /api/auth/*, but AMP CLI uses root-level /auth/cli-login for the login flow
  • /api/tab/* routes are not registered at all

Solution

Add the missing proxy routes in internal/api/modules/amp/routes.go:

  1. Root-level /auth/* routes for CLI login flow (with same security middleware as other management routes)
  2. /api/tab/* routes for Amp Tab functionality

Additional Fix: Logging Panic

The new /api/tab/* routes proxy autocomplete requests to ampcode.com. When users type in VS Code, stale autocomplete requests are canceled ("request aborted due to new request"), which causes Go's context to cancel mid-proxy. This triggers the proxy error handler → Gin's error logging → exposes a pre-existing bug in LogFormatter.

LogFormatter.Format() assumed entry.Caller is always set, but log entries created through Gin's pipe writers (used for gin.DefaultErrorWriter) run in a separate goroutine without caller information. When accessing entry.Caller.File on a nil pointer → panic.

So we just need to check for nil caller before dereferencing. Log entries without caller info now format without the [file:line] component.

Changes

  • internal/api/modules/amp/routes.go: Added /auth, /auth/*path, /api/tab, and /api/tab/*path proxy routes
  • internal/logging/global_logger.go: Handle nil caller in LogFormatter.Format()

Testing

Verified both fixes by running locally:

  • amp login now opens the browser and completes authentication flow
  • Amp Tab in VS Code works without 404 errors

Appendix: Full Panic Log

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x94d3ca]

goroutine 35 [running]:
github.com/router-for-me/CLIProxyAPI/v6/internal/logging.(*LogFormatter).Format(0xc0005fa9c0?, 0xc0002ad500)
        /app/internal/logging/global_logger.go:41 +0xaa
github.com/sirupsen/logrus.(*Entry).write(0xc0002ad500)
        /go/pkg/mod/github.com/sirupsen/logrus@v1.9.3/entry.go:289 +0x95
github.com/sirupsen/logrus.(*Entry).log(0xc0000f7650, 0x2, {0x0, 0x0})
        /go/pkg/mod/github.com/sirupsen/logrus@v1.9.3/entry.go:252 +0x425
github.com/sirupsen/logrus.(*Entry).Log(0xc0000f7650, 0x2, {0xc000352430?, 0xf12d60?, 0x1?})
        /go/pkg/mod/github.com/sirupsen/logrus@v1.9.3/entry.go:304 +0x48
github.com/sirupsen/logrus.(*Entry).Error(...)
        /go/pkg/mod/github.com/sirupsen/logrus@v1.9.3/entry.go:333
github.com/sirupsen/logrus.(*Entry).writerScanner(0xc0000f7650, 0xc0001db0e0, 0xc000454800)
        /go/pkg/mod/github.com/sirupsen/logrus@v1.9.3/writer.go:87 +0x113
created by github.com/sirupsen/logrus.(*Entry).WriterLevel in goroutine 1
        /go/pkg/mod/github.com/sirupsen/logrus@v1.9.3/writer.go:57 +0x31f
CLIProxyAPI Version: dev, Commit: none, BuiltAt: unknown

@gemini-code-assist
Copy link

Summary of Changes

Hello @thurstonsand, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves critical 404 errors affecting the AMP CLI login process and the Amp Tab VS Code extension. It achieves this by adding specific root-level /auth/* and /api/tab/* proxy routes to the AMP module's route configuration, ensuring both features can communicate correctly with the backend services.

Highlights

  • AMP CLI Login Fix: Addresses 404 errors encountered during the amp login flow by introducing missing root-level /auth/* proxy routes, ensuring the complete OAuth authentication process functions correctly.
  • Amp Tab (VS Code) Functionality: Resolves 404 errors for the Amp Tab VS Code extension by adding the necessary /api/tab/* proxy routes, enabling its proper operation.
  • Route Registration: Registers these critical new routes within internal/api/modules/amp/routes.go, applying the same security middleware as other management routes to maintain consistency and security.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly adds the missing proxy routes for /auth/* and /api/tab/* to fix issues with the AMP CLI login flow and VS Code extension. The changes are logical and follow the existing structure. I've provided two comments on the code changes: one suggesting a refactoring to improve maintainability, and another, more critical one, pointing out the lack of automated tests for the new routes. Please add test cases to prevent future regressions.

Comment on lines +113 to +114
ampAPI.Any("/tab", proxyHandler)
ampAPI.Any("/tab/*path", proxyHandler)

Choose a reason for hiding this comment

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

medium

With the addition of these routes, the list of proxy routes is getting long and repetitive. This pattern of registering a base path and a /*path variant is used for many routes in this block (lines 98-114). To improve maintainability and reduce code duplication, consider refactoring this block to register these routes in a loop. For example:

proxyPaths := []string{
    "/internal",
    "/user",
    "/auth",
    "/meta",
    "/telemetry",
    "/threads",
    "/otel",
    "/tab",
}
for _, path := range proxyPaths {
    ampAPI.Any(path, proxyHandler)
    ampAPI.Any(path+"/*path", proxyHandler)
}
ampAPI.Any("/ads", proxyHandler) // /ads doesn't have a /*path variant

@luispater luispater changed the base branch from main to dev December 3, 2025 14:22
@luispater luispater merged commit d72886c into router-for-me:dev Dec 3, 2025
1 check 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