HERMES-GIELIE/api
Konstantin M 31cb8b4e01 perf(webui/session-load-latency) tier2a: cache profile config.yaml parse
_read_profile_model_config() fires on every chat-open that hits the
resolve_model=1 path (one of the 3 calls in the chat-open waterfall).
For sessions under a named profile (non-default), the function
performs:
  - 1× os.path.isfile() call
  - 1× open() of config.yaml
  - 1× yaml.safe_load() of the full file

On a Celeron N3350 with eMMC the open+safe_load alone is single-digit
ms per call, repeated on every chat-open. The /api/session 24h log
showed ?messages=0&resolve_model=1 at p50 1514ms with this YAML
parse as one of the dominant costs.

This wraps the parse in a per-process cache:
  - key = (profile_name, mtime, size)
  - value = parsed dict + monotonic timestamp
  - TTL 60s as a backstop for filesystem mtime resolution issues
  - cap 32 entries (bounded; profiles are bounded in practice)

mtime+size auto-invalidates on edit. The TTL only fires when mtime
resolution is too coarse to detect a same-second write; in normal
operation, every config edit lands as a different mtime and the next
chat-open rebuilds the cache entry.

Threading: a single Lock guards the dict. yaml.safe_load is the slow
step, not the lock, so contention is bounded. The lock is held for
microseconds on hit and milliseconds on miss (parse).

Field-semantics check: the function's signature is unchanged
((provider, default, config_dict) tuple) and the only call sites
(_resolve_effective_session_model_for_display and its sibling)
treat it the same as before. The cache stores the parsed dict;
the function still does the per-call (provider, default) extraction
inline so the tuple's content is identical to the pre-patch path.

No public API change. No behavior change observable other than
faster chat-open for sessions under named profiles.
2026-07-08 22:39:09 +00:00
..
__init__.py
agent_health.py fix(health): send Bearer auth on remote /health/detailed probe (#5418) 2026-07-02 16:24:39 +00:00
agent_sessions.py fix(sessions): open state.db read-only for lineage reads + watcher projection 2026-07-08 20:17:45 +00:00
auth.py fix(#5578): stop login next= param from nesting into itself and exploding the URL 2026-07-05 00:12:19 +00:00
auth_oidc.py fix(#3825): harden oidc endpoint and claim validation 2026-06-30 20:59:19 -04:00
background.py
background_process.py fix(bg): serialize daemon-thread start under a lifecycle lock 2026-07-08 20:58:18 +00:00
clarify.py stage #4524: clarify 409-terminal (id-guarded, loading-cleared) + SSE-notify on expiry (#4504) + v0.51.534 CHANGELOG 2026-06-20 05:36:56 +00:00
commands.py fix(webui): guard non-dict resolve_moa_preset result in resolve_moa_config 2026-07-01 07:54:48 -05:00
compression_anchor.py Address compaction marker and redaction review 2026-06-26 00:12:09 +00:00
compression_recovery.py Live Stream: add compression recovery action 2026-07-04 21:42:32 +08:00
config.py fix(mcp): preserve config overrides for profile reads (#5619) 2026-07-08 16:18:52 +00:00
crash_visibility.py fix(webui): crash visibility — faulthandler + thread excepthook + exit audit (#4633) 2026-07-01 18:01:39 +00:00
dashboard_probe.py
extensions.py fix: prefer IPv4 for extension gallery downloads to prevent timeout on broken IPv6 2026-07-03 20:26:18 +00:00
gateway_chat.py fix(#5564): mint stable per-message ids so large-session forks align 2026-07-04 22:46:56 +00:00
gateway_restart.py fix(health): preserve restart failure contract and proofs (#5156) 2026-06-29 03:44:06 +00:00
gateway_watcher.py fix(sessions): open state.db read-only for lineage reads + watcher projection 2026-07-08 20:17:45 +00:00
goals.py
helpers.py fix(redaction): memoize deterministic API response redactor 2026-06-29 18:22:18 +00:00
kanban_bridge.py rebase(#2814): resolve i18n onto current master + add kanban_view_* keys to all 13 locales 2026-06-23 23:40:45 +00:00
metering.py
models.py perf(webui/session-load-latency) tier1a: cheap-first freshness check in _cached_session_lags_disk 2026-07-08 22:39:08 +00:00
oauth.py
office_documents.py #5142: office-doc preview + safe docx editing (#540), rebased on master; optional deps 2026-07-02 01:15:57 +00:00
onboarding.py feat(#3260): self-hosted provider setup (Ollama/LM Studio) in Settings (i18n complete) 2026-07-02 08:17:44 +00:00
passkeys.py
paths.py
plugin_providers.py
plugins.py
profiles.py fix(#5696): revert profiles cache TTL 60s->4s (stale profile rows); contributor-flagged follow-up 2026-07-06 20:40:08 +00:00
providers.py feat(#3260): self-hosted provider setup (Ollama/LM Studio) in Settings (i18n complete) 2026-07-02 08:17:44 +00:00
request_diagnostics.py perf(webui/session-load-latency) tier2c: per-stage breakdown on /api/session 2026-07-08 22:39:09 +00:00
rollback.py
route_approvals.py fix(#5000): relay mirrored gateway approvals after stream loss 2026-06-27 06:03:24 +00:00
route_session_list_cache.py feat: add Webhooks sidebar filter parity 2026-06-30 17:06:31 +00:00
routes.py perf(webui/session-load-latency) tier2a: cache profile config.yaml parse 2026-07-08 22:39:09 +00:00
run_journal.py Fix run-journal writer-lock cache leak on session delete 2026-07-08 21:13:32 +00:00
runner_client.py fix(gateway): correct approval URL and thread session history into runs API (#4479) 2026-06-19 13:16:39 -04:00
runtime_adapter.py
session_discoverability.py
session_events.py
session_export_html.py #4968: export chat to self-contained themed HTML, rebased on master 2026-07-02 02:36:09 +00:00
session_lifecycle.py fix(#5543): fire-and-forget commit_session_memory + drain-safe managed stop 2026-07-04 21:40:21 +00:00
session_ops.py fix(#5563): align forked context to display for large (compacted) sessions 2026-07-04 20:55:06 +00:00
session_recovery.py Merge latest master into compression recovery action 2026-07-05 10:23:15 +08:00
skill_usage.py
sse_chunked.py stage #4447: opt-in chunked SSE for buffering proxies (#4447) + v0.51.524 CHANGELOG 2026-06-19 22:09:17 +00:00
startup.py
state_sync.py fix(state-sync): mirror WebUI API call counts 2026-07-07 19:48:19 +00:00
streaming.py fix(state-sync): mirror WebUI API call counts 2026-07-07 19:48:19 +00:00
system_health.py fix: keep psutil optional for system health 2026-06-26 20:49:13 +00:00
terminal.py
todo_state.py
turn_journal.py
updates.py fix: drop auto-delete; manual-instruction only (PR #5688 round-3) 2026-07-06 19:02:16 +00:00
upload.py fix(auth): enforce active-profile session IDs 2026-06-30 04:28:15 +00:00
usage.py
webui_session_db.py fix: preserve compression recovery child markers in sidecar rebuild 2026-07-05 06:45:50 +08:00
workspace.py #5142: office-doc preview + safe docx editing (#540), rebased on master; optional deps 2026-07-02 01:15:57 +00:00
workspace_git.py fix(workspace-git): hide git subprocess console windows on Windows (#5692) 2026-07-07 02:07:39 +00:00
worktrees.py