Renew Copilot auth token before each LLM API request attempt#401
Renew Copilot auth token before each LLM API request attempt#401itkonen wants to merge 6 commits intoeditor-code-assistant:masterfrom
Conversation
Agent-Logs-Url: https://github.com/itkonen/eca/sessions/3348aaf5-3cd1-4629-99de-170ec4e63c9d Co-authored-by: itkonen <37696708+itkonen@users.noreply.github.com>
Agent-Logs-Url: https://github.com/itkonen/eca/sessions/41c45749-ba10-49b5-a449-e2e8e29ec513 Co-authored-by: itkonen <37696708+itkonen@users.noreply.github.com>
Agent-Logs-Url: https://github.com/itkonen/eca/sessions/9853614c-f3c8-4487-b99f-bd0d60a3d985 Co-authored-by: itkonen <37696708+itkonen@users.noreply.github.com>
Agent-Logs-Url: https://github.com/itkonen/eca/sessions/545a12ee-f2c6-4cdb-923d-9e02ab7d0520 Co-authored-by: itkonen <37696708+itkonen@users.noreply.github.com>
Renew Copilot auth token before each LLM API request attempt
|
@itkonen Sorry, i just did the fix 5 hours ago, here: #399 Your approach resolves auth before My fix renews and propagates fresh auth inside On retriesWe haven't added retry logic for 401s yet. The 60-second buffer should prevent most expiry cases proactively. If we see the need, we can add targeted retry logic separately - but we'd want to be careful about loops. Thanks. |
|
Fixed in #399, thank you! |
|
Well that's great news, thank you! I'm glad it's getting fixed! |
This is my attempt to fix the Github Copilot token expiration problem which tends to occur in the middle of long agentic workflows (#126):
It interrupts the task, even though the session remains intact so that I can ask the agent to continue. Github Copilot tokens seem to have really short lifespans, so this error tends to occur quite often.
Warning: I don't know much Clojure, and I cannot really evaluate the PR which I ended up with by iterating with Copilot, so this might be mere AI slop. But hopefully the PR gives some idea where the problem occurs.
Copilot Summary:
This pull request implements proactive renewal of GitHub Copilot and other provider auth tokens before each LLM API request attempt, ensuring that long-running or agentic workflows do not fail due to expired tokens. It introduces a new
provider-auth-fnmechanism that replaces the previous staticprovider-authapproach, allowing the system to always use a fresh token and retry with renewed credentials as needed. Comprehensive tests have been added to verify this behavior for both sync and async LLM API requests, including retries.Auth Token Renewal and LLM API Improvements:
provider-auth-fnoption tosync-or-async-prompt!inllm_api.clj, which is invoked before each LLM API request (including retries) to ensure a fresh auth token is used. This replaces the previous staticprovider-authapproach. [1] [2] [3] [4]silent-provider-auth-fninchat/lifecycle.cljto renew provider auth tokens without interrupting ongoing requests on error, and updated chat and rewrite features to use this function for proactive token refresh. [1] [2] [3]Testing and Reliability:
llm_api_test.cljto verify thatprovider-auth-fnis invoked before every sync and async prompt attempt, including retries, and that its result is correctly passed to the LLM API.Minor Fixes:
login.cljwhere chat status and login provider were not correctly reset whenchat-idwas nil.