Skip to content

[DX-1204] Mark v1 callback API as deprecated#2226

Merged
umair-ably merged 6 commits into
mainfrom
DX-1204/v1-callback-overloads
May 27, 2026
Merged

[DX-1204] Mark v1 callback API as deprecated#2226
umair-ably merged 6 commits into
mainfrom
DX-1204/v1-callback-overloads

Conversation

@umair-ably
Copy link
Copy Markdown
Contributor

@umair-ably umair-ably commented May 21, 2026

Intent

This PR brings back the deleted v1 callback styled APIs and instead

  1. Marks them as deprecated
  2. Throws a suitable error and hint pairing to aid LLMs to v2 promises

Why

LLMs relying on training data take more turns than necessary to self-heal when using old v1 callbacks.

Outcome and Evidence

I tasked Claude under emulated constraints e.g. here is the v1 styled callbacks API, assume this is your training data, you are not allowed to use any webfetch/websearch tools, etc.. 3 tasks:

  1. Use your own training data, but no web searches, create a simple publish POC.
  2. With the constraints in mind, create a simple publish POC.
  3. With the constraints in mind, and given a failing unit test based on the v1 api, fix the unit test.

Task 1 - Publish POC with actual training data

Across three models (Opus 4.7, Sonnet 4.6, Haiku 4.5) × five attempts each x for both the pre and post this PR SDK (so 30 total runs), only 1 run actually used v1 callbacks from training. The run that encountered it was running an Ably SDK which included this PR, so the very next tool call fixed the issue.

This shows recent training data has largely caught up with v2 promises, however, the non-deterministic nature of LLMs is still evidenced by that 1 errant run.

Task 2 - Publish POC with emulated training data

If we extrapolate the errant run from task 1 to all runs i.e. emulate stale training data for every run, we start to see some results. All v1 styled runs failed on the very first iteration and hung until the agent stepped in to debug the issue. Opus and Sonnet weren't horrendous here but they took anywhere from 12-14 tool calls to get to a working solution. Haiku on the other hand, took upwards of 25 tool calls.

Likewise, all the v2 styled runs also failed on the very first iteration, however all of them took only 8 tool calls to rectify the issue, including Haiku.

Task 3 - Unit test

Same idea as task 2 except the agent gets a failing unit test instead of a POC, and the goal is to make node --test exit 0. The test runner behaves slightly differently in that v1 failures show up as either an unhandled rejection from deep in the SDK or a test timeout. Opus fixed it in 5 tool calls from reverting to it's own training data, Sonnet went in circles for 22 tool calls, and Haiku couldn't figure it out until it's 5th and final iteration.

Positively, all v2 styled runs landed in 2 iterations at 6-8 tool calls. The logs/conversations clearly showing the error and hint was what steered them to fix it immediately after.

Summary by CodeRabbit

  • Breaking Changes

    • Legacy v1 callback-style calls for auth, realtime channels, presence, and connection.ping now throw synchronously with guidance — migrate to promise-based APIs.
  • Improvements

    • Error objects include an optional hint with remediation and a link to the v2 migration guide.
    • Hook memoization refined for channel history access.
  • Tests

    • Added tests verifying v1-callback usage throws with the new error and hint.
  • Chores

    • Adjusted size thresholds for the minimal realtime bundle.

Review Change Stack

@umair-ably umair-ably force-pushed the DX-1204/v1-callback-overloads branch from 1d3cdf7 to e149a7f Compare May 21, 2026 16:45
@github-actions github-actions Bot temporarily deployed to staging/pull/2226/features May 21, 2026 16:45 Inactive
@github-actions github-actions Bot temporarily deployed to staging/pull/2226/bundle-report May 21, 2026 16:45 Inactive
Copy link
Copy Markdown

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

🤖 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 `@ably.d.ts`:
- Around line 1993-2008: The deprecated authorize overload is missing
parameter-level JSDoc which triggers Typedoc warnings; add `@param` entries for
tokenParams, authOptions, and callback inside the authorize overload's comment
block (the deprecated v1 variant) so Typedoc has docs for each parameter and the
warning is resolved—repeat the same addition for the other deprecated Auth
overload blocks referenced (around the authorize overloads at the other ranges).
- Around line 2639-2647: The deprecation note incorrectly tells users to "await
the returned promise" for RealtimeChannel.unsubscribe; update the comment for
RealtimeChannel.unsubscribe to reflect that the v2 API is synchronous (returns
void) — remove any wording about awaiting a promise and adjust the example to
show simply calling channel.unsubscribe('event', listener) (no await), while
keeping the migration guide link if desired; ensure the docstring and example
align with the declared signature of RealtimeChannel.unsubscribe.

In `@src/common/lib/client/auth.ts`:
- Around line 257-260: The v1 callback detection currently passes
v1CallbackPosition=2 to Utils.detectV1Callback in Auth.authorize (and the
similar spots), so calls like authorize(callback) or authorize(tokenParams,
callback) are not recognized as v1-style and misrouted; update the
detectV1Callback invocation(s) to use v1CallbackPosition=1 (i.e., change the
third numeric arg from 2 to 1) for Auth.authorize (and the same spot(s) that
mirror it) so the helper recognizes a callback at index 0 or 1 and routes those
calls correctly.

In `@src/common/lib/util/utils.ts`:
- Around line 301-304: The remediation message in detectV1Callback incorrectly
always tells users to "await" a returned promise; update detectV1Callback to
emit a context-aware hint: if the guarded API is known to return a promise (e.g.
async methods), keep the current "Remove the trailing callback and `await` the
returned promise — e.g. `await ${exampleCall}`" message, but for non-promise
APIs (such as unsubscribe) emit a generic "Remove the trailing callback and call
the method without a callback — e.g. `${exampleCall}`" message instead;
implement this by adding a boolean parameter or internal check in
detectV1Callback to determine promise-returning methods and branch the
ErrorInfo.hint accordingly, referencing methodName and exampleCall when building
the hint.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0abf3211-8d3c-4401-8204-72cd70458312

📥 Commits

Reviewing files that changed from the base of the PR and between 50f25c9 and e149a7f.

📒 Files selected for processing (12)
  • ably.d.ts
  • src/common/lib/client/auth.ts
  • src/common/lib/client/connection.ts
  • src/common/lib/client/realtimechannel.ts
  • src/common/lib/client/realtimepresence.ts
  • src/common/lib/types/errorinfo.ts
  • src/common/lib/util/utils.ts
  • src/platform/react-hooks/src/hooks/useChannel.ts
  • test/realtime/auth.test.js
  • test/realtime/channel.test.js
  • test/realtime/connection.test.js
  • test/realtime/presence.test.js

@umair-ably umair-ably force-pushed the DX-1204/v1-callback-overloads branch from e149a7f to 7742481 Compare May 22, 2026 10:27
@ably ably deleted a comment from coderabbitai Bot May 22, 2026
@ably ably deleted a comment from coderabbitai Bot May 22, 2026
@ably ably deleted a comment from coderabbitai Bot May 22, 2026
@github-actions github-actions Bot temporarily deployed to staging/pull/2226/features May 22, 2026 10:28 Inactive
@ably ably deleted a comment from coderabbitai Bot May 22, 2026
@github-actions github-actions Bot temporarily deployed to staging/pull/2226/bundle-report May 22, 2026 10:28 Inactive
@github-actions github-actions Bot temporarily deployed to staging/pull/2226/typedoc May 22, 2026 10:28 Inactive
@ably ably deleted a comment from coderabbitai Bot May 22, 2026
@umair-ably
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 22, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 22, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

The PR synchronously rejects legacy v1 trailing callbacks across Auth, Connection, RealtimeChannel, and RealtimePresence using a new detectV1Callback helper that throws ErrorInfo with an actionable hint; TypeScript declarations add deprecated callback overloads and tests validate synchronous throws.

Changes

V1 Callback Deprecation with Error Hints

Layer / File(s) Summary
ErrorInfo schema enhancement with hint field
src/common/lib/types/errorinfo.ts, ably.d.ts
IPartialErrorInfo, ErrorInfo, and PartialErrorInfo gain optional hint?: string; toString() appends hint when present.
detectV1Callback utility
src/common/lib/util/utils.ts
New exported detectV1Callback(args, v2TrailingFnArity) checks for a trailing function when args.length > v2TrailingFnArity and throws an ErrorInfo with code 40000 and a hint directing removal of the trailing callback and the v2 migration guide link.
Auth method wrappers and type declarations
src/common/lib/client/auth.ts, ably.d.ts
authorize, requestToken, createTokenRequest converted to variadic wrappers that call detectV1Callback and delegate to private _...Impl; deprecated v1 callback overloads added to ably.d.ts.
Connection.ping wrapper and type declaration
src/common/lib/client/connection.ts, ably.d.ts
Connection.ping converted to ping(...args) wrapper using detectV1Callback and delegating to _pingImpl; Utils import added; deprecated ping callback overload declared in types.
RealtimeChannel method wrappers and type declarations
src/common/lib/client/realtimechannel.ts, ably.d.ts
publish, subscribe, unsubscribe, and history refactored to detect v1 callbacks synchronously then delegate to private implementations; deprecated v1 callback overloads added.
RealtimePresence method wrappers and type declarations
src/common/lib/client/realtimepresence.ts, ably.d.ts
enter, update, leave, get, history, and subscribe refactored into variadic wrappers calling detectV1Callback and delegating to private _...Impl; deprecated overloads declared in types.
Type declarations for deprecated callbacks
ably.d.ts
Deprecated v1 callback overloads (returning never) added for affected Auth, Connection, RealtimeChannel, and RealtimePresence methods.
React useChannel hook history function binding
src/platform/react-hooks/src/hooks/useChannel.ts
Removed useCallback import; history changed from forwarding useCallback to useMemo returning channel.history bound to the channel instance.
Comprehensive v1 callback rejection tests
test/realtime/auth.test.js, test/realtime/channel.test.js, test/realtime/connection.test.js, test/realtime/presence.test.js
New tests assert synchronous throws with code === 40000, diagnostic message, and err.hint containing “Remove the trailing callback” plus the v2 migration-guide URL.
Bundle size threshold update
scripts/moduleReport.ts
Increment minimal useful Realtime bundle size thresholds (raw and gzipped) by 1 KiB.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 Once callbacks hopped at the tail of a call,
Now promises answer and tidy the hall.
If a v1 callback sneaks into view,
ErrorInfo hints will tell what to do.
Hop quick to the migration trail — woo!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main objective of the PR—deprecating v1 callback APIs—which is the primary change across all modified files.
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.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch DX-1204/v1-callback-overloads

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.

Copy link
Copy Markdown

@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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
ably.d.ts (1)

1993-2053: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Prettier check is still failing for this file (merge blocker).

Lint reports ably.d.ts fails prettier --check; please run Prettier on this file and commit the formatting-only diff so CI can pass.

Also applies to: 2139-2270, 2642-2656, 2689-2702, 2743-2757, 2783-2797, 3488-3500, 3911-3918

🤖 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 `@ably.d.ts` around lines 1993 - 2053, Prettier formatting is failing for
ably.d.ts; run Prettier (or your repo's format script) on ably.d.ts and commit
the resulting formatting-only changes so CI passes. Focus on normalizing
spacing/line breaks around the Auth methods shown (authorize,
createTokenRequest, requestToken and their deprecated overloads) and the
adjacent JSDoc blocks; ensure the file matches the project's Prettier
configuration and only contains whitespace/formatting edits.
🤖 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 `@src/common/lib/client/realtimechannel.ts`:
- Around line 464-467: The two-argument v1 callback shape (subscribe(listener,
callback) and unsubscribe(listener, callback)) is not being detected because
Utils.detectV1Callback(args, 2) only checks the third parameter; update the
detection to check the second parameter instead by calling
Utils.detectV1Callback(args, 1) in both subscribe and unsubscribe before
delegating to _subscribeImpl/_unsubscribeImpl so the trailing callback is caught
and the synchronous migration error is raised.

In `@src/common/lib/client/realtimepresence.ts`:
- Around line 435-437: The subscribe method is incorrectly calling
Utils.detectV1Callback(_args, 2) which skips detecting the v1 two-argument
callback form (both args functions), causing the trailing callback to be
ignored; update the call in subscribe to use the correct max-arguments value
(change the second parameter from 2 to 1) so Utils.detectV1Callback correctly
recognizes the v1 (listener, callback) shape and then call
this._subscribeImpl(_args) as before.

---

Outside diff comments:
In `@ably.d.ts`:
- Around line 1993-2053: Prettier formatting is failing for ably.d.ts; run
Prettier (or your repo's format script) on ably.d.ts and commit the resulting
formatting-only changes so CI passes. Focus on normalizing spacing/line breaks
around the Auth methods shown (authorize, createTokenRequest, requestToken and
their deprecated overloads) and the adjacent JSDoc blocks; ensure the file
matches the project's Prettier configuration and only contains
whitespace/formatting edits.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 809a918d-5675-4134-96a4-410c0b316c93

📥 Commits

Reviewing files that changed from the base of the PR and between e149a7f and 7742481.

📒 Files selected for processing (13)
  • ably.d.ts
  • scripts/moduleReport.ts
  • src/common/lib/client/auth.ts
  • src/common/lib/client/connection.ts
  • src/common/lib/client/realtimechannel.ts
  • src/common/lib/client/realtimepresence.ts
  • src/common/lib/types/errorinfo.ts
  • src/common/lib/util/utils.ts
  • src/platform/react-hooks/src/hooks/useChannel.ts
  • test/realtime/auth.test.js
  • test/realtime/channel.test.js
  • test/realtime/connection.test.js
  • test/realtime/presence.test.js

Comment thread src/common/lib/client/realtimechannel.ts
Comment thread src/common/lib/client/realtimepresence.ts
@umair-ably umair-ably force-pushed the DX-1204/v1-callback-overloads branch from 7742481 to c52b7e6 Compare May 22, 2026 10:33
@github-actions github-actions Bot temporarily deployed to staging/pull/2226/bundle-report May 22, 2026 10:34 Inactive
@github-actions github-actions Bot temporarily deployed to staging/pull/2226/features May 22, 2026 10:34 Inactive
@github-actions github-actions Bot temporarily deployed to staging/pull/2226/typedoc May 22, 2026 10:34 Inactive
Copy link
Copy Markdown

@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.

🧹 Nitpick comments (1)
test/realtime/auth.test.js (1)

1657-1659: ⚡ Quick win

Disable autoconnect for these sync-throw tests.

These cases only validate argument-shape rejection; opening a realtime connection adds avoidable async noise.

♻️ Suggested change
-        var helper = this.test.helper,
-          realtime = helper.AblyRealtime();
+        var helper = this.test.helper,
+          realtime = helper.AblyRealtime({ autoConnect: false });
🤖 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 `@test/realtime/auth.test.js` around lines 1657 - 1659, The tests call
helper.AblyRealtime() which opens a realtime connection and adds async noise;
change the instantiation to disable autoconnect by calling helper.AblyRealtime({
autoConnect: false }) (or the equivalent option your helper uses) so the tests
validate argument-shape rejection synchronously without opening a connection;
update any other occurrences in these "sync-throw" tests that call
AblyRealtime() to use the same { autoConnect: false } option.
🤖 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.

Nitpick comments:
In `@test/realtime/auth.test.js`:
- Around line 1657-1659: The tests call helper.AblyRealtime() which opens a
realtime connection and adds async noise; change the instantiation to disable
autoconnect by calling helper.AblyRealtime({ autoConnect: false }) (or the
equivalent option your helper uses) so the tests validate argument-shape
rejection synchronously without opening a connection; update any other
occurrences in these "sync-throw" tests that call AblyRealtime() to use the same
{ autoConnect: false } option.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 993dce25-2bb1-453d-b036-21d753c22fd9

📥 Commits

Reviewing files that changed from the base of the PR and between 7742481 and c52b7e6.

📒 Files selected for processing (6)
  • ably.d.ts
  • src/platform/react-hooks/src/hooks/useChannel.ts
  • test/realtime/auth.test.js
  • test/realtime/channel.test.js
  • test/realtime/connection.test.js
  • test/realtime/presence.test.js

@umair-ably umair-ably force-pushed the DX-1204/v1-callback-overloads branch from c52b7e6 to 90a42de Compare May 22, 2026 10:38
@github-actions github-actions Bot temporarily deployed to staging/pull/2226/bundle-report May 22, 2026 10:38 Inactive
@github-actions github-actions Bot temporarily deployed to staging/pull/2226/typedoc May 22, 2026 10:38 Inactive
@umair-ably umair-ably requested a review from AndyTWF May 26, 2026 08:46
Comment thread src/common/lib/util/utils.ts Outdated
const n = args.length;
if (typeof args[n - 1] !== 'function') return;
if (n <= minV2Args && typeof args[n - 2] !== 'function') return;
const err = new ErrorInfo('v1 callback signature is no longer supported.', 40000, 400);
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.

40000 is a generic and often overused error code, can we have a new one specifically for this and/or a generic "no longer supported" code?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was intentional in that I'm aware we have an issue with overloaded error codes. However, I opted against addressing this here because it's not really the intention of this PR, and more importantly - Lewis is undergoing the de-overloading efforts for the server side error codes first.

I'll take guidance from his work there and apply it on a wider scale here in a separate PR.

Happy to be challenged if you think we should just address this specifically for this error now. (I can introduce a 40024, but again Lewis's work might mean he starts using this currently unused code, which is why I'd rather wait)

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.

I think it's important. By giving it its own error code it follows the precedent we want to follow in the future and gives LLMs another avenue for discovery (the unique error code). If we must stick with existing error codes, then we should use 40003 for invalid parameter value. But I think a standalone code for "no longer supported" is more specific

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fair enough - updated ably-common here

also updated this PR to use the new code

Comment thread src/common/lib/client/auth.ts Outdated
async authorize(tokenParams: API.TokenParams | null, authOptions: AuthOptions | null): Promise<API.TokenDetails>;

async authorize(
authorize(...args: any[]): Promise<API.TokenDetails> {
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.

Should we use unknown consistently everywhere? Generally more favourable than any


async publish(...args: any[]): Promise<API.PublishResult> {
publish(...args: any[]): Promise<API.PublishResult> {
// Detect a v1-shape trailing callback synchronously, before the async body
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.

We've added this comment in one place but not the myriad of others - is the comment necessary here?

if (n <= minV2Args && typeof args[n - 2] !== 'function') return;
const err = new ErrorInfo('v1 callback signature is no longer supported.', 40000, 400);
err.hint = `Remove the trailing callback. See https://github.com/ably/ably-js/blob/main/docs/migration-guides/v2/lib.md`;
throw err;
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.

Should this be calling out "go and use the Promise signature" explicitly rather than "dont use a callback"

}

unsubscribe(...args: unknown[] /* [event], listener */): void {
Utils.detectV1Callback(args, 2);
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.

unsubscribe never had a callback, so this is redundant

Comment thread src/common/lib/util/utils.ts Outdated
* trailing functions, so e.g. `subscribe(listener, callback)` is always v1
* even though it matches the arity of `subscribe(event, listener)`.
*
* @param minV2Args - The maximum number of args the v2 form accepts. For methods
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.

We say min and then immediately say "the maximum" so this name is misleading.

Perhaps we'd call it v2TrailingFnArity, i.e.

  /**
   * @param v2TrailingFnArity - The arity at which v2 legitimately ends in a function
   *   (e.g. `subscribe(event, listener)` → 2). For methods where v2 never ends in a
   *   function (`authorize`, `publish`, `requestToken`, ...), pass 0.
   */

@github-actions github-actions Bot temporarily deployed to staging/pull/2226/bundle-report May 26, 2026 15:18 Inactive
@github-actions github-actions Bot temporarily deployed to staging/pull/2226/typedoc May 26, 2026 15:18 Inactive
Copy link
Copy Markdown

@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

🤖 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 `@src/common/lib/types/errorinfo.ts`:
- Line 11: IConvertibleToErrorInfo and IConvertibleToPartialErrorInfo don't
include the new hint field, so update their input contracts to accept hint
(e.g., add hint?: string) and ensure any fromValues methods/signatures that
consume those interfaces (refer to fromValues) accept and propagate hint into
the constructed ErrorInfo/PartialErrorInfo; update IConvertibleToErrorInfo,
IConvertibleToPartialErrorInfo and the fromValues implementation(s) to include
and pass through hint.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e2aed483-dc1f-43d2-8061-57577d8c36c4

📥 Commits

Reviewing files that changed from the base of the PR and between c52b7e6 and 40e33ba.

📒 Files selected for processing (13)
  • ably.d.ts
  • scripts/moduleReport.ts
  • src/common/lib/client/auth.ts
  • src/common/lib/client/connection.ts
  • src/common/lib/client/realtimechannel.ts
  • src/common/lib/client/realtimepresence.ts
  • src/common/lib/types/errorinfo.ts
  • src/common/lib/util/utils.ts
  • src/platform/react-hooks/src/hooks/useChannel.ts
  • test/realtime/auth.test.js
  • test/realtime/channel.test.js
  • test/realtime/connection.test.js
  • test/realtime/presence.test.js

Comment thread src/common/lib/types/errorinfo.ts
umair-ably and others added 5 commits May 26, 2026 16:31
- rename minV2Args -> v2TrailingFnArity (clearer semantics; docstring was
  contradicting itself with "maximum" wording)
- use unknown[] consistently in rest signatures across auth, connection,
  channel, and presence guarded methods
- point the hint at the Promise migration explicitly ("v2 uses Promises")
- remove redundant unsubscribe guard (v1 unsubscribe never took a callback)
- drop one-off "synchronous" inline comment from publish; the JSDoc on
  detectV1Callback already explains the sync-throw rationale
- use autoConnect:false in sync-throw tests so they don't open a connection
  just to validate argument-shape rejection

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@umair-ably umair-ably force-pushed the DX-1204/v1-callback-overloads branch from 40e33ba to 71ea4f3 Compare May 26, 2026 15:31
@github-actions github-actions Bot temporarily deployed to staging/pull/2226/bundle-report May 26, 2026 15:32 Inactive
@github-actions github-actions Bot temporarily deployed to staging/pull/2226/typedoc May 26, 2026 15:32 Inactive
Copy link
Copy Markdown

@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.

🧹 Nitpick comments (1)
src/platform/react-hooks/src/hooks/useChannel.ts (1)

59-62: ⚡ Quick win

Consider simplifying to match the publish pattern.

The wrapper function only forwards the first parameter, which means two-argument v1 calls like history(params, callback) would silently drop the callback. Additionally, the type cast to Ably.RealtimeChannel['history'] is unsafe because the wrapper doesn't actually implement all overloads of that type.

Consider using .bind() instead, matching the pattern used for publish:

♻️ Simplify using `.bind()` to preserve all overloads
-  const history: Ably.RealtimeChannel['history'] = useMemo(
-    () => ((params?: Ably.RealtimeHistoryParams) => channel.history(params)) as Ably.RealtimeChannel['history'],
-    [channel],
-  );
+  const history: Ably.RealtimeChannel['history'] = useMemo(
+    () => channel.history.bind(channel),
+    [channel],
+  );

This approach:

  • Preserves all method overloads and arguments correctly (including multi-arg v1 forms for proper detection)
  • Removes the unsafe type cast
  • Matches the pattern already used for publish (line 48)
  • Ensures the v1 callback detection in channel.history receives all arguments as intended
🤖 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 `@src/platform/react-hooks/src/hooks/useChannel.ts` around lines 59 - 62, The
current useMemo wrapper for history only forwards the first param and unsafely
casts to Ably.RealtimeChannel['history'], dropping multi-arg v1 callbacks;
replace the manual wrapper with a bound method like using
channel.history.bind(channel) inside useMemo (same approach as publish) so all
overloads/arguments are preserved, remove the unsafe type cast, and keep history
and channel references in the dependency array.
🤖 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.

Nitpick comments:
In `@src/platform/react-hooks/src/hooks/useChannel.ts`:
- Around line 59-62: The current useMemo wrapper for history only forwards the
first param and unsafely casts to Ably.RealtimeChannel['history'], dropping
multi-arg v1 callbacks; replace the manual wrapper with a bound method like
using channel.history.bind(channel) inside useMemo (same approach as publish) so
all overloads/arguments are preserved, remove the unsafe type cast, and keep
history and channel references in the dependency array.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 90a5b4ea-e0cf-4041-b908-940cb914fa5d

📥 Commits

Reviewing files that changed from the base of the PR and between 40e33ba and 71ea4f3.

📒 Files selected for processing (13)
  • ably.d.ts
  • scripts/moduleReport.ts
  • src/common/lib/client/auth.ts
  • src/common/lib/client/connection.ts
  • src/common/lib/client/realtimechannel.ts
  • src/common/lib/client/realtimepresence.ts
  • src/common/lib/types/errorinfo.ts
  • src/common/lib/util/utils.ts
  • src/platform/react-hooks/src/hooks/useChannel.ts
  • test/realtime/auth.test.js
  • test/realtime/channel.test.js
  • test/realtime/connection.test.js
  • test/realtime/presence.test.js

Per review feedback on #2226: 40000 is generic and overused. ably-common
PR #340 introduces 40025 "API no longer supported" as a dedicated code
for deprecated/removed APIs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@AndyTWF AndyTWF left a comment

Choose a reason for hiding this comment

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

Please add a separate PR to the docs to document the new error code there :shipit:

@umair-ably umair-ably merged commit 1cdc358 into main May 27, 2026
11 of 14 checks passed
@umair-ably umair-ably deleted the DX-1204/v1-callback-overloads branch May 27, 2026 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants