Skip to content

fix: harden startup readiness and discord replies - #77478

Merged
steipete merged 4 commits into
openclaw:mainfrom
NikolaFC:fix/startup-readiness-discord-reply-safety-pr
May 4, 2026
Merged

steipete merged 4 commits into
openclaw:mainfrom
NikolaFC:fix/startup-readiness-discord-reply-safety-pr

Conversation

@NikolaFC

@NikolaFC NikolaFC commented May 4, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR hardens two incident-adjacent paths:

  • Gateway startup/readiness handling:
    • gate sessions.list during startup so Control UI polling does not compete with sidecar/channel readiness through the expensive session scan path;
    • treat native approval gateway-readiness failures as retryable deferrals instead of terminal-looking startup failures;
    • make Discord READY wait retry with reconnect/backoff instead of throwing after one timeout.
  • Discord outbound reply safety:
    • add a final send-boundary scrub for assistant-visible text;
    • drop pure internal trace/commentary/tool-channel text before Discord delivery while preserving code fences and media-only payloads.

Why

A local production incident showed a bad interaction between startup readiness pressure and front-channel output safety. The failure mode included transient Gateway readiness stalls, slow sessions.list startup calls, and Discord-visible internal execution/commentary-like text. This PR adds both startup resilience and a final Discord delivery guard so the channel boundary is safer even if upstream output assembly makes a mistake.

Production validation

  • Production issue: Gateway startup readiness stall + Discord outbound internal trace leakage.
  • Exact patch status: production-running code payload equivalent. The public PR branch intentionally redacts/sanitizes local-only status documentation, so the full commit patch-id differs while the code-only patch-id matches the locally running hotfix.
  • Production live branch/commit: local operator branch/commit recorded in private status docs; omitted from public PR body to avoid exposing deployment fingerprints.
  • Runtime path validated: exact PR commit e5b08409453c55967a89156b480c8e2a8d7a35a9 built and run from a local source checkout via dist/index.js in an isolated OPENCLAW_HOME, loopback-only Gateway, auth disabled, channel plugins disabled.
  • Runtime process evidence: /usr/bin/node dist/index.js gateway --port 29988 --auth none --allow-unconfigured.
  • Health probe: GET /health returned {"ok":true,"status":"live"}.
  • Soak scope: isolated startup/runtime validation; production hotfix soak evidence is tracked locally. This PR branch has not replaced the live production Gateway yet.
  • Rollback: git revert <this commit>, rebuild, and restart the operator-managed Gateway service.

Validation

  • pnpm install --frozen-lockfile
  • node scripts/run-vitest.mjs run --config test/vitest/vitest.extension-discord.config.ts extensions/discord/src/monitor/provider.lifecycle.test.ts extensions/discord/src/monitor/reply-delivery.test.ts
    • Passed: 2 files, 28 tests.
  • OPENCLAW_GATEWAY_PROJECT_SHARDS=1 node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway.config.ts src/gateway/server-methods.control-plane-rate-limit.test.ts
    • Passed: 1 file, 12 tests.
  • node scripts/run-vitest.mjs run --config test/vitest/vitest.infra.config.ts src/infra/approval-handler-bootstrap.test.ts src/infra/exec-approval-channel-runtime.test.ts
    • Passed: 2 files, 30 tests.
  • pnpm build
    • Passed.
  • Isolated runtime smoke:
    • Gateway reached ready on port 29988.
    • /health returned live status.
    • Process path confirmed from /proc/<pid>/cmdline.
  • git diff --check
    • Passed.

Risk / compatibility notes

  • sessions.list is temporarily unavailable during startup until sidecars clear startup gating. Clients should retry retryable startup UNAVAILABLE responses.
  • Discord READY wait now reconnects with backoff until stop/abort; persistent credential/network issues remain operator-visible instead of crashing Gateway startup.
  • The final Discord scrub intentionally removes standalone internal trace/channel lines outside code fences. Code-fenced examples are preserved.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: discord Channel integration: discord gateway Gateway runtime size: M labels May 4, 2026
@clawsweeper

clawsweeper Bot commented May 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

Summary
The PR adds Gateway startup deferrals, Discord READY reconnect retries, final Discord reply scrubbing, regression tests, a status document, and a changelog entry.

Reproducibility: yes. by source inspection: current main has the one-reconnect Discord READY failure path, direct Discord reply delivery without a final send-boundary scrub, and no sessions.list startup gate. I did not perform live Discord or Gateway soak reproduction in this read-only review.

Next step before merge
The remaining blockers are narrow docs/changelog edits that an automated repair pass can safely attempt on the PR branch.

Security
Cleared: The diff adds no dependencies, workflow changes, package-resolution changes, install scripts, or new secret handling; the Discord send-boundary scrub is security-positive once docs are cleaned up.

Review findings

  • [P2] Remove the incident status note from docs — docs/status/openclaw-startup-readiness-and-leak-fix-20260504.md:1
  • [P3] Describe the full user-facing fix in the changelog — CHANGELOG.md:63
Review details

Best possible solution:

Keep the code/test hardening, remove or rewrite the status artifact as generic documentation, broaden the changelog entry to cover the user-facing fixes, then land after targeted checks remain green.

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

Yes by source inspection: current main has the one-reconnect Discord READY failure path, direct Discord reply delivery without a final send-boundary scrub, and no sessions.list startup gate. I did not perform live Discord or Gateway soak reproduction in this read-only review.

Is this the best way to solve the issue?

No, not as-is: the code changes fit the existing startup-unavailable, approval-bootstrap, Discord lifecycle, and outbound-delivery boundaries, but the incident status note belongs in PR evidence or a private artifact rather than source docs. The remaining changelog entry should describe the full user-facing startup and Discord reply-safety fix.

Full review comments:

  • [P2] Remove the incident status note from docs — docs/status/openclaw-startup-readiness-and-leak-fix-20260504.md:1
    The added docs/status page is a PR-specific incident/status artifact rather than generic user documentation: it records local operator evidence, soak keywords, rollback/next-action notes, and a concrete /tmp/openclaw/... log path. docs/AGENTS.md requires docs content to stay generic and avoid local paths, so this should be removed from source docs or rewritten as a generic troubleshooting page.
    Confidence: 0.91
  • [P3] Describe the full user-facing fix in the changelog — CHANGELOG.md:63
    The added entry only covers preserving component-only payloads after text scrubbing, but this PR also changes Gateway startup sessions.list gating, approval-readiness retry handling, Discord READY retry behavior, and Discord internal trace scrubbing. Release notes will omit the main user-facing fixes unless this line is broadened or another single-line Fixes entry is added.
    Confidence: 0.89

Overall correctness: patch is incorrect
Overall confidence: 0.89

Acceptance criteria:

  • pnpm exec oxfmt --check --threads=1 CHANGELOG.md
  • git diff --check

What I checked:

Likely related people:

  • @steipete: Recent main history heavily touches Discord gateway readiness, Discord reply delivery, approval gateway startup, and Discord docs near this PR's surfaces. (role: recent maintainer; confidence: high; commits: 03df3539e934, 3bdaa1ceca29, 5e640b93dae6; files: extensions/discord/src/monitor/provider.lifecycle.ts, extensions/discord/src/monitor/reply-delivery.ts, src/gateway/operator-approvals-client.ts)
  • @vincentkoc: History includes Discord reconnect crash handling and approval/runtime gateway seam work adjacent to the readiness and native-approval paths changed here. (role: adjacent owner; confidence: medium; commits: 02e3061aa709, 0f7d9c957093, 462d8e3bc06a; files: extensions/discord/src/monitor/provider.lifecycle.ts, src/infra/approval-handler-bootstrap.ts, src/infra/exec-approval-channel-runtime.ts)
  • @gumadeiras: History shows the native approval lifecycle assembly and approval replay/hardening work that the bootstrap retry changes build on. (role: introduced behavior; confidence: medium; commits: d78512b09d1d, 6484b41eb9e4, b78202d44ede; files: src/infra/approval-handler-bootstrap.ts, src/infra/exec-approval-channel-runtime.ts, extensions/discord/src/monitor/provider.lifecycle.ts)
  • @scoootscooob: Recent startup control-plane retry work introduced or maintained the startup-unavailable method gate and its tests, which this PR extends to sessions.list. (role: recent maintainer; confidence: medium; commits: ccb847e46f1b; files: src/gateway/server-startup-unavailable-methods.ts, src/gateway/server-methods.control-plane-rate-limit.test.ts)

Remaining risk / open question:

  • The new docs/status page may be published or discovered as product docs even though it reads like a PR-specific incident/status artifact and includes a local log path.
  • I did not run live Discord or Gateway soak tests in this read-only review; the reproduction and validation assessment is based on source inspection, the PR's reported local validation, and current head CI.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 29a3e71106ac.

@NikolaFC

NikolaFC commented May 4, 2026

Copy link
Copy Markdown
Contributor Author

Addressed clawsweeper feedback in 9769dc0daf:

  • P2 fixed: sanitizeDiscordFrontChannelReplyPayloads now preserves non-text payload content (channelData, presentation/interactive blocks, audioAsVoice) when scrubbed text becomes empty, instead of dropping component-only payloads.
  • Added regression coverage in extensions/discord/src/monitor/reply-delivery.test.ts for:
    • component-only channelData payloads
    • presentation-only payloads
  • P3 fixed: added unreleased changelog entry in CHANGELOG.md.

Validation run locally:

  • pnpm test extensions/discord/src/monitor/reply-delivery.test.ts extensions/discord/src/monitor/provider.lifecycle.test.ts
  • OPENCLAW_GATEWAY_PROJECT_SHARDS=1 pnpm test src/gateway/server-methods.control-plane-rate-limit.test.ts
  • pnpm test src/infra/approval-handler-bootstrap.test.ts src/infra/exec-approval-channel-runtime.test.ts
  • pnpm exec oxfmt --check --threads=1 extensions/discord/src/monitor/reply-safety.ts extensions/discord/src/monitor/reply-delivery.test.ts CHANGELOG.md
  • pnpm check:changed (exit 0)

@NikolaFC
NikolaFC force-pushed the fix/startup-readiness-discord-reply-safety-pr branch 2 times, most recently from a454c9b to 8ef28b8 Compare May 4, 2026 21:08
(cherry picked from commit 3956672106b3387d42427a485a9ca01e77f3b78f)
@openclaw-barnacle openclaw-barnacle Bot removed the docs Improvements or additions to documentation label May 4, 2026
@steipete
steipete force-pushed the fix/startup-readiness-discord-reply-safety-pr branch from 88e1aa4 to b1a386e Compare May 4, 2026 22:02
@steipete
steipete merged commit 343f859 into openclaw:main May 4, 2026
108 checks passed
@steipete

steipete commented May 4, 2026

Copy link
Copy Markdown
Contributor

Landed via rebase onto main.

  • CI: PR checks green on head 03a4e2c2c593bb34093ec4848ecb3d3b99175970
  • Local: pnpm test extensions/discord/src/monitor/reply-delivery.test.ts; pnpm exec oxfmt --check --threads=1 extensions/discord/src/monitor/reply-safety.ts extensions/discord/src/monitor/reply-delivery.test.ts; git diff --check
  • Landed SHA: 343f859

Thanks @NikolaFC!

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

Labels

channel: discord Channel integration: discord gateway Gateway runtime size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants