Skip to content

fix(synology-chat): respect SYNOLOGY_RATE_LIMIT=0 by using ?? instead of ||#39220

Open
Nipurn123 wants to merge 2 commits intoopenclaw:mainfrom
Nipurn123:fix/synology-rate-limit-zero
Open

fix(synology-chat): respect SYNOLOGY_RATE_LIMIT=0 by using ?? instead of ||#39220
Nipurn123 wants to merge 2 commits intoopenclaw:mainfrom
Nipurn123:fix/synology-rate-limit-zero

Conversation

@Nipurn123
Copy link
Copy Markdown

Issue

Fixes #39191

Problem

In extensions/synology-chat/src/accounts.ts:83, the rate limit parsing used || instead of ??:

(envRateLimit ? parseInt(envRateLimit, 10) || 30 : 30)

When SYNOLOGY_RATE_LIMIT=0, parseInt("0", 10) returns 0, and 0 || 30 evaluates to 30, silently ignoring the user′s intent.

Solution

Changed || to ?? (nullish coalescing) so that 0 is respected:

(envRateLimit ? parseInt(envRateLimit, 10) ?? 30 : 30)

Now SYNOLOGY_RATE_LIMIT=0 correctly produces rateLimitPerMinute: 0.

Testing

Verified the fix:

  • SYNOLOGY_RATE_LIMIT=0rateLimitPerMinute: 0
  • SYNOLOGY_RATE_LIMIT=5rateLimitPerMinute: 5
  • SYNOLOGY_RATE_LIMIT unset → rateLimitPerMinute: 30

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 7, 2026

Greptile Summary

This PR attempts to fix a bug where SYNOLOGY_RATE_LIMIT=0 was being ignored by changing || to ?? in the rate limit parsing logic. While the ?? swap correctly fixes the 0 case (0 ?? 300), it introduces a functional regression: parseInt returns NaN for invalid input (not null/undefined), so non-numeric env values silently propagate NaN instead of falling back to the default 30. The fix needs to include explicit NaN handling before it's safe to merge.

Confidence Score: 1/5

  • The PR introduces a functional regression where non-numeric SYNOLOGY_RATE_LIMIT values silently propagate as NaN instead of falling back to the default value.
  • The fix correctly addresses the reported SYNOLOGY_RATE_LIMIT=0 case but introduces a regression for invalid env var values. The ?? operator only guards against null/undefined, not NaN. Since parseInt("abc", 10) returns NaN, the fallback to 30 is bypassed, allowing invalid rate limits to propagate silently. This is a functional bug that requires explicit NaN handling before the PR is safe to merge.
  • extensions/synology-chat/src/accounts.ts — line 83 needs a Number.isNaN guard alongside the ?? fix.

Last reviewed commit: 4bfde34

accountOverride.rateLimitPerMinute ??
channelCfg.rateLimitPerMinute ??
(envRateLimit ? parseInt(envRateLimit, 10) || 30 : 30),
(envRateLimit ? parseInt(envRateLimit, 10) ?? 30 : 30),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

?? doesn't guard against NaN from parseInt

parseInt never returns null or undefined — it returns either a number or NaN. The nullish coalescing operator (??) only falls back for null/undefined, so if SYNOLOGY_RATE_LIMIT is set to a non-numeric value (e.g. "abc"), parseInt("abc", 10) returns NaN, and NaN ?? 30 evaluates to NaN — silently propagating an invalid rate limit. The previous || operator would have correctly fallen back to 30 in this case (NaN || 3030).

A correct fix needs to handle both 0 and invalid strings:

Suggested change
(envRateLimit ? parseInt(envRateLimit, 10) ?? 30 : 30),
(envRateLimit ? (Number.isNaN(parseInt(envRateLimit, 10)) ? 30 : parseInt(envRateLimit, 10)) : 30),
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/synology-chat/src/accounts.ts
Line: 83

Comment:
`??` doesn't guard against `NaN` from `parseInt`

`parseInt` never returns `null` or `undefined` — it returns either a number or `NaN`. The nullish coalescing operator (`??`) only falls back for `null`/`undefined`, so if `SYNOLOGY_RATE_LIMIT` is set to a non-numeric value (e.g. `"abc"`), `parseInt("abc", 10)` returns `NaN`, and `NaN ?? 30` evaluates to `NaN` — silently propagating an invalid rate limit. The previous `||` operator *would* have correctly fallen back to `30` in this case (`NaN || 30``30`).

A correct fix needs to handle both `0` and invalid strings:

```suggestion
      (envRateLimit ? (Number.isNaN(parseInt(envRateLimit, 10)) ? 30 : parseInt(envRateLimit, 10)) : 30),
```

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

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: 4bfde340e2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

accountOverride.rateLimitPerMinute ??
channelCfg.rateLimitPerMinute ??
(envRateLimit ? parseInt(envRateLimit, 10) || 30 : 30),
(envRateLimit ? parseInt(envRateLimit, 10) ?? 30 : 30),
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 Badge Restore numeric fallback for invalid SYNOLOGY_RATE_LIMIT

Using ?? with parseInt here breaks the defaulting behavior for malformed non-empty env values (for example SYNOLOGY_RATE_LIMIT=abc), because parseInt returns NaN and NaN ?? 30 stays NaN. That propagates rateLimitPerMinute as NaN, and getRateLimiter in extensions/synology-chat/src/webhook-handler.ts:22-24 will recreate the limiter on every request (NaN !== NaN), effectively disabling rate limiting instead of falling back to 30.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: synology-chat ignores SYNOLOGY_RATE_LIMIT=0 (parseInt || 30 truthy check)

1 participant