fix: harden generic Cortex owner context#34
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (11)
📒 Files selected for processing (6)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughThis PR implements owner context hardening by introducing OwnerContextMode ("server_resolved" | "configured"), centralizing ownership application in CortexClient helpers, removing per-call owner_id from generic cortex_* tools, updating plugin schema and README, gating local SQLite cache on configured ownership, and adding tests enforcing the new behavior. ChangesOwner Context Mode & Multi-Tenant Safety
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
README.md (1)
53-55: ⚡ Quick winClarify quick-start by omitting
ownerIdinserver_resolvedexample.Including
ownerIdin the default hosted/proxy example can imply it is used in that mode. Prefer showing onlyownerIdMode: "server_resolved"in the baseline example, and moveownerIdto a separate self-host (configured) example.Suggested doc tweak
"config": { "cortexUrl": "https://your-cortex-server.example.com", "apiKey": "your-api-key", - "ownerId": "default", "ownerIdMode": "server_resolved" }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@README.md` around lines 53 - 55, Update the quick-start example in README so it does not include "ownerId" when demonstrating the hosted/proxy mode; specifically remove the "ownerId": "default" field from the example that shows "ownerIdMode": "server_resolved" and instead present a separate self-hosted/configured example that includes "ownerId" and "ownerIdMode": "configured" to avoid implying ownerId is used in server_resolved mode.src/__tests__/owner-context.test.ts (1)
34-36: ⚡ Quick winHarden the schema assertion to avoid brittle false passes/fails.
Checking only
"owner_id: Type.Optional"is too narrow. It can miss otherowner_idschema shapes or fail on harmless formatting changes. Use a broader pattern scoped to generic tool schema blocks.Suggested assertion update
- assert.equal( - source.includes("owner_id: Type.Optional"), - false, - "generic tool schemas must not expose caller-supplied owner_id", - ); + assert.equal( + /cortex_(ask|list_contradictions|resolve_contradiction|add_commitment|update_commitment|list_commitments|add_open_loop|resolve_open_loop|list_open_loops)[\s\S]{0,2000}\bowner_id\b/.test(source), + false, + "generic tool schemas must not expose caller-supplied owner_id", + );🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/__tests__/owner-context.test.ts` around lines 34 - 36, The current assertion uses source.includes("owner_id: Type.Optional") which is brittle; update the test in owner-context.test.ts to assert that no owner_id is present anywhere inside the generic tool schema block by replacing the simple includes check on the source variable with a regex-based check scoped to the generic tool schema definition (e.g., locate the GenericToolSchema/definition block in source and assert /GenericToolSchema\s*[:=]\s*Type\.(Object|Record)[\s\S]*owner_id\s*:/s.test(source) is false); keep the assertion logic but use this broader pattern so any owner_id shape (optional, required, different spacing) inside the generic tool schema fails the test.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/index.ts`:
- Around line 144-160: The code must ensure "configured" mode only takes effect
when a real owner namespace exists (not the fallback "default"); keep
shouldSendConfiguredOwner(ownerId, ownerIdMode) as the single canonical guard
and replace any direct checks of ownerIdMode === "configured" (e.g.,
cache/registration/SQLite setup paths mentioned in the review) with calls to
shouldSendConfiguredOwner(ownerId, ownerIdMode); update spots that enable the
SQLite cache/registration logic to require shouldSendConfiguredOwner(...) so a
fallback ownerId of "default" (or empty) will not enable configured behavior or
persist into memories-default.db, and leave withConfiguredOwner and
addOwnerParam to rely on the same helper for consistency.
- Around line 1776-1780: The runtime JSON schema for ownerIdMode in
cortexPlugin.configSchema.jsonSchema is missing the default value, causing a
mismatch with parseConfig() and openclaw.plugin.json; update the ownerIdMode
schema definition (the object containing "type", "enum", and "description") to
include "default": "server_resolved" so the in-process schema matches
parseConfig() and the plugin manifest; ensure the change is applied where
cortexPlugin.configSchema.jsonSchema is defined and leave parseConfig() and
openclaw.plugin.json unchanged.
---
Nitpick comments:
In `@README.md`:
- Around line 53-55: Update the quick-start example in README so it does not
include "ownerId" when demonstrating the hosted/proxy mode; specifically remove
the "ownerId": "default" field from the example that shows "ownerIdMode":
"server_resolved" and instead present a separate self-hosted/configured example
that includes "ownerId" and "ownerIdMode": "configured" to avoid implying
ownerId is used in server_resolved mode.
In `@src/__tests__/owner-context.test.ts`:
- Around line 34-36: The current assertion uses source.includes("owner_id:
Type.Optional") which is brittle; update the test in owner-context.test.ts to
assert that no owner_id is present anywhere inside the generic tool schema block
by replacing the simple includes check on the source variable with a regex-based
check scoped to the generic tool schema definition (e.g., locate the
GenericToolSchema/definition block in source and assert
/GenericToolSchema\s*[:=]\s*Type\.(Object|Record)[\s\S]*owner_id\s*:/s.test(source)
is false); keep the assertion logic but use this broader pattern so any owner_id
shape (optional, required, different spacing) inside the generic tool schema
fails the test.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 49ef526e-65b8-4ab3-ae3b-0704e66264ff
⛔ Files ignored due to path filters (11)
dist/__tests__/owner-context.test.d.tsis excluded by!**/dist/**dist/__tests__/owner-context.test.d.ts.mapis excluded by!**/dist/**,!**/*.mapdist/__tests__/owner-context.test.jsis excluded by!**/dist/**dist/__tests__/owner-context.test.js.mapis excluded by!**/dist/**,!**/*.mapdist/__tests__/plugin-manifest-parity.test.jsis excluded by!**/dist/**dist/__tests__/plugin-manifest-parity.test.js.mapis excluded by!**/dist/**,!**/*.mapdist/index.d.tsis excluded by!**/dist/**dist/index.d.ts.mapis excluded by!**/dist/**,!**/*.mapdist/index.jsis excluded by!**/dist/**dist/index.js.mapis excluded by!**/dist/**,!**/*.mapdist/openclaw.plugin.jsonis excluded by!**/dist/**
📒 Files selected for processing (6)
README.mdopenclaw.plugin.jsonpackage.jsonsrc/__tests__/owner-context.test.tssrc/__tests__/plugin-manifest-parity.test.tssrc/index.ts
3a76fb1 to
546bc83
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/__tests__/owner-context.test.ts (1)
33-43: ⚡ Quick winExpand owner-context guard coverage for
cortex_insights.Given this PR’s owner-hardening scope across generic Cortex tools, consider adding
cortex_insightsto this regression list so schema-levelowner_idreintroduction is caught early.Suggested test diff
const genericOwnerScopedTools = [ "cortex_ask", "cortex_list_contradictions", "cortex_resolve_contradiction", "cortex_add_commitment", "cortex_update_commitment", "cortex_list_commitments", + "cortex_insights", "cortex_add_open_loop", "cortex_resolve_open_loop", "cortex_list_open_loops", ];🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/__tests__/owner-context.test.ts` around lines 33 - 43, Add "cortex_insights" to the genericOwnerScopedTools array in the owner-context test so the owner-context guard covers that tool; update the array defined as genericOwnerScopedTools in src/__tests__/owner-context.test.ts to include "cortex_insights" alongside the other tool names (e.g., "cortex_ask", "cortex_list_contradictions", etc.) and rerun tests to ensure schema-level owner_id regressions are caught.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/__tests__/owner-context.test.ts`:
- Around line 33-43: Add "cortex_insights" to the genericOwnerScopedTools array
in the owner-context test so the owner-context guard covers that tool; update
the array defined as genericOwnerScopedTools in
src/__tests__/owner-context.test.ts to include "cortex_insights" alongside the
other tool names (e.g., "cortex_ask", "cortex_list_contradictions", etc.) and
rerun tests to ensure schema-level owner_id regressions are caught.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 4472cd31-8332-40ac-9026-a98adbfff662
⛔ Files ignored due to path filters (11)
dist/__tests__/owner-context.test.d.tsis excluded by!**/dist/**dist/__tests__/owner-context.test.d.ts.mapis excluded by!**/dist/**,!**/*.mapdist/__tests__/owner-context.test.jsis excluded by!**/dist/**dist/__tests__/owner-context.test.js.mapis excluded by!**/dist/**,!**/*.mapdist/__tests__/plugin-manifest-parity.test.jsis excluded by!**/dist/**dist/__tests__/plugin-manifest-parity.test.js.mapis excluded by!**/dist/**,!**/*.mapdist/index.d.tsis excluded by!**/dist/**dist/index.d.ts.mapis excluded by!**/dist/**,!**/*.mapdist/index.jsis excluded by!**/dist/**dist/index.js.mapis excluded by!**/dist/**,!**/*.mapdist/openclaw.plugin.jsonis excluded by!**/dist/**
📒 Files selected for processing (6)
README.mdopenclaw.plugin.jsonpackage.jsonsrc/__tests__/owner-context.test.tssrc/__tests__/plugin-manifest-parity.test.tssrc/index.ts
✅ Files skipped from review due to trivial changes (1)
- README.md
🚧 Files skipped from review as they are similar to previous changes (3)
- package.json
- src/tests/plugin-manifest-parity.test.ts
- src/index.ts
546bc83 to
181e38b
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/__tests__/owner-context.test.ts`:
- Around line 57-60: The test currently hard-codes a regex to detect owner_id
being passed in client.execute-like calls, which can drift from the canonical
list in genericOwnerScopedTools; update the test to derive its execute-method
checks from the same source as genericOwnerScopedTools (or iterate that array)
instead of a separate regex. Specifically, replace the static regex usage with
logic that builds expected method names/patterns from genericOwnerScopedTools
(or uses that list to assert no caller-supplied owner_id is forwarded),
referencing the test helper/assertion block that checks for
client.(ask|listContradictions|...) and the genericOwnerScopedTools variable so
both stay in sync.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 8170b9e7-a029-4f95-8430-a7d42cc89ae3
⛔ Files ignored due to path filters (11)
dist/__tests__/owner-context.test.d.tsis excluded by!**/dist/**dist/__tests__/owner-context.test.d.ts.mapis excluded by!**/dist/**,!**/*.mapdist/__tests__/owner-context.test.jsis excluded by!**/dist/**dist/__tests__/owner-context.test.js.mapis excluded by!**/dist/**,!**/*.mapdist/__tests__/plugin-manifest-parity.test.jsis excluded by!**/dist/**dist/__tests__/plugin-manifest-parity.test.js.mapis excluded by!**/dist/**,!**/*.mapdist/index.d.tsis excluded by!**/dist/**dist/index.d.ts.mapis excluded by!**/dist/**,!**/*.mapdist/index.jsis excluded by!**/dist/**dist/index.js.mapis excluded by!**/dist/**,!**/*.mapdist/openclaw.plugin.jsonis excluded by!**/dist/**
📒 Files selected for processing (6)
README.mdopenclaw.plugin.jsonpackage.jsonsrc/__tests__/owner-context.test.tssrc/__tests__/plugin-manifest-parity.test.tssrc/index.ts
✅ Files skipped from review due to trivial changes (1)
- README.md
🚧 Files skipped from review as they are similar to previous changes (3)
- package.json
- src/tests/plugin-manifest-parity.test.ts
- openclaw.plugin.json
181e38b to
2ff906c
Compare
Summary
ownerIdModeconfig withserver_resolvedas the hosted/proxy-safe defaultowner_idparameters from generic Cortex ask, contradiction, commitment, and open-loop toolsownerIdis sent only whenownerIdMode: "configured"is explicitly selected for self-host installsWhy
Company Brain tools now use an explicit account-scoped HTTP path, but the older generic Cortex plugin tools still allowed per-call owner overrides or relied on config-owner forwarding. For hosted multi-tenant paths, the effective owner should come from Cortex/proxy auth, not mutable tool params.
Validation
npm testCloses #33
Summary by CodeRabbit
New Features
Documentation
Tests