Skip to content

Fix/bot Fix Memory Consolidation Issues and Integrate Vikingbot as OpenViking Optional Dependency#492

Merged
MaojiaSheng merged 21 commits intomainfrom
fix/bot_fix
Mar 9, 2026
Merged

Fix/bot Fix Memory Consolidation Issues and Integrate Vikingbot as OpenViking Optional Dependency#492
MaojiaSheng merged 21 commits intomainfrom
fix/bot_fix

Conversation

@chenjw
Copy link
Collaborator

@chenjw chenjw commented Mar 9, 2026

Description

This PR contains two main parts:

  1. Fix multiple memory consolidation issues (duplicate session write, hook
    errors, async issues, etc.)
  2. Integrate Vikingbot as an optional dependency of OpenViking, unifying the
    project structure

Detailed Changes

  1. Memory Consolidation & Performance Optimization

1.1 Fix Memory Consolidation Issues

  • Fix duplicate session writes: Prevent the same session from being written
    multiple times
  • Fix hook errors: Handle exceptions during hook execution
  • Fix async issues: Optimize concurrency control for async operations
  • Optimize memory usage: Reduce memory footprint and improve performance

1.2 Related File Changes

  • bot/vikingbot/agent/loop.py - Core Agent loop improvements
  • bot/vikingbot/agent/context.py - Context building optimization
  • bot/vikingbot/agent/memory.py - Memory management fixes
  • bot/vikingbot/hooks/builtins/openviking_hooks.py - Hook system
    improvements
  • bot/vikingbot/session/manager.py - Session management optimization
  1. Integrate Vikingbot as OpenViking Optional Dependency

2.1 Root pyproject.toml Updates

  • New optional dependency groups:
    • bot - Vikingbot core dependencies
    • bot-langfuse, bot-telegram, bot-feishu, bot-dingtalk, bot-slack, bot-qq
  • Fine-grained optional features
    • bot-sandbox, bot-fuse, bot-opencode - Extended features
    • bot-full - All features included
  • Updated package discovery: where = [".", "bot"] to find vikingbot package
    in bot/ directory
  • Updated package data: Add vikingbot static files (skills, console, bridge,
    etc.)
  • New script entry: vikingbot = "vikingbot.cli.commands:app"

2.2 Update Install Prompts in Code (11 files)

Update all install prompts from vikingbot[X] format to openviking[bot-X]:

  • bot/vikingbot/channels/manager.py
  • bot/vikingbot/channels/feishu.py
  • bot/vikingbot/channels/qq.py
  • bot/vikingbot/channels/dingtalk.py
  • bot/vikingbot/channels/openapi.py
  • bot/vikingbot/integrations/langfuse.py
  • bot/vikingbot/cli/commands.py
  • bot/vikingbot/sandbox/backends/opensandbox.py
  • bot/vikingbot/sandbox/backends/aiosandbox.py
  • bot/vikingbot/openviking_mount/viking_fuse.py
  • openviking/server/bootstrap.py

2.3 Documentation Updates

  • Root README.md / README_CN.md: Update installation instructions from uv
    pip install -e bot/ to uv pip install -e ".[bot]"
  • bot/README.md / bot/README_CN.md: Update installation instructions to use
    the new openviking optional dependency approach

2.4 Remove Independent Configuration

  • Delete bot/pyproject.toml - No longer need separate project configuration
  1. Other Improvements

3.1 Rust CLI Enhancements

  • crates/ov_cli/src/commands/chat.rs - Chat command improvements
  • crates/ov_cli/src/main.rs - Main program optimization

3.2 Test File Adjustments

  • Add bot/tests/example.py - Test example
  • Add bot/tests/experience_data_mini.json - Test data
  • Remove bot/tests/test_chat_functionality.py - Old test file

3.3 Server Related

  • openviking/server/routers/bot.py - Bot API router optimization
  • bot/scripts/restart_openviking_server.sh - Server restart script
    optimization

New Installation Methods

Install from PyPI (basic version)

pip install "openviking[bot]"

Install from source (development version)

uv pip install -e ".[bot]"

With optional features

uv pip install -e ".[bot,bot-telegram,bot-langfuse]"

Full version (all features included)

uv pip install -e ".[bot-full]"


Modified Files (33 files)

Added/Modified:

  1. pyproject.toml
  2. uv.lock
  3. README.md
  4. README_CN.md
  5. bot/README.md
  6. bot/README_CN.md
  7. bot/uv.lock
  8. bot/vikingbot/init.py
  9. bot/vikingbot/agent/loop.py
  10. bot/vikingbot/agent/context.py
  11. bot/vikingbot/agent/memory.py
  12. bot/vikingbot/channels/manager.py
  13. bot/vikingbot/channels/feishu.py
  14. bot/vikingbot/channels/qq.py
  15. bot/vikingbot/channels/dingtalk.py
  16. bot/vikingbot/channels/openapi.py
  17. bot/vikingbot/integrations/langfuse.py
  18. bot/vikingbot/cli/commands.py
  19. bot/vikingbot/sandbox/backends/opensandbox.py
  20. bot/vikingbot/sandbox/backends/aiosandbox.py
  21. bot/vikingbot/openviking_mount/viking_fuse.py
  22. bot/vikingbot/hooks/builtins/openviking_hooks.py
  23. bot/vikingbot/session/manager.py
  24. bot/workspace/skills/opencode/SKILL.md
  25. bot/scripts/restart_openviking_server.sh
  26. bot/tests/example.py (NEW)
  27. bot/tests/experience_data_mini.json (NEW)
  28. openviking/server/bootstrap.py
  29. openviking/server/routers/bot.py
  30. crates/ov_cli/src/commands/chat.rs
  31. crates/ov_cli/src/main.rs

Deleted:

  1. bot/pyproject.toml
  2. bot/tests/test_chat_functionality.py

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 and others added 17 commits March 6, 2026 17:55
… and async

- Fix _consolidate_memory hook error by creating temporary Session when given message list
- Remove duplicate session save logic from _consolidate_memory (handled by caller)
- Make normal memory consolidation async like /new command
- Other fixes: streaming response in CLI and OpenAPI channel
- Add vikingbot dependencies to pyproject.toml optional-dependencies
- Update install prompts from vikingbot[X] to openviking[bot-X]
- Update README installation instructions
- Configure setuptools to find vikingbot in bot/ directory
- Add vikingbot package data and script entry
vikingbot is now integrated as part of openviking, no need for separate pyproject.toml
- Update from 'uv pip install -e bot/' to 'uv pip install -e ".[bot]"'
- Add quotes around openviking[bot] for shell safety
@github-actions
Copy link

github-actions bot commented Mar 9, 2026

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

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

Import Error Risk

Unconditional import from openviking.async_client will break when openviking is not installed, violating optional dependency contract.

from openviking.async_client import logger
Async Consolidation Not Backgrounded

Memory consolidation is still awaited (blocking) instead of being run in background as intended.

await self._safe_consolidate_memory(session_clone, archive_all=True)
Disabled Sender Filtering

allow_from message filtering was commented out without replacement, potentially changing behavior.

# allow_from = self._get_channel_allow_from(session_id)
# filtered_messages = self._filter_messages_by_sender(
#     vikingbot_session.messages, allow_from
# )
filtered_messages = vikingbot_session.messages

@github-actions
Copy link

github-actions bot commented Mar 9, 2026

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Fix SSE event delimiter

Restore the double newline (\n\n) when yielding SSE events to ensure proper protocol
compliance. SSE requires events to be separated by a blank line for correct client
parsing.

openviking/server/routers/bot.py [184]

-yield f"{line}\n"
+yield f"{line}\n\n"
Suggestion importance[1-10]: 7

__

Why: SSE protocol requires events to be separated by a blank line (\n\n), so restoring the double newline ensures proper client parsing of the event stream.

Medium
Run consolidation in background

Use asyncio.create_task to run memory consolidation in the background instead of
await. This prevents blocking the response to the user while consolidation
completes.

bot/vikingbot/agent/loop.py [403-404]

 # Run consolidation in background
-await self._safe_consolidate_memory(session_clone, archive_all=True)
+asyncio.create_task(self._safe_consolidate_memory(session_clone, archive_all=True))
Suggestion importance[1-10]: 6

__

Why: Using asyncio.create_task instead of await prevents blocking the user response while memory consolidation completes, improving responsiveness.

Low
Use project-standard logger

Replace the imported logger from openviking.async_client with loguru.logger to
maintain consistent logging across the codebase. This ensures logs are properly
formatted and captured using the project's standard logging setup.

bot/vikingbot/agent/memory.py [2]

-from openviking.async_client import logger
+from loguru import logger
Suggestion importance[1-10]: 5

__

Why: Using loguru.logger maintains consistent logging across the codebase, matching other files like context.py that use loguru.

Low

chenjw added 4 commits March 9, 2026 18:04
Cache VikingClient instances by workspace_id to avoid repeated client creation
- Add _client_cache dictionary for caching
- Add get_cached_client() helper function
- Update both hooks to use cached client
- Change from per-workspace_id cache to true global singleton
- Create client with None as agent_id (works for all workspaces)
- Simplify client management
@MaojiaSheng MaojiaSheng merged commit c4cdb5f into main Mar 9, 2026
53 of 56 checks passed
@MaojiaSheng MaojiaSheng deleted the fix/bot_fix branch March 9, 2026 14:11
@github-project-automation github-project-automation bot moved this from Backlog to Done in OpenViking project Mar 9, 2026
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.

4 participants