Skip to content

[Backport of #25403] fix(data-consumption): prevent hook usage counter from going negative - #25503

Open
Arthurk12 wants to merge 1 commit into
bigbluebutton:v3.0.x-developfrom
Arthurk12:plugins-sdk/3.0/issue/275
Open

[Backport of #25403] fix(data-consumption): prevent hook usage counter from going negative#25503
Arthurk12 wants to merge 1 commit into
bigbluebutton:v3.0.x-developfrom
Arthurk12:plugins-sdk/3.0/issue/275

Conversation

@Arthurk12

Copy link
Copy Markdown
Member

What does this PR do?

The usage counter that tracks how many plugins are listening to a given subscription can reach negative values, which is invalid and likely indicates a bug in the unsubscribe logic.

Extract the hook usage update logic into a dedicated function that guards against negative values and logs a warning when such an update is attempted.

Closes Issue(s)

Closes N/A

More

Closely related to:

The usage counter that tracks how many plugins are listening to a
given subscription can reach negative values, which is invalid and
likely indicates a bug in the unsubscribe logic.

Extract the hook usage update logic into a dedicated function that
guards against negative values and logs a warning when such an
update is attempted.
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The plugin engine now centralizes hook usage count delta handling, logs warnings for underflow, and clamps negative results to zero across custom and general update paths. The HTML5 package now obtains bigbluebutton-html-plugin-sdk from a GitHub pull request tarball instead of version 0.0.103.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: guileme, gustavotrott

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: preventing hook usage counters from going negative in data consumption.
Description check ✅ Passed The description matches the code changes by explaining the negative-counter fix and the warning on invalid updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Checkov (3.3.8)
bigbluebutton-html5/package.json

Traceback (most recent call last):
File "/usr/local/bin/checkov", line 2, in
from checkov.main import Checkov
ModuleNotFoundError: No module named 'checkov'


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
bigbluebutton-html5/imports/ui/components/plugins-engine/data-consumption/utils.ts (1)

13-25: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add focused tests for the shared underflow contract.

Cover both update paths with count = 0 and delta = -1; assert the count remains 0 and the warning includes the hook name, current count, and delta. Also cover normal positive and negative updates.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@bigbluebutton-html5/imports/ui/components/plugins-engine/data-consumption/utils.ts`
around lines 13 - 25, Add focused tests for applyHookUsageCountDelta covering
underflow from count 0 with delta -1, asserting a returned count of 0 and a
warning containing hookName, currentCount, and delta. Also test normal positive
and negative deltas, preserving the expected arithmetic behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@bigbluebutton-html5/package.json`:
- Line 82: Replace the mutable bigbluebutton-html-plugin-sdk PR URL in
package.json with an immutable committed SHA or published release version, then
regenerate the lockfile so it records the pinned dependency and resolved
tarball.

---

Nitpick comments:
In
`@bigbluebutton-html5/imports/ui/components/plugins-engine/data-consumption/utils.ts`:
- Around line 13-25: Add focused tests for applyHookUsageCountDelta covering
underflow from count 0 with delta -1, asserting a returned count of 0 and a
warning containing hookName, currentCount, and delta. Also test normal positive
and negative deltas, preserving the expected arithmetic behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7c6bee2f-ac4e-488a-a6e0-64652a1affb5

📥 Commits

Reviewing files that changed from the base of the PR and between ee28529 and a588e4c.

⛔ Files ignored due to path filters (1)
  • bigbluebutton-html5/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • bigbluebutton-html5/imports/ui/components/plugins-engine/data-consumption/utils.ts
  • bigbluebutton-html5/package.json

"autoprefixer": "^10.4.4",
"babel-runtime": "~6.26.0",
"bigbluebutton-html-plugin-sdk": "0.0.103",
"bigbluebutton-html-plugin-sdk": "https://codeload.github.com/bigbluebutton/bigbluebutton-html-plugin-sdk/tar.gz/refs/pull/279/head",

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.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== package.json relevant line =="
sed -n '78,86p' bigbluebutton-html5/package.json

echo
echo "== package-lock.json relevant entries =="
python3 - <<'PY'
import json, pathlib
p=pathlib.Path("bigbluebutton-html5/package-lock.json")
data=json.loads(p.read_text())
pkg=data.get("packages",{}).get("node_modules/bigbluebutton-html-plugin-sdk")
print(pkg)
for path,node in data.get("packages",{}).items():
    if "bigbluebutton-html-plugin-sdk" in path or path == "":
        if node and ("version" in node or "resolved" in node or "integrity" in node):
            print(path, {"version":node.get("version"), "resolved":node.get("resolved"), "integrity":node.get("integrity")})
PY

echo
echo "== npm lockfile format / semver check (package manager manifests) =="
python3 - <<'PY'
import json
pkg=json.load(open("bigbluebutton-html5/package.json"))
lock=json.load(open("bigbluebutton-html5/package-lock.json"))
print("npm_version:", lock.get("lockfileVersion"), lock.get("lockfileVersion2"), lock.get("lockfileVersion3"))
print("require_lockfile:", lock.get("requiresLockfileGeneratedBy") or "")
print("devDependency:", pkg.get("devDependencies",{}).get("bigbluebutton-html-plugin-sdk"))
PY

Repository: bigbluebutton/bigbluebutton

Length of output: 1509


🌐 Web query:

GitHub refs/pull/279/head tarball URL mutable PR head force push documentation

💡 Result:

GitHub pull request references, such as refs/pull/{number}/head, are read-only references created and managed by GitHub [1][2]. They are not standard branches in your repository; rather, they are special references that point to the latest commit on a pull request's head branch [1][2]. Because these are managed automatically by GitHub, they are considered mutable in that they update automatically to reflect the latest state of the associated pull request (e.g., when new commits are pushed to the PR branch) [1][2]. However, you cannot "force push" to them yourself through standard Git operations, nor can you directly update them via the GitHub REST API or Git command-line tools to point to arbitrary commits [3][1]. Any attempt to modify these specific internal refs via standard push mechanisms will be rejected by GitHub. When retrieving data via tarball or zipball URLs for these references, you are accessing the state of the pull request at that moment as defined by the ref. Because the ref itself is dynamic (mutable) and managed by GitHub, the content behind those URLs will change whenever the underlying pull request head is updated [1][2]. If you require a stable, immutable reference to a specific version of a pull request, you should always use the specific commit SHA (hash) rather than the refs/pull/{number}/head reference [4].

Citations:


Pin the SDK dependency to an immutable revision.

refs/pull/279/head points to the current PR HEAD, so any updated PR commit changes the tarball behind the dependency URL. Regenerate the lockfile and pin a committed SHA or published release version instead of keeping the mutable ref only in package.json.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@bigbluebutton-html5/package.json` at line 82, Replace the mutable
bigbluebutton-html-plugin-sdk PR URL in package.json with an immutable committed
SHA or published release version, then regenerate the lockfile so it records the
pinned dependency and resolved tarball.

@antobinary antobinary added this to the Release 3.0 milestone Jul 23, 2026
@github-actions

Copy link
Copy Markdown

Automated tests have passed!

@github-actions

Copy link
Copy Markdown

This pull request has conflicts ☹
Please resolve those so we can review the pull request.
Thanks.

@lfzawacki
lfzawacki requested a review from GuiLeme July 31, 2026 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants