Skip to content

fix: enable image recognition runtime checks#9203

Draft
jasminemai77 wants to merge 1 commit into
AstrBotDevs:masterfrom
jasminemai77:codex/image-recognition-health
Draft

fix: enable image recognition runtime checks#9203
jasminemai77 wants to merge 1 commit into
AstrBotDevs:masterfrom
jasminemai77:codex/image-recognition-health

Conversation

@jasminemai77

@jasminemai77 jasminemai77 commented Jul 10, 2026

Copy link
Copy Markdown

Summary

  • Enable Gemini image recognition in the local runtime configuration.
  • Add runtime health checks, proxy-aware startup, and browser diagnostics.

Validation

  • Verified Gemini image input with a real API request.
  • Ran configuration, browser smoke, Python compile, and Ruff checks.

Summary by Sourcery

Add runtime configuration guards, health diagnostics, and startup scripts to support stable AstrBot operation with Gemini image recognition and QQTools browser search.

New Features:

  • Introduce a runtime config guard script to enforce AstrBot provider, plugin, and tool settings for Gemini vision and browser-based search.
  • Add a comprehensive runtime health diagnostic script to validate core settings, plugin wiring, browser environment, ports, and recent log signals.
  • Provide a PowerShell startup script and batch wrapper that wire in config guarding, health checks, proxy setup, and safe restart behavior for AstrBot.
  • Document the local runtime stability and troubleshooting workflow, including safe restart and browser_search verification.

Enhancements:

  • Align multiple plugin and feature configs (SelfLearning, Private Companion, AngelHeart, SpectreCore, etc.) around a single persona and reduced slow paths for more predictable behavior.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a comprehensive local runtime stability and diagnostics suite for AstrBot, including a troubleshooting runbook, a health diagnosis script, a configuration alignment script, and PowerShell/batch startup wrappers. The review feedback highlights several critical improvements: resolving a hardcoded user path for uv.exe in the PowerShell script, replacing absolute paths in the documentation with placeholders, optimizing log reading in the health script to avoid loading entire large files into memory, adding a connection timeout for SQLite to handle potential database locks, and handling potential race conditions in process termination.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread start_astrbot.ps1
}

$Root = $PSScriptRoot
$UvPath = "C:\Users\mai\.local\bin\uv.exe"

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.

high

The path to uv.exe is hardcoded to a specific user's directory (C:\Users\mai). This will fail on any machine where the username is not mai. Use the $env:USERPROFILE environment variable to resolve the path dynamically.

$UvPath = Join-Path $env:USERPROFILE ".local\bin\uv.exe"

Comment on lines +10 to +11
Set-Location "D:\Project files\AstrBotCore"
powershell -NoProfile -ExecutionPolicy Bypass -File ".\start_astrbot.ps1"

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.

medium

The runbook contains hardcoded absolute paths like D:\Project files\AstrBotCore. This makes the documentation less portable and confusing for other users who might clone the repository to a different directory. Consider using relative paths or placeholders like <path_to_astrbot_core> instead.

Suggested change
Set-Location "D:\Project files\AstrBotCore"
powershell -NoProfile -ExecutionPolicy Bypass -File ".\start_astrbot.ps1"
Set-Location "<path_to_astrbot_core>"
powershell -NoProfile -ExecutionPolicy Bypass -File ".\start_astrbot.ps1"

Comment on lines +903 to +905
text = "\n".join(
path.read_text(encoding="utf-8", errors="replace")[-200_000:] for path in paths
)

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.

medium

Reading the entire log file into memory with path.read_text() and then slicing the last 200,000 characters can cause high memory usage and performance degradation if the log files grow very large. Consider reading only the end of the file or streaming it.

    def _read_tail(p: Path) -> str:
        try:
            with open(p, "rb") as f:
                f.seek(0, 2)
                f.seek(max(0, f.tell() - 200000))
                return f.read().decode("utf-8", errors="replace")
        except Exception:
            return ""
    text = "\n".join(_read_tail(p) for p in paths)

return []

changed: list[str] = []
with sqlite3.connect(DB_PATH) as conn:

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.

medium

If the AstrBot database is locked (e.g., if the bot is currently running or performing a transaction), sqlite3.connect will raise an OperationalError. Since this script is run as a pre-startup check, setting a connection timeout is recommended to prevent the script from crashing abruptly.

Suggested change
with sqlite3.connect(DB_PATH) as conn:
with sqlite3.connect(DB_PATH, timeout=10.0) as conn:

Comment thread start_astrbot.ps1
$ProcessIds = Get-AstrBotStopPlan -Owners $Owners
foreach ($ProcessId in $ProcessIds) {
Write-Host "Stopping old AstrBot process PID $ProcessId ..." -ForegroundColor Yellow
Stop-Process -Id $ProcessId -Force

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.

medium

Since $ErrorActionPreference = "Stop" is set at the beginning of the script, if the process exits on its own just before Stop-Process is executed, the script will throw a terminating error and crash. Add -ErrorAction SilentlyContinue to prevent this race condition.

        Stop-Process -Id $ProcessId -Force -ErrorAction SilentlyContinue

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