[Architecture] No composition root: DB/history services hand-wired per caller with inconsistent paths; session discovery triplicated
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
Research direction
Start by reading app/core/session.py, app/core/path_utils.py, and the listed call sites in app/main.py, app/ui/tui.py, and the CLI modules to map current service wiring and path discovery. Then trace DBWorker creation and the rollback journal paths in app/core/history.py. Done means the acceptance criteria pass: one storage layout and session discovery path, factory-owned workers, and a test showing undo, history export, and ledger resolve the same database files.
Written by the indexing model from the issue text.
Description
Problem
1. Service graph is rebuilt ad hoc, with different paths each time. Several call sites construct DBWorker + Database + CacheManager + HistoryManager themselves, and they don't agree on where the databases live:
- app/main.py:1128-1133 (
handle_undo_command):Database(session_dir / "autosorter.db"),CacheManager(session_dir / "cache.db"), which are per-session. - app/ui/tui.py:7097-7100 (
action_open_history):Database(get_app_dir() / "autosorter.db"),CacheManager(get_app_dir() / "cache.db"), which are global. - app/cli/ledger_cli.py:266-268: global again, same as the TUI. Also ledger_cli.py:172 and quarantine_cli.py:160.
- app/ui/tui.py:1541, app/ui/tui.py:5744, app/demo.py:25 and
Databaseitself at app/core/db.py:1863 create moreDBWorker()instances. AppSession.__init__(app/core/session.py:199-205) is the canonical wiring, but most of these callers don't use it.
Each DBWorker() starts its own writer thread (app/core/db_worker.py:24-27), so "serialized writes" only holds per worker, not per database file.
2. Session/history discovery is implemented three times:
find_all_history_sessionsin app/main.py:554-605 scansget_session_base_dir(),get_app_dir()/sessionsandget_app_dir().scan_abandoned_sessions_asyncin app/core/session.py:23-120 scansget_session_base_dir()only and openshistory.dbwith plain stdlib sqlite3 first (session.py:64-71) before falling back to the cipher connection.- The
rollback_journal.jsonlocation is rebuilt in app/core/history.py:676, 1297, 1636, 2084 and app/core/session.py:39.
3. Path roots are split across modules. get_app_dir() (app/config.py:70) defaults to ~/.autosorter. get_session_base_dir() (app/core/path_utils.py:333) defaults to a temp dir autosorter_sessions_<user>, unless AUTOSORTER_APP_DIR is set, in which case it uses <app_dir>/sessions. The default layout and the env-override layout are therefore structurally different.
Impact
History export from the TUI or ledger CLI may read a different autosorter.db/cache.db than the one undo/sort used. Session-scoped data can be lost on temp-dir cleanup. Any change to where data lives has to be made in 5+ places.
Proposed approach
- Add
app/core/storage_layout.py(or extend path_utils) as the single source of truth forapp_dir,sessions_dir,session_dir(id),history_db(id),main_db(id|None),cache_db(...),ledger_db()androllback_journal(id). Make the default and the env-override layouts the same. - Add
app/core/session_catalog.pywith onelist_sessions(include_abandoned=...)used by main, tui, ledger_cli, history andscan_abandoned_sessions_async. - Add a factory, for example
AppSession.open_existing(session_id)/Services.for_session(...), that owns oneDBWorkerper DB file and buildsDatabase/CacheManager/HistoryManager. CLI and TUI handlers should call the factory instead of constructing services directly.
Acceptance criteria
- No
DBWorker()construction outside the factory/AppSession(grep). - Undo, history export and the ledger CLI resolve the same DB files for a given session id. A test asserts this.
- One session-discovery implementation, and it never opens history DBs with stdlib
sqlite3.
- Dominant language
- Python
- Stars
- 1
- Forks
- 0
- Avg merge
- 9h 3m
- Merged PRs (30d)
- 361
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from fderuiter/sortify
-
bug ready-for-agent
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
security
Difficulty 2/5 1-3 hours Newbie friendliness 57/100
Maintainers usually reply within 1 day
-
architecture enhancement ready-for-agent
Difficulty 5/5 Over a week Newbie friendliness 35/100
fderuiter/sortify#783 · 1 comment ·
Maintainers usually reply within 1 day
-
enhancement ready-for-human
Difficulty 4/5 3-5 days Newbie friendliness 48/100
fderuiter/sortify#740 · 1 comment ·
Maintainers usually reply within 1 day
-
architecture enhancement ready-for-human
Difficulty 5/5 Over a week Newbie friendliness 25/100
fderuiter/sortify#726 · 1 comment ·
Maintainers usually reply within 1 day
All issues in fderuiter/sortify
Similar issues
-
push_gh-pages fails on master branch on forksPossibly taken A pull request linked to this issue is open or already merged. Opengood first issue infrastructure
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
kuznia-rdzeni/coreblocks#1135 ·
-
good first issue server
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
documentation priority: high
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
a-lex-s/mealie-telegram-bot#54 ·
Maintainers usually reply within 1 day
-
type/test
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
SaltedTan/virgil-language-server#218 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
btclib-org/btclib-wallet#541 ·
Maintainers usually reply within 1 day