--- tags: [cypher, 部署, 架構決策, 踩坑] gloss: self-hosted cypher 和 component 同在 workers.dev zone 觸發 CF 1042,用 global_fetch_strictly_public flag 解,不是 Service Binding。 --- # Same-Zone 1042 用 flag 解不用 Binding ← [[decisions/00-INDEX]] **來源**:`system-dev/wiki/decisions-summary.md`(Cypher 怎麼調用零件避開 same-zone 1042)、`docs/incidents/2026-05-13-cypher-outbound-522.md` **最後更新**:2026-06-27 ## 摘要 Cloudflare Workers 的 same-zone fetch 防護(HTTP 522)在 self-hosted 部署中會踩坑,因為 cypher 和 component 都在 `{sub}.workers.dev`。解法是在 cypher-executor 的 wrangler.toml 加 `global_fetch_strictly_public` flag,讓 same-zone fetch 走公網前門——而非用 Service Binding(那樣更死)。 ## 重點 - **官方部署無此問題**:cypher 在 `cypher.arcrun.dev`、component 在 `*.arcrun.dev` 或 `arcrun-*.workers.dev`,跨 zone,不踩防護。 - **Self-hosted 部署踩坑**:都在 `{sub}.workers.dev`,CF 防止同 zone 自循環死鎖,cypher fetch component 返 522。 - **為什麼不用 Service Binding**:Binding 靜態、修改要 redeploy;component 清單動態(用戶 workflow 決定),改變架構必要性低;flag 無副作用(official 加也沒影響,本就跨 zone)。 - **Flag 部署法**:`cypher-executor/wrangler.toml` 加一行 `compatibility_flags = [ "nodejs_compat", "global_fetch_strictly_public" ]`,然後 cypher 和 auth worker 間的 HTTP fetch 都能通。 - **驗證**:若仍 522 → 檢查 flag 是否生效(某些 Wrangler 版本可能有 bug)。 ## 實體 - **Same-zone 防護**(Cloudflare same-zone protection)— CF Workers 內建的防護機制,禁止 Worker 在同一 zone 內 fetch 另一個 Worker 以防自循環。 - **HTTP 522**(522 Connection Timed Out)— Cloudflare 自有錯誤,表示 fetch 因防護被擋。 - **global_fetch_strictly_public flag**(Cloudflare compatibility flag)— 讓 same-zone fetch 從內部網路改走公網前門的相容旗標,無副作用。 - **cypher-executor**(Cypher 執行引擎)— 調度 workflow 並呼叫零件的 Worker,需加 flag 才能在 self-hosted fetch component。 - **動態 component 清單**(dynamic component list)— workflow 執行時的零件集合,由用戶定義、會變動,無法靜態綁定。 ## 關聯 ### 內文知識關係 - same-zone 防護 >> 在 self-hosted >> 觸發 HTTP 522 - global_fetch_strictly_public flag >> 解決 >> HTTP 522 - global_fetch_strictly_public flag >> 不改變 >> 官方部署 - Service Binding >> 不能解決 >> 動態 component 清單 ### 卡片關係 - [[same-zone-1042用flag解不用binding]] >> 迴避 >> [[service-binding-vs-cypher-binding]] - [[same-zone-1042用flag解不用binding]] >> 涉及事件 >> [docs/incidents/2026-05-13-cypher-outbound-522.md]