Repository navigation
fix(doctor): route setup doctor discovery - #69919
Conversation
🔒 Aisle Security AnalysisWe found 2 potential security issue(s) in this PR:
1. 🟠 Doctor preview loads external channel plugins and passes full account objects to plugin hooks (potential secret exfiltration)
Description
Impact:
Vulnerable flow:
RecommendationTreat doctor hooks as untrusted and avoid passing secrets. Options (can be combined):
Example: sanitize before calling plugin hooks: function sanitizeAccountRecord(account: Record<string, unknown>): Record<string, unknown> {
const { token, accessToken, refreshToken, password, apiKey, secret, ...rest } = account as any;
return rest;
}
function toPluginEmptyAllowlistContext(params: ChannelDoctorEmptyAllowlistLookupParams) {
const { cfg: _cfg, account, parent, ...rest } = params;
return {
...rest,
account: sanitizeAccountRecord(account),
parent: parent ? sanitizeAccountRecord(parent) : undefined,
};
}(Use your actual secret key conventions; ideally leverage existing secret-ref/secret-target metadata rather than ad-hoc field lists.) 2. 🟠 Untrusted plugin code execution via read-only channel plugin discovery in doctor flow
Description
This is dangerous because Impact:
Vulnerable code (entry point): return resolveReadOnlyChannelPluginsForConfig(context.cfg, {
...(context.env ? { env: context.env } : {}),
includePersistedAuthState: false,
}).plugins;(Downstream, this resolution may call RecommendationTreat read-only plugin discovery as untrusted unless the user explicitly opts in. Options to mitigate:
Example direction (conceptual): // resolveReadOnlyChannelPluginsForConfig(..., { loadModules: false })
// so doctor only uses bundled + already-loaded plugins unless explicitly allowedAnalyzed PR: #69919 at commit Last updated on: 2026-04-22T03:42:41Z |
Greptile SummaryThis PR fixes the doctor discovery fallback for configured channels: when Confidence Score: 5/5Safe to merge — the fallback logic is correct and well-covered by the new tests. All remaining findings are P2 style/clarity nits. The core logic (read-only-first, fallback to setup, deduplication via Map, env/cfg threading) is correct and the new test suite covers the primary bug scenario plus edge cases (non-fatal failures, env routing, empty-allowlist path). No files require special attention. Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/commands/doctor/shared/channel-doctor.ts
Line: 73-86
Comment:
**Read-only no-doctor plugin still occupies entry slot**
When a read-only plugin exists for a channel but lacks `doctor`, it is added to the `plugins` array (line 74 via `...readOnlyPlugins`) even though it will be silently skipped by the `if (!plugin.doctor) continue` guard. The loaded/bundled fallback is then also added to `plugins` for the same id. The deduplication map correctly picks up the fallback doctor, so the _result_ is right. However, having the no-doctor read-only entry travel through the loop is unnecessary and could confuse future readers who see an id appear twice in `plugins`.
Consider filtering `readOnlyPlugins` before spreading it so only entries that either have `doctor` or will not be supplemented by a fallback remain:
```typescript
const plugins = [
...readOnlyPlugins.filter((p) => p.doctor),
...channelIds.flatMap((id) => {
if (readOnlyDoctorPluginIds.has(id)) return [];
...
}),
];
```
This is a style/clarity nit — correctness is unaffected.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/commands/doctor/shared/channel-doctor.test.ts
Line: 138-160
Comment:
**Non-fatal test exercises catch path but not the no-doctor fallback path**
The "non-fatal" scenario throws from `resolveReadOnlyChannelPluginsForConfig`, which causes `safeListReadOnlyChannelPlugins` to return `[]`. That means `readOnlyDoctorPluginIds` is empty and the code falls straight through to the loaded/bundled path — it never exercises the distinct "read-only returns a plugin without `doctor`, _then_ falls back" code path that the PR description calls out as the root-cause scenario.
The PR has a separate test for the fallback path (`"falls back to setup doctor adapters"`), so coverage is technically present. But having the non-fatal test share the same channel name (`discord`) for both the throw and the undefined-return path makes it harder to distinguish what's under test. A minor clarity improvement would be to mock `getLoadedChannelPlugin` to return `undefined` explicitly here (it already does via `beforeEach`, so no code change needed — just a comment in the test) so the intent is self-documenting.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix(doctor): route setup doctor discover..." | Re-trigger Greptile |
There was a problem hiding this comment.
Pull request overview
Fixes configured-channel doctor dispatch so it doesn’t stop at a read-only discovered plugin when that plugin doesn’t expose doctor hooks, ensuring setup/loaded doctor adapters still run (and that cfg/env are routed through the affected discovery paths).
Changes:
- Prefer read-only channel plugin discovery for doctor adapters, but fall back to loaded + bundled-setup plugins when the read-only candidate lacks
doctor. - Thread
envthrough doctor preview/repair flows and empty-allowlist scans so discovery uses the intended environment. - Extend empty-allowlist warning context to carry
cfg/env, plus add regression coverage for the fallback and env plumbing.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/commands/doctor/shared/preview-warnings.ts | Adds optional env parameter and consistently uses it for preview-time scans/imports. |
| src/commands/doctor/shared/empty-allowlist-scan.ts | Threads cfg/env into empty-allowlist scanning and extra-warning callbacks. |
| src/commands/doctor/shared/empty-allowlist-policy.ts | Passes cfg/env into the channel-doctor skip hook for accurate adapter discovery. |
| src/commands/doctor/shared/channel-doctor.ts | Implements read-only-first doctor lookup with fallback to loaded/setup adapters; plumbs env into read-only discovery. |
| src/commands/doctor/shared/channel-doctor.test.ts | Adds tests covering read-only preference, fallback when hooks are missing, explicit env routing, and non-fatal setup loading. |
| src/commands/doctor/repair-sequencing.ts | Adds optional env and routes it into repair-time scans/mutations. |
| src/commands/doctor-config-flow.ts | Routes process.env into the updated doctor discovery/mutation paths. |
| src/cli/plugins-install-command.ts | Routes process.env into stale channel doctor mutation collection for install-time config recovery. |
| src/channels/plugins/types.adapters.ts | Extends empty-allowlist doctor context with optional cfg/env for plugin hook implementations. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9c6e90518e
ℹ️ 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".
9c6e905 to
da6193b
Compare
|
Check triage done.
Validation run after fixes:
Full |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0645415928
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 70b30dfee2
ℹ️ 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".
2435218 to
dfc3ac9
Compare
e2c06e0 to
3949be9
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3949be9e11
ℹ️ 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".
e700c7e to
cc38ae4
Compare
cc38ae4 to
90c7067
Compare
|
Merged via squash.
Thanks @gumadeiras! |
Merged via squash. Prepared head SHA: 90c7067 Co-authored-by: gumadeiras <[email protected]> Co-authored-by: gumadeiras <[email protected]> Reviewed-by: @gumadeiras
Merged via squash. Prepared head SHA: 90c7067 Co-authored-by: gumadeiras <[email protected]> Co-authored-by: gumadeiras <[email protected]> Reviewed-by: @gumadeiras
Merged via squash. Prepared head SHA: 90c7067 Co-authored-by: gumadeiras <[email protected]> Co-authored-by: gumadeiras <[email protected]> Reviewed-by: @gumadeiras
Merged via squash. Prepared head SHA: 90c7067 Co-authored-by: gumadeiras <[email protected]> Co-authored-by: gumadeiras <[email protected]> Reviewed-by: @gumadeiras
Merged via squash. Prepared head SHA: 90c7067 Co-authored-by: gumadeiras <[email protected]> Co-authored-by: gumadeiras <[email protected]> Reviewed-by: @gumadeiras
Merged via squash. Prepared head SHA: 90c7067 Co-authored-by: gumadeiras <[email protected]> Co-authored-by: gumadeiras <[email protected]> Reviewed-by: @gumadeiras
Merged via squash. Prepared head SHA: 90c7067 Co-authored-by: gumadeiras <[email protected]> Co-authored-by: gumadeiras <[email protected]> Reviewed-by: @gumadeiras
Merged via squash. Prepared head SHA: 90c7067 Co-authored-by: gumadeiras <[email protected]> Co-authored-by: gumadeiras <[email protected]> Reviewed-by: @gumadeiras
Merged via squash. Prepared head SHA: 90c7067 Co-authored-by: gumadeiras <[email protected]> Co-authored-by: gumadeiras <[email protected]> Reviewed-by: @gumadeiras
* refactor: consolidate command and cron preparation paths Keep one sub-CLI metadata/registration catalog, common cron payload updates, canonical agent migration visitors, and shared account-state projection. Trust typed internal adapters while retaining external validation, effect authority, cancellation settlement, supported migrations and path containment. Wave-5 y10: BELOW-500, 353 net production lines removed (+440/-793 in 19 files). Branch-only handoff for the coordinator's bundle; no standalone PR. Best-effort tradeoffs accepted: - Cron mid-setup reload recovery (#146582): synthetic retirement, no human incident. Setup may fail; the next invocation refreshes the cache. - Recursive shared preparation retry (#102494/#138337): synthetic concurrent callers; production serializes same-job work. Duplicate direct callers may share cancellation. Failed-owner eviction preserves the next sequential run. - Progress publication generation (#143621): synthetic held update/reset. Presentation dedupe may briefly be stale until a subsequent render/reset. - Doctor adapter schema mirror (#69919): malformed synthetic hooks. Invalid executable adapters fail visibly; missing-hook fallbacks and config checks stay. - Setup adapter schema mirror (#165492): typed internal union. Invalid internal adapters fail when used; both supported wizard forms remain. - Injected process schema mirror (#84381): malformed injection was not human SIGTERM report #71710. Invalid adapters fail registration; cancellation stays. - Loaded registry row revalidation/copy (#114942/#158830/#114476): rows already admitted/normalized. Corrupt trusted rows can fail; first-wins authority stays. - Custom compatibility duplicate check (#14223): all callers parse/type it. Hand-crafted invalid JS uses the default branch; external flags still reject it. - Log probe identity matching (#88159, superseded by #168587): abort now joins the sole probe, so replacement cannot race its result. Recovery/settlement stay. - Whole-config deep copy (#71218): no detached-copy incident. Structural copy updates agents/defaults; unrelated future mutation must respect config ownership. - Repeated plugin-root probes (#70012): no disappearing-root incident. Resolve roots once; root replacement can fail discovery. Symlink containment stays. - Second payload getter read (#135319): synthetic review/corpus, not a human report. Ordinary decoded records are read once; stateful accessors may differ. Proof: fresh independent review clean; core types, targeted lint/format, runtime and static cycles, assertion/line-cap ratchets, and suppression suite passed. Focused CLI cohort: 8 files / 41 tests passed. Earlier unchanged account/setup and cold-import checks passed. Cron and commands cohorts were interrupted after partial results; complete owner tests, payload merging, test-graph types, broad check-changed and build/smoke remain unproved at commit preparation. Unattributed local 120-second timeouts retained: two root-command-descriptions catalog cases and agent-via-gateway's Gateway attempt-budget case. No timeout, retry, skip or kept-behavior expectation changes. Env-name budget mismatch (455 vs 454) also exists at original HEAD and pinned main 7dccff5. All runtime proof used isolated HOME/OpenClaw/XDG state; Phase E untouched. * refactor: consolidate cron payload and lazy CLI paths Share daemon and cron method forwarding through the existing lazy binder, remove the cron CLI reexport shim, and consolidate normalization and merge handling without changing public fields, explicit clears, or effect authority. Remove the obsolete bundled discovery reentry mechanism and impossible Doctor issue helper. The full lane now removes 475 net production lines. Best-effort tradeoffs accepted: - Unknown Doctor issue variants supplied by hand-crafted JavaScript return the invalid value rather than a custom error. Typed local producers and exhaustive switches remain; reporting feature #95979 cites no human unknown-kind incident. - Synchronous bundled-module self-discovery may fail through the existing loader diagnostic instead of returning empty inventory. Commit 65f18d6 only pins injected Jiti reentry, not a human incident; ordinary caches remain. - Cron defaults trust staggerMs normalized earlier in the same synchronous call. No await or mutation boundary intervenes; externally supplied invalid values remain rejected by the normalizer. * fix(channels): retain replacement preview deduplication Withdraw the progress compositor generation removal after the Mattermost retiring-publication case failed CI and bounded serial head/base replays remained inconclusive under load. Restore that file exactly to the branch base and keep all Mattermost tests unchanged, following the campaign fallback. Prune the single obsolete mock-export allowance left by the removed bundled discovery reentry fixture. The local mock ratchet passes with 9586 factories. The remaining lane reduction is 471 net production lines across 25 paths.
…#173036) * refactor: consolidate command and cron preparation paths Keep one sub-CLI metadata/registration catalog, common cron payload updates, canonical agent migration visitors, and shared account-state projection. Trust typed internal adapters while retaining external validation, effect authority, cancellation settlement, supported migrations and path containment. Wave-5 y10: BELOW-500, 353 net production lines removed (+440/-793 in 19 files). Branch-only handoff for the coordinator's bundle; no standalone PR. Best-effort tradeoffs accepted: - Cron mid-setup reload recovery (openclaw#146582): synthetic retirement, no human incident. Setup may fail; the next invocation refreshes the cache. - Recursive shared preparation retry (openclaw#102494/openclaw#138337): synthetic concurrent callers; production serializes same-job work. Duplicate direct callers may share cancellation. Failed-owner eviction preserves the next sequential run. - Progress publication generation (openclaw#143621): synthetic held update/reset. Presentation dedupe may briefly be stale until a subsequent render/reset. - Doctor adapter schema mirror (openclaw#69919): malformed synthetic hooks. Invalid executable adapters fail visibly; missing-hook fallbacks and config checks stay. - Setup adapter schema mirror (openclaw#165492): typed internal union. Invalid internal adapters fail when used; both supported wizard forms remain. - Injected process schema mirror (openclaw#84381): malformed injection was not human SIGTERM report openclaw#71710. Invalid adapters fail registration; cancellation stays. - Loaded registry row revalidation/copy (openclaw#114942/openclaw#158830/openclaw#114476): rows already admitted/normalized. Corrupt trusted rows can fail; first-wins authority stays. - Custom compatibility duplicate check (openclaw#14223): all callers parse/type it. Hand-crafted invalid JS uses the default branch; external flags still reject it. - Log probe identity matching (openclaw#88159, superseded by openclaw#168587): abort now joins the sole probe, so replacement cannot race its result. Recovery/settlement stay. - Whole-config deep copy (openclaw#71218): no detached-copy incident. Structural copy updates agents/defaults; unrelated future mutation must respect config ownership. - Repeated plugin-root probes (openclaw#70012): no disappearing-root incident. Resolve roots once; root replacement can fail discovery. Symlink containment stays. - Second payload getter read (openclaw#135319): synthetic review/corpus, not a human report. Ordinary decoded records are read once; stateful accessors may differ. Proof: fresh independent review clean; core types, targeted lint/format, runtime and static cycles, assertion/line-cap ratchets, and suppression suite passed. Focused CLI cohort: 8 files / 41 tests passed. Earlier unchanged account/setup and cold-import checks passed. Cron and commands cohorts were interrupted after partial results; complete owner tests, payload merging, test-graph types, broad check-changed and build/smoke remain unproved at commit preparation. Unattributed local 120-second timeouts retained: two root-command-descriptions catalog cases and agent-via-gateway's Gateway attempt-budget case. No timeout, retry, skip or kept-behavior expectation changes. Env-name budget mismatch (455 vs 454) also exists at original HEAD and pinned main 89f8219. All runtime proof used isolated HOME/OpenClaw/XDG state; Phase E untouched. * refactor: consolidate cron payload and lazy CLI paths Share daemon and cron method forwarding through the existing lazy binder, remove the cron CLI reexport shim, and consolidate normalization and merge handling without changing public fields, explicit clears, or effect authority. Remove the obsolete bundled discovery reentry mechanism and impossible Doctor issue helper. The full lane now removes 475 net production lines. Best-effort tradeoffs accepted: - Unknown Doctor issue variants supplied by hand-crafted JavaScript return the invalid value rather than a custom error. Typed local producers and exhaustive switches remain; reporting feature openclaw#95979 cites no human unknown-kind incident. - Synchronous bundled-module self-discovery may fail through the existing loader diagnostic instead of returning empty inventory. Commit ca10460 only pins injected Jiti reentry, not a human incident; ordinary caches remain. - Cron defaults trust staggerMs normalized earlier in the same synchronous call. No await or mutation boundary intervenes; externally supplied invalid values remain rejected by the normalizer. * fix(channels): retain replacement preview deduplication Withdraw the progress compositor generation removal after the Mattermost retiring-publication case failed CI and bounded serial head/base replays remained inconclusive under load. Restore that file exactly to the branch base and keep all Mattermost tests unchanged, following the campaign fallback. Prune the single obsolete mock-export allowance left by the removed bundled discovery reentry fixture. The local mock ratchet passes with 9586 factories. The remaining lane reduction is 471 net production lines across 25 paths.
Summary
doctorhooks.cfg/envthrough the affected doctor discovery paths.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Root Cause (if applicable)
doctor.Regression Test Plan (if applicable)
src/commands/doctor/shared/channel-doctor.test.tsdoctorfalls back to setup doctor; explicit env and config are routed into read-only discovery.User-visible / Behavior Changes
Configured channel doctor checks run the owning setup/loaded doctor hooks when read-only discovery finds a plugin that does not expose doctor hooks.
Diagram (if applicable)
Security Impact (required)
Yes, explain risk + mitigation: N/ARepro + Verification
Environment
Steps
doctor.Expected
doctor.Actual
Evidence
Human Verification (required)
pnpm check:changed --staged; full extension gate triggered by public adapter contract change.Review Conversations
Compatibility / Migration
Risks and Mitigations
pnpm check:changed --stagedran core and extension type/tests.