Skip to content

improve(discord): avoid repeated account resolution on sends - #128462

Merged
steipete merged 1 commit into
mainfrom
codex/perf-discord-prepared-account-current
Aug 24, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf-discord-prepared-account-current

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where ordinary Discord sends using a configured token repeatedly resolved the same account before provider dispatch. Projection, full-client creation, and channel target resolution each performed equivalent account preparation, adding avoidable CPU work to structured, component, edit, voice, and ordinary message paths.

Why This Change Was Made

The full Discord client now exposes its canonical prepared account so downstream outbound projection and channel resolution can reuse that fact. Generic REST-only client behavior remains unchanged, and explicit-token retry lookup deliberately stays bound to the synthetic REST account identity while outbound projection uses the configured account.

No cache, configuration, protocol, security, storage, media-staging, provider-payload, or retry-policy contract changes.

User Impact

Configured-token Discord outbound work performs one account resolution instead of three before dispatch. Provider requests and payloads remain unchanged.

Evidence

  • Current-base red/green diagnostic: ordinary configured-token sends resolved the account 3 times before the repair and 1 time after it.
  • Provider-boundary semantic differential: configured-token channel, explicit-token configured-default-account, DM, and forum-thread captures are byte-identical; aggregate SHA-256 c18759dab3fef2e858a1694a980c2dac253a5b27be9ea3af0e2d48007ec0210a for both variants.
  • Owner projection benchmark with a representative eight-account config, 9 samples × 50,000 sends: baseline-equivalent 3 resolutions median 465.957 ms; candidate-equivalent 1 resolution median 152.786 ms; 67.21% lower account-projection cost (3.05×). This is isolated owner-cost evidence, not an end-to-end latency claim.
  • Current mock end-to-end timing was noise-limited: 1,118.716 ms baseline vs 1,120.949 ms candidate per 2,000 sends (−0.2%); no whole-path speedup is claimed.
  • Explicit-token retry regression test verifies projection returns the configured ops account while gateway-disconnect retry extension remains bound to the default REST account.
  • Focused owner/sibling tests: 9 files, 202 tests passed.
  • Full Discord extension: 227 files, 2,881 tests passed.
  • node scripts/check-changed.mjs: passed all classified extension and extension-test gates (format, production/test typechecks, type-aware Oxlint 0/0, dead exports, boundaries, guards, import cycles 0). The classifier selected no build lane.
  • git diff --check: clean.
  • Deslop audit: clean.
  • TruffleHog preflight: clean. Codex gpt-5.6-sol / high autoreview: no actionable findings; patch is correct at 0.94 confidence.
  • No credentialed or live Discord mutation was performed; proof uses mocked provider boundaries and exact payload captures.

@clawsweeper

clawsweeper Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord size: S maintainer Maintainer-authored PR labels Aug 24, 2026
@steipete
steipete marked this pull request as ready for review August 24, 2026 02:30
@clawsweeper clawsweeper Bot added 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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Aug 24, 2026
@clawsweeper

clawsweeper Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 23, 2026, 10:35 PM ET / August 24, 2026, 02:35 UTC.

ClawSweeper review

What this changes

The PR reuses a prepared Discord account across outbound message, component, structured, and voice sends to avoid repeated account resolution.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open for normal maintainer handling. Current main still resolves the Discord account separately in client creation, outbound projection, and channel-recipient resolution; this PR centralizes the prepared outbound account while keeping explicit-token retry lookup on the REST account. No actionable correctness or security defect was found, but the branch is behind main and exact-head checks remain in progress.

Priority: P3
Reviewed head: 385c242189cdda8d3e0d756b332e37b314fe09ae
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary optimization with a targeted retry-identity regression test and no concrete patch defect found.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless records mocked provider-boundary differential evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless records mocked provider-boundary differential evidence.
Evidence reviewed 6 items Current-main behavior: Current main creates the REST client with a resolved account but does not expose it to outbound callers, so downstream paths resolve their own account state.
Affected caller path: Current main separately resolves the account for message projection and again resolves the recipient account before channel lookup; the PR derives both from the client-prepared account.
PR identity separation: The proposed client exposes the configured account for projection while retaining the REST account for gateway-disconnect retry lookup.
Findings None None.
Security None None.

Live Verification

Command: pnpm openclaw --help

Result: FAIL (failed) — execution before step 1 run: live-proof package manager pnpm is unavailable after its official installer (curl -fsSL https://get.pnpm.io/install.sh | sh -): command failed without output

live-proof package manager pnpm is unavailable after its official installer (curl -fsSL https://get.pnpm.io/install.sh | sh -): command failed without output

Assertions:

  • FAIL expect_output: Usage: openclaw

How this fits together

Discord outbound delivery prepares a REST client and retry policy, resolves a recipient and channel target, then sends a Discord payload. Per-account outbound settings flow through this path, while gateway-disconnect retry behavior remains tied to the REST client's account identity.

flowchart LR
  A[Outbound Discord request] --> B[Prepare REST client and account]
  B --> C[Resolve recipient and channel]
  B --> D[Bind retry to REST account]
  C --> E[Build outbound payload]
  D --> F[Dispatch Discord request]
  E --> F
Loading

Decision needed

Question Recommendation
After the branch is rebased and its exact-head checks pass, should this maintainer Discord performance repair be merged? Merge after exact-head validation: Accept the owner-boundary simplification once the rebased head has green required checks.

Why: The PR is maintainer-labeled and changes the shared outbound account-preparation path, so final landing remains an explicit maintainer choice.

Before merge

  • Resolve merge risk (P1) - GitHub reports the branch behind main and several exact-head checks are still running; rebase and green exact-head CI are needed before landing.
  • Complete next step (P2) - No concrete repair is needed; this maintainer-labeled PR awaits standard rebase, exact-head CI, and maintainer landing review.
Agent review details

Security

None.

PR surface

Source -1, Tests +28. Total +27 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 5 42 43 -1
Tests 1 28 0 +28
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 70 43 +27

Review metrics

Metric Value Why it matters
Production vs test LOC production -1, tests +28 The optimization removes more production lines than it adds while adding focused retry-identity regression coverage.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Rebase this focused owner-boundary optimization onto current main and land it after exact-head Discord checks confirm preserved retry identity and outbound behavior.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Rebase this focused owner-boundary optimization onto current main and land it after exact-head Discord checks confirm preserved retry identity and outbound behavior.

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

Yes, source-reproducible: current main resolves account state in client construction, outbound projection, and channel-recipient resolution along the same configured-token send path.

Is this the best way to solve the issue?

Yes. Carrying the canonical prepared account from the client owner removes duplicate resolution while the separate REST account preserves existing explicit-token retry semantics.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 1ac7f0161c9e.

Labels

Label changes:

  • add P3: This is a bounded Discord outbound performance optimization with no established user-facing failure or data-delivery regression.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless records mocked provider-boundary differential evidence.

Label justifications:

  • P3: This is a bounded Discord outbound performance optimization with no established user-facing failure or data-delivery regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless records mocked provider-boundary differential evidence.

Evidence

What I checked:

Likely related people:

  • Dallin Romney: Current-main blame attributes the client retry logic and outbound target helper to the recent Discord refactor. (role: introduced current client and outbound structure; confidence: high; commits: 8a3afa8820b4; files: extensions/discord/src/client.ts, extensions/discord/src/send.outbound.ts)
  • Peter Steinberger: Recent current-main history includes a Discord send-surface change touching this same owner area. (role: recent Discord area contributor; confidence: medium; commits: 3aab15c0770c; files: extensions/discord/src/send.components.ts, extensions/discord/src/send.outbound.ts)

Rank-up moves

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

  • Rebase on current main and let the exact-head required checks finish successfully.

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.

Copy link
Copy Markdown
Contributor Author

Land-ready disposition

No blocking findings. The root cause is three equivalent account resolutions on an ordinary configured-token Discord send: outbound projection, full-client construction, and channel recipient resolution. The canonical fix carries the full client's prepared configured account into projection and channel resolution while retaining the synthetic REST account solely for gateway-disconnect retry identity.

Best-fix verdict: best owner-boundary fix. A cache would add invalidation state for process-stable configuration; changing REST-only clients would broaden unrelated semantics; leaving generic channel parsing in this path would retain the duplicate lookup. Production LOC is +42/-43 (net -1); tests are +28/-0.

Behavior proof

  • Current-base red/green: account resolutions 3 → 1.
  • Four provider-boundary routes (configured channel, explicit-token configured default, DM, forum thread) are byte-identical; aggregate SHA-256 c18759dab3fef2e858a1694a980c2dac253a5b27be9ea3af0e2d48007ec0210a on both variants.
  • The explicit-token regression test proves projection uses configured account ops while retry extension remains bound to the disconnected default REST account.
  • Isolated owner benchmark: 465.957 ms for three resolutions vs 152.786 ms for one across 50,000 sends/sample, 9 samples (67.21% lower projection cost, 3.05×). Current whole-path mock timing was noise-limited (−0.2%); no end-to-end speedup is claimed.

Validation

  • node scripts/run-vitest.mjs <9 focused Discord owner/sibling files> — 9 files / 202 tests passed.
  • node scripts/run-vitest.mjs extensions/discord — 227 files / 2,881 tests passed.
  • node scripts/check-changed.mjs — classified format, extension production/test typechecks, type-aware Oxlint 0/0, dead exports, boundaries, guards, and import cycles all passed; no build lane selected.
  • .agents/skills/autoreview/scripts/autoreview --mode uncommitted --engine codex --model gpt-5.6-sol --thinking high — TruffleHog clean; no actionable findings; patch correct at 0.94 confidence.
  • Exact-head hosted CI run 32683257279 is complete and green with no non-green checks.
  • Native OPENCLAW_TESTBOX=1 scripts/pr prepare-run 128462 passed in hosted_exact_or_recent_parent mode and verified remote head 385c242189cdda8d3e0d756b332e37b314fe09ae matches the prepared head.

ClawSweeper disposition: the exact-head review found no correctness or security defect and agreed this is the best solution. Its stale “checks in progress” item is resolved by the green exact-head run above. Its optional rebase rank-up is intentionally skipped: current main has no Discord overlap since the branch base, a merge-tree probe is conflict-free, GitHub reports MERGEABLE, and repository policy avoids rebasing merely for behind-main drift. The maintainer landing decision is accepted for this bounded campaign repair.

Provenance: the duplicate preparation accumulated across the Discord move in #45660, full-client runtime-config preparation in 5d9941c36d4c, and channel recipient resolution added in #86571; no single delivery regression is attributed.

Known proof gap: no credentialed/live Discord mutation was performed. This change does not alter the Discord API request boundary; mocked provider captures, retry-contract coverage, the full plugin suite, and exact-head CI are the available proof. ClawSweeper's unrelated pnpm openclaw --help live-proof attempt did not start because pnpm installation failed in its worker and is not treated as behavior evidence.

Codex source hard gate was checked directly at ../codex/codex-rs/app-server-protocol/src/protocol/v2/turn.rs:71-158, ../codex/codex-rs/core/src/session/turn.rs:153-238, and ../codex/codex-rs/core/src/codex_thread.rs:190-205; those turn/runtime contracts are unrelated to this Discord transport-local repair.

@steipete
steipete merged commit 267f1ad into main Aug 24, 2026
176 checks passed
@steipete
steipete deleted the codex/perf-discord-prepared-account-current branch August 24, 2026 02:52

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 maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

2 participants