{"record":{"id":"3b6f4b015f34b059","repo":"abi/screenshot-to-code","slug":"active-session-active-session-name-r-is-pinned-t","errorCode":null,"errorMessage":"Active session {active_session.name!r} is pinned to set {active_session.eval_set!r}, not {requested_set!r}","messagePattern":"Active session (.+?) is pinned to set (.+?), not (.+?)","errorType":"exception","errorClass":"SessionSetMismatchError","httpStatus":null,"severity":"error","filePath":"backend/evals/sessions.py","lineNumber":162,"sourceCode":"        except sqlite3.IntegrityError:\n            _activate_in_transaction(conn, session_id)\n    finally:\n        conn.close()\n    return get_session(session_id)\n\n\ndef resolve_session_for_run(set_name: str) -> EvalSession:\n    \"\"\"The session eval runs should attach to for this set.\n\n    Active session on the same set wins; a mismatched active session is an\n    error (the caller must explicitly start a new session); no session at\n    all auto-creates one so a bare \"/run_evals with a set\" just works.\n    \"\"\"\n    active = get_active_session()\n    if active is None:\n        return create_session(set_name)\n    if active.eval_set != set_name:\n        raise SessionSetMismatchError(active, set_name)\n    return active\n\n\n@dataclass\nclass SessionModelMeta:\n    position: Optional[int]\n    notes: str\n\n\ndef get_model_meta(session_id: str) -> dict[str, SessionModelMeta]:\n    conn = open_index_db()\n    try:\n        rows = conn.execute(\n            \"SELECT model, position, notes FROM eval_session_models \"\n            \"WHERE session_id = ?\",\n            (session_id,),\n        ).fetchall()\n    finally:","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/abi/screenshot-to-code/blob/d026163f586dfa8c5c10d28c36edd59a9d3b0e88/backend/evals/sessions.py#L144-L180","documentation":"SessionSetMismatchError raised by resolve_session_for_run when an active eval session exists but its eval_set differs from the requested set. By design, one active session per set: a mismatched active session is an error so runs never silently attach to the wrong session; the caller must explicitly start a new session. The f-string interpolates the active session's name, its set, and the requested set.","triggerScenarios":"Activating session for set A, then running evals for set B via /run_evals with a set argument (or the eval sessions page) without deactivating/starting a new session first.","commonSituations":"Switching between eval sets mid-session, forgotten active session from a previous run, or automation that assumes a fresh context per invocation.","solutions":["Start a new session for the target set (POST /eval-sessions) or deactivate/finish the current active session, then retry the run.","Catch SessionSetMismatchError and surface 'finish or start a new session' to the user instead of a raw traceback.","For automation, always create a session per set instead of relying on the ambient active one."],"exampleFix":"# before\nresolve_session_for_run(\"set-b\")  # active session is on set-a -> raises\n\n# after\nfinish_active_session()  # or create a new session via the UI/API\nresolve_session_for_run(\"set-b\")","handlingStrategy":"validation","validationCode":"active = get_active_session()\nif active is not None and active.eval_set != requested_set:\n    raise SessionSetMismatchError(active, requested_set)  # caller decides: finish or new session","typeGuard":null,"tryCatchPattern":"try:\n    session = resolve_session_for_run(set_name)\nexcept SessionSetMismatchError as e:\n    prompt_user_to_start_new_session(set_name)","preventionTips":["Always create a fresh session when switching eval sets instead of reusing the ambient active one.","Catch SessionSetMismatchError at the API layer and return a 409 with a clear remediation message.","Automation should pin eval_set per invocation and never depend on global active state."],"tags":["evals","session","state-mismatch","validation"],"backgroundTag":null,"analyzedSha":"d026163f586dfa8c5c10d28c36edd59a9d3b0e88","analyzedAt":"2026-08-14T22:02:06.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}