Skip to content

fix(workspace): an expired client session no longer becomes the operator (#2261) - #2298

Merged
vybe merged 2 commits into
devfrom
fix/2261-workspace-expiry-identity
Aug 19, 2026
Merged

vybe merged 2 commits into
devfrom
fix/2261-workspace-expiry-identity

Conversation

@dolho

@dolho dolho commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2261.

Summary

#2258's stated residual. Expiry cannot end the platform credential — that would log an operator out of another tab over a client's idle timeout — so endSession → signOut cleared only the portal token and isPlatformSession re-derived from the platform JWT still in the browser. The client's tab silently became the operator's.

Why the flag the issue suggested works now

#2258 rejected it on evidence, and the evidence was about the wire: auth.js installs the platform JWT as an axios.defaults header, per-request headers merge over defaults, so a flag hides the operator's roster on screen while every workspace request still carries the operator's credential. So this fixes the wire first:

Half What it does
The wire Every workspace call moves onto a dedicated instance (portalHttp) whose request interceptor decides the credential and strips whatever axios.defaults merged in. authHeader returns {} while suppressed.
The screen platformFallbackSuppressed, set when a client session expires here; isPlatformSession returns false while set. sessionStorage — survives a refresh of this tab and nothing wider, which is also what leaves the operator's other tab alone.

Neither half works alone, and that is the whole design. streamPortalExecution uses bare fetch with authHeader only, so it was already honest and stays so.

The escape hatch is mandatory, not a nicety. The suppression fails closed, so it necessarily catches the operator when the browser is genuinely theirs — "Continue as <email>" is the one explicit click back in. Re-deriving automatically is the bug.

Three things surfaced while building it

1. The 401 bounce had to move with the transport — and off the wrong question. main.js decided with onWorkspace && localStorage['token']. Workspace calls no longer reach it, so the operator bounce is re-registered via setPlatformSessionLostHandler and fires only when isPlatformSession. That's false in exactly the case the old predicate got wrong: a client at the OTP form on a browser holding an operator's JWT, where one mistyped digit would 401, bounce them to /login, and destroy the operator's session — objection 3 in workspace-session-signout.md, now closed by construction. Without the move, an operator whose JWT expired on the workspace would have sat on "Failed to load your agents" forever.

2. sessionExpired was never rendered. The store has set it since ent#375 and no view read it, so an idle-out was indistinguishable from "you were never signed in" — the form just reappeared. It says which now.

3. resumePath was never read either, so the notice's "pick up where you left off" was a promise the app didn't keep. The sign-in that consumes the expiry navigates there.

Acceptance criteria

AC Where
Expired client on a platform browser sees the expired sign-in, and a refresh keeps it shows the expired sign-in state, and a refresh keeps it there
Operator's session in another tab is not ended leaves the operator's platform session alone (+ __logout never called)
The wire agrees with the screen sends no credential while the UI says signed out, strips a platform JWT merged in from axios defaults
Unit coverage in workspaceSession.spec.js 37 tests (was 28)

A test-harness bug worth flagging

The spec's axios mock returned one shared instance for every create(), so api.js's PERF-269 dedupe wrapper (which replaces .get on its own instance) was also replacing the workspace store's — a stub on it was silently not the code path, and it surfaced only because this PR moved the store onto an instance. create() now returns a fresh instance, like real axios.

Testing

$ npx vitest run tests/unit/workspaceSession.spec.js   # 37 passed
$ npx vitest run                                       # 45 files, 940 passed
$ npx vite build                                       # ✓ built

Not covered by the unit suite (node-only, no DOM): the two new template branches render only in a browser. Their conditions are pure computeds over tested store state, and both carry data-testids for an e2e follow-up.

Docs

docs/memory/feature-flows/workspace-session-signout.md — the residual is struck through with the reason the flag became viable, plus a new "The expiry path (#2261)" section covering both halves, the escape, the bounce move, and the private-mode degradation.

Related to #2261

dolho and others added 2 commits August 19, 2026 10:41
…tor (#2261)

#2258's stated residual. Expiry cannot end the platform credential — that would
log an operator out of another tab over a client's idle timeout — so
`endSession → signOut` cleared only the portal token, and `isPlatformSession`
re-derived from the platform JWT still in the browser. The client's tab silently
became the operator's, roster and all.

#2258 rejected the issue's own suggestion (a "suppress the fallback" flag) on
evidence: `auth.js` installs the platform JWT as an axios DEFAULT header and
per-request headers MERGE over defaults, so a flag hides the operator's roster on
screen while every workspace request still carries the operator's credential.
That objection is about the WIRE, so this fixes the wire first and the flag
becomes honest:

1. Every workspace call moves onto a dedicated instance (`portalHttp`) whose
   request interceptor decides the credential and strips whatever `axios.defaults`
   merged in; `authHeader` returns {} while suppressed. Asserted directly, both
   halves. (`streamPortalExecution` uses bare fetch with `authHeader` only, so it
   was already honest.)
2. `platformFallbackSuppressed` — set when a client session EXPIRES here, cleared
   by `signOut()`, by a client signing in again, and by the operator's explicit
   "Continue as <email>". In sessionStorage: it must survive a refresh of THIS tab
   and nothing wider, which is also what leaves an operator's other tab alone.

The escape hatch is mandatory, not a nicety: the suppression fails closed, so it
necessarily catches the operator when the browser is genuinely theirs.

Three things surfaced while building it, each fixed rather than left:

* **The 401 bounce had to move with the transport** — and off the wrong question.
  `main.js` decided with `onWorkspace && localStorage['token']`; workspace calls no
  longer reach it, so the operator bounce is re-registered through
  `setPlatformSessionLostHandler` and fires only when `isPlatformSession`. That is
  false in exactly the case the old predicate got wrong: a client at the OTP form
  on a browser holding an operator's JWT, where one mistyped digit would 401,
  bounce them to /login and destroy the operator's session (objection 3 in
  `workspace-session-signout.md`). Without the move, an operator whose JWT expired
  would have sat on "Failed to load your agents" forever.
* **`sessionExpired` was never rendered.** The store has set it since ent#375 and
  no view read it, so an idle-out was indistinguishable from "you were never
  signed in" — the form just reappeared. It says which now.
* **`resumePath` was never read either**, so the notice's "pick up where you left
  off" was a promise the app did not keep. The sign-in that consumes the expiry
  navigates there.

The spec's axios mock returned ONE shared instance for every `create()`, so
`api.js`'s PERF-269 dedupe wrapper was overwriting the store's `.get` — a stub on
it was silently not the code path. `create()` now returns a fresh instance, like
real axios.

37 tests in workspaceSession.spec.js (was 28): the four ACs, both bounce paths,
the escape, marker lifecycle, and the private-mode degradation. Full frontend
suite 940 passed, build clean.

Related to #2261

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…#2261 review)

Caught by /review on this PR. The request interceptor kept any `Authorization`
it found on the config, which cannot distinguish "the store decided this" from
"axios merged this in from defaults" — so the property the PR claimed (it strips
an inherited platform JWT) was not the property the code had. It would have
PRESERVED one.

Verified empirically against the shipped axios (1.19.0): an instance created
before `auth.js` mutates `axios.defaults.headers.common` does not inherit that
mutation, so nothing is inherited today and the disclosure is closed by the move
onto the instance. But a security property must not rest on a merge behaviour we
neither control nor test, so the interceptor is now unconditional: delete any
Authorization, then set it from the store, fail-closed when the store is
unreachable.

Two tests replace the one that asserted the wrong thing — an inherited header is
discarded, and a live client session still authenticates (fail-closed is only
correct when there is nothing to send) — plus
tests/unit/axiosInstanceIsolation.spec.js, which pins the axios fact itself
against real axios so a version bump that changes it is visible.

Related to #2261

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

@vybe vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validated via /validate-pr: CI fully green (6 pytest seeds, e2e, build, gitleaks), security scans clean, feature-flow doc updated, regression specs named to the issue. Approving.

@vybe
vybe merged commit 84ff66e into dev Aug 19, 2026
34 of 36 checks passed
trinity-ability pushed a commit that referenced this pull request Aug 19, 2026
….js against #2298

Both PRs added state fields at the same insertion point (kept both), and #2298
(#2261) moved the store onto the dedicated portalHttp instance — this branch's
two new asks calls move with it, exactly as the fetchAsks comment promised
('when that lands, these two calls move with the other 29'), and
workspaceAsks.spec.js stubs portalHttp instead of the global axios (the
workspaceSession.spec.js pattern). All 48 tests across the three affected
specs pass.

Co-Authored-By: Claude Fable 5 <[email protected]>
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