Skip to content

fix(kernel): forward web-UI-initiated delegation results to the home channel (refs #6266)#6286

Merged
houko merged 4 commits into
mainfrom
fix/webui-delegation-forward
Jun 23, 2026
Merged

fix(kernel): forward web-UI-initiated delegation results to the home channel (refs #6266)#6286
houko merged 4 commits into
mainfrom
fix/webui-delegation-forward

Conversation

@houko

@houko houko commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Problem (remaining part of #6266)

#6267 (merged) forwards an async-delegation completion to the agent's home channel mid-turn — but only when the originating turn carries an inbound chat_id. A delegation kicked off from a web-UI turn has no chat_id (the WS sender sets none and uses the canonical session), so the forward was skipped and the delegation result surfaced only in the web-UI session, never on the agent's channel. This is the "agent responds in the web UI instead of forwarding to Telegram" symptom.

Fix

The mid-turn forward in task_registry.rs now resolves its destination as inbound entry.chat_id (if present) → else the home channel's configured default_conversation. A new optional [[sidecar_channels]].default_conversation names that fallback conversation. If neither resolves, the forward stays a no-op — it never guesses a recipient (delivering to a wrong chat is worse than not delivering).

  • librefang-types/config/types.rsdefault_conversation: Option<String> on SidecarChannelConfig (#[serde(default)], additive; existing configs unaffected).
  • librefang-kernel/messaging.rsresolve_agent_default_conversation + pure sidecar_default_conversation helper (mirrors sidecar_default_agent). resolve_agent_home_channel's contract is left unchanged, so the trigger-dispatch caller is unaffected.
  • librefang-kernel/task_registry.rs — destination fallback in the mid-turn forward.
  • kernel_config_schema.golden.json — regenerated for the new field.

Out of scope / for the reporter

The titular "session mixing" sub-claim is not a shared-session bug: web-UI sessions resolve to the canonical entry.session_id and channel sessions to SessionId::for_channel(agent,"<channel>:<chat>") — storage-distinct by construction. Left awaiting the reporter's two SessionIds to confirm (most likely the boot-time web-UI→canonical adoption, not live leakage). The wake-idle forward path is intentionally unchanged (separate from the mid-turn path this issue is about).

Verification

  • cargo check -p librefang-kernel — clean (Docker dev image).
  • cargo clippy -p librefang-kernel --all-targets -- -D warnings — zero warnings.
  • cargo test -p librefang-kernel default_conversation — 6/6 pass (matching-agent resolves; unset/empty → None no-op; non-matching agent doesn't leak; first-match deterministic; serde back-compat).

…channel (#6266)

PR #6267 forwards an async-delegation completion to the agent's home channel mid-turn, but only when the originating turn carries an inbound `chat_id`. A delegation started from a web-UI turn has no `chat_id` (the WS sender sets none and uses the canonical session), so the forward was skipped and the result surfaced only in the web-UI session — never on the agent's channel (the "responds in the web UI instead of forwarding to Telegram" symptom in #6266).

The mid-turn forward now resolves its destination as: the inbound `entry.chat_id` when present, else the home channel's configured `default_conversation`. A new optional `[[sidecar_channels]].default_conversation` names that fallback conversation. When neither is available the forward stays a no-op — it never guesses a recipient.

`resolve_agent_home_channel`'s contract is unchanged (the trigger-dispatch caller is unaffected); the fallback is a separate `resolve_agent_default_conversation` helper. The "session mixing" sub-claim in #6266 is left for reporter confirmation — web-UI and channel sessions are storage-distinct by construction.
@github-actions github-actions Bot added size/M 50-249 lines changed area/docs Documentation and guides area/kernel Core kernel (scheduling, RBAC, workflows) has-conflicts PR has merge conflicts that need resolution labels Jun 23, 2026
@github-actions github-actions Bot added ready-for-review PR is ready for maintainer review and removed has-conflicts PR has merge conflicts that need resolution labels Jun 23, 2026
…te lines

One sentence per line in CHANGELOG bullets per project prose rules.

Also collapses the redundant `let kernel_arc = arc;` in task_registry.rs
into the `if let Some(kernel_arc) = ...` binding directly.
@houko
houko enabled auto-merge (squash) June 23, 2026 06:17
…ter one

review follow-up: sidecar_default_conversation used find_map, so when an agent's first home channel (the one resolve_agent_home_channel picks) had no default_conversation it skipped ahead to a later channel's default. The forward would then pair the home channel with a different channel's conversation id and deliver to the wrong place. Switch to find().and_then() so it reads only the first agent-matching channel's default, and add a regression test.
@houko
houko merged commit 3410756 into main Jun 23, 2026
32 checks passed
@houko
houko deleted the fix/webui-delegation-forward branch June 23, 2026 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/docs Documentation and guides area/kernel Core kernel (scheduling, RBAC, workflows) ready-for-review PR is ready for maintainer review size/M 50-249 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants