Skip to content

fix(server-core): resolve a request only against the check of its own tokens - #387

Open
Exeloo wants to merge 7 commits into
mainfrom
fix/session-pending-tokens
Open

Exeloo wants to merge 7 commits into
mainfrom
fix/session-pending-tokens

Conversation

@Exeloo

@Exeloo Exeloo commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Closes #267

In a hosted editor, a request could be answered with the result of a pending session check that was started for other tokens. SessionStore._authenticate now ties every pending check to the tokens it checks:

  • Same tokens: the request waits on that check, as before.
  • Other tokens: the request waits for that check to settle, then is checked with its own tokens. Checks of one session run one after the other.
  • A request without tokens signs the session out even while a check is pending, and that check no longer signs it back in when it settles later.
  • A request whose pending check was replaced (by a sign-out, a dropped session or another check) gets a signed-out session of its own: not stored, the shared session untouched, no new API call.
_authenticate(session, cookies):
  key = JSON.stringify([access, refresh])
  pending, same key   -> wait on it
  pending, other key  -> wait for it to settle, then check again with own tokens
  check replaced      -> return false -> resolve() answers a fresh signed-out session

AGENTS.md (hosted sessions) describes the token-bound checks.

How do you test this PR?

New tests in packages/server-core/test/session/session-store.spec.ts, with stand-in verify functions (no real auth API):

Test Before After
"never resolves a request against the pending check of other tokens" expected [ 'access-ada' ] to deeply equal [ 'access-ada', 'access-bob' ]: the second request reused the first check (1 failed, 7 passed) 8/8
"answers requests whose check a sign-out replaced with a signed-out session of their own", "signs out a session dropped while its check was pending" (against the round-1 source) 2 failed, 11 passed: the request got the shared session 13/13 session tests

The other new tests cover a refused check with a waiter on other tokens, an outage after the record was replaced, and a session dropped during a pending check.

Commands run from the worktree on the last code commit (14b9c3e): server-core unit tests (24 files, 135 passed, 0 skipped), pnpm typecheck, pnpm build, pnpm lint, commit hooks: all pass. prettier --check AGENTS.md passes after the final docs edit (0bce216). e2e not run (unit-level change).

Integration: a scratch branch with every editor branch of this sweep merged passed pnpm build, lint, typecheck, pnpm test --force (1014 passed, 1 skipped) and the full e2e suite with the engine (141/141, Chromium only).

Merge danger

  • Two-way door: in-memory session logic only, no data or schema change.
  • Blast radius: the hosted (ONLINE) editor's session store. @nanoforge-dev/editor-server-core has no runtime dependents outside the editor. This is auth-state code on the hosted path; merging to main deploys the editor app.
  • Squash at merge: the re-check added in 0f54aed is undone by 14b9c3e, so the intermediate commits don't read as the final behaviour.
  • AGENTS.md: fix/server-core-fs-safety (fix(server-core): keep project file operations inside the project #384) edits the same hosted-sessions line. Whoever merges second keeps both texts, as the integration branch did.
  • Checks with different tokens queue one after another per session (accepted).

Follow-up issues

None filed.

Quality gate

Lane Result HEAD covered
Docs Updated: AGENTS.md hosted sessions (a5c225b, b693fd6, 0bce216) 0bce216
Correctness Pass after 3 rounds (round 2 Important fixed in 14b9c3e) 0bce216
Performance Pass (one extra check when two token sets hit one session, accepted) round 1 (1c57589 and the first sign-out fix)
Accessibility N/A: no UI -
Security Pass after 3 rounds (round 1 Blocking fixed by 14b9c3e) 0bce216
Style Pass (round 1 minors applied: key rename, commit subject reworded) round 1; pnpm lint on 14b9c3e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

packages:server-core Related to Server core package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A concurrent session check with other tokens reuses the pending verification

1 participant