Skip to content

fix(backend): restore ruff compliance across surfsense_backend - #1672

Merged
MODSetter merged 2 commits into
MODSetter:devfrom
Yigtwxx:fix/backend-ruff-imports
Aug 8, 2026
Merged

fix(backend): restore ruff compliance across surfsense_backend#1672
MODSetter merged 2 commits into
MODSetter:devfrom
Yigtwxx:fix/backend-ruff-imports

Conversation

@Yigtwxx

@Yigtwxx Yigtwxx commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

The ruff / ruff-format pre-commit hooks run against every Python file a PR touches, so a lint violation sitting on dev is inherited by the next PR that edits the same file — even when that PR did not go near the offending lines.

This is not hypothetical. #1648 only appends a helper function near the bottom of app/routes/documents_routes.py, and its Backend Quality has been red on ruff-check since it rebased onto current dev:

ruff-check...............................................................Failed
- hook id: ruff
- files were modified by this hook
Found 1 error (1 fixed, 0 remaining).

The error is in the import block that file already had:

$ uvx ruff@0.12.5 check --fix --diff app/routes/documents_routes.py
-from app.knowledge_store.paths import virtual_path_to_doc
 from app.auth.context import AuthContext
 from app.db import (
     ...
 )
+from app.knowledge_store.paths import virtual_path_to_doc

What was wrong

Against dev at 339fe12, using the version the hook pins (ruff-pre-commit v0.12.5):

$ uvx ruff@0.12.5 check .
Found 21 errors.
[*] 20 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option).

$ uvx ruff@0.12.5 format --check .
11 files would be reformatted, 2204 files already formatted

19 I001, one RUF022, one UP038, plus eleven files with format drift.

Changes

Twenty violations are ruff check --fix output, no hand edits — unsorted import blocks and one unsorted __all__.

One hand edit. UP038 in app/proprietary/platforms/reddit/fetch.py:159: isinstance(cookies, (list, tuple)) becomes isinstance(cookies, list | tuple). Ruff only offers this as an unsafe fix and the hook runs a plain --fix, so it would stay red otherwise. The two forms are equivalent on the project's Python 3.12 floor.

Eleven files reformatted by ruff format. None of them overlap the files above, so every one of those hunks is pure whitespace.

Every import move is alphabetical within its existing group. No import crosses a side-effect boundary, and the deliberately placed asyncio event-loop policy block in documents_routes.py — the one with the # Force asyncio to use standard event loop before unstructured imports comment — is untouched.

Testing

$ cd surfsense_backend && uvx ruff@0.12.5 check .
All checks passed!

$ uvx ruff@0.12.5 format --check .
2215 files already formatted

Clean on both, repo-wide, with the pinned version.

The four test files among the 21 are excluded by the hook's own exclude pattern, so they were never gating anything; they are included here so ruff check . is clean as a whole rather than clean-except-where-nobody-looks.

High-level PR Summary

This PR restores ruff linter and formatter compliance across the entire backend codebase. It fixes 21 linting violations (20 import sorting issues and 1 isinstance modernization) and reformats 11 files with whitespace corrections. The changes were causing pre-commit hook failures for subsequent PRs that touched affected files, even when those PRs didn't introduce the violations. All fixes are automated tool output except for one hand-edited isinstance type union syntax update to use Python 3.12's native | operator.

⏱️ Estimated Review Time: 5-15 minutes

💡 Review Order Suggestion
Order File Path
1 surfsense_backend/app/proprietary/platforms/reddit/fetch.py
2 surfsense_backend/app/knowledge_store/paths/__init__.py
3 surfsense_backend/alembic/env.py
4 surfsense_backend/app/agents/chat/multi_agent_chat/main_agent/middleware/kb_persistence/middleware.py
5 surfsense_backend/app/agents/chat/multi_agent_chat/main_agent/middleware/knowledge_tree/middleware.py
6 surfsense_backend/app/agents/chat/multi_agent_chat/shared/middleware/filesystem/backends/kb_postgres.py
7 surfsense_backend/app/agents/chat/multi_agent_chat/subagents/shared/run_reader.py
8 surfsense_backend/app/agents/chat/runtime/mention_resolver.py
9 surfsense_backend/app/knowledge_store/index/converge.py
10 surfsense_backend/app/knowledge_store/index/project.py
11 surfsense_backend/app/knowledge_store/index/rows.py
12 surfsense_backend/app/routes/documents_routes.py
13 surfsense_backend/app/services/folder_service.py
14 surfsense_backend/app/services/revert_service.py
15 surfsense_backend/app/tasks/celery_tasks/knowledge_store/index_tasks.py
16 surfsense_backend/scripts/check_migration_flow.py
17 surfsense_backend/scripts/migrate_knowledge_store.py
18 surfsense_backend/app/agents/chat/multi_agent_chat/main_agent/middleware/knowledge_store_persistence/commit_turn.py
19 surfsense_backend/app/knowledge_store/index/folders.py
20 surfsense_backend/app/knowledge_store/paths/resolve.py
21 surfsense_backend/app/knowledge_store/service.py
22 surfsense_backend/app/tasks/connector_indexers/local_folder_indexer.py
23 surfsense_backend/tests/integration/knowledge_store/index/test_converge.py
24 surfsense_backend/tests/integration/knowledge_store/index/test_project.py
25 surfsense_backend/tests/integration/knowledge_store/test_migrate.py
26 surfsense_backend/tests/integration/knowledge_store/test_migrate_placement.py
27 surfsense_backend/tests/integration/knowledge_store/test_path_column.py
28 surfsense_backend/tests/integration/knowledge_store/test_service.py
29 surfsense_backend/tests/integration/test_okf_path_identity.py
30 surfsense_backend/tests/unit/knowledge_store/test_recorded_virtual_path.py
31 surfsense_backend/tests/unit/middleware/test_git_tree_backend.py
32 surfsense_backend/tests/unit/services/test_model_connections.py

Need help? Join our Discord

The ruff pre-commit hooks run against every Python file a PR touches, so
a lint violation that lands on dev is inherited by the next PR that edits
the same file. `app/routes/documents_routes.py` is the live example: its
import block is unsorted on dev, and PR MODSetter#1648 — which only appends a
helper function far below the imports — has been failing Backend Quality
on `ruff-check` because of it.

`ruff check .` reported 21 violations on dev (339fe12): 19 I001, one
RUF022, and one UP038. Twenty are `--fix` output. The UP038 is the one
hand edit, `isinstance(cookies, (list, tuple))` to `isinstance(cookies,
list | tuple)` in the Reddit fetcher, because ruff only offers it as an
unsafe fix and the pinned hook runs a plain `--fix`; the two forms are
equivalent on the project's Python 3.12 floor.

`ruff format` covers eleven further files that had drifted. None of them
overlap the files above, so each is pure whitespace.

Every import move is alphabetical within its existing group — no import
crosses a side-effect boundary, and the deliberately placed asyncio
policy block in documents_routes.py is untouched.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CpY4T39RzhWyUV9qQpPWw7
@vercel

vercel Bot commented Aug 7, 2026

Copy link
Copy Markdown

@Yigtwxx is attempting to deploy a commit to the Rohan Verma's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 38fde455-89cd-4925-93c3-e2f4c30a5154

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

…n check

The pre-commit security scan runs detect-secrets over every file a PR
touches. This branch only reorders imports in check_migration_flow.py,
but that pulls the file into the scan and trips on its pre-existing
localhost fallback DSN, which is not a real credential.
@MODSetter
MODSetter merged commit 24de170 into MODSetter:dev Aug 8, 2026
5 of 11 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