Skip to content

Comments

fix: LineBot 超時時回覆使用者錯誤訊息#125

Merged
yazelin merged 7 commits intomainfrom
fix/linebot-timeout-reply
Feb 25, 2026
Merged

fix: LineBot 超時時回覆使用者錯誤訊息#125
yazelin merged 7 commits intomainfrom
fix/linebot-timeout-reply

Conversation

@yazelin
Copy link
Owner

@yazelin yazelin commented Feb 25, 2026

Summary

  • 修正 Claude CLI 超時(480 秒)後不回覆使用者的問題
  • 超時時如有部分文字回應(text_buffer),發送已收集到的內容
  • 完全無回應時,發送「處理時間過長,請稍後再試」錯誤提示

問題背景

最近 linebot-group 連續兩次因 WebFetch / search_knowledge 工具超時,使用者等了 8 分鐘完全沒收到任何回覆。原因是超時後直接 return None,未發送任何訊息。

Test plan

  • 確認正常回應流程不受影響
  • 模擬超時場景,確認使用者收到錯誤提示
  • 確認有部分 text_buffer 時會發送已收集的內容

🤖 Generated with Claude Code

yazelin and others added 2 commits February 25, 2026 09:50
These were backup copies created when Vite was introduced and are no longer referenced anywhere.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
之前 Claude CLI 超時(480 秒)且無圖片生成時,直接 return None
導致使用者等了 8 分鐘卻完全沒收到任何回覆。

現在改為:
- 如有部分文字回應(text_buffer),發送已收集到的內容
- 如完全無回應,發送「處理時間過長,請稍後再試」提示

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gemini-code-assist
Copy link

Summary of Changes

Hello @yazelin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取請求主要解決了 LineBot 在 AI 服務處理超時時的無回應問題,顯著提升了使用者體驗。透過引入更完善的錯誤處理機制,LineBot 現在能夠在 AI 回應延遲時提供部分內容或友善的錯誤提示,避免使用者長時間等待卻一無所獲。此外,此 PR 還包含了一項重要的前端架構調整,即移除了 frontend/_legacy_scripts 目錄下的所有舊版 JavaScript 檔案,這暗示著前端代碼庫進行了大規模的清理或遷移。

Highlights

  • LineBot 超時回應優化: 修正了 LineBot 在 AI 處理超時後不回覆使用者的問題,確保使用者能收到即時回饋。
  • 部分回應發送機制: 優化了超時處理邏輯,若 AI 在超時前已產生部分文字回應,則會將這些已收集的內容發送給使用者。
  • 超時錯誤提示: 若 AI 在超時時完全沒有回應,則會發送一個預設的錯誤提示訊息給使用者。
  • 前端舊版腳本移除: 移除了 frontend/_legacy_scripts 目錄下的所有舊版前端 JavaScript 檔案,這代表著前端架構的重大重構或遷移。

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • backend/src/ching_tech_os/services/linebot_ai.py
    • 新增了處理 AI 回應超時的邏輯,確保在超時時能發送部分回應或錯誤提示。
    • 移除了在超時情況下直接返回 None 的行為,改為提供使用者回饋。
  • frontend/_legacy_scripts/agent-settings.js
    • 移除了舊版 Agent 設定應用程式的 JavaScript 檔案。
  • frontend/_legacy_scripts/ai-assistant.js
    • 移除了舊版 AI 助手應用程式的 JavaScript 檔案。
  • frontend/_legacy_scripts/ai-log.js
    • 移除了舊版 AI Log 應用程式的 JavaScript 檔案。
  • frontend/_legacy_scripts/api-client.js
    • 移除了舊版 API 客戶端 JavaScript 檔案。
  • frontend/_legacy_scripts/code-editor.js
    • 移除了舊版程式碼編輯器模組的 JavaScript 檔案。
  • frontend/_legacy_scripts/config.js
    • 移除了舊版全域配置 JavaScript 檔案。
  • frontend/_legacy_scripts/desktop.js
    • 移除了舊版桌面模組的 JavaScript 檔案。
  • frontend/_legacy_scripts/device-fingerprint.js
    • 移除了舊版裝置指紋產生器 JavaScript 檔案。
  • frontend/_legacy_scripts/external-app.js
    • 移除了舊版外部應用程式模組的 JavaScript 檔案。
  • frontend/_legacy_scripts/file-manager.js
    • 移除了舊版檔案管理器模組的 JavaScript 檔案。
  • frontend/_legacy_scripts/file-opener.js
    • 移除了舊版檔案開啟器模組的 JavaScript 檔案。
  • frontend/_legacy_scripts/file-utils.js
    • 移除了舊版檔案工具模組的 JavaScript 檔案。
  • frontend/_legacy_scripts/header.js
    • 移除了舊版 Header 模組的 JavaScript 檔案。
  • frontend/_legacy_scripts/icons.js
    • 移除了舊版圖示定義 JavaScript 檔案。
  • frontend/_legacy_scripts/image-viewer.js
    • 移除了舊版圖片檢視器模組的 JavaScript 檔案。
  • frontend/_legacy_scripts/knowledge-base.js
    • 移除了舊版知識庫模組的 JavaScript 檔案。
  • frontend/_legacy_scripts/linebot.js
    • 移除了舊版 LineBot 管理介面 JavaScript 檔案。
  • frontend/_legacy_scripts/login.js
    • 移除了舊版登入模組 JavaScript 檔案。
  • frontend/_legacy_scripts/matrix-rain.js
    • 移除了舊版 Matrix 雨效果 JavaScript 檔案。
  • frontend/_legacy_scripts/memory-manager.js
    • 移除了舊版記憶管理應用程式 JavaScript 檔案。
  • frontend/_legacy_scripts/message-center.js
    • 移除了舊版訊息中心模組 JavaScript 檔案。
  • frontend/_legacy_scripts/notification.js
    • 移除了舊版通知模組 JavaScript 檔案。
  • frontend/_legacy_scripts/path-utils.js
    • 移除了舊版路徑工具模組 JavaScript 檔案。
  • frontend/_legacy_scripts/pdf-viewer.js
    • 移除了舊版 PDF 檢視器模組 JavaScript 檔案。
  • frontend/_legacy_scripts/permissions.js
    • 移除了舊版權限模組 JavaScript 檔案。
  • frontend/_legacy_scripts/prompt-editor.js
    • 移除了舊版 Prompt 編輯器應用程式 JavaScript 檔案。
  • frontend/_legacy_scripts/public.js
    • 移除了舊版公開分享頁面邏輯 JavaScript 檔案。
  • frontend/_legacy_scripts/settings.js
    • 移除了舊版設定應用程式 JavaScript 檔案。
  • frontend/_legacy_scripts/share-dialog.js
    • 移除了舊版分享對話框模組 JavaScript 檔案。
  • frontend/_legacy_scripts/share-manager.js
    • 移除了舊版分享管理應用程式 JavaScript 檔案。
  • frontend/_legacy_scripts/socket-client.js
    • 移除了舊版 Socket.IO 客戶端模組 JavaScript 檔案。
  • frontend/_legacy_scripts/terminal.js
    • 移除了舊版終端機應用程式 JavaScript 檔案。
  • frontend/_legacy_scripts/text-viewer.js
    • 移除了舊版文字檢視器模組 JavaScript 檔案。
  • frontend/_legacy_scripts/theme.js
    • 移除了舊版主題管理模組 JavaScript 檔案。
  • frontend/_legacy_scripts/user-profile.js
    • 移除了舊版使用者設定檔模組 JavaScript 檔案。
  • frontend/_legacy_scripts/window.js
    • 移除了舊版視窗模組 JavaScript 檔案。
Activity
  • 此拉取請求由 yazelin 建立,並包含了對 LineBot AI 服務超時處理邏輯的修正。目前沒有其他審閱者活動或評論。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

這項 PR 主要修正了 LineBot 在 AI 處理超時後沒有回覆的問題,並移除了大量舊版的前端腳本。後端 linebot_ai.py 的修改確保了在超時或失敗的情況下,能根據是否有部分回應來發送適當的訊息給使用者,這解決了原本的問題。此外,大量舊版 JavaScript 檔案的移除是一項很好的程式碼清理工作。我在程式碼中發現一處邏輯重複的問題,並已提出具體的修改建議以提高程式碼的可維護性。整體而言,這是一項有價值的修正與重構。

Comment on lines 621 to 627
elif response.message and response.message.strip():
# 超時但有部分文字回應,發送已收集到的內容
logger.info(f"失敗但有部分文字回應({len(response.message)} 字元),嘗試發送")
ai_response = response.message.strip()
else:
return None
# 完全沒有回應,發送錯誤提示
ai_response = "⚠️ 抱歉,處理時間過長,請稍後再試一次。"

Choose a reason for hiding this comment

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

medium

此處的 elif/else 區塊與下方的 L628-L634 區塊邏輯重複。當 response.tool_calls 為真但沒有 generated_images 時,會執行此處的邏輯。然而,若移除此區塊,程式流程會自然地落到下方的 elif response.message ... 判斷,這不僅能達到相同的效果,也能讓程式碼更簡潔、易於維護。

建議移除此重複的邏輯區塊。

yazelin and others added 4 commits February 25, 2026 11:12
之前 raw_response 只在 success=True 時記錄,失敗時一律存 None。
但超時時 Claude 可能已產生部分文字,應該記錄以便除錯。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Claude CLI(ACP)內部多輪工具呼叫時,前幾輪的 WebSearch/WebFetch
可能已成功完成,但最後一輪工具卡住導致整體超時。

新增 _fallback_summarize_from_tools() 函數:
- 優先從已完成的搜尋/抓取結果中提取有用內容回覆使用者
- 其次使用 text_buffer 中的部分文字
- 最後才顯示通用錯誤訊息

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
每次伺服器重啟會在 /tmp 建立新的 ching-tech-os-cli-* base 目錄,
舊的不會自動清除,長期累積數百個空目錄。

新增 cleanup_cli_temp_dirs 排程:
- 每天凌晨 4:00 執行
- 刪除超過 1 天的舊 CLI base 目錄
- 排除當前正在使用的目錄

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- test_process_message_with_ai_failed_response_without_tool_calls:
  失敗時不再 return None,改為回覆錯誤提示
- test_start_and_stop_scheduler: 排程數量 6→7(新增 cleanup_cli_temp_dirs)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@yazelin
Copy link
Owner Author

yazelin commented Feb 25, 2026

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

此 PR 修正了 LineBot 在 AI 超時後不回覆的問題,透過後備機制改善了使用者體驗。同時也新增了清理暫存目錄的排程任務,有助於系統維護。程式碼變更大致良好,我提出了一些關於簡化重複邏輯與移除未使用參數的建議。

另外,注意到這次提交移除了大量 frontend/_legacy_scripts 下的檔案,但 PR 描述中並未提及。建議補充說明這部分變更的背景,例如是否為計畫中的前端重構,以利於審核者理解完整的變更範圍。

# ============================================================


async def _fallback_summarize_from_tools(response, user_message: str) -> str:

Choose a reason for hiding this comment

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

medium

user_message 參數在此函式中並未使用,建議移除以保持程式碼簡潔。請記得同時更新呼叫此函式的地方。

Suggested change
async def _fallback_summarize_from_tools(response, user_message: str) -> str:
async def _fallback_summarize_from_tools(response) -> str:

Comment on lines 667 to 673
elif response.message and response.message.strip():
# 沒有 tool_calls 但有部分文字回應
logger.info(f"失敗但有部分文字回應({len(response.message)} 字元),嘗試發送")
ai_response = response.message.strip()
else:
return None
# 完全沒有回應,發送錯誤提示
ai_response = "⚠️ 抱歉,處理時間過長,請稍後再試一次。"

Choose a reason for hiding this comment

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

medium

這段 elif/else 程式碼與 _fallback_summarize_from_tools 函式中的邏輯重複了。即使沒有 tool_calls_fallback_summarize_from_tools 也能處理 response.message 和完全無回應的情況。建議將此處的邏輯統一由 _fallback_summarize_from_tools 處理,以避免程式碼重複並提高可維護性。

依 code review 建議:
- 移除 _fallback_summarize_from_tools 未使用的 user_message 參數
- 合併重複的 elif/else 分支,統一由 _fallback_summarize_from_tools 處理

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@yazelin yazelin merged commit 5275409 into main Feb 25, 2026
2 checks passed
@yazelin yazelin deleted the fix/linebot-timeout-reply branch February 25, 2026 04:32
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