Skip to content

perf(inbound): trim dispatch and command startup imports#52374

Merged
vincentkoc merged 10 commits intomainfrom
fix/inbound-auth-store-churn
Mar 22, 2026
Merged

perf(inbound): trim dispatch and command startup imports#52374
vincentkoc merged 10 commits intomainfrom
fix/inbound-auth-store-churn

Conversation

@vincentkoc
Copy link
Copy Markdown
Member

Summary

  • lazy-load abort and ACP dispatch helpers from dispatch-from-config
  • split TTS config reads from TTS runtime synthesis and remove reply-payloads from the static dispatch path
  • move the built-in command handler table behind a runtime boundary in commands-core

Measured impact

  • src/auto-reply/reply/dispatch-from-config.ts
    • before: ~13.4s / +270MB
    • after: ~1.0s / +107MB
  • src/auto-reply/reply/commands-core.ts
    • before: ~5.3s / +347MB
    • after: ~21.5s / +48MB
    • note: tsx wall time is noisy here; the RSS drop is the meaningful signal
  • src/auto-reply/reply/get-reply-run.ts
    • current probe: ~1.86s / +71.6MB

Validation

  • pnpm test -- src/auto-reply/reply/dispatch-from-config.test.ts
  • pnpm test -- src/auto-reply/reply/commands-core.test.ts

Notes

  • I did not use the full repo check gate for the commit because it currently trips on unrelated local formatting changes outside this batch.

@openclaw-barnacle openclaw-barnacle bot added channel: discord Channel integration: discord gateway Gateway runtime agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Mar 22, 2026
@vincentkoc vincentkoc self-assigned this Mar 22, 2026
@vincentkoc vincentkoc marked this pull request as ready for review March 22, 2026 16:57
@vincentkoc vincentkoc requested a review from a team as a code owner March 22, 2026 16:57
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 22, 2026

Greptile Summary

This PR pursues startup-time and memory improvements by converting several heavy static imports into lazy dynamic imports behind *.runtime.ts shim modules, splitting utility modules (e.g. tts-config, abort-primitives, context-cache) from their heavy runtime dependencies, and inlining a handful of simple one-liner helpers to avoid pulling in large dependency graphs. The measured RSS reductions for dispatch-from-config (~163 MB) and commands-core (~299 MB) are significant.

Key observations:

  • shouldSuppressReasoningPayload is correctly inlined as payload.isReasoning === true — the original function was a single-line wrapper with no additional logic.
  • resolveTtsConfig(cfg).mode ?? "final" is correctly replaced by resolveConfiguredTtsMode(cfg) — the semantics are identical.
  • The local normalizeDiscordChatType in session-key-normalization.ts produces identical output to the SDK's normalizeChatType for all known Discord chat types.
  • normalizeCommandBodyLite in commands-context.ts omits the getTextAliasMap() alias-resolution step that the original normalizeCommandBody performed. This silently changes the contract of commandBodyNormalized: slash-command aliases registered via the command registry will no longer be resolved before reaching command handlers. Whether this affects real commands depends on what aliases are currently registered, but it creates a latent maintenance hazard.
  • parseActivationCommand in group-activation.ts previously truncated multi-line input to the first line before matching; the inline regex replacement no longer does so, which could silently misparse edge-case multi-line activation config values.
  • The PR notes that the full check gate was intentionally bypassed due to unrelated local formatting issues — the two targeted test suites (dispatch-from-config, commands-core) were verified independently.

Confidence Score: 4/5

  • Safe to merge with one targeted fix: normalizeCommandBodyLite should either restore alias resolution or explicitly document the intentional behavior change.
  • The lazy-loading refactor is well-structured and the core correctness of each substitution (TTS mode, reasoning suppression, Discord chat-type normalisation) has been verified. The main concern is normalizeCommandBodyLite silently dropping alias resolution, which could break command aliases in ways that are hard to test statically. The multi-line activation-command gap is a minor edge case. The targeted test suites pass, and the memory/startup wins are real and well-measured.
  • src/auto-reply/reply/commands-context.ts (alias resolution gap in normalizeCommandBodyLite) and src/auto-reply/group-activation.ts (multi-line input handling).

Comments Outside Diff (2)

  1. src/auto-reply/reply/commands-context.ts, line 781-805 (link)

    P1 normalizeCommandBodyLite silently drops text-alias resolution

    The original normalizeCommandBody from commands-registry performs a final lookup in getTextAliasMap() to canonicalize registered aliases (e.g. resolving /h/help, or any plugin-registered alias). normalizeCommandBodyLite omits this step entirely.

    As a result, commandBodyNormalized in CommandContext now carries the raw (un-aliased) command body. Every command handler in handleCommands that matches against the canonical form will silently miss invocations sent via an alias. Since the alias table is populated at runtime (including plugin commands), this regression is hard to catch in static tests.

    If the intent is to keep the alias lookup lazy, the resolution should happen inside handleCommands after loadCommandHandlersRuntime() has been awaited — or a dedicated loadCommandNormalizationRuntime() shim should be called at the start of buildCommandContext.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/auto-reply/reply/commands-context.ts
    Line: 781-805
    
    Comment:
    **`normalizeCommandBodyLite` silently drops text-alias resolution**
    
    The original `normalizeCommandBody` from `commands-registry` performs a final lookup in `getTextAliasMap()` to canonicalize registered aliases (e.g. resolving `/h``/help`, or any plugin-registered alias). `normalizeCommandBodyLite` omits this step entirely.
    
    As a result, `commandBodyNormalized` in `CommandContext` now carries the raw (un-aliased) command body. Every command handler in `handleCommands` that matches against the canonical form will silently miss invocations sent via an alias. Since the alias table is populated at runtime (including plugin commands), this regression is hard to catch in static tests.
    
    If the intent is to keep the alias lookup lazy, the resolution should happen inside `handleCommands` after `loadCommandHandlersRuntime()` has been awaited — or a dedicated `loadCommandNormalizationRuntime()` shim should be called at the start of `buildCommandContext`.
    
    How can I resolve this? If you propose a fix, please make it concise.
  2. src/auto-reply/group-activation.ts, line 299-302 (link)

    P2 Multi-line activation commands no longer truncated to first line

    normalizeCommandBody extracted singleLine before colon-normalisation, so a value like /activation:always\nsome trailing text was correctly reduced to /activation always and then matched. The replacement regex operates on the raw trimmed string; because . does not match \n and $ anchors to end-of-string (no m flag), it won't transform a command whose colon appears on the first line of a multi-line string. The subsequent /activation match regex also fails because $ won't match mid-string.

    In practice, activation commands are unlikely to be multi-line, but the behavioural gap is worth noting if any integration passes a multi-line config value here.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/auto-reply/group-activation.ts
    Line: 299-302
    
    Comment:
    **Multi-line activation commands no longer truncated to first line**
    
    `normalizeCommandBody` extracted `singleLine` before colon-normalisation, so a value like `/activation:always\nsome trailing text` was correctly reduced to `/activation always` and then matched. The replacement regex operates on the raw `trimmed` string; because `.` does not match `\n` and `$` anchors to end-of-string (no `m` flag), it won't transform a command whose colon appears on the first line of a multi-line string. The subsequent `/activation` match regex also fails because `$` won't match mid-string.
    
    In practice, activation commands are unlikely to be multi-line, but the behavioural gap is worth noting if any integration passes a multi-line config value here.
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/auto-reply/reply/commands-context.ts
Line: 781-805

Comment:
**`normalizeCommandBodyLite` silently drops text-alias resolution**

The original `normalizeCommandBody` from `commands-registry` performs a final lookup in `getTextAliasMap()` to canonicalize registered aliases (e.g. resolving `/h``/help`, or any plugin-registered alias). `normalizeCommandBodyLite` omits this step entirely.

As a result, `commandBodyNormalized` in `CommandContext` now carries the raw (un-aliased) command body. Every command handler in `handleCommands` that matches against the canonical form will silently miss invocations sent via an alias. Since the alias table is populated at runtime (including plugin commands), this regression is hard to catch in static tests.

If the intent is to keep the alias lookup lazy, the resolution should happen inside `handleCommands` after `loadCommandHandlersRuntime()` has been awaited — or a dedicated `loadCommandNormalizationRuntime()` shim should be called at the start of `buildCommandContext`.

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/auto-reply/group-activation.ts
Line: 299-302

Comment:
**Multi-line activation commands no longer truncated to first line**

`normalizeCommandBody` extracted `singleLine` before colon-normalisation, so a value like `/activation:always\nsome trailing text` was correctly reduced to `/activation always` and then matched. The replacement regex operates on the raw `trimmed` string; because `.` does not match `\n` and `$` anchors to end-of-string (no `m` flag), it won't transform a command whose colon appears on the first line of a multi-line string. The subsequent `/activation` match regex also fails because `$` won't match mid-string.

In practice, activation commands are unlikely to be multi-line, but the behavioural gap is worth noting if any integration passes a multi-line config value here.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "perf(inbound): trim dispatch and command..." | Re-trigger Greptile

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eb374c45e8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@vincentkoc vincentkoc force-pushed the fix/inbound-auth-store-churn branch from f9aa835 to 185b5c3 Compare March 22, 2026 18:44
@openclaw-barnacle openclaw-barnacle bot added size: M and removed channel: discord Channel integration: discord gateway Gateway runtime agents Agent runtime and tooling size: XL labels Mar 22, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 185b5c3d46

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b9fe709dcd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@vincentkoc vincentkoc merged commit 5369ea5 into main Mar 22, 2026
38 of 39 checks passed
@vincentkoc vincentkoc deleted the fix/inbound-auth-store-churn branch March 22, 2026 20:19
frankekn pushed a commit to artwalker/openclaw that referenced this pull request Mar 23, 2026
)

* perf(inbound): trim dispatch and command startup imports

* fix(reply): restore command alias canonicalization

* style(reply): format command context

* fix(reply): restore runtime shim exports

* test(reply): mock ACP route seam

* fix(reply): repair dispatch type seams
furaul pushed a commit to furaul/openclaw that referenced this pull request Mar 24, 2026
)

* perf(inbound): trim dispatch and command startup imports

* fix(reply): restore command alias canonicalization

* style(reply): format command context

* fix(reply): restore runtime shim exports

* test(reply): mock ACP route seam

* fix(reply): repair dispatch type seams
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 25, 2026
)

* perf(inbound): trim dispatch and command startup imports

* fix(reply): restore command alias canonicalization

* style(reply): format command context

* fix(reply): restore runtime shim exports

* test(reply): mock ACP route seam

* fix(reply): repair dispatch type seams

(cherry picked from commit 5369ea5)
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 25, 2026
)

* perf(inbound): trim dispatch and command startup imports

* fix(reply): restore command alias canonicalization

* style(reply): format command context

* fix(reply): restore runtime shim exports

* test(reply): mock ACP route seam

* fix(reply): repair dispatch type seams

(cherry picked from commit 5369ea5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant