A scheduled heartbeat muted interim messages by rewriting the turn's display
settings, and the agent build read that muted value to freeze the session's
delegation mode. Heartbeats run under the user's session key, so on a cold
agent cache a heartbeat built (and cached, and pinned) an inline agent for an
interim-on chat, and the user's later turns ran inline. The heartbeat rewrite
no longer touches interim: TurnRunner already drops interim messages for a
heartbeat turn, and the TurnContext keeps the chat's configured value, which
is what a fresh agent's delegation.gateway_mode reads.
A fresh agent restored its session's tools[] pin (schema bytes) but kept the
build-time inline flag, so the next rebuild from fresh definitions
(compaction boundary, /reload-mcp, Bot Chat refresh) re-derived the other
variant and flipped the chat mid-conversation. restore_agent_tool_prefix now
re-freezes the flag from the restored delegate_task, making the pin
authoritative.
Docs: inline turns past the notify interval still get the long-running
notice (display.long_running_notifications); the stability sentence now
names compaction, /reload-mcp and heartbeats, and the post-update exception;
a deferred delegate_task (tool_search.defer) stays background.
Tests: heartbeat-first turn with an agent cache (interim on stays
background, control, interim off stays inline), a composed cell with agent
cache + real SessionDB pin + heartbeat + restart, and pin restore followed by
a compaction or /reload-mcp refresh in both directions.
On a messaging chat with display.interim_assistant_messages off, a top-level
delegate_task still produced two messages: a "checks are running, I don't have
the findings yet" reply and, later, the real answer. Top-level model
delegations always run in the background (ea8a8b4af8), and the tool text tells
the model to "give a one-line status and END YOUR TURN" (c89f3b8800). That
status is the turn's final answer, not interim text, so no display setting
held it back.
New key delegation.gateway_mode: auto | inline | background (alias async).
auto (default) joins the children inside the turn on a messaging chat whose
resolved interim setting is off (global, display.platforms.<p> override or
platform default). The parent waits in the tool call, gets the results there
and sends one answer. API, local and webhook surfaces keep the background
path under auto. Chats with interim messages on are unchanged: same schema
bytes, same async dispatch.
How it works:
- The gateway resolves the mode from the turn's own profile-scoped config
when it builds a session's agent (gateway/session_execution.py), and the
agent's first tool build freezes it (like the one-shot pin).
- An inline session carries the joined delegate_task variant the one-shot
path already uses: "results return in this tool call", no live-control
parameters, no END YOUR TURN.
- Dispatch follows the delegate_task schema the session carries
(session_joins_delegation), so schema and behaviour cannot disagree. The
schema rides the session's tools[] pin: a config change applies from the
next session (/new), as delegation.backend does, and a cache eviction or
restart never flips a running chat.
- Inline children run on the existing synchronous path: attached to the
parent, so /stop and an interrupting follow-up stop them; the per-child
heartbeat keeps the parent's activity fresh for the inactivity watchdog;
the async completion registry is not used. Nested and one-shot delegation
are unchanged.
Refs #95522.
Gateway-owned sessions (in-process turns and managed workers alike) got
the runner's prefill examples, loaded once when the daemon started from
the launch profile: a prefill_messages_file path or file edited after
that never reached a new session. On pre-merge main every `hermes chat`
process read the file once at startup from its own profile.
session_prefill() resolves the path from the session policy's
creation-time config, relative to the session's own profile home. The
file is read by the creation attempt's commit (commit_local_session),
before its write transaction; on the async create paths that runs in
tracked_write's worker thread, not on the owner's event loop. The
snapshot is carried with that creation attempt. It is held in the owning
authority's memory only when that attempt's commit creates the session.
An overlapping retry or a conflicting create never replaces it, and a
refused or failed create (for example a retry of a deleted session) holds
nothing. Other sessions cannot evict it, an edit after creation reaches
only new sessions, and deleting the session releases it. A session this
owner did not create (restored after a gateway restart, or a new branch)
reads the file once on first use and keeps it; main's CLI likewise
re-read it on every start. The in-process agent build and
construct_inputs for managed workers share the snapshot, so both send the
same examples. Bypass sessions still never load the profile's file. The
HERMES_PREFILL_MESSAGES_FILE env precedence is unchanged.
Related open PR, not used: #124630 (re-reads the active profile on every
agent build for multiplexed messaging turns, against the pre-split
layout; does not read the session's frozen config).
Refs #134889 (CFG-7)
Refs #139523
Main's -v built AIAgent(verbose_logging=True, quiet_mode=False): DEBUG logging in the CLI
process plus the agent's verbose status lines on screen. The CLI-side DEBUG logging is
the CLI's own and is unchanged; the agent now lives in the gateway, which always built it
quiet, and the thin client refused -v.
- session.create gains `verbose` (bool; CREATE_FIELDS + CanonicalCreateParams, TS/OpenRPC
regenerated); LocalSessionPolicy.verbose; _build_fresh_agent passes quiet_mode=False for
such a session, so its status prints reach the viewer as agent.print (local turns
already project _print_fn). verbose_logging stays off in the shared gateway process (a
process-wide root DEBUG handler would leak across sessions).
- CLI: HermesCLI sends its -v at session.create.
LEDGER: FLAG-031 (W9).
(cherry picked from commit 3d3f8228e85ca7cee034ceaa5af072ec6d4f21c9)
Main's CLI passed run_budget_seconds to AIAgent (flag over agent.run_budget_seconds):
an 80% wrap-up notice and capped provider timeouts per run. The thin client refused the
flag and the rewired CLI dropped it, so the gateway agent ran with the owner's config.
- session.create gains `run_budget` (CREATE_FIELDS): a positive number, frozen as the
session policy's agent.run_budget_seconds; bool/zero/negative/text are invalid_params.
- LocalSessionPolicy.run_budget_seconds; _build_fresh_agent passes it as
AIAgent(run_budget_seconds=...) for a local session (None keeps the old config read).
- CLI: HermesCLI keeps the explicit flag and GatewaySessionStore sends it at
session.create.
Harness: 39_run_budget_pipe. LEDGER: FLAG-030 (W9).
(cherry picked from commit 1778c1d628acea8d39a81e570eda5ab0be73694a)
Mechanism: under a session authority /api/sessions/{id}/chat runs through
the canonical turn, which builds its agent in session_execution with
fallback_model=_refresh_fallback_model() and re-applies the profile chain to
a reused cached agent, regardless of the admission's confirmed_runtime_lock.
On a primary 429/auth failure a locked turn silently moved to the profile
fallback, and nothing at settlement compared the served runtime with the
lock. Main builds the locked agent with fallback_model=None and refuses a
mismatched turn in _finish_turn_result.
Fix: session_api_turn.api_runtime_locked() names the executing API
admission's confirmed lock. The fresh build passes no fallback chain under
it, a reused agent gets an empty chain, and a cached agent already moved
onto a fallback is evicted and rebuilt. At settlement
(_run_conversation_with_approval) a locked turn runs the adapter's existing
_turn_runtime_metadata: its runtime rides the usage, and a mismatch makes
the stored result a failed turn carrying main's error text.
Red on r12-integ1:
tests/gateway/test_api_model_lock_fallback.py::test_locked_session_chat_does_not_fall_back_to_the_profile_chain
(real daemon + API server; loopback primary 429 insufficient_quota, healthy
loopback backup in fallback_providers; the backup received the locked turn).
tests/gateway/test_api_model_lock_fallback.py::test_locked_turn_served_by_another_runtime_settles_failed
(settlement mismatch refusal).
Review: dokterdok N63
(cherry picked from commit 2baba0cfb0075de5a4aa34fbfaac6e5184d11f29)
Main made the strict ruff config the default (`ruff check .`, blocking), and
the branch's code carried 278 findings under it (main itself is clean). Fixed:
- PLW1510 (86): `check=False` on each subprocess.run, preserving behaviour,
as main's own sweep (0006a5e229) did.
- ASYNC220 (9, test fixtures only): `noqa` with the reason, main's convention
for a Popen that returns at once and whose handle the test drives.
- ruff's safe autofixes plus the narrow unsafe ones (UP006/UP037/RUF100/RUF013/
PLR0402/RUF059 underscore renames/UP031/UP041/UP017/FURB167/PIE807/RUF007/
RUF015/RUF022/FURB162), and by hand: four %-formats to f-strings, three
unused unpacked names, one fixture loop over `.items()`.
No behaviour change. `ruff check .` passes; scripts/check passes; the 412 test
files mirroring every edited file pass (3 tests/pm files that fail only under
that batch's uv lookup pass solo, before and after this commit).
These four launch options had no working path on the canonical gateway. Classic
`hermes chat` refused them and pointed users at `hermes --tui ...`. The Ink TUI sent
them in session.create, but CREATE_FIELDS rejected them (4001 invalid_params at the
canonical contract), and canonicalRequest threw before the session existed.
localCreationOptions read the documented, exported HERMES_ACCEPT_HOOKS=1, so with
that variable set no TUI session could be created at all. HERMES_TUI_PASS_SESSION_ID
was read by nothing and was silently dropped. On main the in-process TUI gateway and
cli.py applied all four, and tests/hermes_cli/test_cli_preloaded_skills.py covered
the -s preload. That test was deleted on the branch with no replacement.
All four options are now creation fields of the session that names them, applied
by the owner:
- skills: rendered once with build_preloaded_skills_prompt (off the owner loop,
only for a new session; a retried request_id resumes the frozen route) and stored
in the frozen LocalSessionPolicy.skills_prompt. The in-process turn appends it to
the ephemeral prompt and the managed worker passes it as ephemeral_system_prompt,
matching the CLI/TUI startup preload. A typo among good names is logged and
skipped, as on main. When no name resolves, creation is refused with unknown_skill.
A bypass (--safe-mode / --ignore-user-config) launch refuses -s because it must
not read the profile.
- checkpoints: folded into the frozen config's checkpoints.enabled, which the
in-process agent already reads through _checkpoint_agent_kwargs(policy config).
The managed worker now passes it too.
- pass_session_id: frozen in the request and passed to AIAgent (in-process and
managed), so "Session ID: <id>" rides the system prompt.
- accept_hooks: consents to the profile's configured shell hooks (per-user
allowlist, off-loop) and registers them on the owner, like the in-process
--accept-hooks. It is a no-op on a bypass launch, so an exported
HERMES_ACCEPT_HOOKS=1 cannot brick --safe-mode.
Classic `hermes chat` is a gateway client too: it forwards the same fields, plus
HERMES_ACCEPT_HOOKS=1 when that variable is exported, instead of refusing them.
The Ink TUI maps HERMES_TUI_SKILLS to a list and the flags to booleans, and the
pipe bootstrap stops leaking HERMES_TUI_CHECKPOINTS/HERMES_TUI_PASS_SESSION_ID into a
spawned daemon. The canonical contract (CanonicalCreateParams plus the generated
TS/OpenRPC) advertises the new fields.
Live proof: a real `python -m gateway.run` daemon on a fake home, a real WS
session.create per field, the real Ink mapping via tsx with HERMES_ACCEPT_HOOKS=1
exported, and a real turn against a loopback model. The skill body and
"Session ID: <id>" reach the model's system prompt, a write snapshots into the
checkpoint store (no snapshot without the flag), and the hook command lands in
the allowlist. A real `hermes chat -Q -q ... -s X --checkpoints --pass-session-id
--accept-hooks` exits 0 with the skill in its prompt. On the base, all of these
were refused with invalid_params, Ink threw, and classic chat exited 2.
Review: https://github.com/NousResearch/hermes-agent/pull/106742#pullrequestreview-5456384314