utilitas 2001.1.129 → 2001.1.131

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/AGENTS.md CHANGED
@@ -14,3 +14,15 @@ For all documentation files, line length limits are not required.
14
14
  ### Python
15
15
 
16
16
  - Follow PEP 8 style guidelines.
17
+
18
+ ## 項目分析與開發要點 (Project Design & Development)
19
+
20
+ ### 1. PostgreSQL 連接與 pgvector 初始化流控
21
+ 在 `lib/dbio.mjs` 中,為了防止併發查詢時出現 `DeprecationWarning: Calling client.query() when the client is already executing a query` 警告,採取了以下關鍵設計:
22
+
23
+ - **痛點**:`pg` 庫的 `connect` 事件監聽器不支援異步等待。若直接在監聽器註冊 `pgvector`,註冊查詢會與業務查詢在同一個客戶端併發執行,產生競態條件。
24
+ - **解決依據**:
25
+ - **手動管理連接**:在 `rawQuery` 和 `rawExecute` 中,針對 PostgreSQL 顯式通過 `conn.connect()` 獲取客戶端。
26
+ - **狀態標記**:使用 `pgCheckedClients` (WeakSet) 標記已完成初始化註冊的物理連接,確保「每個物理連接僅註冊一次」且不造成內存洩漏。
27
+ - **強制流控**:在執行業務 SQL 前 `await pgvector.registerType(client)`,從而保證:`獲取連接` -> `註冊完成` -> `執行查詢` 的嚴格異步順序。
28
+ - **AI 注意**:不要使用 `pool.query` 繞過此邏輯。