Commit Graph

3195 Commits

Author SHA1 Message Date
Teknium
38bfb94b5c fix(image_gen): OpenRouter's Grok image row is x-ai/grok-imagine-image-2.0
OpenRouter's Image API catalog (GET /api/v1/images/models) no longer lists
x-ai/grok-imagine-image-quality; it lists x-ai/grok-imagine-image-2.0. Swap
the curated _IMAGE_API_MODELS row, with every knob taken from the live
catalog entry: the same 14 aspect ratios, 1K/2K, n=1, 3 references, plus a
quality enum (low|medium) the old row never declared.

The direct xAI backend keeps grok-imagine-image-quality: xAI's authed
/v1/image-generation-models still serves it.
2026-11-02 07:57:26 -08:00
kshitijk4poor
df128a1cb4 refactor(telegram): read a video note through the video branch at each site
The video-note support added a second, line-for-line copy of the video
branch in _observed_media_source and _handle_media_message, differing only in
the attribute read and the log label. Take `msg.video or msg.video_note` once
in each place instead, keeping the "video note" label for circles, and rejoin
the video_note entry of the _media_message_type table onto the next line.

adapter.py is over the 2,000-line cap, where units may only shrink: this
brings the file back to its origin/main line count (7380), so the PR adds
no lines to it. Behaviour is unchanged; the video and video-note cases of
test_native_video_is_cached and test_reply_to_a_video_note_caches_it still
pass, and each still fails with its branch removed.
2026-11-01 19:35:16 +05:30
kshitijk4poor
840d104031 fix(telegram): an uncaptioned video note keeps the group silence notice
group_reply_expected treats an uncaptioned voice note or audio file as spoken
(its words are not in the message text), so it returns None and the silence
notice stays. Video notes now reach the agent too, and a circle without a
caption is the same case: the question is in the audio. Without this it came
out reply_expected=False, so in a group with require_mention off a spoken
question in a circle could vanish behind a bare silence marker.

Tests: the new video-note row of
test_reply_expected_follows_who_the_group_message_addresses fails without the
change (False != None) and passes with it. Docs updated in the same sentence
that lists voice notes and audio files.
2026-11-01 19:35:16 +05:30
kshitijk4poor
ed960fe960 fix(telegram): localize the download-failure reply for video notes
The video-note branch passes the label "video note" to
_surface_media_cache_failure, which translates the chat reply through
_MEDIA_KIND_KEYS. The label had no entry there, so a German or Japanese user
whose circle failed to download got a translated sentence with the English
words "video note" in it. Map it to the existing kind_video key ("video file"
in every catalog). The agent-visible note keeps the English "video note".

Scope: no new catalog key; a circle is reported as a video file in the reply,
which every locale already translates.

Test: test_video_note_failure_reply_is_localized (added with the test fold
later in this stack) fails with this entry removed.
2026-11-01 19:35:16 +05:30
Horizont367
016bc1df65 feat(telegram): support video note messages 2026-11-01 19:35:16 +05:30
kshitijk4poor
94bd083712 fix(mattermost): tidy the user-ID setup hint and move the plugin test
Follow-up to the cherry-picked setup-text fix (salvage of #147215).

- Wizard step 4 and the plugin's security hint now share the same lines.
  Before this they had drifted: only the wizard said where on the page
  the ID is. Step 4 now says what the step is for instead of opening
  with "the profile dialog does not show your user ID".
- Add a route for non-admins: a logged-in browser tab can open
  /api/v4/users/me with its session cookie and get the user's own ID.
  Mattermost reads the session cookie on API requests and only checks
  CSRF on non-GET requests, so a plain GET works.
- The allowlist help text points back at step 4 again rather than
  repeating one of the lookups.
- Docs (en + zh-Hans): indent the curl block under its list item so the
  list no longer splits in two, add the browser route, note that
  `mmctl user list` needs `--all` past 200 users, and use the canonical
  docs URL (the .html form redirects).
- Move the plugin setup test into tests/gateway/test_mattermost_plugin_setup.py
  next to the existing plugin setup tests and its _patch_setup_io helper,
  so it no longer writes a real .env. Drop the assertions that pinned the
  new wording; keep the ones that pin the old, wrong advice and the two
  documented lookups.

Both setup tests fail on origin/main and pass here.
2026-11-01 19:24:04 +05:30
xxxigm
4e89a6d585 fix(mattermost): stop sending setup to a profile dialog that has no user id
Mattermost documents the id on the System Console user page and on
GET /api/v4/users/username/<username>. /users/me with the bot token is the bot.
2026-11-01 19:24:04 +05:30
Teknium
ab8bd7ba4f docs(teams): correct which cards carry the command in their button data
Only cards sent by an older build carry cmd/desc in the button data; cards from
this build carry just the prompt id.
2026-10-31 22:19:18 -07:00
Teknium
ce0602e8a9 fix(telegram): catch NetworkError, not TelegramError, after a kept-prompt edit fails
TelegramError is absent from the shared Telegram test stubs, so the import
broke test_slash_confirm_forum_callback_followup_keeps_existing_thread_behavior
with an ImportError. NetworkError covers the same transient cases (timeouts
and network failures subclass it in python-telegram-bot); BadRequest is still
caught first and keeps the decision-only fallback.
2026-10-31 22:19:18 -07:00
Teknium
44678e5647 fix(telegram): network error on a resolved-prompt edit keeps the prompt
Review nit: edit_keeping_prompt suppressed every exception and fell back to the decision-only text, so a transient network error after an edit that went through replaced the kept prompt. Only a BadRequest falls back now.
2026-10-31 22:19:18 -07:00
Teknium
631b00c3f6 refactor(feishu): shared card sender no longer parses approval text
Review finding: _send_interactive_card read card elements and stripped the approval deadline line on every card, including update-prompt cards. _send_exec_approval_prompt now builds the stored body from prompt.text and passes it as extra state.
2026-10-31 22:19:18 -07:00
Teknium
288c0c1cae fix(teams): approval card stays under the size cap for long non-ASCII commands
Review finding: every button's data carried the 2000-char command preview, so a long CJK command made a ~30 KB card, over Teams' ~28 KB limit, and the send fell back to the plain-text prompt. The preview now stays in the adapter keyed by a per-prompt id (bounded to 256 entries); the buttons carry only that id. Cards sent before a restart still read cmd/desc from their button data.
2026-10-31 22:19:18 -07:00
Teknium
02a790293d fix(gateway): timed-out and resolved approval cards keep the full request
- Timeout edit: the card now keeps why the command was flagged next to the
  command (the reason was dropped; the command was already kept).
- Teams: button data carries the card's own command preview instead of a
  200-char stub, so a resolved or expired card shows the whole command.
- Telegram, Slack and Feishu resolved cards drop the "If you don't answer
  within N minutes it will NOT run" line, which no longer applies once
  someone decided (Teams never carried it; timed-out cards already replace
  the body).
2026-10-31 22:19:18 -07:00
Teknium
92c86afb1f fix(gateway): resolved approval cards keep the request on Telegram, Feishu and Teams
Clicking a button on an approval card replaced the whole message with only
the decision ("✅ Approved once by Ana"), so a shared chat lost the record
of WHAT was approved. Discord and Slack already kept the body.

- Telegram: exec-approval and slash-confirm resolutions keep the prompt's
  own rendering (Message.text_html rebuilds it from the entities, code
  block included) and append the decision; a prompt with no readable body,
  or one the appended line pushes past the length cap, still gets the
  decision alone so the buttons never stay live. New sibling module
  telegram_resolved_prompt.py; the adapter facade does not grow.
- Feishu: the card body is kept in the per-card state at send time and
  rendered above the decision on the replacement card.
- Teams: a click after the approval ended replaced the card with only
  "expired"; it now keeps the command and reason like the resolved card.
2026-10-31 22:19:18 -07:00
Teknium
95d0629df4 fix(photon): a misshapen lines payload keeps the iMessage line lookup best-effort
The lookup moved before the opt-in wait and its except was narrowed; an
unexpected `lines` shape then raised AttributeError and aborted setup before
access was configured. Catch AttributeError/TypeError again, as main did.
2026-10-31 22:09:38 -07:00
Teknium
ce02e4686d fix(photon): photon status routing row gives up after 5 s on an unreachable API
The live opt-in row reused list_users' 30 s timeout, so a black-holed API stalled
`hermes photon status` (previously offline-only) for 30 s. Thread a timeout through
list_users/find_user_by_phone and use 5 s for the status row only.
2026-10-31 22:09:38 -07:00
Teknium
a97f13ff3f fix(photon): setup without a phone number ends on saved-not-live, not "complete"
routing_live defaulted to True, so skipping the phone prompt still printed
"Photon setup complete. Start the gateway" although nothing can route. Start from
False (only an opted-in number flips it) and give the no-phone path its own ending
naming the command that finishes setup.
2026-10-31 22:09:38 -07:00
Teknium
9bc94eb21d fix(photon): look up the iMessage line before the opt-in wait; skip the wait when there is none
A user row without assignedPhoneNumber started a 5-minute wait that told the user only
"text the line Photon assigns": the dedicated-line lookup ran after the wait. Look the
line up first; with still no line, skip the wait and say how to finish (text the line
once it shows up, then `hermes photon status`).
2026-10-31 22:09:38 -07:00
Teknium
d47a49d46c fix(photon): setup only says "complete" once the number can route; bound the opt-in wait
The opt-in step let setup end on "✓ Photon setup complete" even when the
wait timed out, was interrupted with Ctrl-C, or was skipped on a non-TTY
run, so the user was told to start the gateway for a number Photon still
refuses ("Target not allowed for this project").

- setup: when the number is not opted in, the closing line says the setup
  was saved but routing is NOT live, names the line to text, and points at
  `hermes photon status`; exit code stays 0 (config was written).
- wait_for_opted_in_user: add a wall-clock deadline next to the attempt
  cap, so slow list calls (30 s HTTP timeout each) cannot stretch the
  advertised 5-minute wait to half an hour.
2026-10-31 22:09:38 -07:00
Teknium
5d9b27cd23 feat(photon): gate setup success on iMessage opt-in via first message
Photon's delivery plane only routes numbers whose user row carries
meta.opt_in, and that flag is set server-side when the human sends ONE
message from their phone to the row's assignedPhoneNumber. A registered
row without it looks configured everywhere but never sends or receives:
outbound fails with 'Target not allowed for this project'. Client-supplied
meta is ignored on create, so the API cannot produce the flag.

- auth.py: user_opted_in(), find_routable_user() (an opted-in duplicate
  wins over list order; find_user_by_phone uses it, so setup re-runs and
  status refreshes reuse the routable row), wait_for_opted_in_user() poll
  (rides out transient list failures).
- cli.py setup step [4/5]: prints the assigned line to text and waits for
  the opt-in to land (Ctrl-C skips; non-TTY runs skip the wait).
- status: live 'routing' row (opted in / not opted in, with the line to
  text), emitted from auth.py like the credential summary.
2026-10-31 22:09:38 -07:00
Teknium
3a73078f3a feat(slack): show emoji reactions in thread context
In channels where people answer by reacting instead of replying, the
thread-context block the agent sees on a cold start dropped reactions, so a
message with twelve check-marks and no replies read as "nobody responded".

conversations.replies already returns each message's reactions array under
the history scopes the adapter requires: no extra API call, no new scope.
Each context line now ends with a compact marker such as
"[reactions: ✅x12 👀]" (up to 8 distinct emoji, then
"+N more"). Emoji names are reduced to Slack's emoji-name charset so a
crafted name cannot forge context structure, and the marker stays out of
parent_text, which drives mention wake checks.

The helper lives in the adapter_reactions_context sibling so the adapter
facade only gains the call site. Read-side only: it does not route
reaction_added events (#10583).
2026-10-31 22:08:19 -07:00
kshitijk4poor
c419cf7c86 fix(telegram): replies to a channel or anonymous-admin post keep the notice
Telegram fills from_user with a service account (777000 for a linked
channel's auto-forward, GroupAnonymousBot for an anonymous admin) and sets
sender_chat on posts signed by a chat. Those counted as replies to another
member, so in a discussion group with require_mention off a question
commenting on a channel post (including the bot's own channel's post) came
out reply_expected=False and could vanish behind a bare silence marker. A
reply to a chat-signed post is now treated like a reply to an unknown author
(None, the notice stays). Only a reply to another known member is chatter.

_replies_to_other_member had a single caller whose earlier branches already
settle its reply-to-bot and unknown-author checks, so the reply decision is
now one branch in group_reply_expected; _quoted_reply gains its return type.
Behaviour for every existing test row is unchanged.

Tests: the channel auto-forward and anonymous-admin rows fail on the previous
commit and pass here (68 passed with test_telegram_thread_fallback.py).
2026-10-31 15:33:49 +05:30
kshitijk4poor
61794f3f17 fix(telegram): a reply to an unknown author keeps the notice without a "?"
A group reply whose quoted message has no from_user was not counted as a
reply to another member, but then fell through to the chatter rule, so a
statement like "agreed" came out reply_expected=False and a bare silence
marker sent nothing. The Telegram docs (and the WhatsApp rule in #133672)
promise the notice whenever the quoted author is unknown. Such replies now
return None before the chatter rule. The forum-topic-root check moves into a
small _quoted_reply helper both paths share; reply-to-bot and topic-root
behaviour is unchanged.

Found by the automated review on this PR. Test: the new statement row fails on
the previous commit and passes here; the existing "agreed?" row passed on both
because the question rule hid the gap.
2026-10-31 15:33:49 +05:30
kshitijk4poor
5bb0e7d87d fix(telegram): uncaptioned voice notes and audio files keep the silence notice in groups
group_reply_expected judges the message text or caption, and a voice note or
audio file without a caption has none: no "?", so it came out
reply_expected=False. In a group with require_mention off, a spoken question
to the bot could then vanish behind a bare silence marker. Voice and audio
without a caption now return None (the notice stays); a captioned one is
judged by its caption, and photos, stickers, documents and locations are
unchanged.

Tests: the voice-note and audio-file rows fail on the previous commit and pass
here; the captioned-voice and uncaptioned-photo rows are controls.
2026-10-31 15:33:49 +05:30
Diego Sánchez
e97cdd16fe fix(telegram): match the WhatsApp rule on unknown reply authors and indented commands
Review follow-ups from a standards audit:
- A reply whose quoted author is unknown is no longer treated as a reply to
  another member, so a question there keeps the notice, as in #133672.
- A command with leading whitespace counts as addressed to the bot, matching
  how the gateway parses commands.
- _merge_into_pending keeps the original seed semantics (get/None) instead of
  setdefault, while staying at the adapter's line cap.
- The photo-batch test now runs the merged turn through the runner's delivery
  path: unaddressed silence is not sent, the addressed batch gets the notice.
- Docs note the unknown-identity, unknown-author and forum-root cases.
2026-10-31 15:33:49 +05:30
Diego Sánchez
dc6519da4a fix(telegram): let a silence marker stand on group messages not addressed to the bot
The Telegram adapter never set MessageEvent.reply_expected, so silence_allowed()
always saw None and every bare [SILENT] / NO_REPLY on a group message became the
"returned only a silence marker" notice, posted to the whole group (#120051).

group_reply_expected (telegram_context.py) sets the per-message signal from #123271,
with the same rule the WhatsApp adapter gets in #133672:
- True for DMs and for a group message addressed to this bot: @mention, reply to
  the bot, wake word (mention_patterns) or /command, in text or a caption. The
  #110952 fallback stays.
- False for a group message addressed to someone else (a reply to another member,
  or one that opens by @mentioning someone else) and for plain chatter. A forum
  topic's root anchor is not a reply to a person.
- None for channel posts, an unknown bot identity, and an unaddressed message with
  a "?", which may be a question for the bot.

Photo bursts and albums merge through absorb_reply_expected, so a batch that
includes a photo addressed to the bot stays True.
2026-10-31 15:33:49 +05:30
Jeffrey Quesnelle
50d2adf1cd Merge pull request #146715 from NousResearch/fix/credential-stores-top-level
fix(secrets): move secret caches and the Photon token to the profile home root
2026-10-30 23:49:30 -04:00
emozilla
f413c2ee9a fix(secrets): delete old secret-store copies instead of moving them
The agent can write cache/ and runtime/, so a file there may be a link or a
forged record. Hermes now deletes a Bitwarden or 1Password cache in cache/, or
a Photon sidecar record in runtime/, on first use without reading it, and
reads and writes only the copy at the top of the profile home. All four stores
are regenerated on use.

- Remove utils.adopt_legacy_file and the paths built on it.
- home_data_layout: split SECRET_CACHE_STORES into SECRET_CACHE_FILES and
  LEGACY_SECRET_CACHE_PATHS.
- Backups leave out the four top-level names; the old slashed entries never
  matched a root entry.
- The dashboard Files API takes its hidden names from the shared list.
2026-10-30 13:46:07 -04:00
Ben Barclay
e924f75176 fix(redact): the log formatter reads no config
RedactingFormatter resolved a routed profile's redaction policy per
record from config, under the logging handler's lock. It now reads only
in-memory state: the live secret scope, and the policy recorded when that
profile's .env or config is loaded, or when log routing is set up for it
(resolve_profile_policy). Unknown means redact, the secure default.

This removes load_config_readonly_nowait() and the no-boot read scope.
2026-10-30 11:13:02 -04:00
Ben Barclay
8ae88edc8a fix(redact): the log formatter never waits for config
RedactingFormatter reads a routed profile's redaction policy from config
while holding the logging handler's lock. A thread holding _CONFIG_LOCK
(for example one booting a remote profile) that logs then waits for the
handler lock: a lock-order cycle. On the booting thread itself the read
re-entered the boot and ConfigBackendUnavailable escaped the formatter.

load_config_readonly_nowait() returns None instead of waiting: when
_CONFIG_LOCK is held by another thread, or when the read would start a
remote boot fetch (config_backend.without_boot()). The formatter then
redacts (the secure default) and does not cache that answer.

The remote backend's lock-order tests move to their own file.
2026-10-30 11:13:02 -04:00
Ben Barclay
3c88843c81 fix(remote-config): resolve the credential before the fetch lock, never log under a backend lock
The profile's boot fetch resolved its bearer while holding the per-profile
fetch lock. Resolving the Nous token can import hermes_cli.auth, so the
lock was held across a module import (and its import lock).

- Each boot attempt resolves the bearer holding no backend lock, then
  takes the fetch lock only for the GET; waiters share its result.
- Messages produced under the fetch lock or a profile's state lock are
  collected and logged after release: a log handler can read config.
- A same-thread re-entry into a profile's own load raises
  ConfigBackendUnavailable at once instead of waiting on itself.
2026-10-30 11:13:02 -04:00
kshitijk4poor
606b83456b fix(discord): release the /model picker once it is answered
A switch or cancel in the Discord /model picker set `resolved` but never
called `stop()`. discord.py kept the view registered and its 120 s timeout
running, and when that timeout fired it replaced the "Model Switched" or
"cancelled" card with "Selection expired — no model change" (#143851).
Since #145948 the other prompt views stop when answered, and
ChoicePickerView already did.

`_switch_selected_model` and `_on_cancel` now call `self.stop()` as soon
as they set `resolved`, before any await. A slow switch therefore can't
run into the timeout, and the view leaves discord.py's store at once.
The `on_timeout` guards from the previous commit still handle a timeout
discord.py had already queued when the click landed (stop() can't cancel
that task); both now carry a comment saying so.

Test: the two picker answers join `test_answered_view_is_released`, which
asserts the view is finished.

Fix proposed in #143851 by @jimstratus; the same guard was first
submitted in #69685 by @tuancookiez-hub.

Co-authored-by: Jim Stratus <116782964+jimstratus@users.noreply.github.com>
2026-10-30 11:24:44 +05:30
oddtazz
6abdd20449 fix(discord): keep the resolved footer when a prompt view times out
A Discord button view keeps running its timeout after a click resolves it.
_HermesView.on_timeout and ModelPickerView.on_timeout did not check
`resolved`, so the timeout overwrote the "Approved/Denied by ..." footer
(or the switched-model embed) with "expired" on a prompt that was already
answered. ChoicePickerView already had this guard; this applies it to the
base view (slash-confirm, update, clarify) and the model picker.

Move _resolve_exec_approval_admin_gate into adapter_config_readers.py
(re-exported from adapter.py) to offset the facade's line growth.

[Salvage, rebased onto main: since #145948 slash-confirm, update and clarify
stop() when answered, and the exec card has its own on_timeout (retire,
guarded by _backend_settled), so its test case is dropped. The base guard
still covers a timeout discord.py dispatched in the same tick a click
landed: stop() cannot cancel an on_timeout task that is already queued.]
2026-10-30 11:24:44 +05:30
emozilla
2bed5b2258 fix(secrets): move secret caches and the Photon token to the profile home root
The Bitwarden and 1Password disk caches (bws_cache.json, bws_cache.enc.json,
op_cache.json) and the Photon sidecar runtime record (photon-sidecar.json) now
live directly in the profile home instead of cache/ and runtime/. A sandbox
that hides credential files by path can only hide them safely at the top of
the home: the agent can rename a folder it writes, such as cache/ or runtime/,
and read a hidden file below it at the new path.

The first read moves a copy from the old path with a rename, so the file keeps
its permissions. When both copies exist, Hermes removes the old one; when the
move fails, Hermes keeps reading and writing the old copy, so only one copy is
ever live. Clearing a cache or deleting the record removes both locations.

SECRET_CACHE_STORES in hermes_cli/home_data_layout.py lists these stores at
both locations, and every guard that keeps a list of credential stores uses
it: PROFILE_CREDENTIAL_PATHS (profile export and distribution), the file
tools' read and write denies, and the gateway's media-delivery deny. The
1Password cache was missing from all of them. The dashboard Files API blocks
the new basenames, backups leave the top-level stores out, and the flat-install
.gitignore ignores them.

A new test takes each store's path from its writer and checks that every guard
covers it at the current and the old location.
2026-10-29 22:21:46 -04:00
kshitijk4poor
a74843a203 chore(process): the ddgs and WhatsApp comments match the code again
Review (nits 5, 10): the ddgs worker's marker and comment said its 30 s cap kills the worker's
group; _terminate_and_reap signals the worker pid only. The WhatsApp adapter still described
adopting a crashed gateway's bridge, which no longer survives its gateway (it is spawn_owned);
adoption now only meets a bridge a pre-update gateway or another process left, and needs no
re-pair. Comments only.
2026-10-29 16:58:09 +05:30
kshitijk4poor
86488a3c8f fix(raft): disconnect no longer sleeps on the event loop waiting for a bridge child to go
Review (W6): RaftAdapter._stop_bridge runs from async disconnect() and ended with
release_process_group_once_empty at its default 1 s timeout, against the API's own rule
(timeout=0 for async callers). proc.terminate() signals only the leader, so any child left in the
bridge's group made disconnect stall the loop for the full second (main: 0 s). It now probes once
(timeout=0), like the WhatsApp adapter and LSP; a group with a live member stays covered either
way. The dashboard's WhatsApp pairing stop runs on the event loop too and gets the same.

Test: stopping a bridge whose helper survives TERM returns well under the old 1 s wait and keeps
the group covered; fails with the default timeout.
2026-10-29 16:58:09 +05:30
kshitijk4poor
aae69cfaf4 fix(browser): Windows still stops its harness daemons at exit; a known agent-browser pid is still a group leader
Round-2 review of the exit-path fold:
- Windows records no ownership (_own_harness_daemon is POSIX-only), so the owned-only exit stop
  would have stopped nothing there. stop_owned_harness_daemons stops every driven daemon on
  Windows, as the exit path did before.
- _own_local_daemon keeps its one-syscall group-leader check for an already-owned pid, so a stale
  pid file whose pid was recycled is never treated as the owned daemon.
- The ddgs marker now says the worker runs until its search returns, which is unbounded if primp hangs.
- test_mcp_stdio_init_timeout still patched tools.mcp_tool._get_mcp_stderr_log (dropped in the
  previous commit); the replaced-daemon test uses a reaped child's pid instead of a fixed 4242; the
  two browser kill -9 tests treat macOS's EPERM for a zombie-only group as gone.

cleanup_all_browsers keeps stopping every driven daemon: /browser connect|disconnect call it so the
next call runs on the new endpoint, and a daemon latches its endpoint when it starts
(TestBackendSwapRetargetsDaemons). Its reload of a daemon another Hermes started on the same name
is main's behaviour, unchanged here.
2026-10-29 16:58:09 +05:30
kshitijk4poor
edbb589c60 chore(process): the supervisor refuses a malformed parent pgid; two comments match the code again
- process_supervisor.sh compares every register line with its parent pgid. An empty or non-numeric
  value made each comparison error out and `|| continue` dropped every registration silently; it
  now exits 2 with a message. (Python always passes os.getpgid(0), so this is robustness, not a
  live bug.) Test: the script refuses "" and "12x".
- The ddgs worker's detached-spawn marker said the worker exits on owner death because it blocks
  on stdin. It does not: communicate() writes the request and closes stdin at once, so a worker
  whose owner dies mid-search finishes that search. The marker now says so.
- mcp_tool_lifecycle's child-filter comment said LSP servers and the slash worker "use
  start_new_session"; they are owned children under the supervisor now.
2026-10-29 16:58:09 +05:30
kshitijk4poor
57644ec000 fix(process): a family's stop path releases its group only once the group is empty
Same class as the router fix: nine stop paths released their group from the owner-death supervisor
as soon as the leader exited, but members that ignore TERM or outlive the leader keep the group
alive. Releasing it let those members survive a later kill -9 of this process.

Lightpanda, real-profile Chrome, embedded cua-driver, the TTS command provider, dashboard WhatsApp
pairing, the raft and WhatsApp bridges, verify's app server, agent-browser session groups, and
Browser Use harness daemons stopped by --reload now go through release_process_group_once_empty.

New test stops a raft bridge whose TERM-ignoring helper survives. It fails when raft releases
unconditionally, and the group stays covered with the fix. Test seams moved from the per-module
release_process_groups name to the shared helper.

Reported by Greptile on #137057 (thread on the router).
2026-10-29 16:58:09 +05:30
kshitijk4poor
6ff702ec0d chore(process): mark the agent/plugin detached spawns that are not owned children, with the reason
The detached-spawn check (scripts/check_detached_spawns.py, from the owned-child API) flags every
start_new_session outside spawn_owned. Five sites in this family are deliberately not owned. Each
now carries a `detached-spawn: ok — <why>` marker, so the check passes without a baseline entry:

- iron-proxy daemon: meant to outlive the CLI that started it; `hermes egress stop` ends it
  through the pidfile + nonce.
- google_meet bot: reached through files across turns and stopped by meet_leave (pid in
  .active.json).
- photon sidecar: exits on stdin EOF (PHOTON_SIDECAR_WATCH_STDIN). kill -9 probe with that exact
  watch block: 0 of 1 survived; the same probe with the watch off: 1 of 1 survived.
- ddgs search worker: awaited under a 30 s cap that kills its group. Blocked reading its request
  on a stdin pipe, it exits when the owner dies (kill -9 probe: 0 of 1 survived).
- secret_sources command helper: awaited under a hard timeout (default 3 s) that kills its group.

Comments only; no behaviour change.
2026-10-29 16:58:09 +05:30
kshitijk4poor
9c0641eb47 fix(raft): the raft bridge dies with the gateway that started it (orphans after kill -9: 1 -> 0)
`raft agent bridge` was a plain Popen child of the gateway. A SIGKILLed or OOM-killed gateway
reparented it to init, where it kept polling Raft and posting wakes to a channel endpoint nobody
serves, forever. The next gateway starts a second bridge beside it.

_spawn_bridge now starts it through process_identity.spawn_owned (its own group, handed to the
owner-death supervisor, recorded in the spawn ledger as "raft-bridge"), and _stop_bridge releases
the group once the bridge has exited (a bridge it failed to stop stays covered).

Measured on Linux, real adapter _spawn_bridge with a stand-in `raft` CLI, owner SIGKILLed,
6 s settle: origin/main 1 of 1 survived; this commit 0 of 2 descendants (bridge + supervisor).
New kill -9 / live-owner case and a _stop_bridge release test; reverting spawn_owned to the
main-era Popen turns the kill -9 case red. test_raft_adapter's multiplex test now patches the
adapter's spawn_owned seam.
2026-10-29 16:58:09 +05:30
kshitijk4poor
73804ca2f9 fix(whatsapp): the Node bridge dies with the gateway that started it (orphans after kill -9: 1 -> 0)
The bridge is spawned detached (start_new_session, via windows_detach_popen_kwargs) so a container
stop reaches it directly (#127047). Detached also meant a SIGKILLed or OOM-killed gateway left it
running forever: still holding the port and the logged-in WhatsApp session, serving a /messages
queue nobody polls. The next gateway's connect() only recovers it if the bridge reports the same
session, script hash and read-receipt config; otherwise it kills it through the pidfile or port path,
or with a foreign profile on that port refuses to start.

The bridge now starts through process_identity.spawn_owned (_spawn_bridge_process): it still
leads its own session, and its group goes to the per-process owner-death supervisor, so it dies the
moment the gateway dies, however it dies. disconnect() releases the group once the bridge has exited.
A bridge it failed to stop stays covered. Windows keeps its detach flags (windows_detach_flags)
and its taskkill tree kill unchanged. The pidfile / port reaping for bridges left by older versions
stays: it covers bridges this process never owned.

Measured on Linux, real node bridge stand-in, owner SIGKILLed, 6 s settle:
origin/main 1 of 1 bridge survived; this commit 0 of 2 descendants (bridge + supervisor).
tests/hermes_cli/test_owned_agent_subprocs.py: a real kill -9 owner and a live control owner
through _spawn_bridge_process (child + same-group grandchild gone in 15 s, the live owner's tree
untouched), plus disconnect() releasing the group. Reverting spawn_owned to the main-era Popen turns
the kill -9 case red. Existing connect / stale-bridge tests now patch the adapter's spawn_owned
seam instead of the global subprocess.Popen, which also starts the supervisor.
2026-10-29 16:58:09 +05:30
kshitijk4poor
1d90557426 refactor: the Discord approval card retires through the views' shared embed stamp
`ExecApprovalView.retire` repeated `_HermesView._expire_embed`: grey
the first embed, stamp the footer, edit the message. The only
differences were that retire removed the controls (`view=None`) and
logged a failed edit.

`_expire_embed` now takes `keep_controls` (default True, so the other
views' timeouts look the same as before), and retire calls it with
False. A failed stamp is now logged at debug instead of silently dropped, for
every view that stamps through it (approval, slash confirm, update,
clarify; the model and choice pickers have their own timeout edit).

Raised by review of #145948. The copied block came from 39b2158afc
(Gille, 2026-10-27, #145948).
2026-10-29 09:45:17 +05:30
kshitijk4poor
62c89c1894 refactor: the Discord approval card's timeout notice goes through edit_message
The gateway's timeout notice looked up the Discord-only
`expire_exec_approval` on the adapter's type by name and called it to
strip the card's buttons. That method duplicated `edit_message`'s
channel lookup, formatting and truncation.

Since #145948, every Discord approval card with a request id registers
a settle observer. A card whose request had already ended is retired
right after it is sent. On timeout, the observer's `retire("timeout")`
removes the buttons, so the notice only needs to replace the text.

`_edit_card` now always uses `edit_message`, and
`DiscordAdapter.expire_exec_approval` is gone. A timed-out card
therefore gets one button-removing edit instead of two, and core no
longer probes for a platform method by name.

`edit_message` is the streaming editor: content over the platform's
limit is truncated in place behind a dangling "(1/N)" marker, and the
adapter keeps a saturated-preview entry for it until a final edit that a
card never gets. After the timeout the card's text is the only record of
the command, so the body now gives the command whatever room the
adapter's per-chat limit leaves, measured in the platform's own units
(`max_message_length_for_chat` with `message_len_fn_for_chat`, so
Telegram's UTF-16 count is honoured). `_ea_fit`'s own copy of the
prefix bisection becomes `fit_prefix` in `gateway/platforms/base.py`, a
suffix-adding wrapper over the existing `_custom_unit_to_cp`, shared by
both. A run of three or more backticks in the
command would close the card's fence and let Discord's formatter rewrite
a table after it into a longer bullet list, so such runs are split with
zero-width spaces. The body is built inside `_edit_card`'s guard, so a
failure there still falls back to sending the notice.

The lifecycle test that races the timeout notice against `retire` now
drives the notice through `edit_message`; both orders still end with
the notice text and no controls. A new test drives the real
path, `_post_timeout_notice` → `_edit_card` → Discord's `edit_message`,
with a 5,000-char command, a heredoc holding fenced Markdown tables and
a run of seven backticks: one in-place edit that fills the message
exactly, only the card's own fence, no "(1/" marker, no preview entry,
no new message. Another fills a UTF-16-counting adapter with ASCII and
with emoji, and one whose limit lookup raises still gets the notice as a
new message. Removed the two tests of the deleted method; the two notice tests' fake adapters gain
`max_message_length_for_chat` and `message_len_fn_for_chat`.

Raised by review of #145948. `expire_exec_approval` and the probe came
from 4f86e97791 (Gille, 2026-10-27, #145948).
2026-10-29 09:45:17 +05:30
Teknium
67bce8c25d fix(slack): strip mention labels before emphasis parsing in rich_text
A labelled mention such as <#C1|dev_ops_alerts> or <!subteam^S1|@eng_team_x>
was split by the italic regex on its underscores before the leaf mention
split ran, so Slack showed the token literally with a stray italic run.
The label is dropped from the element anyway, so drop it up front.
2026-10-28 19:38:41 -07:00
Muneeb Anjum
a0f9c92bd7 fix(slack): render mentions as rich_text elements in rich_blocks
rich_text does not interpret mrkdwn, so <@U…>, <#C…>, <!subteam^S…> and
<!here|channel|everyone> tokens inside lists, quotes and table cells were
emitted as text and rendered literally. Split them into user/channel/
usergroup/broadcast elements at the emphasis leaf so surrounding bold/
italic/strike spans survive.

Fixes #133315. Squashed from #133323 (095821f, 53c8268, fcf7c97, 9fd0327).
2026-10-28 19:38:41 -07:00
Victor Kyriazakos
31d5f1d44d feat(whatsapp): log delivery and read status of sent messages to gateway.log
Baileys reports the delivery status of messages Hermes sends
(`messages.update` with `update.status` in 1:1 chats, a per-recipient
`message-receipt.update` in groups), but the bridge only handled poll
updates there, so operators could not see whether a reply was delivered
or read.

The bridge now queues a `delivery_status` event for status changes of its
own sends (tracked IDs only, so messages typed on the linked phone are
never reported). The adapter logs one gateway.log line per change and
never dispatches it as an inbound message.
2026-10-28 19:34:11 -07:00
Teknium
f3acd8ff33 fix(whatsapp): run the bridge reaps off the gateway event loop
The reaps now wait out a SIGTERM grace (up to 6s each) with time.sleep, and
connect() called them inline on the loop every platform shares, freezing
Telegram/Discord/etc. while a slow WhatsApp bridge exited. Run them via
asyncio.to_thread. The psutil-fallback test reads /proc of every process,
which names files under the real Hermes home on a box running Hermes, so
it opts out of the home write guard.
2026-10-28 19:21:20 -07:00
Teknium
7b90783f76 fix(whatsapp): keep main's TIME-WAIT-aware port_is_free for the respawn wait
Replaying the branch onto main linearly resurrected port_accepts_listen, the
duplicate helper the branch dropped when it merged main (#140186 already
gives port_is_free the bridge's SO_REUSEADDR semantics). Restore the merged
tree: one helper, one contract.
2026-10-28 19:21:20 -07:00
unsupportedpastels
fb45657d55 fix(whatsapp): don't treat the old bridge's TIME_WAIT as a busy port
The port-free wait used a plain bind probe, which Linux refuses while the
previous bridge's closed connections sit in TIME_WAIT (up to 60s). node's
listen sets SO_REUSEADDR and succeeds then, so a normal restart failed with
whatsapp_bridge_port_busy after 10s and waited for the reconnect backoff.
Probe with SO_REUSEADDR on POSIX so only a live listener blocks the spawn.
2026-10-28 19:21:20 -07:00