Skip to content

FIX: fixes multiple issues in the OpenViking chat functionality and unifies session ID generation logic between Python and Rust CLI implementations.#446

Merged
MaojiaSheng merged 23 commits intomainfrom
fix/ov_chat_bug
Mar 6, 2026
Merged

FIX: fixes multiple issues in the OpenViking chat functionality and unifies session ID generation logic between Python and Rust CLI implementations.#446
MaojiaSheng merged 23 commits intomainfrom
fix/ov_chat_bug

Conversation

@chenjw
Copy link
Collaborator

@chenjw chenjw commented Mar 5, 2026

Description

Summary

This branch fixes multiple issues in the OpenViking chat functionality and
unifies session ID generation logic between Python and Rust CLI
implementations.

Key Changes

  1. Unified Session ID Generation
    - Implemented machine unique ID as default session ID for both Python and
    Rust CLI
    - Added get_or_create_machine_id() function that uses hostname or
    generates a random ID
    - Session ID logic is now consistent across Python and Rust
    implementations
  2. SessionKey Construction Logic
    - Unified to use type="cli"
    - channel_id defaults to "default"
    - chat_id is now used as session_id
  3. Logging Improvements
    - Removed loguru dependency from openviking/server/routers/bot.py
    - Switched to using unified logger from openviking_cli.utils.logger
    - Added bot logging configuration options to server bootstrap
    - Simplified log messages for sandbox and langfuse
  4. Chat Command Fixes
    - Removed unsupported --logs parameter from chat command
    - Fixed UTF-8 issues in chat command
    - Added tab indentation to Think, Calling, and Result lines in CLI output
    - Removed unused handle_chat_direct function
  5. Testing Infrastructure
    - Added comprehensive test suite for chat commands
    - Added test_all.sh script for running tests
    - Added pytest configuration and test fixtures
  6. Sandbox Refactoring
    - Removed docker/aiosandbox backends
    - Simplified SRT configuration
  7. Rust CLI Improvements
    - Added new chat_v2.rs implementation
    - Added configuration module
    - Simplified main.rs
  8. Release Workflow
    - Added first release workflow
    - Updated release workflow with correct working directory

Files Modified

  • 35 files changed, 1118 insertions(+), 625 deletions(-)
  • Key areas: CLI commands, session management, logging, testing, sandbox

Related Issue

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

Changes Made

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • Linux
    • macOS
    • Windows

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Screenshots (if applicable)

Additional Notes

chenjw added 14 commits March 4, 2026 22:04
…nfig

- Remove docker and aiosandbox from available backends
- Remove settings_path from SrtBackendConfig (now auto-generated in workspace)
- Update SRT settings path to workspace/sandboxes/{session}-srt-settings.json
- Update README examples to use srt backend and remove settingsPath
…nfig

- Remove docker and aiosandbox from available backends
- Remove settings_path from SrtBackendConfig (now auto-generated in workspace)
- Update SRT settings path to workspace/sandboxes/{session}-srt-settings.json
- Update README examples to use srt backend and remove settingsPath
@chenjw chenjw changed the title Fix/ov chat bug FIX: fixes multiple issues in the OpenViking chat functionality and unifies session ID generation logic between Python and Rust CLI implementations. Mar 5, 2026
@chenjw chenjw requested a review from qin-ctx March 5, 2026 11:59
@github-actions
Copy link

github-actions bot commented Mar 5, 2026

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Machine ID Stability

The get_or_create_machine_id function uses DefaultHasher which is not guaranteed to be stable across Rust versions. This could lead to different machine IDs for the same machine if the Rust version changes.

/// Get or create a unique machine ID.
///
/// This function will:
/// 1. Try to get the hostname from environment variables
/// 2. If that fails, generate a random ID and store it in the config directory
pub fn get_or_create_machine_id() -> Result<String> {
    let home = dirs::home_dir()
        .ok_or_else(|| Error::Config("Could not determine home directory".to_string()))?;
    let machine_id_path = home.join(".openviking").join("machine_id");

    // Try to read existing machine ID
    if machine_id_path.exists() {
        if let Ok(content) = std::fs::read_to_string(&machine_id_path) {
            let trimmed = content.trim();
            if !trimmed.is_empty() {
                return Ok(trimmed.to_string());
            }
        }
    }

    // Try to get hostname from environment variables
    if let Ok(hostname) = std::env::var("HOSTNAME").or_else(|_| std::env::var("COMPUTERNAME")) {
        let trimmed = hostname.trim();
        if !trimmed.is_empty() {
            // Save it for future use
            if let Some(parent) = machine_id_path.parent() {
                let _ = std::fs::create_dir_all(parent);
            }
            let _ = std::fs::write(&machine_id_path, trimmed);
            return Ok(trimmed.to_string());
        }
    }

    // Generate a random ID as a last resort
    use std::collections::hash_map::DefaultHasher;
    use std::hash::{Hash, Hasher};
    use std::time::{SystemTime, UNIX_EPOCH};

    let mut hasher = DefaultHasher::new();
    if let Ok(n) = SystemTime::now().duration_since(UNIX_EPOCH) {
        n.hash(&mut hasher);
    }
    let pid = std::process::id();
    pid.hash(&mut hasher);
    let random_id = format!("cli_{:x}", hasher.finish());

    // Save it for future use
    if let Some(parent) = machine_id_path.parent() {
        let _ = std::fs::create_dir_all(parent);
    }
    let _ = std::fs::write(&machine_id_path, &random_id);

    Ok(random_id)
Private Attribute Usage

Storing the log file as process._log_file (a private attribute) is not ideal practice, though it works for this use case.

process._log_file = log_file

@github-actions
Copy link

github-actions bot commented Mar 5, 2026

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Initialize log_file_path in outer scope

Initialize log_file_path in the outer function scope to avoid a NameError when
accessing it in the early exit check, especially if the logging setup succeeded but
the process exits quickly.

openviking/server/bootstrap.py [141-171]

 def _start_vikingbot_gateway(enable_logging: bool, log_dir: str) -> subprocess.Popen:
     """Start vikingbot gateway as a subprocess."""
     print("Starting vikingbot gateway...")
 
     # Check if vikingbot is available
     ...
     # Prepare logging
     log_file = None
+    log_file_path = None  # Initialize in outer scope
     stdout_handler = subprocess.PIPE
     stderr_handler = subprocess.PIPE
Suggestion importance[1-10]: 4

__

Why: Initializing log_file_path in the outer scope prevents a potential NameError when accessing it in the early exit check, improving code robustness.

Low

chenjw added 7 commits March 5, 2026 20:45
- Update Python to use py-machineid library
- Update Rust to use machine-uid crate
- Remove unused chat_v2.rs
- Move machine ID from file storage to system-provided IDs
- Add fallback to "default" if system ID is unavailable

```bash
# Install VikingBot from source (in OpenViking root directory)
uv pip install -e bot/
Copy link
Collaborator

Choose a reason for hiding this comment

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

.[bot] 这种会不会好点

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

现在vikingbot还是源码安装,下个pr改成.[bot] 这样

@MaojiaSheng MaojiaSheng merged commit 57b3206 into main Mar 6, 2026
26 of 28 checks passed
@github-project-automation github-project-automation bot moved this from Backlog to Done in OpenViking project Mar 6, 2026
@MaojiaSheng MaojiaSheng deleted the fix/ov_chat_bug branch March 6, 2026 03:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants