本卡屬 FR-181(母卡 FR-181 母案(同清單上一張)),卡 A-2,批 5。只改 主 repo。依賴:A-1。

這張卡做什麼(白話)

主系統這邊六種指令的「送」那一段換掉:原本是「寫 DB 正本 → 主動打 Agent 8443」,改成「寫 DB 正本 → 敲一下 Redis 的鈴」,掛在那台 Agent 長輪詢上的請求就會醒來自己查表拿走。六種:派工(工單 insert 事件後)、重啟(管理頁按鈕後)、升級(分批轉下發後)、設定變了(授權清冊等 13 類改動後)、立即換證、取消檢測——後兩種原本沒有 DB 正本(只發不記),改成寫進 agent_requests。直推那支 AgentCommandService 整支保留,只在 send() 開頭加開關 AGENT_DIRECT_PUSH_ENABLED 預設 False 擋掉(決策者裁「留著怕未來要開」)。心跳回來那條「補推」改成只敲鈴、仍不夾帶任何東西(11-01 裁示不翻)。連線欄用的 last_command_status 停寫、欄位留著(FE B-3 改二態)。

reuse/extend/new

extend:core/plugins/_agent_commands.py——_push_after_commit/push_restart_after/push_update_soon/redispatch_on_heartbeat 的「送」全部改成 waiter.notify(agent_uid)(正本已在 DB,長輪詢端點自己查);with_command_push 的 _PUSH_AFTER 改成 notify;record_probe_after 刪(連線欄改二態)。_agent_config_notify.notify_agent_after_commit 改寫 agent_requests(kind=config_changed)+notify(取代直推 /config/notify)。_agent_keys.py:118 立即換證改 fire(agent, credentials_renew)。AgentCommandService:整支保留,send() 開頭加 if not settings.AGENT_DIRECT_PUSH_ENABLED: return CommandResult.disabled()(D6 開關,預設 False,config/config.py 加變數);run_now/after_commit 不動。redispatch_on_heartbeat 留一行 notify(心跳回來順手敲一下鈴,仍不夾帶)。last_command_status 停寫(欄位留,B-3 FE 改二態)

在哪裡

repo:~/Projects/Billows/Audit-Manager/compliance-manager-be
改既有:core/plugins/_agent_commands.py
改既有:core/plugins/_agent_config_notify.py 135
改既有:core/plugins/_agent_keys.py 118
改既有:app/remote_agent/service/agent_command_service.py 55(開關)
改既有:config/config.py(AGENT_DIRECT_PUSH_ENABLED)
改既有:test/test_agent_command_service.py

怎麼做

驗收(首腦照這個驗)

pytest 既有 test_agent_command_service 改成新語意綠;突變:拿掉 AGENT_DIRECT_PUSH_ENABLED 判斷 → 守衛紅。DEV+123 Agent(F-2 版)實測:派工 3 秒內開跑;管理頁按重啟 → Agent 重啟且旗標清掉、不重複重啟;分批升級轉成下發 → Agent 3 秒內開始下載;改授權清冊 → Agent 3 秒內拉到;按立即換證 → agent_requests 一列 done、Agent log 有 renew;grep -rn 'data_plane_client().command\|\.send(' core/ app/ 只剩開關後那一處

必讀