Skip to content

fix(discord): pass config to subagent thread binding#70945

Merged
steipete merged 3 commits intoopenclaw:mainfrom
jai:fix/discord-subagent-cfg-forwarding
Apr 24, 2026
Merged

fix(discord): pass config to subagent thread binding#70945
steipete merged 3 commits intoopenclaw:mainfrom
jai:fix/discord-subagent-cfg-forwarding

Conversation

@jai
Copy link
Copy Markdown
Contributor

@jai jai commented Apr 24, 2026

Summary

Describe the problem and fix in 2–5 bullets:

  • Problem: Discord thread-bound subagent spawning can fail before child startup because the subagent hook calls autoBindSpawnedDiscordSubagent without the resolved runtime config.
  • Why it matters: the pre-bind channel resolution path may need config for Discord REST/proxy/account context, so it silently returns null and surfaces a generic “Unable to create or bind…” error.
  • What changed: forward api.config into autoBindSpawnedDiscordSubagent and update the hook regression test to assert that config is passed.
  • What did NOT change (scope boundary): no Discord permission/webhook behavior, no thread-binding defaults, and no ACP binding logic changes.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

Root Cause (if applicable)

  • Root cause: the Discord subagent_spawning hook omitted cfg: api.config when delegating to autoBindSpawnedDiscordSubagent, while downstream channel resolution can require runtime config even when a token is available.
  • Missing detection / guardrail: existing lifecycle tests passed cfg directly into autoBindSpawnedDiscordSubagent, and the hook test asserted the old delegated call shape without cfg.
  • Contributing context (if known): thread-bound spawning fails before provisional child session startup, so failures surface as generic session-mode unavailable errors.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: extensions/discord/src/subagent-hooks.test.ts
  • Scenario the test should lock in: subagent_spawning forwards the resolved Discord runtime config into autoBindSpawnedDiscordSubagent.
  • Why this is the smallest reliable guardrail: this bug was specifically at the hook delegation boundary; lifecycle tests already cover direct cfg usage.
  • Existing test that already covers this (if any): lifecycle tests cover direct auto-bind config/token behavior, but not hook forwarding.
  • If no new test is added, why not: N/A

User-visible / Behavior Changes

Discord thread-bound subagent sessions should be able to use the runtime config during auto-bind channel resolution instead of failing with the generic bind error when config is required.

Diagram (if applicable)

Before:
subagent_spawning -> autoBindSpawnedDiscordSubagent(no cfg) -> channel resolution can return null

After:
subagent_spawning -> autoBindSpawnedDiscordSubagent(cfg) -> channel resolution has runtime context

Security Impact (required)

  • New permissions/capabilities? (Yes/No) No
  • Secrets/tokens handling changed? (Yes/No) No
  • New/changed network calls? (Yes/No) No
  • Command/tool execution surface changed? (Yes/No) No
  • Data access scope changed? (Yes/No) No
  • If any Yes, explain risk + mitigation: N/A

Repro + Verification

Environment

  • OS: Linux
  • Runtime/container: local OpenClaw source checkout
  • Model/provider: N/A
  • Integration/channel (if any): Discord
  • Relevant config (redacted): Discord thread bindings enabled with spawnSubagentSessions=true

Steps

  1. Trigger a Discord subagent_spawning hook for a thread-requested subagent session.
  2. Mock autoBindSpawnedDiscordSubagent and inspect the delegated arguments.
  3. Confirm the hook passes api.config to auto-bind.

Expected

  • Hook delegates with cfg: api.config.

Actual

  • Before this PR, hook delegated without cfg.

Evidence

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Targeted verification:

npm test -- --run extensions/discord/src/subagent-hooks.test.ts extensions/discord/src/monitor/thread-bindings.lifecycle.test.ts

Test Files  2 passed (2)
Tests       44 passed (44)

Human Verification (required)

  • Verified scenarios: targeted Discord hook test and lifecycle auto-bind tests pass locally; live gateway restart and live Discord thread-bound native subagent spawn were verified on the jai-work/finn production runtime after applying this one-line runtime patch.
  • Edge cases checked: direct lifecycle auto-bind tests still pass with cfg/token scenarios; the same patch was also applied to jai-personal and the Mac mini LaunchDaemon restart was verified.
  • What you did not verify: full live coverage across every Discord account/channel, every managed runtime, or unrelated ACP thread-binding paths.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? (Yes/No) Yes
  • Config/env changes? (Yes/No) No
  • Migration needed? (Yes/No) No
  • If yes, exact upgrade steps: N/A

Risks and Mitigations

  • Risk: cfg forwarding could expose unintended config dependency in tests.
    • Mitigation: the callee already accepts optional cfg and direct lifecycle tests already exercise cfg-aware behavior.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 24, 2026

Greptile Summary

This PR forwards api.config as cfg into autoBindSpawnedDiscordSubagent within the subagent_spawning hook, closing the gap where channel resolution could silently return null when runtime config was required. The accompanying test update adds a cfg-shape assertion to lock in the delegation contract at the hook boundary.

Confidence Score: 5/5

Safe to merge — one-line bug fix with targeted test coverage and no interface changes.

The change is minimal, correct, and directly mirrors how api.config is already used elsewhere in the same file (e.g., resolveThreadBindingFlags). The test update properly asserts the new argument shape. No architectural concerns or missing guards were identified.

No files require special attention.

Reviews (3): Last reviewed commit: "fix(discord): pass config to subagent th..." | Re-trigger Greptile

@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord size: XS labels Apr 24, 2026
@jai
Copy link
Copy Markdown
Contributor Author

jai commented Apr 24, 2026

Closing for now. This was a provisional patch from local investigation; I need to verify intended usage/upstream behavior before proposing a fix.

@jai
Copy link
Copy Markdown
Contributor Author

jai commented Apr 24, 2026

Reopening as a draft fix for #71054. Keeping draft while we validate the linked bug report and maintainer expectations.

@jai jai reopened this Apr 24, 2026
@jai jai marked this pull request as draft April 24, 2026 09:51
@jai jai force-pushed the fix/discord-subagent-cfg-forwarding branch from febf39e to 527802e Compare April 24, 2026 10:12
@jai jai marked this pull request as ready for review April 24, 2026 10:12
@steipete steipete force-pushed the fix/discord-subagent-cfg-forwarding branch from 527802e to e704e6c Compare April 24, 2026 22:46
@steipete steipete merged commit 3a6d50d into openclaw:main Apr 24, 2026
66 checks passed
@steipete
Copy link
Copy Markdown
Contributor

Landed via rebase onto main.

  • Local gates: pnpm test extensions/discord/src/subagent-hooks.test.ts extensions/discord/src/monitor/thread-bindings.lifecycle.test.ts, pnpm test extensions/discord/src/monitor/provider.proxy.test.ts extensions/discord/src/monitor/provider.startup.test.ts, node scripts/run-additional-boundary-checks.mjs, pnpm check:changed
  • CI: green on pushed head 3cf46096de24b697299a81373d2219d5efe368ae
  • Source head: 3cf4609
  • Landed commits: 84571e45ce, 21162233d5, 3a6d50deb3

Added the requested hardening by making cfg required at the Discord subagent auto-bind helper boundary, plus fixed the latest main Discord gateway fetch boundary red so the merge SHA stayed green.

Thanks @jai!

@jai jai deleted the fix/discord-subagent-cfg-forwarding branch April 25, 2026 01:00
Angfr95 pushed a commit to Angfr95/openclaw that referenced this pull request Apr 25, 2026
Angfr95 pushed a commit to Angfr95/openclaw that referenced this pull request Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Discord thread-bound native subagent sessions fail before binding without runtime config

2 participants