fix(redis-lock): URL parsing fix + lock domain single-flight (PR-1)#709
fix(redis-lock): URL parsing fix + lock domain single-flight (PR-1)#709jlin53882 wants to merge 2 commits intoCortexReach:masterfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ecda19381b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| * 目前工廠函式在 Redis 不可用時正確返回 null,確保現有 file lock 行為不受影響。 | ||
| */ | ||
|
|
||
| import Redis from 'ioredis'; |
There was a problem hiding this comment.
Declare ioredis as a runtime dependency
src/redis-lock.ts now has a top-level import 'ioredis', but this package is not added to package.json/package-lock.json. In a clean install, importing this module will throw ERR_MODULE_NOT_FOUND, so any future use of determineLockDomain() silently falls back to file lock and the new URL-parsing test cannot run when dependencies are installed from lockfile. Please add ioredis as a declared dependency in this same change.
Useful? React with 👍 / 👎.
Codex 對抗性審查問題回應感謝 Codex 的對抗性審查。以下是逐項回應: 🔴 Critical — Dead Integration(已修復 ✅)Codex 聲稱: 沒被使用,Redis locking 完全沒有接入寫入路徑。 驗證結果:✅ 屬實。 確實被定義但從未被任何寫入路徑呼叫。 修復內容(commit ):
🟡 Medium — Connection Leak(已修復 ✅)Codex 聲稱:健康檢查成功後 Redis client 連線不關閉,會 leak。 驗證結果:✅ 方向正確,但描述不夠精確。真正問題是:健康檢查成功後 被 return,但沒有任何地方儲存這個 reference,後續根本無法使用同一個連線。 修復內容:
🟡 Medium — Sticky Fallback(不成立 ❌)Codex 聲稱:Redis 單次失敗後永久放棄,即使後來恢復也不重試。 驗證結果:❌ 不成立。Codex 把兩件事搞混了:
是刻意設計,用 single-flight 避免 lock domain 分裂(req-A 用 Redis lock,req-B 用 file lock)。File lock failure 不 retry 是對的,避免 Redis 掛掉時觸發 storm。 ❌ 不成立 — 測試檔 SyntaxErrorCodex 聲稱: 有 JS SyntaxError,無法執行。 驗證結果:❌ 不成立。測試檔完全正常,執行結果:13/13 通過。Codex 的診斷是錯誤的。 完整問題清單
PR #709 審查流程說明Codex 做的是 spec 符合性掃描("實作符合描述嗎"),但沒有 cross-file code path tracing 的視角,所以才會同時出現「漏抓真正的問題」和「誤判正常的行為」。這是對抗性審查的價值所在——它挑戰的是整個假設框架,而不只驗證實作細節。 |
測試檔已加入 CI manifest ✅commit
CI 執行方式: npm test # 含 redis-url-parsing.test.mjs
npm run test:storage-and-schema # 只跑 storage-and-schema 群組 |
6df6831 to
ff10636
Compare
ff10636 to
0545c91
Compare
PR-1 基礎設施(URL parsing + single-flight decision):
新增:
- src/redis-lock.ts:parseRedisUrl() 修復 URL 解析 bug
- 正確處理 legacy (host:port)、auth、rediss://、query string
- 舊實作 .replace('redis://','') 破壞含密碼/TLS/query 的 URL
- test/redis-url-parsing.test.mjs:13 個測試案例
修改:
- src/store.ts:加入 getLockDomain() single-flight 決策
- 全程序只決定一次 Redis 或 file lock
- 避免 concurrent request 在 init 完成前看到不同 lock domain
- 若 redis-lock.js 不存在或匯入失敗,預設用 file lock(不影響現有行為)
PR-1:URL parsing fix + lock domain single-flight
變更範圍
PR 拆分設計背景
本 PR 為 #704 拆分方案的第一階段(PR-1/3)。完整設計見:PR704_SPLIT_DESIGN_v3.md
對抗式審查(Claude Code)