fix: add logging for refresh token flow and use local os keychain as source of truth. (#14531)

This commit is contained in:
Ian Chua
2026-07-03 22:27:17 +08:00
committed by GitHub
parent 02799e68ed
commit aa7986b8d0
2 changed files with 179 additions and 16 deletions
+10 -1
View File
@@ -287,7 +287,7 @@ public:
bool refresh_if_expiring(std::chrono::seconds skew, const std::string& reason);
RefreshResult refresh_from_storage(const std::string& reason, bool async = false);
RefreshResult refresh_now(const std::string& refresh_token, const std::string& reason, bool async = false);
RefreshResult refresh_session_with_token(const std::string& refresh_token);
RefreshResult refresh_session_with_token(const std::string& refresh_token, const std::string& reason = "");
// Session state helpers. nickname is the human-facing UI label after provider fallback resolution.
bool set_user_session(const std::string& token,
@@ -350,6 +350,9 @@ private:
std::string map_to_json(const std::map<std::string, std::string>& map);
void json_to_map(const std::string& json, std::map<std::string, std::string>& map);
// Refresh token lock
std::string token_lock_path() const;
// Member variables - configuration
std::string log_dir;
std::string config_dir;
@@ -370,6 +373,12 @@ private:
SessionInfo session;
mutable std::mutex session_mutex;
// Refresh diagnostics (see docs/analysis/refresh_token_already_used.md). Epoch seconds so the
// refresh-failure log can report token staleness without holding a lock or logging any token.
std::atomic<long long> last_refresh_success_epoch{0}; // 0 = no success yet this process
const long long agent_start_epoch{std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::system_clock::now().time_since_epoch()).count()};
// Member variables - connection state
bool is_connected{false};
bool enable_track{false};