Skip to content

fix: separate token-refresh outcomes from login events [Better data collection] - #2300

Open
PetrDlouhy wants to merge 2 commits into
mainfrom
claude/login-vs-refresh-events
Open

fix: separate token-refresh outcomes from login events [Better data collection]#2300
PetrDlouhy wants to merge 2 commits into
mainfrom
claude/login-vs-refresh-events

Conversation

@PetrDlouhy

Copy link
Copy Markdown
Contributor

Problem

Blendkit-Client emits token-refresh outcomes as "login" tasks (RefreshTokenNewTask(…, "login"), one per connected add-on). handle_login_task therefore reported refreshes as logins. Measured on production (2026-09-11):

  • login_completed: ~405 of 1,816 rows (22%) have no login_started from the same machine within 30 min — refreshes and per-instance duplicates.
  • login_failed: 0 of 84 follow a login_started; 79 are Failed to refresh token: … 400 on 16 machines. The event measured forced logouts, not failed logins.

Fix

The event name follows preferences.login_attempt, which is True only between LoginOnline.execute and write_tokens/cancel/clean_login_data, and is reset at register() (crash-safe):

task login_attempt event
finished True login_completed
finished False token_refreshed
error True login_failed
error False token_refresh_failed (+ message)

The refresh failures keep flowing under an honest name — they're a real signal (users silently logged out).

Tests

Four cases via the real add-on preference; the earlier write_tokens test is removed — it guarded the wrong seam (refreshes never reach write_tokens directly).

Server side

A refresh emits one task per open Blender instance → dedup by (system_id, minute) server-side. Existing production rows get relabelled by BlenderKit-server PR (D in the plan) using the OAuth grant type, so this fix is a precision improvement for new versions, not a prerequisite.

🤖 Generated with Claude Code

Blendkit-Client delivers token *refresh* outcomes as "login" tasks, one
per connected add-on, so login_completed counted every silent refresh and
login_failed was 100% refresh failures on production (84 of 84 rows).

handle_login_task now names the event by preferences.login_attempt, which
is set only by LoginOnline and cleared by write_tokens, cancel and
register(): login_completed/login_failed for add-on-started logins,
token_refreshed/token_refresh_failed otherwise. The refresh failures stay
visible under an honest name - 16 machines were being force-logged-out
by 400s on refresh.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@PetrDlouhy PetrDlouhy self-assigned this Sep 11, 2026
The helper built token_refresh_completed; the tests and the server-side
relabel (Blendkit-server#3871) use token_refreshed. Pass both names
explicitly instead of composing them.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@codecov

codecov Bot commented Sep 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 33.22%. Comparing base (9d7756e) to head (089313a).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2300      +/-   ##
==========================================
- Coverage   33.22%   33.22%   -0.01%     
==========================================
  Files          86       86              
  Lines       27246    27254       +8     
==========================================
+ Hits         9053     9054       +1     
- Misses      18193    18200       +7     
Flag Coverage Δ
python 33.22% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
bkit_oauth.py 55.62% <100.00%> (-3.62%) ⬇️
tests/test_bkit_oauth.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant