Skip to content

Conversation

@MODSetter
Copy link
Owner

@MODSetter MODSetter commented Oct 13, 2025

Description

Added missed migration for #390

High-level PR Summary

This PR adds a missed database migration (revision 26) that introduces a language column to the llm_configs table with a default value of 'English'. The migration includes both upgrade and downgrade logic with safety checks to prevent duplicate column additions. Additionally, this PR includes code formatting cleanup across multiple files, removing timestamps from previous migration headers and standardizing whitespace and formatting in agent prompt files.

⏱️ Estimated Review Time: 15-30 minutes

💡 Review Order Suggestion
Order File Path
1 surfsense_backend/alembic/versions/26_add_language_column_to_llm_configs.py
2 surfsense_backend/app/routes/llm_config_routes.py
3 surfsense_backend/app/routes/chats_routes.py
4 surfsense_backend/app/agents/researcher/configuration.py
5 surfsense_backend/app/agents/researcher/prompts.py
6 surfsense_backend/app/agents/researcher/qna_agent/prompts.py
7 surfsense_backend/app/agents/researcher/sub_section_writer/prompts.py
8 surfsense_backend/app/agents/researcher/qna_agent/nodes.py
9 surfsense_backend/alembic/versions/23_associate_connectors_with_search_spaces.py
10 surfsense_backend/alembic/versions/24_fix_null_chat_types.py
11 surfsense_backend/alembic/versions/25_migrate_llm_configs_to_search_spaces.py

Need help? Join our Discord

Analyze latest changes

Summary by CodeRabbit

  • New Features

    • Added language support to LLM configurations with a default of English.
    • Researcher prompts can now include language-specific instructions for answers.
  • Bug Fixes

    • More resilient language selection when applying user preferences, reducing errors when preferences or configurations are missing.
  • Database

    • New migration adds a language column to LLM configurations and backfills existing records.
  • Chores

    • Cleaned up migration metadata headers; no functional impact.
  • Style/Refactor

    • Formatting and readability improvements across prompts and routes with no behavioral changes.

@vercel
Copy link

vercel bot commented Oct 13, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
surf-sense-frontend Building Building Preview Comment Oct 13, 2025 3:16am

@MODSetter MODSetter merged commit ffd861b into main Oct 13, 2025
4 of 8 checks passed
@coderabbitai
Copy link

coderabbitai bot commented Oct 13, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Adds a new Alembic migration to introduce a nullable language column to llm_configs with default 'English' and backfill. Injects optional language instructions into researcher prompts via a new helper. Tightens guarded access and iteration for language selection in chats routes. Several files receive header/formatting-only updates.

Changes

Cohort / File(s) Summary
Alembic header cleanup
surfsense_backend/alembic/versions/23_associate_connectors_with_search_spaces.py, .../24_fix_null_chat_types.py, .../25_migrate_llm_configs_to_search_spaces.py
Removed Create Date from revision headers; no logic changes.
New migration: add language to llm_configs
surfsense_backend/alembic/versions/26_add_language_column_to_llm_configs.py
Adds language column (nullable, server_default 'English'); backfills NULLs; drops column on downgrade.
Researcher configuration & prompts
surfsense_backend/app/agents/researcher/configuration.py, .../prompts.py
Config: whitespace only. Prompts: new _build_language_instruction(...); get_answer_outline_system_prompt(...) now injects language directive.
QnA agent
surfsense_backend/app/agents/researcher/qna_agent/nodes.py, .../qna_agent/prompts.py
Nodes: formatting around prompt construction; no semantic changes. Prompts: reflowed function signatures only.
Sub-section writer prompts
surfsense_backend/app/agents/researcher/sub_section_writer/prompts.py
Reformatted function declarations across lines; no logic changes.
Routes: language selection & prefs
surfsense_backend/app/routes/chats_routes.py, .../llm_config_routes.py
Chats: add guarded checks when deriving language from user/search space LLM configs; formatting tweaks. LLM config routes: whitespace-only changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as User
  participant R as chats_routes
  participant DB as Database
  participant P as Researcher Prompts
  participant L as LLM

  U->>R: Create/continue chat
  R->>DB: Load user preference + search space + LLM configs
  DB-->>R: LLM configs (fast/long_context/strategic, language)
  rect rgba(200,235,255,0.3)
    note right of R: New/modified
    R->>R: Select language (guarded checks, fallback to first config)
  end
  R->>P: Build system prompt (language passed)
  rect rgba(220,255,220,0.4)
    note right of P: New helper injects language instruction
    P-->>R: System prompt with optional language directive
  end
  R->>L: Send prompt + user input
  L-->>R: Response
  R-->>U: Answer
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

A nibble of words, a hop through code,
I tuck in “language” along the road.
Columns grow, prompts now sing,
In English first—yet any tongue can spring.
With guarded steps I choose just right—
Thump-thump! The chat now speaks polite. 🐇✨

✨ 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 dev

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9429c2b and a3f50eb.

📒 Files selected for processing (11)
  • surfsense_backend/alembic/versions/23_associate_connectors_with_search_spaces.py (0 hunks)
  • surfsense_backend/alembic/versions/24_fix_null_chat_types.py (0 hunks)
  • surfsense_backend/alembic/versions/25_migrate_llm_configs_to_search_spaces.py (0 hunks)
  • surfsense_backend/alembic/versions/26_add_language_column_to_llm_configs.py (1 hunks)
  • surfsense_backend/app/agents/researcher/configuration.py (1 hunks)
  • surfsense_backend/app/agents/researcher/prompts.py (1 hunks)
  • surfsense_backend/app/agents/researcher/qna_agent/nodes.py (2 hunks)
  • surfsense_backend/app/agents/researcher/qna_agent/prompts.py (4 hunks)
  • surfsense_backend/app/agents/researcher/sub_section_writer/prompts.py (4 hunks)
  • surfsense_backend/app/routes/chats_routes.py (2 hunks)
  • surfsense_backend/app/routes/llm_config_routes.py (2 hunks)

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.

Copy link

@recurseml recurseml bot left a comment

Choose a reason for hiding this comment

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

Review by RecurseML

🔍 Review performed on 9429c2b..a3f50eb

✨ No bugs found, your code is sparkling clean

✅ Files analyzed, no issues (11)

surfsense_backend/alembic/versions/23_associate_connectors_with_search_spaces.py
surfsense_backend/alembic/versions/24_fix_null_chat_types.py
surfsense_backend/alembic/versions/25_migrate_llm_configs_to_search_spaces.py
surfsense_backend/alembic/versions/26_add_language_column_to_llm_configs.py
surfsense_backend/app/agents/researcher/configuration.py
surfsense_backend/app/agents/researcher/prompts.py
surfsense_backend/app/agents/researcher/qna_agent/nodes.py
surfsense_backend/app/agents/researcher/qna_agent/prompts.py
surfsense_backend/app/agents/researcher/sub_section_writer/prompts.py
surfsense_backend/app/routes/chats_routes.py
surfsense_backend/app/routes/llm_config_routes.py

@Tarun2605
Copy link
Contributor

Thank you!

aptdnfapt pushed a commit to aptdnfapt/SurfSense that referenced this pull request Oct 19, 2025
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.

3 participants