Skip to content

Fix first-load session race (live: 10/20 loads failed) - #2

Merged
abuzaro21 merged 1 commit into
mainfrom
fix/session-bootstrap-race
Oct 30, 2026
Merged

abuzaro21 merged 1 commit into
mainfrom
fix/session-bootstrap-race

Conversation

@abuzaro21

@abuzaro21 abuzaro21 commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

Problem

On the public deployment of v1.0.0 (https://decide-demo.onrender.com), 10 of 20 fresh page loads showed Error: proposal not found in this session.

At boot, GET /api/scenarios lazily creates session A while load() explicitly creates session B. Both POSTs run concurrently. If A's Set-Cookie lands after the scenario was created under B, every later request carries A. Localhost latency hid the race.

Fix

ui/src/api.ts: newSession() chains after any in-flight session creation, so the last cookie stored is always the session the caller awaited. The UI client is the only code change. The engine, API, policies and evaluator are unchanged.

Test

New Playwright test that holds the first session response until the scenario exists. It fails on v1.0.0 and passes with the fix. Results: 10/10 E2E, 95/95 unit tests, typecheck clean.

Not deployed. Deploying requires the owner's approval, because the live service is pinned to v1.0.0 (7e77900).

🤖 Generated with Claude Code

Summary by Sourcery

Serialize concurrent session creation to ensure initial page loads consistently use the session associated with their scenario.

Bug Fixes:

  • Prevent first-load session races that could leave the UI using a session that does not own the loaded scenario.

Documentation:

  • Update the documented Playwright test count to include the new first-load race regression test.

Tests:

  • Add an end-to-end regression test covering delayed session responses during initial page load.

…rst load across two sessions

On the live deployment the boot requests and the initial scenario load each started a session concurrently;
when the older session's response landed last, the page read a session that did not own the proposal
('proposal not found in this session', 10 of 20 fresh loads). Engine, API and policies unchanged.
Adds a deterministic Playwright regression test (holds the first session response until the scenario exists).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sourcery-ai

sourcery-ai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Fixes the first-load session race by serializing UI session creation, ensuring a late response cannot replace the session that owns the newly created scenario. Adds a deterministic Playwright regression test and updates the documented E2E count; server-side behavior is unchanged.

Sequence diagram for serialized first-load session creation

sequenceDiagram
    participant UI as UI client
    participant API as Session API
    participant Scenario as Scenario API
    participant Browser as Browser cookie jar

    UI->>UI: newSession()
    UI->>API: POST /api/session A
    UI->>UI: newSession() waits for sessionPromise
    API-->>Browser: Set-Cookie session A
    UI->>API: POST /api/session B
    API-->>Browser: Set-Cookie session B
    UI->>Scenario: POST /api/scenarios/*
    Scenario-->>UI: scenario owned by session B
    UI->>Scenario: GET /api/scenarios/*
    Scenario-->>UI: scenario found in session B
Loading

File-Level Changes

Change Details Files
Serialize concurrent session creation to prevent stale Set-Cookie responses from overwriting the session used by the page.
  • Chain each new session request after the prior session promise, while allowing recovery after a rejected request.
  • Preserve the latest session promise so callers continue to await the session creation they initiated.
ui/src/api.ts
Add an end-to-end regression test that deterministically reproduces the first-load session race.
  • Delay the first session response until scenario creation completes.
  • Verify the page renders the expected verdict without a missing-proposal error.
e2e/judge.spec.ts
Update the documented end-to-end test count.
  • Change the README test command documentation from nine to ten Playwright tests.
README.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Oct 30, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7b40eb1b-0f7b-43f6-864a-51ab378ebe6c
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@abuzaro21
abuzaro21 merged commit e9f8d0a into main Oct 30, 2026
5 checks passed
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