Skip to content

refactor(license): one refresh path — the upload drain, plus one retry on 401 - #151

Merged
minarc merged 1 commit into
mainfrom
refactor/single-refresh-path
Sep 26, 2026
Merged

minarc merged 1 commit into
mainfrom
refactor/single-refresh-path

Conversation

@minarc

@minarc minarc commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Behavior change

This is phase 1b of simplifying auth. Now that recording no longer depends on token freshness (#150), refreshing ahead of need buys nothing. The license is refreshed in one place: the upload drain, just before it sends, and once more (bypassing the local expiry check) if the server answers 401.

Removed Why it existed Why it can go
Retry daemon's per-sweep refresh and look-ahead (maybeRefreshLicense) So no hook ever met an expired token Hooks no longer care; the drain refreshes when it sends
SessionStart refresh Same SessionStart now spawns a detached drain instead of uploading in-process, so it never waits on the network
Stop-triggered recovery worker (lib/hook-license-recovery.js, deleted) Refresh even when an expired gate left nothing queued Capture always queues now, so the regular Stop drain refreshes
backoff_exhausted terminal state Stop retrying after about an hour of failures It stranded an open session until restart. Transient failures now keep retrying at the 30-minute cap. A record left by an older version is ignored
aheadMs / renewSkewSeconds, retryFailedLogs / retryFailedTranscripts Support for the above Unused

Kept: the single-flight refresh lock and cooldown, backoff, the 401/410 (re-sign-in) and 402 (revoked) terminal states, and SessionStart clearing a terminal state to give a new session one attempt. The sign-in banner now decides from the state the session found, before that clear.

New: an upload rejected with 401 triggers one forced refresh and a resend of just the rejected files. It isn't charged against the chunk's retry budget, because the token was refused, not the chunk.

Net source change: +94 / −220 lines (8 files; one file deleted).

Simulation (the earlier session-verification harness, re-run on this branch)

Scenario main before #150 This PR
3-hour refresh outage, no new session backoff_exhausted; dark until restart, 255 events lost 0 events lost; the same session recovers within one 30-min backoff step
20-min outage 12 events lost 0 lost
Steady 8-hour session 8 refreshes, 0 lost 8 refreshes, 0 lost. The token is briefly expired between refreshes, which only delays uploads by up to one drain

Docs

Telemetry / privacy impact

No change to what is recorded or retained.

Validation

  • node --test: 457 pass, 0 fail, plus 8 random-order seeds with no failures
  • New test/upload-unauthorized.test.js: a 401 refreshes once and resends; a persistent 401 keeps the chunk without spending its budget; other failures still spend it and trigger no refresh.
  • Tests for removed behavior were deleted or rewritten to the new behavior: the daemon refresh, the renew-ahead window, the SessionStart refresh, backoffExhausted, and "the sixth failure is terminal".
  • Against main's code, the 6 tests that pin the new behavior fail.

🤖 Generated with Claude Code

…y on 401

Phase 1b of simplifying auth. With recording decoupled from token freshness
(#150), refreshing ahead of need buys nothing, so the license is refreshed in
one place: the upload drain, just before it sends, and once more with the
local expiry check bypassed when the server answers 401.

Removed:
- the retry daemon's per-sweep refresh and look-ahead (maybeRefreshLicense);
  the daemon only drains;
- the SessionStart refresh; SessionStart spawns a detached drain instead of
  uploading in-process, so it never waits on the network (this also finishes
  the SessionStart half of the earlier endpoint-trust work);
- the Stop-triggered recovery worker, lib/hook-license-recovery.js;
- the backoff_exhausted terminal state: transient failures keep retrying at
  the 30-minute cap, so an outage recovers without restarting Claude Code; a
  record left by an older version is ignored;
- aheadMs / renewSkewSeconds and the now-unused retryFailedLogs /
  retryFailedTranscripts wrappers.

Kept: the single-flight refresh lock, backoff, the 401/410 and 402 terminal
states, and SessionStart clearing a terminal state for one new attempt. The
sign-in banner now decides from the state the session found, before that
clear. A 401 on upload is not charged against the chunk's retry budget.

Net source change: +94 / -220 lines. ADR 001 gets a dated amendment
superseding decision 2 and the Stop-recovery amendment; the plugin README's
refresh and retention paragraphs follow (the latter was left stale by #150).

Simulation (the earlier session-verification harness, drains only per tick):
a 3-hour refresh outage lost 255 events and stayed dark until restart; now 0
events are lost and the same session recovers within one 30-minute backoff
step. A steady 8-hour session still makes 8 refreshes and loses nothing; the
token is briefly expired between refreshes, which only delays uploads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@minarc
minarc requested a review from a team as a code owner September 26, 2026 16:26
@minarc
minarc requested review from tsook and removed request for a team September 26, 2026 16:26
@minarc
minarc enabled auto-merge (squash) September 26, 2026 16:26
@minarc
minarc merged commit acc8eb3 into main Sep 26, 2026
2 of 3 checks passed
@coderabbitai

coderabbitai Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Essentials

Run ID: 665b5b1c-ed11-4712-b813-c4478c3468fb

📥 Commits

Reviewing files that changed from the base of the PR and between 6bbeade and 083c444.

📒 Files selected for processing (17)
  • docs/adr/001-license-token-lifecycle.md
  • skillmeter/README.md
  • skillmeter/scripts/drain_once.js
  • skillmeter/scripts/lib/hook-license-recovery.js
  • skillmeter/scripts/lib/license-activation.js
  • skillmeter/scripts/lib/license-status.js
  • skillmeter/scripts/lib/transfer.js
  • skillmeter/scripts/monitors/retry_daemon.js
  • skillmeter/scripts/session_start.js
  • skillmeter/scripts/stop.js
  • test/capture-decoupled.test.js
  • test/expiry-recovery.test.js
  • test/license-activation.test.js
  • test/license-status.test.js
  • test/retry-daemon.test.js
  • test/session-start-refresh.test.js
  • test/upload-unauthorized.test.js
 __________________________________________________
< Turning your WTFs per minute into OMGs per hour. >
 --------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

minarc added a commit that referenced this pull request Sep 26, 2026
Found mechanically: a scan of every export for uses outside its own module,
a scan for functions referenced only by their definition, and a grep for
concepts #150/#151 removed. No behaviour changes.

Dead code
- credstore.setLicenseToken: no production caller since refresh commits
  through commitRefresh (#148); its one test now simulates the other
  client's sign-in with commitSignin, the path that client actually uses.
- credstore's LICENSE_EXPIRY_SKEW_SECONDS export: its only outside users
  were the daemon and the Stop recovery, both removed.

Comments that described removed behaviour
- license-activation: "no reactive force path" (there is one, for 401s);
  the daemon as a refresh caller.
- license-status: the daemon reading the record, a "reactivated" outcome
  nothing writes, "SessionStart bypasses the refresh lock" (not since #137),
  and backoff pointing at the superseded ADR 001 decision 2.
- transfer: the module header and sealFinalSessionArtifacts said SessionStart
  and the monitor upload; the function spawns a detached drain itself.
- session_start: "even if the daemon gave up last time".

Tests
- expiry-recovery titles and header named a recovery worker that no longer
  exists; they now say what they check.
- session-start-refresh dropped its unused lock-age fixture branch;
  retry-daemon dropped endpoint env the daemon no longer uses.

ADR 003 gets a dated note: hooks no longer skip on an expired license,
backoff_exhausted is gone, and there is no Stop recovery worker.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
minarc added a commit that referenced this pull request Sep 26, 2026
Found mechanically: a scan of every export for uses outside its own module,
a scan for functions referenced only by their definition, and a grep for
concepts #150/#151 removed. No behaviour changes.

Dead code
- credstore.setLicenseToken: no production caller since refresh commits
  through commitRefresh (#148); its one test now simulates the other
  client's sign-in with commitSignin, the path that client actually uses.
- credstore's LICENSE_EXPIRY_SKEW_SECONDS export: its only outside users
  were the daemon and the Stop recovery, both removed.

Comments that described removed behaviour
- license-activation: "no reactive force path" (there is one, for 401s);
  the daemon as a refresh caller.
- license-status: the daemon reading the record, a "reactivated" outcome
  nothing writes, "SessionStart bypasses the refresh lock" (not since #137),
  and backoff pointing at the superseded ADR 001 decision 2.
- transfer: the module header and sealFinalSessionArtifacts said SessionStart
  and the monitor upload; the function spawns a detached drain itself.
- session_start: "even if the daemon gave up last time".

Tests
- expiry-recovery titles and header named a recovery worker that no longer
  exists; they now say what they check.
- session-start-refresh dropped its unused lock-age fixture branch;
  retry-daemon dropped endpoint env the daemon no longer uses.

ADR 003 gets a dated note: hooks no longer skip on an expired license,
backoff_exhausted is gone, and there is no Stop recovery worker.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@minarc minarc mentioned this pull request Sep 26, 2026
minarc added a commit that referenced this pull request Sep 26, 2026
MINOR: recording no longer depends on the license being fresh (#150), and
unsent data is now removed at sign-out and after seven days. Also ships the
credential-store hardening (#147, #148) and the single refresh path (#151).
#152 and #153 change only docs and leftovers.

`paths.js` derives PLUGIN_VERSION from this file, so the sign-in banner and
the X-Plugin-Version header follow. Loaded value confirmed: 0.39.0.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@minarc
minarc deleted the refactor/single-refresh-path branch September 26, 2026 16:37
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