fix: isOwnedByAgent derived ownership (#448)#522
fix: isOwnedByAgent derived ownership (#448)#522jlin53882 wants to merge 1 commit intoCortexReach:masterfrom
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Review Claw 🦞 — PR 說明本 PR 是 #509 的乾淨版本,移除了所有 scope creep 內容。 問題背景(Issue #448)\isOwnedByAgent()\ 在 \src/reflection-store.ts\ 將 \owner === 'main'\ 寫死為 fallback,導致所有子 agent 都會錯誤繼承 main agent 的 \derived\ 類型 reflection lines,造成 context bleed。 修正內容1. \src/reflection-store.ts\ — isOwnedByAgent() 核心 fix \\diff
行為對照:
2. \index.ts\ — _initialized P1 bug fix \\diff
原因:如果 \parsePluginConfig()\ 拋例外,flag 已設為 true,未來所有 測試驗證
不在本 PR 範圍內的內容以下內容原本在 #509,已全數移除,未來將各自獨立開 PR:
Supersedes PR #509 (closed) |
|
Hi @jlin53882, the |
rwmjhb
left a comment
There was a problem hiding this comment.
Review: fix: isOwnedByAgent derived ownership (#448)
多 agent 场景下 main agent 的 derived items 泄漏到其他 agent 是真实 bug。但实现有几个问题:
Must Fix
-
幂等 guard 时机不对:
_initialized在onStart完成前就被设置,如果初始化抛异常,后续register()调用会被永久阻塞。 -
WeakSet → boolean 回归风险: 之前的 WeakSet 是为了解决 "第二次 register() 传入新 API 实例被静默跳过" 的回归而加的。换成 module-level boolean 会丢失 per-instance 感知,可能重新引入那个 bug。
-
缺少测试:
isOwnedByAgent的itemKind=derived分支没有对应的测试覆盖。
Questions
register()是否可能在 plugin 生命周期中被不同的 API 实例多次调用?如果是,boolean guard 不够用。- EADDRINUSE crash (port 11434) 是环境问题还是测试引入的?
Update: WeakSet.clear() IssueThe WeakSet.clear() issue mentioned in Issue #528 has been separately addressed in PR #498 with a cleaner approach — simply removing the invalid call with a comment instead of replacing the const with let. No additional changes needed in this PR for the WeakSet.clear issue. |
6ee36d6 to
a589c0f
Compare
- isOwnedByAgent:當itemKind="derived"時不做owner="main" fallback,防止子agent錯誤繼承main的derived lines - 修補_initialized時機:_initialized=true移到register()初始化成功後(Must Fix 1) - 恢復WeakSet:使用WeakSet<OpenClawPluginApi>追蹤per-instance,防止第二個API instance被靜默跳過(Must Fix 2) - resetRegistration:加入_resetInitialized() backward alias,維持公共API相容 - 新增test/isOwnedByAgent.test.mjs:11個測試案例覆蓋derived/invariant/legacy所有情境(Must Fix 3)
a589c0f to
fcf23f5
Compare
Response to ReviewThank you for the detailed review. Must Fix 1 & 2:
|
Review SummaryAutomated multi-round review (7 rounds, Claude + Codex adversarial). Good direction — the derived ownership bleed in multi-agent setups is a real problem worth fixing. Must Fix
Nice to Have
Questions
Please address the must-fix items. Once resolved, this is ready to merge. |
Response to ReviewThank you for the detailed review. Please see my responses below. Must Fix 1 & 2 — Already fixed in latest commit (fcf23f5)Both issues were present in an earlier version of this PR. The latest commit (
If you reviewed an earlier version of this PR, please re-review the latest commit — it should show the WeakSet is properly restored and the timing issue is resolved. Must Fix 3 — CI cli-smoke failureThe CI failure on
Must Fix 4 — EADDRINUSE port 11434Confirmed as environmental — full test suite crash before completing, unrelated to this PR. QuestionsIssue #448 confirmed by maintainers? register() lifecycle — can it be called with different API instances? Nice to HaveOptional chaining on Legacy combined reflection ownership fix — The SummaryAll Must Fix items are addressed in commit |
48eecb7 to
fcf23f5
Compare
|
I'll analyze this and get back to you. |

Summary
Fixes \isOwnedByAgent\ in \src/reflection-store.ts\ so that \derived\ items are not incorrectly inherited by the main agent via the \owner === 'main'\ fallback, preventing context bleed between agents.
Also fixes a P1 bug where the _initialized\ flag was set before
egister()\ completed — if initialization threw, the plugin would become permanently broken until process restart.
Changes
Testing
Related: Supersedes PR #509, which contained scope creep issues (unrelated features bundled in the same PR). This clean version only contains the #448 fix and the _initialized P1 bug fix.