Skip to content

fix(runtime-host): retain actionable compatibility handshake details for remote profiles - #3246

Merged
Astro-Han merged 5 commits into
apache:mainfrom
Sun-GLiang:fix/issue-3203-runtime-host-compatibility
Aug 19, 2026
Merged

fix(runtime-host): retain actionable compatibility handshake details for remote profiles#3246
Astro-Han merged 5 commits into
apache:mainfrom
Sun-GLiang:fix/issue-3203-runtime-host-compatibility

Conversation

@Sun-GLiang

Copy link
Copy Markdown
Contributor

Summary

  • retain safe structured HostIncompatible diagnostics in a typed permanent reconnect error
  • format actionable epoch, protocol-range, and composition mismatch guidance consistently for CLI, TUI, and Desktop
  • preserve the compatibility gate and no-retry/no-replay behavior while documenting recovery in English and Chinese

Fixes #3203

Verification

  • npm --workspace @maka/runtime-host test — 992 passed
  • npm --workspace maka-agent test — 288 passed
  • npm --workspace @maka/desktop test — 933 passed
  • npm run typecheck — passed
  • npm run lint — passed
  • npm run format:check — passed
  • focused cross-surface regression — 42 passed

Root npm test was also run but is not fully green because of two failures outside this diff that reproduce independently on this macOS environment:

  • packages/runtime node-pty-write-lifecycle: child spawnSync reaches its fixed 10-second timeout
  • packages/eval install-preflight: /var and /private/var canonical-path assertion mismatch

Review focus

This adds a public Runtime Host client error contract and therefore requires the independent human review described in CONTRIBUTING.md. Please pay particular attention to the details allowlist and the permanent reconnect classification.

AI use

Select exactly one:

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: Codex implemented the typed compatibility error, formatter, projections, tests, and documentation. Both commits contain Generated-by: Codex trailers.

Checklist

  • Tests cover the change and fail without it
  • Lint, format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 35a2f6de-7fa9-48bf-a88f-5e4a2aee7dfc

📥 Commits

Reviewing files that changed from the base of the PR and between 7f1121e and dafb60f.

📒 Files selected for processing (2)
  • packages/runtime-host/src/__tests__/host-profile.test.ts
  • packages/runtime-host/src/client/remote-compatibility-error.ts

Included review availability: Your plan provides up to 3 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Summary

This PR gives remote Runtime Host compatibility failures a typed, stable error path. It preserves profile identity, compatibility epoch, protocol range, composition identity, and revision in structured diagnostics. CLI, TUI, and Desktop receive consistent diagnostics and recovery guidance.

The change extends the existing compatibility gate and permanent reconnect-error path. It does not create a parallel retry or recovery path. Incompatible connections remain non-retryable and do not replay commands, change profiles, or update the Host automatically.

The solution is focused and coherent. The new error module centralizes formatting, protocol-range checks, sanitization, and recovery guidance. Unicode Cc, Cf, Zl, and Zp characters are replaced with U+FFFD in human-readable Host values. Structured diagnostic fields retain the raw values. No deletion or simplification is evident without reducing regression coverage.

Tests cover epoch, protocol-range, and composition mismatches, sensitive-data exclusion, Unicode sanitization, unavailable Desktop profiles, rejected queued queries, no replay, and a single connection attempt. Reported validation includes 1,010/1,010 Runtime Host tests, typecheck, lint, and format checks. English and Chinese documentation describe compatible builds and required Host service restarts.

Complexity delta

  • Adds one typed public error, one error code, and one details interface.
  • Adds centralized formatting, sanitization, and protocol-range overlap logic.
  • Reuses the existing compatibility gate and permanent reconnect state.
  • Adds test fixtures and assertions across Runtime Host, CLI, and Desktop.
  • Adds no configuration, retry state, transport fallback, or automatic recovery path.
  • Increases public API and test-maintenance scope, but removes generic error ambiguity and duplicated guidance.
  • Total maintenance complexity stays justified because the shared error path keeps diagnostics consistent.

Review-relevant risks

  • User-visible CLI, TUI, and Desktop error behavior changes.
  • The packages/runtime-host client surface gains exported compatibility types and an error code.
  • The error retains raw remote composition and revision values in typed details. Formatted output sanitizes control and formatting characters and excludes sensitive configuration.
  • Permanent failure behavior affects operational recovery because incompatible connections do not retry or replay.
  • English and Chinese documentation define recovery guidance.

These user-visible, public-contract, security-sensitive, and operational-recovery changes require independent human review under repository policy. No licensing, release, or governance effect was identified in the current diff. Required-check results are based on reported verification and remain unverified here. The person performing the merge must review the final diff, and a maintainer makes the final determination.

Walkthrough

The PR adds a typed remote compatibility error that preserves handshake details, prevents incompatible reconnects, projects unavailable states in Desktop, and provides consistent CLI/TUI diagnostics and documentation.

Changes

Remote compatibility handling

Layer / File(s) Summary
Compatibility error contract and formatting
packages/runtime-host/src/client/remote-compatibility-error.ts, packages/runtime-host/src/client/index.ts
Adds a permanent error with a stable code, structured client/host metadata, conditional protocol and composition details, sanitization, and recovery instructions.
Connection rejection and reconnect behavior
packages/runtime-host/src/client/host-profile.ts, packages/runtime-host/src/__tests__/host-profile.test.ts, packages/runtime-host/src/__tests__/reconnecting-connection.test.ts
Incompatible handshakes now produce the specialized error before readiness. Tests verify redaction, permanent classification, rejected queued queries, no replay, and no retry.
Profile projection, CLI coverage, and troubleshooting
apps/desktop/src/main/__tests__/runtime-host-profile-service.test.ts, packages/cli/src/__tests__/runtime-host-cli-context.test.ts, docs/runtime-host-remote-access.md, docs/runtime-host-remote-access.zh-CN.md
Tests verify unavailable Desktop projection and consistent CLI/TUI diagnostics. Documentation describes compatibility checks and operator-led Host restart requirements.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Merge Risk: 🔵 Low · up to dafb6

Compatibility errors may still render remote Host composition data containing control characters, making CLI, TUI, or Desktop guidance misleading or unsafe to read. The PR is otherwise mergeable with explicit owner awareness and follow-up on sanitizing this diagnostic output.

Sequence Diagram(s)

sequenceDiagram
  participant RemoteHost
  participant host_profile
  participant ClientSurface
  RemoteHost->>host_profile: return HostIncompatible handshake
  host_profile->>ClientSurface: raise RuntimeHostRemoteCompatibilityError
  ClientSurface-->>RemoteHost: show diagnostics or unavailable profile
Loading

Possibly related PRs

Suggested reviewers: m4n5ter

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: preserving actionable compatibility handshake details for remote profiles.
Description check ✅ Passed The description includes the required summary, issue link, verification results, AI disclosure, checklist, and behavior-change declaration.
Linked Issues check ✅ Passed The implementation, tests, exports, projections, safeguards, and bilingual documentation satisfy the coding objectives in issue [#3203].
Out of Scope Changes check ✅ Passed The changes remain within the issue scope: compatibility error projection, surface coverage, safety tests, and troubleshooting documentation.
Ai Use Disclosure ✅ Passed The PR description selects substantive generative tooling and names Codex with scope; all five commits introduced after main contain standalone Generated-by: Codex trailers.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Retain remote Runtime Host compatibility diagnostics

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Preserve allowlisted remote compatibility details in a typed permanent reconnect error.
• Surface actionable mismatch guidance consistently across CLI, TUI, and Desktop.
• Document recovery while retaining compatibility gating and terminal reconnect behavior.
Diagram

graph TD
  HOST["Remote Host"] -->|incompatible handshake| CONNECTOR["Profile Connector"] --> ERROR["Typed Compatibility Error"] --> LIFECYCLE["Reconnect Lifecycle"]
  ERROR --> SURFACES["CLI TUI Desktop"] --> GUIDANCE["Operator Guidance"]
Loading
High-Level Assessment

The shared typed error is the strongest approach because it preserves the existing compatibility gate and permanent reconnect semantics while giving every client surface one stable, actionable contract. Generic wrapping would lose structured diagnostics, while exposing the complete handshake would unnecessarily leak operational fields; both were appropriately avoided through an explicit allowlist.

Files changed (9) +533 / -4

Enhancement (1) +5 / -0
index.tsExport the compatibility error contract +5/-0

Export the compatibility error contract

• Publishes the compatibility error class, stable error code, and structured details type through the Runtime Host client API.

packages/runtime-host/src/client/index.ts

Bug fix (2) +89 / -3
host-profile.tsClassify incompatible remote profile handshakes +2/-3

Classify incompatible remote profile handshakes

• Replaces the generic permanent reconnect error with the typed remote compatibility error, retaining structured handshake diagnostics at the compatibility gate.

packages/runtime-host/src/client/host-profile.ts

remote-compatibility-error.tsDefine safe remote compatibility diagnostics +87/-0

Define safe remote compatibility diagnostics

• Introduces a permanent reconnect error containing frozen, allowlisted client and Host compatibility fields. Formats epoch differences and only includes protocol or composition guidance when those values actually mismatch.

packages/runtime-host/src/client/remote-compatibility-error.ts

Tests (4) +423 / -1
runtime-host-profile-service.test.tsVerify Desktop compatibility error projection +92/-0

Verify Desktop compatibility error projection

• Adds a multi-profile regression test proving an enabled incompatible remote profile remains unavailable and exposes the shared error message. It also verifies unaffected local and backup profiles retain their independent readiness states.

apps/desktop/src/main/tests/runtime-host-profile-service.test.ts

runtime-host-cli-context.test.tsTest CLI and TUI compatibility propagation +112/-0

Test CLI and TUI compatibility propagation

• Covers epoch, protocol-range, and composition mismatches for CLI and TUI remote profiles. Verifies the typed code, formatted message, and allowlisted client and Host details survive through the CLI connection context.

packages/cli/src/tests/runtime-host-cli-context.test.ts

host-profile.test.tsValidate typed compatibility diagnostics and redaction +160/-0

Validate typed compatibility diagnostics and redaction

• Tests typed permanent classification, conditional mismatch formatting, actionable recovery text, and exclusion of credentials and unrelated handshake fields. Also verifies incompatibility fails before readiness without retrying.

packages/runtime-host/src/tests/host-profile.test.ts

reconnecting-connection.test.tsPrevent incompatible reconnect retries and replay +59/-1

Prevent incompatible reconnect retries and replay

• Adds a regression test confirming compatibility failures terminate reconnection after one attempt. Queued requests receive the fatal error and are never replayed against the disconnected connection.

packages/runtime-host/src/tests/reconnecting-connection.test.ts

Documentation (2) +16 / -0
runtime-host-remote-access.mdDocument remote compatibility recovery +8/-0

Document remote compatibility recovery

• Explains the incompatibility error code, diagnostic fields, and operator recovery sequence. Documents that clients neither mutate Host configuration nor expose sensitive connection data.

docs/runtime-host-remote-access.md

runtime-host-remote-access.zh-CN.mdAdd Chinese compatibility troubleshooting guidance +8/-0

Add Chinese compatibility troubleshooting guidance

• Adds the Chinese translation of remote compatibility diagnostics, recovery steps, and security boundaries.

docs/runtime-host-remote-access.zh-CN.md

@qodo-code-review

qodo-code-review Bot commented Aug 19, 2026

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Host revision injects diagnostics ✓ Resolved 🐞 Bug ⛨ Security
Description
The formatter inserts the Host-controlled compositionRevision verbatim into Error.message, while
protocol validation permits Unicode line separators and bidirectional controls; an incompatible Host
can therefore forge or visually reorder content in Desktop recovery dialogs and logs. This violates
the PR's safe-diagnostic contract and should be fixed before merge.
Code

packages/runtime-host/src/client/remote-compatibility-error.ts[73]

+      `Host composition revision ${details.host.compositionRevision}`,
Relevance

●●● Strong

Recent runtime-host reviews accept strict validation and diagnostic-boundary hardening for untrusted
protocol data.

PR-#3230

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Incoming incompatible frames validate compositionRevision by rejecting only C0 controls and DEL,
so characters such as U+2028/U+2029 and bidirectional controls remain valid. The PR newly copies
that remote value into the error message, and Desktop places the message directly into a native
recovery dialog and logs the same error.

packages/runtime-host/src/protocol/index.ts[250-270]
packages/runtime-host/src/protocol/index.ts[380-395]
packages/runtime-host/src/server/host-kernel.ts[436-459]
apps/desktop/src/main/runtime-host-boot.ts[1390-1414]
apps/desktop/src/main/runtime-host-boot.ts[651-658]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Prevent Host-controlled composition revisions from injecting line separators or bidirectional formatting into compatibility error messages.

## Issue Context
Keep the structured `details.host.compositionRevision` value unchanged for the typed contract, but escape unsafe characters when projecting it into the human-readable message. Reuse the closest existing safe-string/diagnostic formatting seam if one exists; otherwise make a small local formatter and add a regression test. This introduces no new state, configuration, or public surface.

## Fix Focus Areas
- packages/runtime-host/src/client/remote-compatibility-error.ts[69-74]
- packages/runtime-host/src/__tests__/host-profile.test.ts[597-615]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
Review mode: ⚖️ Balanced: This changes a public typed error contract and terminal reconnect behavior across runtime, CLI, and Desktop, requiring a careful full review.

Grey Divider

Tip of the day
💡 Did you know, you can show, collapse, or hide each part of a finding: code, evidence, and all

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread packages/runtime-host/src/client/remote-compatibility-error.ts Outdated

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head 3d417486fb5a55d4b3e5ee4de1ee9d02cfe923de.

The typed compatibility error belongs at the Runtime Host client boundary, and the permanent/no-retry/no-replay behavior remains coherent across CLI, TUI, and Desktop. Current CI is green, and the PR body plus both commits carry complete Codex provenance disclosure.

Two items remain before approval:

  • The existing Qodo inline finding is a valid P2; I confirmed the failure path and replied in that thread with the smallest projection-boundary fix.
  • This changes user-visible compatibility errors in CLI, TUI, and Desktop. Please add representative screenshots of a terminal surface and the Desktop recovery dialog; before/after captures are preferred.

No additional P0-P2 findings were found. Because this changes a public client contract and security-sensitive diagnostics, independent human review is still required before merge.

AI-assisted review disclosure: Codex reviewed the exact-head diff, existing feedback, projection paths, tests, live CI, thread state, UI evidence, and provenance metadata. No external model was used. Astro-Han authorized this review campaign.

中文说明

整体职责边界、永久失败语义和跨端共用投影都合理,当前 CI 全绿,AI disclosure 也完整。

合并前仍有两项:现有 Qodo 评论属于有效 P2,需要在可读消息投影处清理换行分隔符和 bidi controls,同时保留结构化 details 原值;此外该 PR 改变 CLI、TUI、Desktop 的用户可见错误,请补 terminal 和 Desktop recovery dialog 截图,最好包含前后对比。

public client contract 与安全相关诊断仍需独立人工审查。

Replace Unicode control and formatting characters only in the human-readable Host revision projection while retaining the raw typed detail.

Generated-by: Codex
@Sun-GLiang

Copy link
Copy Markdown
Contributor Author

Review evidence

Fixed the inline security finding in 46a5f7a9f. The human-readable projection now replaces Unicode Cc/Cf/Zl/Zp characters with U+FFFD while details.host.compositionRevision retains the exact raw value. The new regression first reproduced the forged line/bidi path and now proves the message is single-line and free of those character classes.

Terminal surface

Representative output produced through the real connectRuntimeHostCli()connectRemoteRuntimeHostProfile() incompatible-handshake path:

issue-3203-terminal

Desktop recovery surface

Production-backed Settings page after enabling the incompatible remote profile; Local remains available, the remote Host becomes unavailable, and the shared recovery message is shown:

issue-3203-desktop

Verification after the fix:

  • npm --workspace @maka/runtime-host test — 993 passed
  • npm run typecheck — passed
  • npm run lint — passed
  • npm run format:check — passed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/runtime-host/src/client/remote-compatibility-error.ts (1)

69-73: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Sanitize the Host composition ID before formatting.

Line 72 interpolates details.host.compositionId without the existing sanitizer. The HostIncompatible.compositionId value comes from the remote handshake. A remote Host can therefore inject ANSI or other control characters into CLI, TUI, or log output.

Apply formatRuntimeHostDiagnosticValue to the Host composition ID. Keep the structured detail unchanged.

Disposition: fix-now.

Proposed fix
-      `Host composition id ${details.host.compositionId}`,
+      `Host composition id ${formatRuntimeHostDiagnosticValue(details.host.compositionId)}`,

As per path instructions, reuse the closest existing seam before adding new behavior; this fix reuses formatRuntimeHostDiagnosticValue.

Source: Path instructions

🧹 Nitpick comments (1)
packages/runtime-host/src/__tests__/host-profile.test.ts (1)

721-726: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove the as never cast from the fixture.

The cast disables TypeScript validation for the activity payload. The fixture can continue to compile after HostActivitySnapshot changes even when its shape is invalid. Use the actual HostActivitySnapshot type, or omit activity when the tests do not need it.

Disposition: optional.

As per path instructions, choose the smallest coherent solution and flag concrete test-maintenance risks.

Source: Path instructions


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 97fb1eda-f493-4607-a482-b905c6fc60fb

📥 Commits

Reviewing files that changed from the base of the PR and between 3d41748 and 46a5f7a.

📒 Files selected for processing (2)
  • packages/runtime-host/src/__tests__/host-profile.test.ts
  • packages/runtime-host/src/client/remote-compatibility-error.ts

Included review availability: Your plan provides up to 3 included reviews per hour; 2 remain after this review.

Preserve upstream lifecycle-aware CLI conflict coverage alongside remote compatibility projections.

Generated-by: Codex
Keep structured compatibility details exact while replacing control characters in the human-readable Host composition id. Use the typed Host activity fixture shape in coverage.

Generated-by: Codex
@Sun-GLiang

Copy link
Copy Markdown
Contributor Author

Addressed the latest CodeRabbit review in dafb60f: the human-readable Host composition id now uses the same Unicode control-character sanitizer as composition revision, while structured details retain the exact remote value. The regression test was verified red then green. I also removed the optional as-never fixture cast by using the real HostActivitySnapshot shape. Fresh verification: Runtime Host 1010/1010, typecheck, lint, and format:check all pass.

@Sun-GLiang

Copy link
Copy Markdown
Contributor Author

@Astro-Han the requested sanitizer fix and representative screenshots are now present, and the branch has been merged with current main. When convenient, please re-review exact head dafb60f. GitHub did not allow this fork author to create a formal review request through the API.

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head dafb60f29244248bcafad7dc8475c8794e94d7d3.

The earlier diagnostic-injection finding is fully addressed: both Host-controlled composition fields are sanitized at the human-readable projection boundary, while typed structured details preserve their exact values. The regression covers control characters, bidirectional formatting, and Unicode line/paragraph separators.

I also verified the requested terminal and Desktop screenshots. The existing thread is resolved, all checks are green, all five commits carry Generated-by: Codex, and I found no additional P0–P3 issues. Because this changes a public contract, security diagnostics, and user-visible behavior, please retain the required independent human review before merge.

AI-assisted review disclosure: Codex reviewed the exact-head diff, prior feedback and remediation, tests, live threads and CI, screenshots, and provenance metadata. No external model was used. Astro-Han authorized this review campaign.

中文说明

原诊断注入问题已完整修复:两个 Host 控制字段只在可读消息投影时清理危险 Unicode 字符,结构化 details 仍保留原值;测试覆盖充分。Terminal 与 Desktop 截图、线程、CI 和 AI trailer 均已核实,没有新的 P0–P3。该 PR 涉及公开契约、安全诊断及用户可见行为,合并前仍需独立人工审查。

@Astro-Han
Astro-Han merged commit 074f719 into apache:main Aug 19, 2026
18 checks passed
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.

fix(runtime-host): retain actionable compatibility handshake details for remote profiles

2 participants