Skip to content

Topic/upstream session lifecycle 20260412#167

Merged
everett4320 merged 6 commits intoOpenLAIR:mainfrom
everett4320:topic/upstream-session-lifecycle-20260412
Apr 12, 2026
Merged

Topic/upstream session lifecycle 20260412#167
everett4320 merged 6 commits intoOpenLAIR:mainfrom
everett4320:topic/upstream-session-lifecycle-20260412

Conversation

@everett4320
Copy link
Copy Markdown
Collaborator

Summary

This PR fixes multi-provider session lifecycle stability and performance issues on topic/upstream-session-lifecycle-20260412, while keeping full provider support (claude/cursor/codex/gemini/openrouter/local/nano).

Key outcomes:

  • New session appears in sidebar immediately after first message.
  • Multi-session concurrent switching no longer stalls for minutes.
  • Session/message routing no longer cross-talks across provider/project scopes.
  • Invalid project owner fallback prevents FOREIGN KEY constraint failed noise.
  • Backward compatibility preserved for existing projects with large historical sessions.

Root Causes Addressed

  1. Realtime routing used sessionId in several paths instead of consistently using actualSessionId ?? sessionId.
  2. Session UI identity relied on session.id only, which is insufficient in multi-provider / multi-project contexts.
  3. Session loading stale-guard could drop valid responses; clear-then-load behavior caused temporary blank sessions.
  4. Codex session lookups repeatedly rescanned ~/.codex/sessions, causing heavy latency under concurrent usage.
  5. Invalid ownerUserId in config could violate DB FK constraints.

What Changed

Frontend

  • Added optimistic session insertion flow for sidebar (OPTIMISTIC_SESSION_CREATED_EVENT) with scoped dedup identity project::provider::sessionId.
  • Unified identity keys in sidebar/workspace selection/editing paths.
  • Hardened session activity/progress tracking with scoped keys.
  • Unified realtime routing to actualSessionId ?? sessionId.
  • Added scoped filter debug plumbing (disabled by default).
  • Improved session loading:
    • provider resolution priority: session-bound -> active provider -> persisted provider -> inferred -> default
    • skip history loading for temporary IDs (new-session-* / temp-*)
    • generation-based stale request guards to prevent late response overwrite
    • safer cache candidate keys:
      • keep project+session(+provider) compatibility
      • remove legacy project-only fallback to avoid cross-session replay

Backend

  • Added Codex session-created event builder including projectName.
  • Unified Codex session file resolution path across message loading and token usage.
  • Added Codex session file path cache + index cache (with invalidation on deletion).
  • Added ownerUserId validation/fallback to authenticated/valid user to avoid FK errors.

Compatibility

  • No provider restrictions introduced.
  • Existing historical projects/sessions remain supported.
  • No external API breaking changes.

Verification

Automated

  • npm run typecheck
  • npm run test -- --run --maxWorkers=1
  • Result: 19 passed files / 110 passed tests

Manual smoke

  • First message in new session appears in sidebar immediately.
  • 2-3 concurrent sessions across providers can run and switch without minute-level wait.
  • Existing historical projects/sessions load without cross-session leakage.

Scope (public upstream branch only):\n- Port queue/steer workflow for chat dispatch, including queued-turn persistence, steer promotion, pause/resume semantics, and settlement reconciliation.\n- Add session scope isolation helpers and tests to prevent cross-project/provider session collisions when session IDs overlap.\n- Strengthen realtime protocol with explicit lifecycle events: session-accepted, session-busy, and session-state-changed.\n- Enrich lifecycle/session-created payloads with projectName metadata for more reliable client-side routing and state ownership.\n- Keep Nano provider command/session status flows aligned with other providers in active-session and lifecycle handling.\n\nUpstream safety constraints applied:\n- Excluded local/private product policy changes (Codex-only strategy, auth/license stack, workspace-root hard-cut/backfill behavior).\n- Excluded branding and private demo/link routing changes (kept Dr. Claw naming).\n- Avoided introducing server-side CODEX_ONLY/provider lock-in behavior into upstream.\n\nCompatibility notes:\n- Lifecycle protocol additions are provider-agnostic and transport-level; no Windows-only behavior was hardcoded.\n- Existing macOS/Linux provider command paths remain unchanged.\n\nValidation:\n- node --check server/index.js\n- node --check server/claude-sdk.js\n- node --check server/cursor-cli.js\n- node --check server/gemini-cli.js\n- npm run test -- ... (blocked: vitest executable missing in this environment)\n- npm run typecheck (blocked: tsc executable missing in this environment)
@everett4320 everett4320 merged commit 1a64608 into OpenLAIR:main Apr 12, 2026
1 check passed
@everett4320 everett4320 deleted the topic/upstream-session-lifecycle-20260412 branch April 12, 2026 21:06
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