Skip to content

fix(kohaku): clean runtime display when kt is the core#3

Merged
Yidhar merged 3 commits into
mainfrom
fix/kohaku-runtime-noise
Jun 27, 2026
Merged

fix(kohaku): clean runtime display when kt is the core#3
Yidhar merged 3 commits into
mainfrom
fix/kohaku-runtime-noise

Conversation

@Yidhar

@Yidhar Yidhar commented Jun 27, 2026

Copy link
Copy Markdown
Owner

Summary

When KohakuTerrarium (kt) is the core, the chat surfaced backend runtime detail instead of the model's message. Three fixes, all keeping provider differences inside the adapter.

1. Show only the LLM message, not kt runtime noise (cc7fc11)

  • The consumer mirrored every kt --json protocol line as terminal output, replaying the whole machine stream into the live-execution card. Now only genuine non-JSON stdout is surfaced; protocol lines are parsed-only.
  • classify() recognizes kt's full vocabulary (text / activity / turn_start / turn_end / error); turn.rs drops telemetry + turn_start and translates genuine tool/subagent calls into normalized items.
  • A stateful SentinelDisplayFilter withholds the <<<SWITCHYARD_JSON_BEGIN>>>…END>>> delegation block (incl. markers split across deltas) from the live bubble while the full body still reaches the router for delegation. Structured errors are surfaced as the response reason; no-delta turn_end.text bodies stream live.
  • Frontend renderMessageBody strips sentinel blocks defensively; the shared strip_sentinel_blocks stays conservative (no cross-provider behavior change).

2. Count kt tool activity as commands; drop the kt.exe driver headline (04f8e1e)

  • Stop emitting execution_telemetry for kohaku — kt.exe is Switchyard's driver, not a model action (it was hijacking the "正在运行 kt.exe" headline and inflating the command count). The resolved invocation stays in the archived raw-output artifact.
  • Map genuine kt tool/subagent activity to command_execution items so the live card counts them ("已运行 N 条命令") and shows the running one in its headline.

3. Reflect completed commands on the live card, not "暂无工具事件" (ed8caee)

  • After dropping the kt.exe telemetry, a turn whose tools had all completed fell through to "Provider 正在运行,暂无工具事件…" even with commandCount > 0. The card now falls back to the most recent command that ran, consistent with the count (also improves codex/claude).

Verification

cargo fmt --all -- --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspace --all-targets, and the frontend npm run build all pass. New: a split-sentinel path in fake_kt and an integration test asserting no protocol mirroring, no sentinel leakage, no execution_telemetry, and tool activity surfaced as counted command_execution items.

🤖 Generated with Claude Code

Yidhar and others added 3 commits June 27, 2026 15:28
When kt is the core, the chat flooded with backend runtime detail and the
delegation sentinel leaked into the live bubble. Root causes (all inside the
kohaku adapter, per the provider-differences-stay-in-the-adapter invariant):

- The consumer mirrored every `kt --json` protocol line as terminal output,
  replaying the whole machine stream into the live-execution card. Only genuine
  non-JSON stdout is now surfaced; protocol lines are parsed-only.
- kt's native vocabulary (text/activity/turn_start/turn_end/error) was unknown
  to the shared recognizers, so activity/turn_start rendered as generic
  [activity] markers. classify() now recognizes the full vocabulary; turn.rs
  drops telemetry + turn_start and translates genuine tool/subagent calls into
  normalized (collapsed) tool_call cards.
- The sentinel streamed token-by-token, leaking fragments into the bubble. A
  stateful SentinelDisplayFilter withholds any BEGIN..END block (and partial
  markers split across deltas) from the display channel while the full body
  still reaches the router for delegation.
- Structured turn errors are surfaced as the response reason instead of a raw
  JSONL dump; no-delta turn_end.text bodies now stream live.

Frontend: renderMessageBody strips sentinel blocks defensively (complete +
unclosed-trailing) regardless of delegate parsing. The shared
strip_sentinel_blocks stays conservative (no cross-provider behavior change).

Tests: fake_kt gained a split-sentinel path; a new integration test asserts no
protocol mirroring and no sentinel leakage into the chat.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…eadline

The live-execution card showed "正在运行 kt.exe" and counted the driver as a
command, while the real kt tool activity wasn't counted. Both stemmed from the
kt.exe execution_telemetry feeding the frontend's `commandLine` (which drives
both the running headline and `commandCount`):

- Stop emitting execution_telemetry for kohaku — kt.exe is Switchyard's own
  driver, not a model action. The resolved invocation is still recorded in the
  archived raw-output artifact for replay/diagnostics.
- Map genuine kt tool/subagent activity to command_execution items (was
  tool_call) so the live card counts them ("已运行 N 条命令") and shows the
  running one in its headline ("正在运行 <tool>") — the same surfaces
  codex/claude drive via their command items. start->done/error merge (by
  command) into one transitioning card.

The integration test now asserts kohaku emits no execution_telemetry and that
tool activity surfaces as counted command_execution items.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
After kohaku stopped emitting the kt.exe execution_telemetry, a turn whose
tools had all completed (none currently running, and no launcher commandLine
to fall back on) fell through to the "Provider 正在运行,暂无工具事件…" status
even while `commandCount` showed commands had run — a confusing contradiction.

The live-execution card now falls back to the most recent command that ran
("已运行 <cmd>") when none is currently active, keeping the headline consistent
with the count. This also improves codex/claude (the last real command shows
between batches instead of the launcher invocation).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Yidhar
Yidhar merged commit 722e4f7 into main Jun 27, 2026
1 check passed
@Yidhar
Yidhar deleted the fix/kohaku-runtime-noise branch June 27, 2026 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant