Skip to content

Harden trading bridge integration and CI coverage#20

Merged
jadenfix merged 3 commits into
mainfrom
jaden/bridge-optimization
Feb 17, 2026
Merged

Harden trading bridge integration and CI coverage#20
jadenfix merged 3 commits into
mainfrom
jaden/bridge-optimization

Conversation

@jadenfix

Copy link
Copy Markdown
Owner

No description provided.

@greptile-apps

greptile-apps Bot commented Feb 17, 2026

Copy link
Copy Markdown

Greptile Summary

Consolidated multiple trading control tools into a unified trading_hft interface with confidence-gated high-impact actions, adding capability negotiation between the bridge and daemon for protocol compatibility.

Key Changes:

  • Unified tool surface: replaced 6 separate tools with single trading_hft action-based interface
  • Confidence gate system: high-impact actions (engine_start, engine_resume, strategy_promote_candidate, risk_reset_kill_switch) require passing connectivity, latency, compatibility, and precondition checks before execution
  • Capability negotiation: added Control.Capabilities command to report protocol versions, schema versions, and supported commands
  • CI coverage: added dedicated test jobs for Rust crates and TypeScript extension
  • Health diagnostics: new doctor command validates daemon/gateway integration and tool availability

Issues Found:

  • risk_reset_kill_switch precondition check reads from riskState.kill_switch_engaged but should check engineState.kill_switch_engaged for consistency with other kill switch checks

Confidence Score: 4/5

  • Safe to merge with one logic issue in precondition checking that should be fixed
  • Major refactoring adds robust safety features (confidence gates, capability negotiation, precondition checks) with good test coverage. One logic bug in risk_reset_kill_switch precondition check needs correction before merge - it checks the wrong state object which could allow resetting when kill switch isn't actually engaged.
  • index.ts:504-513 needs correction to check engineState instead of riskState for kill switch status

Important Files Changed

Filename Overview
.openclaw/extensions/trading-bridge/src/index.test.ts New test file covering capabilities parsing, compatibility checks, and command building with good edge case coverage
.openclaw/extensions/trading-bridge/src/index.ts Major refactoring to unified trading_hft tool with confidence-gated high-impact actions, capabilities caching, and precondition checks
crates/trading_daemon/src/main.rs Added Control.Capabilities command support, schema version reporting in status responses, and comprehensive tests
crates/trading_protocol/src/lib.rs Added Control.Capabilities command, STATUS_SCHEMA_VERSION constant, and new payload types for capability reporting
trading-cli Added capabilities and doctor commands with comprehensive health checking of daemon and gateway integration

Sequence Diagram

sequenceDiagram
    participant Agent as AI Agent
    participant Gateway as OpenClaw Gateway
    participant Bridge as Trading Bridge Extension
    participant Daemon as Trading Daemon (Rust)
    
    Note over Agent,Daemon: High-Impact Action Flow (engine_start)
    
    Agent->>Gateway: POST /tools/invoke<br/>trading_hft(action=engine_start)
    Gateway->>Bridge: Execute tool
    
    Bridge->>Bridge: Check connection status
    Bridge->>Daemon: Control.Capabilities
    Daemon-->>Bridge: protocol_version, status_schema_version, commands
    Bridge->>Bridge: Validate compatibility<br/>(protocol>=1, schema>=2, commands)
    
    Bridge->>Daemon: Control.Ping
    Daemon-->>Bridge: ok + latency_ms
    Bridge->>Bridge: Check latency <= 250ms
    
    par Refresh Snapshots
        Bridge->>Daemon: Engine.Status
        Daemon-->>Bridge: engine state + strategies
    and
        Bridge->>Daemon: Risk.Status
        Daemon-->>Bridge: risk state + limits
    end
    
    Bridge->>Bridge: Precondition Check<br/>(kill_switch_engaged?)
    
    alt Confidence Gate Passed
        Bridge->>Daemon: Control.Start
        Daemon-->>Bridge: Status response
        Bridge-->>Gateway: ok=true + confidence + data
        Gateway-->>Agent: Success result
    else Confidence Gate Failed
        Bridge-->>Gateway: ok=false + failed checks
        Gateway-->>Agent: Blocked by confidence gate
    end
    
    Note over Agent,Daemon: Low-Impact Action Flow (engine_status)
    
    Agent->>Gateway: POST /tools/invoke<br/>trading_hft(action=engine_status)
    Gateway->>Bridge: Execute tool
    Bridge->>Daemon: Engine.Status
    Daemon-->>Bridge: Status payload
    Bridge-->>Gateway: ok=true + data
    Gateway-->>Agent: Success result
Loading

Last reviewed commit: d380e5d

@greptile-apps greptile-apps 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.

11 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +504 to +513
case "risk_reset_kill_switch": {
const killSwitch = riskState?.kill_switch_engaged;
return {
name: "action_precondition",
passed: killSwitch === true,
details:
killSwitch === true
? "kill switch engaged; reset allowed"
: "kill switch is not engaged; reset rejected for confidence",
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

precondition check uses riskState?.kill_switch_engaged but should check engineState?.kill_switch_engaged for consistency with engine_start/engine_resume checks

Suggested change
case "risk_reset_kill_switch": {
const killSwitch = riskState?.kill_switch_engaged;
return {
name: "action_precondition",
passed: killSwitch === true,
details:
killSwitch === true
? "kill switch engaged; reset allowed"
: "kill switch is not engaged; reset rejected for confidence",
};
case "risk_reset_kill_switch": {
const killSwitch = engineState?.kill_switch_engaged;
return {
name: "action_precondition",
passed: killSwitch === true,
details:
killSwitch === true
? "kill switch engaged; reset allowed"
: "kill switch is not engaged; reset rejected for confidence",
};
}

@jadenfix

Copy link
Copy Markdown
Owner Author

@greptile

@greptile-apps

greptile-apps Bot commented Feb 17, 2026

Copy link
Copy Markdown

Greptile Summary

This PR significantly hardens the trading bridge integration by introducing a comprehensive confidence-gating system for high-impact trading actions. The changes unify the dual-tool pattern into a single trading_hft control-plane tool with protocol negotiation via Control.Capabilities, precondition checks for critical operations (engine start/resume/kill-switch), and extensive CI coverage for both Rust and TypeScript components.

Key changes:

  • Replaced separate trading_status and trading_control tools with unified trading_hft tool supporting 14 actions
  • Added confidence gate system that validates daemon connection, protocol compatibility, ping latency, and state snapshots before executing high-impact actions
  • Implemented Control.Capabilities command across the stack (protocol, daemon, bridge) for version negotiation
  • Added status_schema_version tracking to enable future schema evolution
  • Created comprehensive test suite for TypeScript bridge with Node's built-in test runner
  • Added two new CI jobs for testing Rust crates and TypeScript extension
  • Introduced doctor diagnostic command in trading-cli for integration health checks
  • Enhanced precondition validation: engine_start/engine_resume now correctly check engineState?.kill_switch_engaged (aligned in commit 04c0b54)

Confidence Score: 5/5

  • Safe to merge with high confidence in production readiness
  • The PR demonstrates excellent engineering practices: comprehensive test coverage (both unit tests and CI jobs), defensive precondition checking for safety-critical operations, proper protocol versioning for forward compatibility, and thorough validation. The kill-switch precondition fix was addressed in a follow-up commit within the same PR. All changes are well-structured and follow a clear architectural pattern.
  • No files require special attention

Important Files Changed

Filename Overview
.github/workflows/non-agent-tests.yml Adds two new CI jobs for testing Rust trading crates and trading bridge TypeScript extension
.openclaw/extensions/trading-bridge/src/index.ts Major refactor: replaces dual tool pattern with unified trading_hft tool, adds confidence gate system with precondition checks, capabilities negotiation, and comprehensive health checks for high-impact actions
crates/trading_daemon/src/main.rs Adds Control.Capabilities handler, status_schema_version tracking, daemon build info payload, and corresponding unit tests
crates/trading_protocol/src/lib.rs Adds STATUS_SCHEMA_VERSION constant, Control.Capabilities command enum variant, and payload structs for capabilities and daemon build info
trading-cli Adds doctor diagnostic command and capabilities command, with comprehensive health checks for daemon/gateway integration

Sequence Diagram

sequenceDiagram
    participant Agent as AI Agent
    participant Gateway as OpenClaw Gateway
    participant Bridge as Trading Bridge Extension
    participant Daemon as Trading Daemon (Rust)
    participant Engine as Trading Engine

    Note over Bridge,Daemon: On Connection
    Bridge->>Daemon: Control.Capabilities
    Daemon-->>Bridge: protocol_version, status_schema_version, command_kinds_supported

    Note over Agent,Engine: High-Impact Action Flow (e.g., engine_start)
    Agent->>Gateway: trading_hft {action: "engine_start"}
    Gateway->>Bridge: Execute Action
    
    Bridge->>Daemon: Control.Capabilities (cached)
    Bridge->>Bridge: Validate protocol compatibility
    Bridge->>Daemon: Control.Ping
    Daemon-->>Bridge: pong (latency check)
    
    Bridge->>Daemon: Engine.Status + Risk.Status
    Daemon-->>Bridge: Current state snapshot
    
    Bridge->>Bridge: preconditionCheck(kill_switch_engaged)
    alt Kill Switch Engaged
        Bridge-->>Gateway: Confidence Gate Failed
        Gateway-->>Agent: Action Blocked
    else Kill Switch Clear
        Bridge->>Daemon: Control.Start
        Daemon->>Engine: Start Trading Engine
        Daemon-->>Bridge: Success
        Bridge-->>Gateway: Action Completed
        Gateway-->>Agent: Success Response
    end
Loading

Last reviewed commit: 04c0b54

@greptile-apps greptile-apps 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.

12 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@jadenfix jadenfix merged commit 0a1337d into main Feb 17, 2026
5 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.

1 participant