Skip to content

fix(discord): apply access policy during active Control UI turns - #140929

Merged
steipete merged 3 commits into
mainfrom
codex/discord-live-policy
Sep 7, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/discord-live-policy

Conversation

@steipete

@steipete steipete commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Related: #140550. Reported by @DonnieFi.

What Problem This Solves

Fixes an issue where users saved a Discord guild or user allowlist in the Control UI but the running bot continued to reject newly allowed messages while active Control UI turns deferred channel reload.

Why This Change Was Made

This implements the maintainer-approved contract change: policy-only writes publish through the existing validated runtime-config path without restarting Discord. The reload classifier treated account fields as restart-required, and Discord admission retained startup policy. src/gateway/config-reload-plan.ts now supports single-segment account wildcards; extensions/discord/src/shared.ts declares the dynamic fields; one account-owned reader in extensions/discord/src/monitor/live-policy.ts supplies current policy to message, command, component, reaction, presence, guild-join, and voice admission.

The reader binds before startup awaits, caches name resolution, and rejects stale results before admission. Numeric guild/channel IDs skip unnecessary directory resolution. Deadline-bound interactions keep their existing initial-response behavior. The obsolete startup-only reaction-registration gate and constructor-only voice fields are removed. Existing prepared-policy and standalone native-command behavior remain supported.

Reading disk during manual start would bypass validated publication, and publishing transport changes during active work would break the retained drain contract. Token, proxy, intents, command registration, voice configuration, enablement, and mixed policy/transport writes therefore keep deferred atomic publication. No config options, dependencies, storage semantics, protocol versions, or SDK exports are added.

User Impact

Newly allowed traffic is admitted during active Control UI work without reconnecting the bot. Revocation prevents admission still awaiting metadata or pairing-store lookup; already admitted work retains its context. A slow name-policy lookup produces an explicit ephemeral component response or empty autocomplete choices. Discord, shared configuration, and plugin documentation describe this contract.

Evidence

  • The mock-Gateway harness uses real Discord admission: the running handler denies before the allowlist write, admits the newly allowed user while the turn stays active, and denies after revocation, including a message held in metadata lookup. No stop/start occurs. Core classification and retained restart deferral: 12 selected tests passed.
  • Blacksmith Testbox: 391 Discord tests passed across 24 files, including voice E2E, interaction deadlines, startup binding, policy cache/currentness, and pending-admission revocation. Two older voice fixtures were also corrected to select their intended STT/TTS mode and supply genuinely missing guild metadata; their original failures were reproduced on the baseline.
  • Provider blacksmith-testbox, lease tbx_01m1x41824da5qz3h22y5mtzk4, run. This is isolated synthetic boundary proof, not live Discord-service authentication.
  • node scripts/check-changed.mjs --base origin/main: passed. git diff --check: passed. Independent Codex autoreview against merge base 93562ca9054dea9eda853d9c527190a19e8581ec: scoped-clean through P2 after final changes.
  • pnpm build: passed. OPENCLAW_LOCAL_CHECK=0 node --import tsx scripts/profile-extension-memory.mts --extension discord --skip-combined --concurrency 1: passed (379.4 MiB maximum RSS). The copied Gateway regression fails on baseline 93562ca9054dea9eda853d9c527190a19e8581ec at “policy-only publication must not wait for the active turn”, then passes on this source. Exact head: f3cd999f484a4825252f7061899c770f7f63af6c.
  • Final test-only follow-up: node scripts/run-vitest.mjs extensions/discord/src/monitor/provider.test.ts test/discord-live-policy.integration.test.ts test/extension-test-boundary.test.ts passed 53 tests, locally and in Testbox run 34092309439 (lease tbx_01m1x9w1haap5q6qw70qcfsvzd, stopped). The relocated harness uses actual Gateway work admission and fails at the same intended assertion on the original baseline. node scripts/check-changed.mjs --base HEAD passed before the follow-up commit; independent review of the follow-up is clean through P2. Production source is unchanged from the full build/profile proof.
  • The refreshed CI exposed an inventory-dependent fixed shard-name assertion in the tooling job-cap test. That test now checks mixed-runner packing without pinning incidental names/counts; all existing job-cap, file-conservation, placement, family, timing, build-isolation, and runner-capacity assertions remain. node scripts/run-vitest.mjs test/scripts/ci-node-test-plan.test.ts test/discord-live-policy.integration.test.ts extensions/discord/src/channel.test.ts: 89 passed after a clean rebase to a325c39220f1c114c61b1ce15d85dec603ba2d2d. The test-only correction passed independent review and changed-file checks after installing main’s committed dependencies. No production CI change.
  • LOC: production +692/-153 = +539 net; tests +1214/-153 = +1,061 net; docs +47/-1 = +46 net. Production growth uses the explicit feature-class authorization for this contract change: the shared reader and each asynchronous admission owner must consume/fence current policy. Connected duplicate and obsolete paths were removed; behavior and tests were retained.
  • CI state: success for exact head f3cd999f484a4825252f7061899c770f7f63af6c: run 34094259868. The earlier provider/boundary and inventory-dependent test failures are resolved.

Release-note context: Discord access-policy edits apply during active Control UI work without reconnecting the channel; transport changes preserve validated deferred publication.

Exact focused Testbox commands
node scripts/run-vitest.mjs src/gateway/config-reload.test.ts src/gateway/server-reload-handlers.test.ts -t 'honors per-account dynamic policy paths|admits newly allowed Discord messages|defers channel hot reload until active embedded work drains|uses the default channel reload deferral timeout'

node scripts/run-vitest.mjs extensions/discord/src/channel.test.ts extensions/discord/src/monitor/live-policy.test.ts extensions/discord/src/monitor/listeners.presence.test.ts extensions/discord/src/monitor/listeners.guild-join.test.ts extensions/discord/src/monitor/provider.allowlist.test.ts extensions/discord/src/monitor/provider.startup.test.ts extensions/discord/src/monitor.test.ts extensions/discord/src/monitor/agent-components.live-policy-deadline.test.ts extensions/discord/src/monitor/monitor.agent-components.test.ts extensions/discord/src/monitor/questions.test.ts extensions/discord/src/monitor/agent-components.modal-presentation-failure.test.ts extensions/discord/src/monitor/native-command.options.test.ts extensions/discord/src/monitor/native-command.think-autocomplete.test.ts extensions/discord/src/monitor/native-command.plugin-dispatch.test.ts extensions/discord/src/voice/access.test.ts extensions/discord/src/voice/ingress.test.ts extensions/discord/src/voice/command.test.ts extensions/discord/src/voice/participant-context.test.ts extensions/discord/src/voice/voice-receive.test.ts extensions/discord/src/voice/voice-runtime.e2e.test.ts extensions/discord/src/voice/voice-runtime.secret-owner.e2e.test.ts extensions/discord/src/voice/transcripts-source.test.ts extensions/discord/src/voice/speaker-context.test.ts extensions/discord/src/voice/manager.ready-listener.test.ts

pnpm build

OPENCLAW_LOCAL_CHECK=0 node --import tsx scripts/profile-extension-memory.mts --extension discord --skip-combined --concurrency 1

@clawsweeper

clawsweeper Bot commented Sep 7, 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.

@steipete
steipete marked this pull request as ready for review September 7, 2026 06:34
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: discord Channel integration: discord gateway Gateway runtime size: XL maintainer Maintainer-authored PR labels Sep 7, 2026
@clawsweeper clawsweeper Bot added P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 7, 2026
@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 7, 2026, 3:18 AM ET / 07:18 UTC.

ClawSweeper review

What this changes

Discord reads newly published access policies without reconnecting during active Control UI turns, with updated admission checks, regression coverage, and documentation.

Merge readiness

✅ Ready for maintainer review

The fix remains necessary on current main. No blocking patch defect was found, and the explicit maintainer decision resolves the earlier wildcard-contract concern.

Priority: P0
Reviewed head: f3cd999f484a4825252f7061899c770f7f63af6c

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent owner-level repair with meaningful boundary proof, focused regression coverage, and no blocking finding.
Proof confidence 🐚 platinum hermit (4/6) ✨ media proof bonus Sufficient (linked_artifact): The captured Testbox report and inspected, repository-authorized mock-Gateway harness exercise actual publication and Discord admission, observing grant, revoke, pending-metadata rejection, and no restart during active work. This establishes the changed boundary, not live Discord-service authentication.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The captured Testbox report and inspected, repository-authorized mock-Gateway harness exercise actual publication and Discord admission, observing grant, revoke, pending-metadata rejection, and no restart during active work. This establishes the changed boundary, not live Discord-service authentication.
Evidence reviewed 8 items Current main still needs the repair: At fetched main, Discord declares only inbound batching and acknowledgement settings as dynamic; the dispatcher still captures group policy at construction. No merged replacement is established by the supplied related-item context.
Account-owned policy and revision fencing: The reader retains the account's transport settings, derives policy from committed runtime configuration, shares name-resolution work, rejects superseded asynchronous results, and checks account cancellation. Its runtime-config dependency is OpenClaw's own snapshot implementation; this change does not depend on the Codex harness.
Approved reload contract: The captured maintainer comment explicitly retains single-segment wildcard matching for the seven existing Discord policy fields, exact-rule precedence, and deferred transport/mixed writes: #140929 (comment). The classifier and documentation implement that decision without adding configuration options.
Findings None None.
Security None None.

How this fits together

The Gateway validates configuration changes and publishes the runtime snapshot consumed by Discord. Discord uses that snapshot to decide whether incoming messages, interactions, and voice activity may enter agent workflows.

flowchart TD
  A[Control UI configuration save] --> B[Gateway validates change]
  B --> C{Policy only?}
  C -->|Yes| D[Publish runtime configuration]
  C -->|No| E[Deferred channel restart]
  D --> F[Discord admission checks]
  G[Incoming Discord activity] --> F
  F --> H[Admit or reject activity]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +539, Tests +1061, Docs +46. Total +1646 across 59 files.

View PR surface stats
Area Files Added Removed Net
Source 39 692 153 +539
Tests 17 1214 153 +1061
Docs 3 47 1 +46
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 59 1953 307 +1646

Review metrics

Metric Value Why it matters
Configuration surface 7 existing policy fields; 0 new options The approved change alters publication timing without introducing another operator setting.
Production versus test growth Production +539 net; tests +1,061 net The stated production-growth justification is one shared policy reader plus revision checks across asynchronous admission owners.

Technical review

Best possible solution:

Make saving access policy a dependable in-product recovery path while preserving atomic deferred publication for transport changes and the documented boundary for already admitted work.

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

Yes: current-main restart classification and retained startup policy support the reported active-turn stall, and the supplied harness reports an intended baseline failure. This read-only review did not execute it.

Is this the best way to solve the issue?

Yes: the patch reuses validated runtime publication and existing account-policy helpers, with an explicitly approved reload contract and retained transport deferral.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 00fd5d6a4049.

Labels

Label justifications:

  • P0: The linked report describes blocked Discord setup despite a healthy connection, with recovery requiring a terminal-driven Gateway restart.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The captured Testbox report and inspected, repository-authorized mock-Gateway harness exercise actual publication and Discord admission, observing grant, revoke, pending-metadata rejection, and no restart during active work. This establishes the changed boundary, not live Discord-service authentication.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured Testbox report and inspected, repository-authorized mock-Gateway harness exercise actual publication and Discord admission, observing grant, revoke, pending-metadata rejection, and no restart during active work. This establishes the changed boundary, not live Discord-service authentication.

Evidence

What I checked:

Likely related people:

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

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-07T06:44:28.095Z sha 1487f209186513e368950692002c6087d1683ba7 :: blocked before merge. :: none
  • reviewed 2026-09-07T06:58:25.550Z sha a59a4963a979fa8d0dde8f8da59d7aeb554980ed :: needs maintainer review before merge. :: none

@steipete

steipete commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Maintainer decision: retain the documented single-segment wildcard reload contract. This implements the explicitly approved policy-publication change for #140550. The declaration is limited to the seven existing Discord policy fields; exact rules win at the same depth, and token, enablement, whole-account, and mixed transport/policy changes retain restart deferral. The classifier and active-work admission checks passed in Testbox. No new SDK exports or configuration options are introduced.

The two CI failures are being corrected in a test-only follow-up: the provider fixture now keeps real account-policy exports, and the Gateway/Discord harness moves from the core-only test tree into test/discord-live-policy.integration.test.ts. All 53 focused follow-up checks passed locally, including the unchanged grant/revoke/no-restart assertions. A fresh independent review found no actionable issues. Exact-head CI will be rerun before native preparation.

@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 7, 2026
@steipete
steipete force-pushed the codex/discord-live-policy branch from a59a496 to f3cd999 Compare September 7, 2026 07:11
@steipete
steipete merged commit 1ebb4c0 into main Sep 7, 2026
186 checks passed
@steipete
steipete deleted the codex/discord-live-policy branch September 7, 2026 07:23
@steipete

steipete commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant