Repository navigation
feat: 閒置斷線自動重登 + 登入頻率限制(60 秒) - #25
Open
PttCodingMan wants to merge 1 commit into
Open
PttCodingMan wants to merge 1 commit into
PttCodingMan wants to merge 1 commit into
Conversation
- 同一帳號 60 秒內只允許一次登入嘗試(失敗也算),超過回 LOGIN_THROTTLED + retry_after - 閒置超過 60 秒的下一次呼叫前先用 get_time 探測,斷線才重登;先探測再呼叫,避免寫入操作重試重複送出 - 主動登出或從未登入時不自動登入 - login/logout docstring 提示 agent 不需做完事就登出、不要反覆 login Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011od43ZvAoaP413L1eYeWSD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
問題
放太久會被 PTT 斷線,之後的呼叫失敗,agent 會反覆呼叫
login();但登入太頻繁又會被 PTT 擋下。做法
讓 server 自己處理斷線與登入頻率,不靠 agent 判斷何時登出。
_activate):同一帳號 60 秒內只允許一次登入嘗試(失敗也算)。超過時不連 PTT,直接回{"code": "LOGIN_THROTTLED", "retry_after": N}。連線活著時login()本來就不重登,不受影響。_ensure_alive,由_call_ptt_service在每次呼叫前執行):距上次呼叫超過 60 秒時,先用get_time探測,斷線才重登(同樣受頻率限制)。NOT_LOGGED_IN。logout已持有_pool_lock,呼叫時跳過探測以免死結。login/logoutdocstring 提示 agent:不需做完事就登出、不要反覆login、遇到LOGIN_THROTTLED依retry_after等待。兩個門檻是
api_ptt.py開頭的LOGIN_MIN_INTERVAL、IDLE_PROBE_SECONDS。測試
src/test_auto_relogin.py:頻率限制、失敗也計入、活著不重登、閒置後自動重登、剛用過不探測、重登被擋時不送出原操作、登出後不自動登入。test_switch_to_dead_relogs會在同一瞬間重登,改為把上次登入時間往前推 60 秒以避開新限制。pytest src:27 passed;mypy .通過。皆以假 Service 測試,尚未對真實 PTT 驗證。🤖 Generated with Claude Code
https://claude.ai/code/session_011od43ZvAoaP413L1eYeWSD
Generated by Claude Code