Skip to content

fix(gateway): honor ambient channel opt-in during config loading - #157387

Merged
steipete merged 1 commit into
mainfrom
fix/gateway-ambient-channel-opt-in
Sep 25, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/gateway-ambient-channel-opt-in

Conversation

@steipete

@steipete steipete commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

docs/cli/gateway/running.md says a Gateway only auto-configures channels from ambient environment variables when started with --ambient-channels; otherwise channels need an explicit channels.<id> block. In practice, a Gateway started without the flag still enables channels from the environment.

Live reproduction on main (d36ba5479c3), isolated state and port, empty channels config, DISCORD_BOT_TOKEN inherited from the shell, no --ambient-channels:

openclaw gateway run --port <port> --bind loopback
[gateway] auto-enabled plugins for this runtime without writing config:
- Discord configured, enabled automatically.
[discord] [default] starting provider

The throwaway QA Gateway logged into a real Discord bot and received a channel session before it was stopped. Any process that happens to inherit a bot token (a dev Gateway, an agent worker shell, CI) can silently come online as that bot.

Why This Change Was Made

openclaw gateway run already selects the ambient policy (src/cli/gateway-cli/run.ts), and config reloads already forward it. Initial startup config loading did not: prepareGatewayServerBootstrap never passed the policy to loadGatewayStartupConfigSnapshot, so plugin auto-enable fell back to its local "allow" default. The synthesized channel block was then classified as explicit consent in resolveConfiguredChannelPresencePolicy, escaping the ambient-only filter.

This change:

  • makes the startup loader require the selected ambientEnvTriggers policy and forwards it from bootstrap, matching the reload path;
  • derives explicit channel consent from the authored activation source config instead of the runtime config that auto-enable may have synthesized;
  • removes the two duplicate "allow" parameter defaults so config-presence owns the single default.

Explicit channels.<id> config still works and can still read credentials from the environment. Explicit disables stay authoritative. --ambient-channels (and the deprecated --dev-ambient-channels) still opt in for that process, including reloads.

User Impact

Gateways no longer come online on a messaging channel just because a token exists in their environment.

Compatibility (maintainer decision: land the fix; the old env-only default is not preserved): stable v2026.7.1 enabled env-only channels by default, and v2026.9.6 still does through this bypass (#112011 introduced the opt-in for dev mode, #123174 extended it to every Gateway). Operators who configure a channel only through an environment token will see that channel stay off after upgrading until they add channels.<id> config (for example channels.discord.enabled=true) or start with --ambient-channels. No existing config becomes invalid, so there is no Doctor migration; inferring consent from the presence of credentials would recreate the bug. The existing startup warning names the remediation. A release note should call this out.

Evidence

  • New boundary test src/gateway/server-startup-config.ambient-channels.test.ts drives initial config loading and reload with a fake env token: default suppression, ambient opt-in, explicit channel config, and explicit disable with opt-in. The suppression cases fail on current main.
  • node scripts/run-vitest.mjs over the new test plus startup recovery, plugin activation, startup plugins/log, channel plugin ids, plugin auto-enable core/channels, and gateway run option-collision suites: 440 passed.
  • Lint clean; production typecheck and all test-type graphs pass. Locally, check-changed's full-tree unused-export scan timed out under extreme host load; CI covers it.
  • Codex autoreview: scoped-clean ("patch is correct").
  • All reproduction used scrubbed environments with a fake token; no real credentials were used in tests.

Production LOC: +11 / −3. Tests: +127. Docs: +1 / −1.

@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: S labels Sep 24, 2026
@steipete
steipete marked this pull request as ready for review September 24, 2026 16:07
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 24, 2026
@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 25, 2026, 11:34 AM ET / 15:34 UTC (Revision 3).

ClawSweeper review

What this changes

The branch passes the Gateway’s ambient-channel choice into initial config loading, uses authored channel settings as explicit consent, and adds startup, reload, and operator-documentation coverage.

Merge readiness

⛔ Blocked before merge - 6 items remain

Keep open. Current main still has the documented ambient-channel opt-in bypass. The repair appears sound, but its final channel-transport effect and upgrade behavior need proof before merge.

Priority: P1
Reviewed head: ffbf3e98c4996d3dbfbc67e7c491b476ac3d2640

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The focused repair has useful regression coverage, while final channel-effect and released-upgrade proof remain missing.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: Authority-chain proof required: The changed initial loader and authored-config policy feed channel startup, but after-fix evidence uses a fake token and stops at config and activation results. A redacted candidate Gateway trace should show env-only denial before network I/O and explicit-config or opt-in connection; a released-version upgrade should show the warning and recovery. No stored-data contract changes. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: Authority-chain proof required: The changed initial loader and authored-config policy feed channel startup, but after-fix evidence uses a fake token and stops at config and activation results. A redacted candidate Gateway trace should show env-only denial before network I/O and explicit-config or opt-in connection; a released-version upgrade should show the warning and recovery. No stored-data contract changes. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 11 items Documented default: Current-main Gateway documentation requires an explicit channel config block unless ambient channels are opted in.
Current-main bypass: The CLI selects suppression by default, but initial config loading on current main calls plugin auto-enable without passing that policy.
Introduced loader repair: The pinned patch passes the selected ambient policy from Gateway bootstrap into initial plugin auto-enable.
Findings 1 actionable finding [P3] Report the new test suite’s measured cost
Security Needs attention Prove denial before channel transport: The changed policy treats authored configuration as consent. The added tests stop at selection, so they do not establish that an env-only credential cannot reach the final transport start path on a candidate Gateway.

How this fits together

The Gateway combines operator configuration, inherited environment credentials, and a process flag to select channel plugins. That selection determines which messaging channels can connect to external services.

flowchart LR
  A[Operator channel config] --> D[Initial config loading]
  B[Inherited credentials] --> D
  C[Ambient opt-in flag] --> D
  D --> E[Channel activation policy]
  E --> F[Plugin startup]
  F --> G[Channel transport]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: Authority-chain proof required: The changed initial loader and authored-config policy feed channel startup, but after-fix evidence uses a fake token and stops at config and activation results. A redacted candidate Gateway trace should show env-only denial before network I/O and explicit-config or opt-in connection; a released-version upgrade should show the warning and recovery. No stored-data contract changes. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Report the new test suite’s measured cost (P3) - This new startup and reload suite adds recurring CI work, but the PR body reports only an aggregate pass count. Record its single-worker wall time and CI duration as required by the repository test policy.
  • Resolve security concern: Prove denial before channel transport - The changed policy treats authored configuration as consent. The added tests stop at selection, so they do not establish that an env-only credential cannot reach the final transport start path on a candidate Gateway.
  • Resolve merge risk (P1) - The after-fix evidence has not shown an inherited env-only credential rejected before channel network I/O while explicit config and ambient opt-in still connect.
  • Resolve merge risk (P1) - A v2026.9.6-to-candidate run has not verified that an existing env-only operator sees the suppression warning and can restore channel activation through the documented path.
  • Complete next step (P2) - Add redacted candidate Gateway transport and v2026.9.6 upgrade evidence, then report the new test file’s measured cost. Update the PR body to trigger re-review; if it does not, ask a maintainer to comment @clawsweeper re-review.

Findings

  • [P3] Report the new test suite’s measured cost — src/gateway/server-startup-config.ambient-channels.test.ts:60-61
  • [medium] Prove denial before channel transport — src/plugins/channel-presence-policy.ts:422
Agent review details

Security

Needs attention: The diff adds no supply-chain surface and narrows activation, but rejection of an inherited credential at final channel I/O remains unproven.

PR surface

Source +8, Tests +127, Docs 0. Total +135 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 5 11 3 +8
Tests 4 127 0 +127
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 139 4 +135

Review metrics

None.

Root-cause cluster

Relationship: canonical
Canonical: #157387
Summary: Earlier merged PRs established the ambient opt-in policy; this PR addresses its remaining initial-loader bypass.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Verify transport and upgrade behavior (recommended)
    Capture a redacted candidate Gateway run for env-only denial and authorized connection, then record a v2026.9.6-to-candidate upgrade with the warning and recovery path.

Technical review

Best possible solution:

Complete the existing opt-in policy with a visible suppression warning and verify both final channel effects and released-version upgrade recovery before landing.

Do we have a high-confidence way to reproduce the issue?

Yes. Current-main source exposes the policy omission, and the PR body records a pre-fix live Discord connection; I did not execute the checkout.

Is this the best way to solve the issue?

Yes in design. Carrying the selected policy through the existing loader and checking authored configuration addresses the identified bypass, subject to final-effect and upgrade proof.

Full review comments:

  • [P3] Report the new test suite’s measured cost — src/gateway/server-startup-config.ambient-channels.test.ts:60-61
    This new startup and reload suite adds recurring CI work, but the PR body reports only an aggregate pass count. Record its single-worker wall time and CI duration as required by the repository test policy.
    Confidence: 0.94

Overall correctness: patch is correct
Overall confidence: 0.86

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 07347aca9edc.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The current bypass can bring an inherited messaging credential online without the documented opt-in.
  • merge-risk: 🚨 compatibility: The accepted opt-in policy becomes effective for shipped env-only setups, and their upgrade recovery still needs verification.
  • merge-risk: 🚨 message-delivery: An existing env-only channel may stop receiving messages until its operator explicitly enables it.
  • merge-risk: 🚨 security-boundary: Authored configuration becomes channel-start consent, but denial of the nearest unauthorized inherited credential has not been observed at final I/O.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Authority-chain proof required: The changed initial loader and authored-config policy feed channel startup, but after-fix evidence uses a fake token and stops at config and activation results. A redacted candidate Gateway trace should show env-only denial before network I/O and explicit-config or opt-in connection; a released-version upgrade should show the warning and recovery. No stored-data contract changes. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

Security concerns:

  • [medium] Prove denial before channel transport — src/plugins/channel-presence-policy.ts:422
    The changed policy treats authored configuration as consent. The added tests stop at selection, so they do not establish that an env-only credential cannot reach the final transport start path on a candidate Gateway.
    Confidence: 0.84

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Josh Avant: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Capture redacted candidate Gateway output showing inherited-token denial before I/O and authorized connection; remove private IPs, keys, phone numbers, and endpoints.
  • Record the v2026.9.6 upgrade warning and recovery outcome, plus the new suite’s measured wall time and CI duration.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-24T16:15:37.069Z sha c923204 :: blocked before merge. :: [P3] Report the new test suite’s measured cost
  • reviewed 2026-09-25T15:16:05.071Z sha c923204 :: needs real behavior proof before merge. :: [P3] Report the new test suite’s measured cost

Carry the selected Gateway ambient policy into initial config auto-enable,
matching reload preparation. Require that policy at the startup config
boundary and classify explicit channel presence from authored source rather
than generated runtime enablement. Remove duplicate detector defaults.

Preserve explicit channel configuration and both ambient opt-in flags.
Document that the policy also applies to reloads and managed services.

Release-note context: env-only channel activation bypassed the documented
opt-in in stable releases through v2026.9.6. Affected operators must add
channels.<id> configuration or use --ambient-channels. Existing suppression
warnings explain the enablement path; no config migration should infer
operator consent from environment credentials. Completes the policy work
from #112011 and #123174 across the loader extracted in #110779.

Validation: 440 focused tests passed. Before the fix, the new suite had two
expected failures (suppression bypass and generated consent) and three
passes; after the fix all five pass. The authored-config/prior-release
corpus run had 24 passes and five 120-second timeouts, all in the first
Doctor checkpoint before Gateway config loading. No causal connection to
this fix was found; migration/worker timing remains a separate follow-up.
A standalone replay was stopped while waiting for the legitimate artifact
lock held by check-changed, before it reached Vitest.

The changed-check aggregate passed production typing, all 25 test-type
graphs, formatting, config docs, plugin boundaries and earlier guards, but
failed on the full-tree Knip export scan's 600-second timeout. The same
scan timed out when run alone with its unchanged limit; production/script
export scans passed. Changed-file lint passed with zero warnings/errors.
The native-state schema guard passed. The supplemental database-first
scan was stopped after over 16 minutes under host load around 179; later
media, sidecar, import-cycle, webhook and pairing guards were not run.
Full changed-check validation is not claimed green.
@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 25, 2026
@steipete
steipete force-pushed the fix/gateway-ambient-channel-opt-in branch from c923204 to ffbf3e9 Compare September 25, 2026 15:27
@steipete
steipete merged commit 8c5b7c2 into main Sep 25, 2026
191 checks passed
@steipete
steipete deleted the fix/gateway-ambient-channel-opt-in branch September 25, 2026 16:08
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 26, 2026
…nclaw#157387)

Carry the selected Gateway ambient policy into initial config auto-enable,
matching reload preparation. Require that policy at the startup config
boundary and classify explicit channel presence from authored source rather
than generated runtime enablement. Remove duplicate detector defaults.

Preserve explicit channel configuration and both ambient opt-in flags.
Document that the policy also applies to reloads and managed services.

Release-note context: env-only channel activation bypassed the documented
opt-in in stable releases through v2026.9.6. Affected operators must add
channels.<id> configuration or use --ambient-channels. Existing suppression
warnings explain the enablement path; no config migration should infer
operator consent from environment credentials. Completes the policy work
from openclaw#112011 and openclaw#123174 across the loader extracted in openclaw#110779.

Validation: 440 focused tests passed. Before the fix, the new suite had two
expected failures (suppression bypass and generated consent) and three
passes; after the fix all five pass. The authored-config/prior-release
corpus run had 24 passes and five 120-second timeouts, all in the first
Doctor checkpoint before Gateway config loading. No causal connection to
this fix was found; migration/worker timing remains a separate follow-up.
A standalone replay was stopped while waiting for the legitimate artifact
lock held by check-changed, before it reached Vitest.

The changed-check aggregate passed production typing, all 25 test-type
graphs, formatting, config docs, plugin boundaries and earlier guards, but
failed on the full-tree Knip export scan's 600-second timeout. The same
scan timed out when run alone with its unchanged limit; production/script
export scans passed. Changed-file lint passed with zero warnings/errors.
The native-state schema guard passed. The supplemental database-first
scan was stopped after over 16 minutes under host load around 179; later
media, sidecar, import-cycle, webhook and pairing guards were not run.
Full changed-check validation is not claimed green.

Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant