Skip to content

feat(backend): add chat session listing API and wire selector - #13

Merged
locke69321 merged 4 commits into
mainfrom
codex/backend-chat-session-listing
Feb 7, 2026
Merged

feat(backend): add chat session listing API and wire selector#13
locke69321 merged 4 commits into
mainfrom
codex/backend-chat-session-listing

Conversation

@locke69321

@locke69321 locke69321 commented Feb 7, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

Release Notes

  • New Features

    • Chat sessions listing: View and access your previously created conversations.
    • Agent status tracking: Monitor agent activity and operational status.
  • Bug Fixes

    • Improved error handling for chat operations with meaningful feedback when sessions are unavailable.
  • Improvements

    • Chat initialization now automatically loads existing sessions instead of creating new ones by default.

@coderabbitai

coderabbitai Bot commented Feb 7, 2026

Copy link
Copy Markdown

Walkthrough

This PR introduces agent status monitoring and chat session management capabilities with new /agent/status and /chat/sessions endpoints. It adds supporting service and repository layers, refactors FastAPI startup using an async lifespan context manager, enhances error handling for chat operations, and updates the frontend to retrieve and load chat sessions.

Changes

Cohort / File(s) Summary
Agent Status Feature
router.py, schemas.py, dtos.py, agent_service.py
Introduces /agent/status endpoint with AgentStatusResponse model, AgentStatusData DTO, and new AgentService class that aggregates active runs and subagent data to report status as "active" or "idle" with lastRunAt timestamp.
Chat Session Management
router.py, chat_service.py, sqlalchemy_repo.py
Adds /chat/sessions listing endpoint, list_sessions() service method, and repository methods get_chat_session() and list_chat_sessions() ordered by descending creation date.
Chat Service Validation
chat_service.py
Adds input validation to add_message() and list_messages() with ValueError("Session not found") for missing sessions; refactors prompt construction to use prior message history.
Repository Query Methods
sqlalchemy_repo.py
Adds list_runs_by_status() and latest_run() methods to support agent status aggregation and run tracking.
Application Lifecycle Refactor
main.py
Replaces explicit startup event hook with async lifespan() context manager for deterministic DB initialization via FastAPI's lifecycle management.
Frontend Session Integration
client.ts, chat.tsx, -index.smoke.test.tsx
Adds listChatSessions() API client method; refactors chat route with loadSessions() callback to fetch existing sessions on mount, set active session, or create default; adds mock responses for sessions endpoint in tests.
Test Infrastructure
conftest.py, test_chat_memory_api.py, test_db_repo_and_types.py
Updates DB environment configuration to always set SQLite paths deterministically; expands integration and unit test coverage for session listing, message history validation, and agent status behavior in idle/active states.

Sequence Diagram

sequenceDiagram
    participant Client
    participant API as /agent/status
    participant AgentService
    participant SqlAlchemyRepository
    participant Database

    Client->>API: GET /agent/status
    API->>AgentService: get_status()
    AgentService->>SqlAlchemyRepository: list_runs_by_status(RUNNING)
    SqlAlchemyRepository->>Database: Query Run records<br/>where status=RUNNING
    Database-->>SqlAlchemyRepository: [Run, ...]
    SqlAlchemyRepository-->>AgentService: [Run, ...]
    AgentService->>SqlAlchemyRepository: latest_run()
    SqlAlchemyRepository->>Database: Query Run ordered<br/>by created_at DESC
    Database-->>SqlAlchemyRepository: Run | None
    SqlAlchemyRepository-->>AgentService: Run | None
    AgentService-->>API: AgentStatusData<br/>(status, subagents,<br/>activeRuns, lastRunAt)
    API-->>Client: AgentStatusResponse
Loading
sequenceDiagram
    participant Client
    participant API as /chat/sessions
    participant ChatService
    participant SqlAlchemyRepository
    participant Database

    Client->>API: GET /chat/sessions
    API->>ChatService: list_sessions()
    ChatService->>SqlAlchemyRepository: list_chat_sessions()
    SqlAlchemyRepository->>Database: Query ChatSession<br/>ordered by created_at DESC
    Database-->>SqlAlchemyRepository: [ChatSession, ...]
    SqlAlchemyRepository-->>ChatService: [ChatSession, ...]
    ChatService-->>API: [ChatSessionData, ...]
    API-->>Client: [ChatSessionResponse, ...]
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • locke69321/elara-assistant#12: Frontend implementation of agent status panel and session listing UI that integrates with the backend endpoints and repository methods introduced in this PR.

Poem

🐰 A rabbit hops through agent paths,
Listing sessions, checking status graphs,
Lifecycle managed with context care,
New endpoints bloom in the spring air! 🌱
Sessions dance, runs now tracked so clear,
Our burrow's smarter, year by year! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main changes: adding a chat session listing API and wiring a selector, which aligns with the primary objectives and commits in the PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/backend-chat-session-listing

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 and usage tips.

locke69321 commented Feb 7, 2026

Copy link
Copy Markdown
Owner Author

@locke69321
locke69321 force-pushed the codex/backend-chat-session-listing branch 2 times, most recently from df35da1 to 228e8e7 Compare February 7, 2026 07:34
@locke69321
locke69321 marked this pull request as ready for review February 7, 2026 07:35
@locke69321
locke69321 force-pushed the codex/backend-chat-session-listing branch from 39c795e to 661f3a9 Compare February 7, 2026 07:59
@locke69321
locke69321 changed the base branch from codex/ui-kanban-first-dashboard to graphite-base/13 February 7, 2026 08:03
@locke69321
locke69321 force-pushed the codex/backend-chat-session-listing branch from 661f3a9 to 095c0a7 Compare February 7, 2026 08:04
@locke69321
locke69321 changed the base branch from graphite-base/13 to main February 7, 2026 08:05
@locke69321
locke69321 force-pushed the codex/backend-chat-session-listing branch from 095c0a7 to 53da2bb Compare February 7, 2026 08:05

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Feb 7, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

locke69321 commented Feb 7, 2026

Copy link
Copy Markdown
Owner Author

Merge activity

  • Feb 7, 2:01 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Feb 7, 2:01 PM UTC: @locke69321 merged this pull request with Graphite.

@locke69321
locke69321 merged commit 301e2ef into main Feb 7, 2026
13 checks passed
@locke69321
locke69321 deleted the codex/backend-chat-session-listing branch February 7, 2026 14:01
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