Skip to content

Register slash commands automatically at bot startup - #54

Merged
rstover-fo merged 2 commits into
mainfrom
claude/agent-neo4j-memory-bg7tqa
Aug 24, 2026
Merged

rstover-fo merged 2 commits into
mainfrom
claude/agent-neo4j-memory-bg7tqa

Conversation

@rstover-fo

@rstover-fo rstover-fo commented Aug 24, 2026 •

Copy link
Copy Markdown
Owner

Registration was manual-only (npm run register), which left a trap: a guild authorized after the last run — or authorized without the applications.commands scope, where registration itself fails with 50001 Missing Access — has the runtime allowlist open but no slash commands registered, and nothing surfaces it. Live case today: the home server's re-authorization granted the missing scope, but commands stayed invisible because nobody could run the script from a phone.

Changes

  • bot/src/register.ts (new): the registration loop extracted into a shared module — one idempotent PUT of the full command set per guild in allowedGuildIds.
  • bot/src/index.ts: startup awaits registerCommands(config) before login, so every deploy converges the registered commands with the code. Failure is log-and-continue by design: a Discord API blip must not keep the gateway down.
  • bot/scripts/register-commands.ts: now delegates to the shared module; npm run register remains the standalone manual lever.
  • bot/src/__tests__/register.test.ts (new): pins one PUT per allowed guild with the configured credentials, and that API failures propagate to the caller (who decides fatality).

Verification

Bot suite: 482 tests across 37 files, typecheck clean.

On merge

The bot's Railway service (watch bot/**, branch main) redeploys automatically; the boot log will show [bot] Registered N command(s) to guild … and slash commands appear in the authorized server immediately.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UxahiFZLtf5tER2MuEo9Bo


Generated by Claude Code

Greptile Summary

This change moves guild slash-command registration into shared startup code so configured guilds are synchronized whenever the bot starts. A reproduced startup failure remains in bot/src/index.ts: gateway login waits for every serial guild registration attempt to finish, so slow Discord REST failures or retry windows can keep the bot unavailable for their combined duration.

The startup registration should run independently of gateway login while retaining its aggregate error logging and the manual recovery command.

Confidence Score: 4/5

The change should not merge until gateway login is decoupled from slow command-registration requests.

A focused executable harness exercised the original startup path with delayed successful and failed guild registrations, and directly observed gateway login occur only after all serial requests settled.

Files Needing Attention: bot/src/index.ts needs its startup ordering changed so command synchronization cannot block client.login().

T-Rex T-Rex Logs

What T-Rex did

  • Filed a finding-comment-proof for a posted P1 finding and attached three artifacts documenting the startup and login sequence.
  • Filed a second finding-comment-proof for another posted P1 finding.
  • Validated the startup ordering by running the harness through the real main() and registerCommands() with a mocked Discord boundary; it reported elapsedMs=125 and the event sequence guild-1:start, guild-1:end, guild-2:start, guild-2:end, guild-3:start, guild-3:end, login, showing login waits until all registrations finish.

View all artifacts

T-Rex Ran code and verified through T-Rex

Fix all with Greploop Fix All in Claude Code

Prompt To Fix All With AI
### Issue 1
bot/src/index.ts:117
**Gateway login waits for cumulative guild registration time**

`main()` awaits `registerCommands(config)` before calling `client.login()`, while registration sends each guild request serially. A slow Discord REST failure or retry for every allowlisted guild therefore delays gateway connection by the combined duration, leaving the bot unavailable until the full registration loop settles. Start registration as best-effort asynchronous work with rejection logging, then begin gateway login without waiting for every registration attempt.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "Isolate per-guild registration failures" | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

Registration was manual-only (npm run register), which left a trap: a
guild authorized after the last run -- or authorized without the
applications.commands scope, where registration itself fails with 50001
Missing Access -- has the runtime allowlist open but no commands
registered, and nothing surfaces it. Live case: the home server's
re-authorization granted the scope, but commands stayed invisible
because nobody could run the script from a phone.

The registration loop moves to src/register.ts, shared by startup and
the script. Startup awaits it before login (idempotent PUT per allowed
guild, so every deploy converges commands with the code) and treats
failure as log-and-continue: a Discord API blip must not keep the
gateway down, and npm run register remains the manual lever.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UxahiFZLtf5tER2MuEo9Bo
@vercel

vercel Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
v0-production-data-application Ready Ready Preview, v0 Aug 24, 2026 1:36am

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

Copy link
Copy Markdown

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: c39c085951

ℹ️ 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".

Comment thread bot/src/register.ts Outdated
Codex P2 on #54, valid: a rejection from one guild (e.g. 50001 Missing
Access) exited the loop, leaving every later allowlisted guild with
stale or absent commands. Each guild now registers inside its own
try/catch; failures log per guild and surface once as an aggregate
error, so npm run register still exits non-zero and startup still logs
the problem while reachable guilds stay in sync.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UxahiFZLtf5tER2MuEo9Bo
@rstover-fo
rstover-fo merged commit 4fc58ea into main Aug 24, 2026
5 checks passed
Comment thread bot/src/index.ts
// manual recovery lever. Await it so a registration burst can't race
// the first interactions after login.
try {
await registerCommands(config)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Gateway login waits for cumulative guild registration time

main() awaits registerCommands(config) before calling client.login(), while registration sends each guild request serially. A slow Discord REST failure or retry for every allowlisted guild therefore delays gateway connection by the combined duration, leaving the bot unavailable until the full registration loop settles. Start registration as best-effort asynchronous work with rejection logging, then begin gateway login without waiting for every registration attempt.

Artifacts

Gateway login waited for three slow guild registrations

  • Executed the authored startup harness against the original await-based path and shows login occurred only after two failed and one successful slow registration settled.

Original startup source with awaited command registration

  • Captured the executed source excerpt showing `await registerCommands(config)` at original line 117 before `client.login`.

Authored focused startup ordering test source

  • Captured the authored test harness that runs real startup and registration control flow with three delayed simulated guild REST responses.

View artifacts

T-Rex Ran code and verified through T-Rex

Prompt To Fix With AI
This is a comment left during a code review.
Path: bot/src/index.ts
Line: 117

Comment:
**Gateway login waits for cumulative guild registration time**

`main()` awaits `registerCommands(config)` before calling `client.login()`, while registration sends each guild request serially. A slow Discord REST failure or retry for every allowlisted guild therefore delays gateway connection by the combined duration, leaving the bot unavailable until the full registration loop settles. Start registration as best-effort asynchronous work with rejection logging, then begin gateway login without waiting for every registration attempt.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code

This branch was successfully deployed

1 active deployment
Preview — 9b13837d Deployed Aug 24, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants