Skip to content

Conversation

@ggazzo
Copy link
Member

@ggazzo ggazzo commented Nov 19, 2025

Proposed changes (including videos or screenshots)

Issue(s)

Steps to test or reproduce

Further comments

Summary by CodeRabbit

Release Notes

  • Refactor
    • Migrated patch system to middleware-based architecture for dynamic patch application and registration.

✏️ Tip: You can customize this high-level summary in your review settings.

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Nov 19, 2025

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is targeting the wrong base branch. It should target 8.2.0, but it targets 8.1.0

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Nov 19, 2025

⚠️ No Changeset found

Latest commit: 9297b03

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 19, 2025

Walkthrough

The changes replace an internal patch-tracking mechanism with a middleware-based approach for the patch injection system. A new withMiddleware higher-order function is introduced to manage a composable middleware chain, while makeFunction is refactored to apply patches through this pipeline. Public exports are updated to expose the new middleware functionality.

Changes

Cohort / File(s) Summary
Export configuration
packages/patch-injection/src/index.ts
Removed export of './definition' module; added export of './midleware' module to reflect new public API.
Patch application refactoring
packages/patch-injection/src/makeFunction.ts
Replaced manual patch data structures and accumulation loop with middleware-based pipeline. Public API now exposes patch(), originalSignature(), and patchSignature() methods attached to returned function via Object.assign. Removed dependency on internal addPatch, calledFunctions, and functions tracking.
Middleware infrastructure
packages/patch-injection/src/midleware.ts
New generic withMiddleware<F> function that wraps a function with a mutable middleware chain. Exposes run() to execute the chain and use() to register middleware dynamically with disposer support.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant PatchedFn as Patched Function
    participant Middleware as Middleware Chain
    participant OriginalFn as Original Function

    Client->>PatchedFn: Call patched function(args)
    PatchedFn->>Middleware: Execute middleware runner
    loop For each middleware
        Middleware->>Middleware: Transform context
    end
    Middleware->>OriginalFn: Invoke with final context
    OriginalFn-->>Middleware: Return result
    Middleware-->>PatchedFn: Return result
    PatchedFn-->>Client: Return result

    Client->>PatchedFn: patch(fn, condition?)
    PatchedFn->>Middleware: Register middleware via use()
    Middleware-->>PatchedFn: Return disposer
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 A middleware chain so fine and bright,
Patches flowing through the night,
No more manual tracking here,
The pipeline makes the path so clear!
—Signed, The Code Rabbit 🐇✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'chore: Introduce middleware support for function patching' directly aligns with the main changes in the PR: introducing a new middleware-based approach to patch application in the patch-injection package.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/middleware

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 and usage tips.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 19, 2025

📦 Docker Image Size Report

➡️ Changes

Service Current Baseline Change Percent
sum of all images 0B 0B 0B
account-service 0B 0B 0B
authorization-service 0B 0B 0B
ddp-streamer-service 0B 0B 0B
omnichannel-transcript-service 0B 0B 0B
presence-service 0B 0B 0B
queue-worker-service 0B 0B 0B
rocketchat 0B 0B 0B

📊 Historical Trend

---
config:
  theme: "dark"
  xyChart:
    width: 900
    height: 400
---
xychart
  title "Image Size Evolution by Service (Last 30 Days + This PR)"
  x-axis ["11/18 22:53", "11/19 23:02", "11/21 16:49", "11/24 17:34", "11/27 22:32", "11/28 19:05", "12/01 23:01", "12/02 21:57", "12/03 21:00", "12/04 18:17", "12/05 21:56", "12/08 20:15", "12/09 22:17", "12/10 23:26", "12/11 21:56", "12/12 22:45", "12/13 01:34", "12/15 22:31", "12/16 22:18", "12/17 21:04", "12/18 23:12", "12/19 23:27", "12/20 21:03", "12/22 18:54", "12/23 16:16", "12/24 19:38", "12/25 17:51", "12/26 13:18", "12/29 19:01", "12/30 20:52", "01/28 14:42 (PR)"]
  y-axis "Size (GB)" 0 --> 0.5
  line "account-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.00]
  line "authorization-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.00]
  line "ddp-streamer-service" [0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.00]
  line "omnichannel-transcript-service" [0.14, 0.14, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.00]
  line "presence-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.00]
  line "queue-worker-service" [0.14, 0.14, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.00]
  line "rocketchat" [0.35, 0.35, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.00]
Loading

Statistics (last 30 days):

  • 📊 Average: 1.5GiB
  • ⬇️ Minimum: 1.4GiB
  • ⬆️ Maximum: 1.6GiB
  • 🎯 Current PR: 0B
ℹ️ About this report

This report compares Docker image sizes from this build against the develop baseline.

  • Tag: pr-37560
  • Baseline: develop
  • Timestamp: 2026-01-28 14:42:26 UTC
  • Historical data points: 30

Updated: Wed, 28 Jan 2026 14:42:26 GMT

@codecov
Copy link

codecov bot commented Nov 19, 2025

Codecov Report

❌ Patch coverage is 97.05882% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 70.76%. Comparing base (464adcb) to head (9297b03).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #37560      +/-   ##
===========================================
- Coverage    70.79%   70.76%   -0.04%     
===========================================
  Files         3158     3156       -2     
  Lines       109390   109370      -20     
  Branches     19682    20069     +387     
===========================================
- Hits         77445    77398      -47     
- Misses       29919    29944      +25     
- Partials      2026     2028       +2     
Flag Coverage Δ
e2e 60.28% <ø> (-0.10%) ⬇️
e2e-api 47.85% <ø> (+0.01%) ⬆️
unit 71.96% <97.05%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ggazzo ggazzo changed the base branch from develop to release-8.0.0 December 24, 2025 18:04
@ggazzo ggazzo changed the base branch from release-8.0.0 to develop December 24, 2025 18:04
@ggazzo ggazzo added this to the 8.2.0 milestone Jan 28, 2026
@ggazzo ggazzo marked this pull request as ready for review January 28, 2026 14:38
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 3 files

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@packages/patch-injection/src/midleware.ts`:
- Around line 18-25: The disposer currently uses middlewares.indexOf(middleware)
which will remove the first matching function when the same middleware is
registered multiple times; change use so each registration gets a unique entry
(e.g., wrap the provided middleware in a per-registration object/wrapper or
generate a token) and push that unique entry into middlewares (use the unique
wrapper/token when calling buildRunner); have the returned disposer remove that
exact entry (indexOf(wrapper/token)) so removals target the correct registration
and then rebuild runner with buildRunner().
🧹 Nitpick comments (2)
packages/patch-injection/src/index.ts (1)

1-4: Remove commented-out exports and confirm the API change.

Line 1 and Line 4 leave commented exports in production code. If definition types are still public, re-export them explicitly; otherwise delete the commented lines and document the breaking change for consumers.

♻️ Suggested cleanup
-// export * from './definition';
 export * from './makeFunction';
 export * from './midleware';
-// export * from './addPatch';

As per coding guidelines Avoid code comments in the implementation.

packages/patch-injection/src/midleware.ts (1)

7-13: Confirm middleware execution order (currently last-registered runs first).

Line 8 composes with reduce, which makes the most recently added middleware execute first. If you want registration order to run first (common middleware behavior), switch to reduceRight or reverse the array.

♻️ Option to preserve registration order
-		return middlewares.reduce(
+		return middlewares.reduceRight(

Comment on lines +18 to +25
const use = (middleware: Middleware<F>) => {
middlewares.push(middleware);

runner = buildRunner();
return () => {
const index = middlewares.indexOf(middleware);
if (index > -1) {
middlewares.splice(index, 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Disposer can remove the wrong middleware when the same function is registered twice.

Line 23 uses indexOf(middleware). If the same middleware is registered multiple times, the disposer for the later registration removes the first entry. Wrap the middleware per registration (or store an entry token) so disposal removes the correct instance.

🐛 Ensure disposer targets the exact registration
 const use = (middleware: Middleware<F>) => {
-	middlewares.push(middleware);
+	const entry: Middleware<F> = (ctx, next) => middleware(ctx, next);
+	middlewares.push(entry);

 	runner = buildRunner();
 	return () => {
-		const index = middlewares.indexOf(middleware);
+		const index = middlewares.indexOf(entry);
 		if (index > -1) {
 			middlewares.splice(index, 1);
 		}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const use = (middleware: Middleware<F>) => {
middlewares.push(middleware);
runner = buildRunner();
return () => {
const index = middlewares.indexOf(middleware);
if (index > -1) {
middlewares.splice(index, 1);
const use = (middleware: Middleware<F>) => {
const entry: Middleware<F> = (ctx, next) => middleware(ctx, next);
middlewares.push(entry);
runner = buildRunner();
return () => {
const index = middlewares.indexOf(entry);
if (index > -1) {
middlewares.splice(index, 1);
🤖 Prompt for AI Agents
In `@packages/patch-injection/src/midleware.ts` around lines 18 - 25, The disposer
currently uses middlewares.indexOf(middleware) which will remove the first
matching function when the same middleware is registered multiple times; change
use so each registration gets a unique entry (e.g., wrap the provided middleware
in a per-registration object/wrapper or generate a token) and push that unique
entry into middlewares (use the unique wrapper/token when calling buildRunner);
have the returned disposer remove that exact entry (indexOf(wrapper/token)) so
removals target the correct registration and then rebuild runner with
buildRunner().

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.

1 participant