Skip to content

fix: resolve replay mode errors in Redis and Firestore no-op request handlers#138

Merged
sohankshirsagar merged 2 commits intomainfrom
sohan/fix-redis-firestore-noop
Mar 13, 2026
Merged

fix: resolve replay mode errors in Redis and Firestore no-op request handlers#138
sohankshirsagar merged 2 commits intomainfrom
sohan/fix-redis-firestore-noop

Conversation

@sohankshirsagar
Copy link
Contributor

Summary

Fixes two bugs in replay mode that cause crashes when background requests hit the noOpRequestHandler path in handleReplayMode. A customer reported TypeError: Expected result to be array of values from rate-limit-redis and Error: Original doc function not available from Firestore during replay.

Changes

  • Redis: Return type-appropriate defaults from sendCommand and commandsExecutor no-op handlers.
    Previously both returned undefined, which breaks callers that validate the response type. For example, rate-limit-redis uses EVALSHA and strictly expects an array result — receiving undefined throws TypeError: Expected result to be array of values. Now returns [] for EVAL/EVALSHA commands and null (standard Redis nil) for everything else.
  • Firestore: Fix this/self scoping bug in collection.add no-op handler.
    The noOpRequestHandler arrow function captured this from the enclosing regular function, which binds to the CollectionReference instance — not the FirestoreInstrumentation instance where originalCollectionDocFn is stored. Changed this.originalCollectionDocFnself.originalCollectionDocFn so the property lookup hits the instrumentation class. The .call(this, "") argument correctly remains this (the CollectionReference context).\

Context

The Redis error specifically surfaces when rate-limit-redis express middleware fires during replay. The rate limiter's Redis calls land on the no-op path because they execute before/outside the SDK's HTTP span context, so handleReplayMode classifies them as background requests. The no-op handler just needs to return a value that won't crash the caller — the rate limiter effectively becomes a pass-through in replay mode.
The Firestore error surfaces from AMQP consumer jobs (ch.consume) that write to Firestore outside of any traced HTTP request — these are genuine background requests where the no-op path is the correct behavior, but the this/self bug prevented it from working.

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.

1 issue found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/instrumentation/libraries/firestore/Instrumentation.ts">

<violation number="1" location="src/instrumentation/libraries/firestore/Instrumentation.ts:706">
P1: Calling Firestore `doc("")` here can still throw in replay mode. Use `doc()` with no argument so the no-op path returns an auto-ID `DocumentReference` instead of an invalid empty document path.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@tusk-dev
Copy link

tusk-dev bot commented Mar 13, 2026

Tusk is paused for this PR

View output

Tip

New to Tusk Unit Tests? Learn more here.

View check history

Commit Status Output Created (UTC)
b450cc5 Generated 13 tests - 13 passed Tests Mar 13, 2026 9:39PM
3665f12 Tusk is paused for this PR Output Mar 13, 2026 9:51PM

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
@sohankshirsagar sohankshirsagar added the Tusk - Pause For Current PR Pause Tusk for future commits in the current PR label Mar 13, 2026
@sohankshirsagar sohankshirsagar merged commit 5df98d6 into main Mar 13, 2026
19 checks passed
@sohankshirsagar sohankshirsagar deleted the sohan/fix-redis-firestore-noop branch March 13, 2026 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Tusk - Pause For Current PR Pause Tusk for future commits in the current PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants