-
Notifications
You must be signed in to change notification settings - Fork 22
FIX: Codeflash does not exit on invalid api key #863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
codeflash/api/cfapi.py
Outdated
| "Please generate a new one at https://app.codeflash.ai/app/apikeys ,\n" | ||
| "then set it as a CODEFLASH_API_KEY environment variable.\n" | ||
| "For more information, refer to the documentation at " | ||
| "https://docs.codeflash.ai/getting-started/codeflash-github-actions#add-your-api-key-to-your-repository-secrets." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
404 error and remove the dot at the end of the url
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't have this section yet, I was thinking to add it, or should I just remove this placeholder and keep https://app.codeflash.ai/app/apikeys only ?
codeflash/api/cfapi.py
Outdated
| return None | ||
|
|
||
|
|
||
| def validate_api_key(api_key: Optional[str] = None) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dont duplicate this call. it is already happening. please handle it there
06e16ea to
2f001bb
Compare
codeflash/api/cfapi.py
Outdated
| def validate_api_key() -> None: | ||
| """Validate the API key by making a request to the /cfapi/cli-get-user endpoint. | ||
| Raises SystemExit if the API key is invalid (403) or missing. | ||
| This should be called early in the CLI flow before starting optimization. | ||
| """ | ||
| logger.debug("validate_api_key: Starting API key validation") | ||
| api_key = get_codeflash_api_key() | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this
|
oops, sorry, I misunderstood what was happening, LGTM now |
|
I don't think we need to always validate the API key, we can validate just for non-init commands |
ae6d1f8 to
7eb6a38
Compare
…b.com/codeflash-ai/codeflash into fix/invalid-api-key/stop-optimization
| @@ -1,3 +1,5 @@ | |||
| """Module for interacting with the Codeflash API.""" | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this comment, users are not expected with the API
User description
https://linear.app/codeflash-ai/issue/CF-784/codeflash-does-not-exit-on-invalid-api-key
When we have invalid API Key optimization should be stopped, even though it continue. in this PR we are validating the API key user info before lunching optimizer.
PR Type
Bug fix, Enhancement
Description
Validate API key before optimizer starts
Add clear error messages and exit codes
Handle outdated CLI via min_version check
Improve cleanup on failures and interrupts
Diagram Walkthrough
File Walkthrough
cfapi.py
Introduce API key validation and version gatingcodeflash/api/cfapi.py
validate_api_keyhelper using/cli-get-user.min_versionand require CLI upgrade.optimizer.py
Early key validation and safer failure handlingcodeflash/optimization/optimizer.py
validate_api_key()before optimizer initialization.