Skip to content

feat(studio): TR-10 short-lived sessions with rotating refresh (onto main) - #1113

Merged
dwolfson merged 5 commits into
mainfrom
claude/tr10-on-main
Nov 18, 2026
Merged

dwolfson merged 5 commits into
mainfrom
claude/tr10-on-main

Conversation

@dwolfson

Copy link
Copy Markdown
Owner

TR-10 (Dan, 2026-11-18: "TR-10 Merge it"). This brings the Studio session-refresh work, claude/tr10-studio-session-refresh (48b3268, Architect PASS 2026-11-15), onto current main. It was never merged.

What changes

  • Short-lived session JWTs. STUDIO_JWT_TTL_MINUTES, default 15.
    • While you're active, the page refreshes the JWT, and each refresh re-checks your Egeria sign-in.
    • Refreshes stop STUDIO_SESSION_MAX_HOURS after sign-in (default 8); then you sign in again.
  • Rotating refresh tokens. Replaying a refresh token revokes the session.
  • Single-flight refresh. A refresh runs once at a time, within a page and across its tabs.
  • Sign-out ends refresh.
  • trellis-auth: create_access_token takes a TTL and extra claims.

The merge

  • trellis-auth: auth.py and test_auth.py merged automatically, and the Architect found the result right. TR-10 changed create_access_token; main changed validate_egeria_token (TR-24). Studio's refresh re-check now uses main's TR-24 validation.
  • The only conflict was semantic, with TR-48: .env.example still listed the removed STUDIO_JWT_TTL_HOURS. Fixed in 2ad17b5, which documents the two new settings.

Checks

  • Architect: read-back PASS, and the R1 fix passed its re-read.
  • Studio tests: 116 passed, 7 skipped, 0 failed, both env ways.
  • trellis-auth tests: 150, with 1 failure that is already on main. It's tracked as TR-57: pyegeria 6.3.0 raises a 401 in that test.
  • Gate b447, run on the pre-fix head 6b44239:
    • main suite 15413/0;
    • harness 2087/0;
    • analytics 294/0;
    • the only new failure was the .env.example test, which 2ad17b5 fixes.
  • Deploy: this is not deployed. Studio 8840 needs its own go-ahead. Laz's Studio env sets no STUDIO_* names, so the rename changes nothing there.

🤖 Generated with Claude Code

…Egeria, sign-out ends refresh

Owner decision: "shorter TTL + refresh".

- Studio's session JWTs now live STUDIO_JWT_TTL_MINUTES (default 15) and
  carry sid (one per sign-in, kept across refreshes) and auth_time.
  STUDIO_SESSION_MAX_HOURS (default 8) caps a session counted from
  sign-in; the Egeria token still caps every JWT.
- POST /api/auth/refresh mints a new JWT for the same sid only when
  every check holds:
  - the presented JWT is valid and not signed out;
  - the session is under its maximum age;
  - its Egeria token hasn't expired;
  - Egeria still accepts the token, asked as the user with a
    no-password client (egeria.check_signin -> get_my_profile).
  Egeria refusing it is a 401 and also signs the session out here.
  Egeria unreachable is a 503 with no new JWT, and the session runs on.
- Logout carries the JWT and revokes its sid. From then on every JWT of
  that session is refused on every non-public path (StudioLoginMiddleware
  over trellis-auth's gate, and current_user) and can't be refreshed. A
  JWT without a sid is refused too, so deploying this signs current
  sessions out once.
- The page refreshes in the last third of a JWT's life (30 s to 5 min
  before exp) only if it was used while that JWT was live; an untouched
  tab lapses. The decision is session_refresh.js, pure and node-tested.
  A 401/403 ends the session. The new JWT reaches the EA panel by the
  existing studio:session event, and EA swaps a same-sid JWT in quietly
  (no app restart, no sidebar reload).
- trellis-auth create_access_token gains keyword-only ttl and
  extra_claims (additive; extra claims can't replace the contract).

Read-back advisories:
- EA open_in_studio: a lock per (user, label) is held across the check
  and the save, so a double click or two tabs on one EA save once.
  Still not atomic across processes (noted in the code).
- A signed-out JWT re-sent after its exp is refused by Studio's
  /api/auth/me and by EA's whoami. EA can't see Studio's sign-outs, so
  at EA a signed-out JWT works until its exp (at most the TTL).

Limits (sessions.py): revocations live in process memory (a restart
forgets them; short JWTs bound that). No session outlives the Egeria
token it signed in with (about an hour on laz), because Studio holds no
password to renew it.

Signed-off-by: Dan Wolfson <dan.wolfson@pdr-associates.com>
…sion

The Architect's read-back criteria, sent ahead.

- Sign-in returns an access JWT (15 min by default) and a refresh token:
  opaque, random, known to Studio only by its SHA-256, and bound to one
  session's sid, its user and the Egeria token it signed in with.
- POST /api/auth/refresh {refresh_token} now trades the refresh token for
  a new access token AND a new refresh token. Each refresh token works
  once (rotation). Presenting a used one is a replay: every access and
  refresh token of that session is revoked, and the answer is 401.
- Identity can't change: the new access token is minted for the refresh
  token's own user. An access token sent with the request must have the
  same sub and sid, or the session is revoked.
- Re-checks are as before (maximum age; Egeria token unexpired; Egeria
  still accepts it, asked as the user). If Egeria refuses it, the
  session is revoked and the answer is 401. If Egeria can't be asked,
  it's a 503 and the refresh token stays unused, so a retry isn't
  mistaken for a replay.
- /api/auth/refresh is a public path, gated by its refresh token, so a
  page whose access token just expired can still refresh. An expired
  access token alone is a 401 everywhere, never anonymous.
- Logout takes the access token, the refresh token or both (an expired
  access token still works for this), revokes the sid and drops its
  refresh tokens.
- The page keeps the refresh token in sessionStorage beside the JWT,
  replaces both on refresh, sends both on sign-out and clears both. It
  never hands the refresh token to EA.

Tests: one per criterion, including rotation, replay revoking the chain,
a mismatched identity, an Egeria refusal, an expired Egeria token, sign-
out by either token, and an expired access token with no refresh is 401.

Signed-off-by: Dan Wolfson <dan.wolfson@pdr-associates.com>
…s tabs

Read-back advisory on d8f5603. A double-fire would send one refresh
token twice, which Studio reads as a replay and revokes the session.

- singleFlight (session_refresh.js, node-tested): calls made while a
  refresh is running share it.
- Across tabs (a duplicated tab copies sessionStorage, so it holds the
  same refresh token), refreshes run one at a time under a Web Lock
  ('studio-refresh'). Inside the lock the page re-reads its token and
  re-decides, so a tab another tab has just rotated doesn't send a stale
  refresh token.
- Tabs of one session tell each other on a BroadcastChannel when they
  rotate (the new tokens) or end the session (a refusal, or sign-out),
  matched by sid, so news about another session is ignored.

Signed-off-by: Dan Wolfson <dan.wolfson@pdr-associates.com>
…5fb2ea

Brings origin/claude/tr10-studio-session-refresh (48b3268; Architect
PASS 2026-11-15) onto current main. Dan, 2026-11-18: "TR-10 Merge it".

Signed-off-by: Dan Wolfson <dan.wolfson@pdr-associates.com>
The TR-10 merge left .env.example with the removed STUDIO_JWT_TTL_HOURS
and without the two settings that replace it, so
test_every_setting_studio_reads_is_in_the_example failed. This was a
semantic conflict with TR-48, not a textual one. Document
STUDIO_JWT_TTL_MINUTES (default 15) and STUDIO_SESSION_MAX_HOURS
(default 8) instead.

Studio tests: 116 passed, 7 skipped, both env ways.

Signed-off-by: Dan Wolfson <dan.wolfson@pdr-associates.com>
@dwolfson
dwolfson merged commit 7d3d1eb into main Nov 18, 2026
4 checks passed
@dwolfson
dwolfson deleted the claude/tr10-on-main branch November 20, 2026 19:16
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