fix: add missing discordUserIds param and settings variable#55
fix: add missing discordUserIds param and settings variable#55alanfeng99 wants to merge 1 commit intomoazbuilds:masterfrom
Conversation
Two runtime crashes prevented the daemon from starting: 1. config.ts: `parseSettings` was called with `discordUserIds` from `loadSettings`/`reloadSettings` but the function signature did not declare the parameter, causing a ReferenceError. 2. runner.ts: `execClaude` destructured `getSettings()` directly into named vars but later referenced the full `settings` object for `sessionTimeoutMs`, causing a ReferenceError.
There was a problem hiding this comment.
Pull request overview
Fixes two startup-crashing ReferenceErrors in the daemon by aligning settings parsing and usage between config.ts and runner.ts.
Changes:
- Update
parseSettingsto accept and use adiscordUserIdsparameter (preserving large Discord snowflake IDs). - Fix
execClaudeto keep asettingsobject (instead of only destructuring) so later references don’t crash. - Reformat several long statements/arrays for readability and consistency.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/config.ts | Adds discordUserIds parameter to parseSettings and passes extracted snowflake IDs from raw JSON text. |
| src/runner.ts | Fixes settings reference in execClaude (and related call sites) and includes various formatting-only adjustments. |
Comments suppressed due to low confidence (2)
src/config.ts:295
sessionTimeoutMsis read fromsettingsin runner.ts, butSettings/parseSettings()do not include this field, so any configured value in settings.json will be dropped during parsing and the timeout will always fall back toCLAUDE_TIMEOUT_MS. Consider addingsessionTimeoutMs(likely optional) to theSettingstype,DEFAULT_SETTINGS, andparseSettings()with basic numeric validation so the setting is actually respected without relying onanycasts downstream.
function parseSettings(
raw: Record<string, any>,
discordUserIds?: string[],
): Settings {
const rawLevel = raw.security?.level;
const level: SecurityLevel =
typeof rawLevel === "string" && VALID_LEVELS.has(rawLevel as SecurityLevel)
? (rawLevel as SecurityLevel)
: "moderate";
src/runner.ts:388
timeoutMsis derived via(settings as any).sessionTimeoutMs, butSettingscurrently doesn’t define/parsesessionTimeoutMs, so this will never pick up a value from settings.json and theanycast masks the type error. OncesessionTimeoutMsis part ofSettings/parseSettings, use the typed field here (and consider validating it’s a finite positive number before using it).
const settings = getSettings();
const securityArgs = buildSecurityArgs(settings.security);
const { CLAUDECODE: _, ...cleanEnv } = process.env;
const baseEnv = { ...cleanEnv } as Record<string, string>;
const timeoutMs = (settings as any).sessionTimeoutMs || CLAUDE_TIMEOUT_MS;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -363,13 +442,20 @@ async function execClaude(name: string, prompt: string): Promise<RunResult> { | |||
| const timeoutMs = (settings as any).sessionTimeoutMs || CLAUDE_TIMEOUT_MS; | |||
There was a problem hiding this comment.
Same issue as above: timeoutMs uses (settings as any).sessionTimeoutMs, but the parsed Settings object doesn’t currently carry that field, so configured timeouts can’t take effect and the any cast hides the mismatch. Prefer a typed settings.sessionTimeoutMs once it’s added to Settings/parseSettings, with a sane fallback to CLAUDE_TIMEOUT_MS.
| const timeoutMs = (settings as any).sessionTimeoutMs || CLAUDE_TIMEOUT_MS; | |
| const timeoutMs = settings.sessionTimeoutMs ?? CLAUDE_TIMEOUT_MS; |
Summary
parseSettingswas called with adiscordUserIdsargument fromloadSettings/reloadSettings, but the function signature only accepted one parameter (raw). This caused aReferenceError: discordUserIds is not definedat startup.execClaudedestructuredgetSettings()directly into named variables but later referenced the fullsettingsobject forsessionTimeoutMs, causing aReferenceError: settings is not definedduring session bootstrap.Both bugs are crash-on-start — the daemon cannot launch without these fixes.
Test plan
bun run src/index.ts start --weband verify daemon starts without ReferenceErrorsessionTimeoutMssetting is respected when configured🤖 Generated with Claude Code