oliver-zehentleitner / maity
clean-up: core platform: the app shell's per-request asset walk, CLI and config repetition, app start-up wiring, small copies
tsk-581bcbm72g95 Open
From the clean-up audit tsk-hgnbapyw7hnh (uncovered files, G1 core platform), read at 9dfd4b65. Paths are under hub/src/maity_hub/.
1. Slow path on a hot route: every app-shell answer re-reads and re-versions the dashboard
- Files:
shell.py:393-408(ShellRoute.handle) callsshell_response(411-417) on the event loop, not in the thread pool. - What is wrong:
- It reads
index.htmlfrom disk on every call. versioned(315-335) callsasset_versions(165-178), which walks brand/, css/, js/ and vendor/ (about 170 files) with oneos.statper file._refs_currentstats each stylesheet's references again._inside_shell(384-386) builds the same document a second time for a stored public page.- Every dashboard navigation that loads the shell pays this, and a slow disk stalls every other request on the loop.
app.py:648-649already keeps the hashing off the event loop at start-up. - Proposal: build the composed shell once and cache it, keyed by index.html's mtime and size plus a cheap signature of the asset directories, or once per process. Both paths share the cache. At the least, run it in the thread pool.
- Effort: S
- Risk: low. The version query and the headers stay; test_app covers the shell.
2. Duplication: cli.py opens and checks the database the same way six times
- Files:
make_engine, thenrequire_current_schema, thenexcept SchemaNotCurrentErrorandexcept (SQLAlchemyError, ImportError), atcli.py:167-184,254-263,280-286,330-336,406-412and432-438. Some paths skipengine.dispose()on failure:_owner_createreturns at 334-336, before itstry/finally. - Proposal: one
_current_engine(settings)helper, or a context manager that disposes. - Effort: S
- Risk: low.
3. Debt: a type: ignore on a global monkeypatch of uvicorn
- Files:
cli.py:643replacesuvicorn.supervisors.multiprocess.Processfor the whole process (# type: ignore[misc])._WorkerProcess.server(695-703) relies on uvicorn's private_server.- A uvicorn upgrade can break both without a test failing.
- Proposal: set the patch around
supervisor.run()and restore it afterwards. Add a test that fails when uvicorn'sProcessno longer has_server. - Effort: S
- Risk: low.
4. Duplication and a silent truncation in config.py
- Files:
- Whole-number settings go through
parse_number(a float) andint()(config.py:221-241): MAITY_WORKERS, MAITY_REPLICAS, MAITY_DB_POOL_SIZE, MAITY_DB_MAX_OVERFLOW, MAITY_DB_ASYNC_POOL_SIZE, MAITY_DB_POOL_RECYCLE, MAITY_AVATAR_DECODE_MEMORY_MB and MAITY_AVATAR_DECODES.
- So MAITY_WORKERS=2.9 starts 2 workers and says nothing.
- The public-page settings use parse_whole (493-500), which refuses such a value.
parse_alias_limit(518-526) isparse_wholewithout a default, andparse_limit(503-515) repeats the same digit check.parse_skill_source(294-296) is a wrapper ofparse_skill_urlwith one caller.- The https-URL shape check is written three times:
parse_skill_url(299-308),parse_s3_endpoint(365-401),parse_join_url(630-663). - The host normalisation
.lower().rstrip('.')is at 181, 418, 659 andmail/environment.py:71. - Proposal: whole numbers through
parse_whole,parse_alias_limitincluded; inlineparse_skill_source; one_https_origin(name, value)for the shared URL checks. - Effort: S
- Risk: low. A fractional value that starts the hub today would refuse to start; say so in the changelog.
5. Design: the app's start-up wiring is written by hand
- Files:
- The lifespan (
app.py:338-448) starts 21 background objects one by one and stops them by hand in reverse (416-448).
- A new worker needs edits in both lists.
- A start that raises half-way leaves the started ones running.
- app.py imports
servinginside three functions (175, 192, 290), but serving.py imports no app module at load time (serving.py:12-22; it imports app only insideapp(), at 184). - Proposal: keep the started workers in a list or a
contextlib.ExitStackand stop them in reverse in afinally. Import serving at the top. - Effort: S
- Risk: low.
6. Duplication: the load-test handle pattern twice
- Files:
loadtest.py:227HANDLE = re.compile(r'lt-[0-9]+')repeatspaths.py:35LOADTEST_HANDLE; the docstrings say they mean the same accounts. - Proposal: use
paths.LOADTEST_HANDLE. - Effort: S
- Risk: none.
7. Test debt: a skip that can never run
- Files:
hub/tests/test_catalog.py:35-36skips a language whose words file is missing.test_catalog.py:27-29already requires every interface language to have one, so the skip never runs; if it did, it would hide a missing file. - Proposal: drop the skip.
- Effort: S
- Risk: none.
Covered elsewhere
- The copied background
Workerclass that item 5 starts: tsk-dzpzpn5xrm5j item 1. That card says the start and stop order in app.py must stay the same; item 5 keeps it.
Effort sum: 7 x S = 7 points.
Notes
Maity Coder Claude 003 · Nov 20, 2026, 17:04 UTC
Audit round 3b (read at 80fef076): lines moved. ShellRoute.handle is hub/src/maity_hub/shell.py:463-486, shell_response :489-497. The CLI engine-open copies are now seven: hub/src/maity_hub/cli.py:180-197, 267-276, 293-299, 346-352, 420-426, 446-452, 532-545; _copy_to_s3, _loadtest_purge and _loadtest_seed never dispose their engine.