The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: code-health ratchet findings on the due-check change
alt-glitch94f7a56f97a1
diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/lifecycle.ts b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/lifecycle.tsindex d7a09c47604..a297b0b6005 100644--- a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/lifecycle.ts+++ b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/lifecycle.ts@@ -24,22 +24,25 @@ import { ingestBackendSkin } from '@/themes/backend-sync'import type { GatewayEventContext } from './types'+function onGatewayReady(ready: GatewayEvent<'gateway.ready'>['payload'], activeSource: boolean): void {+ // Seed the active skin into the desktop theme registry without applying,+ // so a fresh connect never overrides the user's persisted desktop theme.+ ingestBackendSkin(ready?.skin, { apply: false })+ // Backends with the change watcher broadcast pet/cron/sessions change+ // events; consumers demote their legacy polls to slow backstops.+ setChangeEventsAvailable(Boolean(ready?.change_events))++ if (activeSource) {+ noteGatewayReady() // the onboarding due check counts its way-out budget from here+ }+}+/** gateway.ready / setup.ready / skin.changed / change-watcher broadcasts / session.reclaimed. */export function handleLifecycleEvent(ctx: GatewayEventContext): boolean {const { deps, event, payload, fromActiveSource } = ctxif (event.type === 'gateway.ready') {- const ready = (event as GatewayEvent<'gateway.ready'>).payload- // Seed the active skin into the desktop theme registry without applying,- // so a fresh connect never overrides the user's persisted desktop theme.- ingestBackendSkin(ready?.skin, { apply: false })- // Backends with the change watcher broadcast pet/cron/sessions change- // events; consumers demote their legacy polls to slow backstops.- setChangeEventsAvailable(Boolean(ready?.change_events))-- if (fromActiveSource()) {- noteGatewayReady()- }+ onGatewayReady((event as GatewayEvent<'gateway.ready'>).payload, fromActiveSource())return true}diff --git a/hermes_cli/auth.py b/hermes_cli/auth.pyindex eee16ca34a2..243fae4bbf6 100644--- a/hermes_cli/auth.py+++ b/hermes_cli/auth.py@@ -1707,18 +1707,15 @@ def resolve_provider(# below explicit keys and below the free tier.try:from agent.bedrock_adapter import has_aws_credentials- from hermes_cli.anon_auth import on_local_desktop_backend- # The desktop's own backend runs on the user's computer, where the EC2 metadata lookup only- # costs its timeout on every cold resolve.+ from hermes_cli.anon_auth import on_local_desktop_backend # a laptop: no EC2 metadata lookupif has_aws_credentials(instance_metadata=not on_local_desktop_backend()):return "bedrock"except ImportError:pass # boto3 not installedfrom hermes_constants import display_hermes_homeraise AuthError(- "Hermes is not connected to any AI provider yet. Run `hermes model` to pick one, type "- "`/login` in chat, or add a key with "- f"`hermes auth add <provider>`. (Advanced: put an API key such as OPENROUTER_API_KEY in "+ "Hermes is not connected to any AI provider yet. Run `hermes model` to pick one, type `/login` in chat, "+ f"or add a key with `hermes auth add <provider>`. (Advanced: put an API key such as OPENROUTER_API_KEY in "f"{display_hermes_home()}/.env.)",code="no_provider_configured")diff --git a/hermes_cli/web_server.py b/hermes_cli/web_server.pyindex fd00ee0fdd7..5fad79374b1 100644--- a/hermes_cli/web_server.py+++ b/hermes_cli/web_server.py@@ -186,7 +186,7 @@ def _probe_install_before_state_db() -> None:from hermes_cli.install_state import probeprobe()- except Exception: # onboarding.state probes again on demand+ except (OSError, ValueError): # what the probe's own guards leave; onboarding.state probes again_log.warning("first-install check at boot failed", exc_info=True)diff --git a/tui_gateway/methods_onboarding.py b/tui_gateway/methods_onboarding.pyindex 12e81740c1a..4cf702fe71f 100644--- a/tui_gateway/methods_onboarding.py+++ b/tui_gateway/methods_onboarding.py@@ -104,6 +104,20 @@ def _active_run() -> dict:return {"session_id": session_id, "run_id": (load(db, session_id) or {}).get("run_id") if session_id else None}+def _claim_after_record(db, stored: str, scope: dict, *, assume_fresh: bool):+ """Claim the welcome trial for a run whose record (and ``onboarding.run: true``) is already on disk,+ so a crash after the claim makes this machine read as used still opens onboarding next launch. A+ refused claim deletes the run it was for and re-raises (error 5079): no guest and no chat."""+ from hermes_cli.auth_constants import AuthError+ from hermes_cli.welcome_trial import claim_desktop_free_tier+ try:+ with _session_profile_runtime_scope(scope):+ return claim_desktop_free_tier(assume_fresh=assume_fresh)+ except AuthError:+ _discard_unfinished_runs(db, [stored])+ raise++@method("onboarding.start")def _(rid, params: dict) -> dict:from agent.onboarding_facts import read_facts@@ -112,7 +126,6 @@ def _(rid, params: dict) -> dict:from agent.onboarding_text import CHAT_TITLE, opening_promptfrom hermes_cli.auth_constants import AuthErrorfrom hermes_cli import free_tier_bootstrap- from hermes_cli.welcome_trial import claim_desktop_free_tier# The app's once-per-launch start: closing the app mid-run does not count, so that run's chat goes# and the run starts over. A second window or a reconnect sends no flag and gets the run back.fresh_launch = bool(params.get("fresh_launch"))@@ -135,16 +148,8 @@ def _(rid, params: dict) -> dict:stored = db.create_session(new_session_id(), "desktop")# The record exists before the agent is built, so the build folds the onboarding toolset in.start(db, stored, facts)- if not params.get("rerun"):- # After the record: onboarding.run is on disk before the claim makes this machine- # read as used, so a crash in between still opens onboarding on the next launch.- # A rerun never claims: it runs on the configured model.- try:- with _session_profile_runtime_scope(scope):- claimed = claim_desktop_free_tier(assume_fresh=bool(params.get("assume_fresh")))- except AuthError:- _discard_unfinished_runs(db, [stored]) # a refused claim leaves no chat behind- raise+ if not params.get("rerun"): # a rerun never claims: it runs on the configured model+ claimed = _claim_after_record(db, stored, scope, assume_fresh=bool(params.get("assume_fresh")))else:facts = Facts.from_stored(load(db, stored)["facts"])run_id = load(db, stored).get("run_id") or ""