Claude/pr51 fixes lq2g s - #51
Conversation
username-as-message (index.js):
- Smart username detection in bot.on('text'): when no pending action and
the user types a 3-30 char alphanumeric string they haven't linked yet,
bot asks "Is X your Runewager username?" with confirm/cancel inline keyboard
- New 'confirm_smart_username' action: confirms and saves the smart-detected
username with full XP/badge/onboarding tracking, same as explicit /linkrunewager
- 'await_runewager_username' handler now reads returnTo field: when the
bonus flow set returnTo:'w30_bonus', the bot resumes the bonus request
automatically after linking (skipping the extra /bonus step)
- checkBonusEligibility returns needsUsername:true (not just ok:false) so
callers can distinguish the missing-username case from other failures
- w30_request_start handles needsUsername inline: sets pendingAction with
returnTo:'w30_bonus' and prompts for username directly in the flow;
user gets their bonus request processed without leaving the conversation
prod-run.sh:
- VPS deploy-path fallback: if index.js not found at script location,
falls back to /var/www/html/Runewager automatically
- Always performs a safe restart (systemctl restart or kill+nohup) after
git pull so any pulled code changes take effect immediately; removes the
previous "bot already running — skipping launch" skip path
https://claude.ai/code/session_01X3PxGFF5zzKptQwVkjYzzN
…elegram
Adds a single admin-only /deploy command that runs the full deploy
cycle (git pull → npm ci → safe restart) without touching the VPS.
Also adds a startup notification so admins always know when the bot
comes back online after a restart or crash.
/deploy flow:
- Persists runtime state before touching anything
- Runs git pull origin main with 30s timeout; reports first output line
- Runs npm ci --omit=dev with 3min timeout; reports ok/fail
- Edits the status message live at each step so the admin sees progress
- Broadcasts a "bot is restarting" notice to ALL admin IDs
- Waits 1.5s for Telegram delivery, then calls systemctl restart runewager
- Falls back to process.exit(0) if systemctl is unavailable (lets
systemd/nohup restart the process automatically)
Startup admin notification:
- On every bot.launch() success, sends all admins a 🟢 online message
with timestamp, PID, and Node version — confirms deploys landed cleanly
Supporting changes:
- Added child_process { execFile, spawn } to top-level requires
- Added PROJECT_DIR = path.resolve(__dirname) constant
- Added runCmd() helper: promise-wrapped execFile, never throws,
returns { ok, out, err } for clean inline error handling
https://claude.ai/code/session_01X3PxGFF5zzKptQwVkjYzzN
Adds disable_notification: true to the admin 🟢 "Bot Online" message so it arrives as a silent notification and doesn't alert anyone mid-deployment or overnight. https://claude.ai/code/session_01X3PxGFF5zzKptQwVkjYzzN
…etection Addresses all PR #50 review comments from CodeAnt AI: 1. systemctl calls in ensure_systemd_service() now guarded with `command -v systemctl` before daemon-reload / enable — prevents set -e exit on non-systemd hosts; falls back with a clear warning. 2. logrotate binary feature-detected before validation dry-run — if logrotate is absent the script warns and returns cleanly instead of producing a noisy error or silently doing nothing. 3. crontab binary feature-detected before fallback cron job insertion — prevents unbound-variable / command-not-found errors on minimal systems that have no crontab installed. All three code paths continue to degrade gracefully with informative warn() messages and never exit the script unexpectedly. https://claude.ai/code/session_01X3PxGFF5zzKptQwVkjYzzN
|
CodeAnt AI is reviewing your PR. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughAdded deployment functionality with admin-only command for live git and npm operations, restart signaling, and bot startup notifications. Introduced smart username detection for Runewager accounts with confirmation flow and mid-bonus-request restoration. Enhanced prod-run.sh with fallback directory resolution and conditional guards for systemctl, logrotate, and crontab utilities. Changes
Sequence DiagramssequenceDiagram
actor User
participant Bot
participant DataStore as Data Store
participant BonusFlow as Bonus Flow
User->>Bot: Types Runewager username (no pending action)
Bot->>Bot: Smart detection triggered
Bot->>User: Prompts to confirm/modify username
User->>Bot: Confirms username (confirm_smart_username)
Bot->>DataStore: Link username to user account
Bot->>DataStore: Update onboarding state
Bot->>DataStore: Award XP
alt returnTo field exists (mid-flow)
Bot->>BonusFlow: Resume pending flow (e.g., w30_bonus)
BonusFlow->>BonusFlow: Re-evaluate eligibility
BonusFlow->>User: Continue with next step
else No pending flow
Bot->>User: Confirm linking complete
end
sequenceDiagram
actor Admin
participant Bot
participant System as System (git/npm)
participant Systemd as Systemctl/Init
participant AdminNotif as Admin Notification
Admin->>Bot: Issues /deploy command
Bot->>Bot: Validates admin permission
Bot->>Admin: Sends live status: starting deployment
Bot->>System: Execute git pull
Bot->>Admin: Sends live status: git pull result
Bot->>System: Execute npm ci
Bot->>Admin: Sends live status: npm ci result
Bot->>Systemd: Attempt systemctl restart
alt systemctl success
Systemd->>Bot: Service restarted
else systemctl unavailable/fails
Bot->>System: Fallback: kill + nohup restart
System->>Bot: Process restarted
end
Bot->>Admin: Sends deployment complete status
Note over Bot,Admin: On bot startup, admin receives<br/>online notification with timestamp
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
Nitpicks 🔍
|
| const allOk = gitResult.ok && npmResult.ok; | ||
| const summary = allOk ? '✅ All steps succeeded' : '⚠️ Some steps had warnings — check below'; | ||
|
|
||
| await edit( |
There was a problem hiding this comment.
Suggestion: The /deploy command restarts the bot process even when git pull or npm ci fail, meaning it can deliberately restart into a broken or partially updated state contrary to the intended "pull, install, then restart" flow, likely causing the new process to crash or misbehave until manually fixed. [logic error]
Severity Level: Critical 🚨
- ❌ /deploy can restart bot after failed git or npm steps.
- ⚠️ Bot may restart into inconsistent or broken deployment state.| await edit( | |
| if (!allOk) { | |
| await edit( | |
| `🚀 *Deployment summary* — ${ts()}\n\n` | |
| + `${gitLine}\n` | |
| + `${npmLine}\n\n` | |
| + `${summary}\n\n` | |
| + `③ Restart skipped — one or more steps failed.`, | |
| ); | |
| return; | |
| } | |
Steps of Reproduction ✅
1. As an admin (ID present in `ADMIN_IDS` from `index.js:14-18`), run the `/deploy`
command in Telegram, which executes the handler defined at `index.js:1216-1280`
(`bot.command('deploy', async (ctx) => { ... })` after passing `requireAdmin(ctx)` at
`index.js:1200-1207`).
2. In an environment where `git pull` fails (e.g. merge conflict, network issue, or local
changes), the call `runCmd('git', ['pull', 'origin', 'main'], PROJECT_DIR, 30000)` at
`index.js:1234` returns `{ ok: false, err: '...' }`, so `gitResult.ok` is `false` and
`gitLine` describes the failure.
3. The subsequent `npm ci` step runs via `runCmd('npm', ['ci', '--omit=dev'], PROJECT_DIR,
180000)` at `index.js:1245`; regardless of whether `npmResult.ok` is true or false, the
expression `const allOk = gitResult.ok && npmResult.ok;` at `index.js:1250` evaluates to
`false` because `gitResult.ok` is already `false`.
4. Despite `allOk` being `false`, the code immediately edits the status message with `③
Restarting bot now…` (lines `1253-1259`) and then executes the restart block at
`index.js:1261-1279`, sending a restart note to all admins and calling `spawn('systemctl',
['restart', 'runewager'], ...)` followed by `process.exit(0)`; the bot process is
restarted even though the codebase or dependencies were not successfully updated, risking
a new process that fails to start correctly or runs with mismatched code/deps.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** index.js
**Line:** 1253:1253
**Comment:**
*Logic Error: The `/deploy` command restarts the bot process even when `git pull` or `npm ci` fail, meaning it can deliberately restart into a broken or partially updated state contrary to the intended "pull, install, then restart" flow, likely causing the new process to crash or misbehave until manually fixed.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.|
CodeAnt AI finished reviewing your PR. |
…regex Addresses all PR #51 CodeAnt AI review comments: 1. Critical 🚨 — /deploy now aborts restart when git pull or npm ci fail. Previously the bot restarted unconditionally, potentially loading broken code. Now an early return is taken with a clear "restart skipped" message so the host stays on the last known-good version. 2. Sanitize deploy output sent to Telegram — new sanitizeCmdOutput() helper strips backtick characters (which break Markdown code spans) and truncates to 200 chars before embedding git/npm output in bot messages. Prevents Telegram parse errors and avoids leaking raw long error text. 3. Fix username detection regex — /^[A-Za-z0-9_.\\-]{3,30}$/ contained a double-backslash that matched literal '\' characters in usernames. Corrected to /^[A-Za-z0-9_.-]{3,30}$/ — only alphanumerics, underscore, dot, and hyphen are accepted. 4. prod-run.sh systemctl audit — all three call sites are already consistently guarded (ensure_systemd_service, restart block, diagnostics). No changes needed; confirmed safe on non-systemd hosts. https://claude.ai/code/session_01X3PxGFF5zzKptQwVkjYzzN
#52) …regex Addresses all PR #51 CodeAnt AI review comments: 1. Critical 🚨 — /deploy now aborts restart when git pull or npm ci fail. Previously the bot restarted unconditionally, potentially loading broken code. Now an early return is taken with a clear "restart skipped" message so the host stays on the last known-good version. 2. Sanitize deploy output sent to Telegram — new sanitizeCmdOutput() helper strips backtick characters (which break Markdown code spans) and truncates to 200 chars before embedding git/npm output in bot messages. Prevents Telegram parse errors and avoids leaking raw long error text. 3. Fix username detection regex — /^[A-Za-z0-9_.\\-]{3,30}$/ contained a double-backslash that matched literal '\' characters in usernames. Corrected to /^[A-Za-z0-9_.-]{3,30}$/ — only alphanumerics, underscore, dot, and hyphen are accepted. 4. prod-run.sh systemctl audit — all three call sites are already consistently guarded (ensure_systemd_service, restart block, diagnostics). No changes needed; confirmed safe on non-systemd hosts. https://claude.ai/code/session_01X3PxGFF5zzKptQwVkjYzzN
User description
Summary by CodeRabbit
Release Notes
New Features
Improvements
CodeAnt-AI Description
Link Runewager username by typing it naturally and resume bonus requests without extra steps
What Changed
Impact
✅ Shorter bonus request✅ Fewer interrupted bonus requests✅ Remote in-chat deploy with restart confirmation💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.