Follow-up to #497, which deferred these two by agreement rather than folding them into a fix PR. Filing so they are not lost now that #497 has merged.
Both live in services/session_service.py and touch the same function, so they are cheap to do together.
1. N+1 in list_sessions
_enrich_session_ownership calls list_terminals_by_session() once per tmux session (session_service.py:132). On a shared cao-server with many sessions and frequent polling (web UI, ops tooling) that is per-session DB churn on a hot read path.
Suggested fix: fetch once via list_all_terminals() and group by tmux_session before enriching.
Raised by @gutosantos82 and by Copilot during the #497 review. Note #497 reduced the subprocess half of this — the persisted working_directory means the pane-cwd fallback now only fires for pre-migration rows — but the per-session query remains.
2. exc_info on the two swallowed-exception logs
session_service.py:134 and :160 log recoverable failures with an f-string and no exc_info, so the traceback is dropped and a DB or backend problem cannot be diagnosed without reproducing locally. The surrounding code deliberately swallows these to keep list_sessions from blanking, which is right — but the diagnostic should survive.
Suggested fix: lazy formatting plus exc_info=True, matching the repo's logging style for recoverable errors.
Raised by Copilot during the #497 review.
Happy to take both if useful.
Follow-up to #497, which deferred these two by agreement rather than folding them into a fix PR. Filing so they are not lost now that #497 has merged.
Both live in
services/session_service.pyand touch the same function, so they are cheap to do together.1. N+1 in
list_sessions_enrich_session_ownershipcallslist_terminals_by_session()once per tmux session (session_service.py:132). On a sharedcao-serverwith many sessions and frequent polling (web UI, ops tooling) that is per-session DB churn on a hot read path.Suggested fix: fetch once via
list_all_terminals()and group bytmux_sessionbefore enriching.Raised by @gutosantos82 and by Copilot during the #497 review. Note #497 reduced the subprocess half of this — the persisted
working_directorymeans the pane-cwd fallback now only fires for pre-migration rows — but the per-session query remains.2.
exc_infoon the two swallowed-exception logssession_service.py:134and:160log recoverable failures with an f-string and noexc_info, so the traceback is dropped and a DB or backend problem cannot be diagnosed without reproducing locally. The surrounding code deliberately swallows these to keeplist_sessionsfrom blanking, which is right — but the diagnostic should survive.Suggested fix: lazy formatting plus
exc_info=True, matching the repo's logging style for recoverable errors.Raised by Copilot during the #497 review.
Happy to take both if useful.