[PR #256] [MERGED] fix: Comparison between inconvertible types #301

Closed
opened 2026-06-05 17:22:34 -04:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/deepagentsjs/pull/256
Author: @jkennedyvz
Created: 2/27/2026
Status: Merged
Merged: 3/2/2026
Merged by: @christian-bromann

Base: mainHead: fix-finding-autofix-e23715e4


📝 Commits (1)

  • 3cad6af Fix for Comparison between inconvertible types

📊 Changes

1 file changed (+5 additions, -2 deletions)

View changed files

📝 libs/deepagents/src/middleware/summarization.ts (+5 -2)

📄 Description

General fix approach: Avoid comparing cause directly to null in a way that confuses static analysis when its type is a wide union. Instead, structure the loop so that cause is checked for truthiness (or explicitly for undefined/null) in a way that the analyzer understands, while keeping the same runtime behavior of walking the .cause chain until it ends.

Best concrete fix here: Change the while (cause != null) loop into an infinite for (;;) or while (true) loop that breaks when cause is null/undefined. Inside the loop, first check if cause is falsy (if (!cause) break;). Then run the existing logic: if ContextOverflowError.isInstance(cause) return true; otherwise compute the next cause from cause.cause when available, otherwise set it to undefined. This preserves exactly the same semantics (termination when cause becomes undefined or null) but removes the flagged direct comparison in the loop header.

Concretely, in libs/deepagents/src/middleware/summarization.ts, in the isContextOverflow function, replace:

let cause: unknown = err;
while (cause != null) {
  if (ContextOverflowError.isInstance(cause)) {
    return true;
  }
  cause =
    typeof cause === "object" && cause !== null && "cause" in cause
      ? (cause as { cause?: unknown }).cause
      : undefined;
}
return false;

with:

let cause: unknown = err;
for (;;) {
  if (!cause) {
    break;
  }
  if (ContextOverflowError.isInstance(cause)) {
    return true;
  }
  cause =
    typeof cause === "object" && "cause" in cause
      ? (cause as { cause?: unknown }).cause
      : undefined;
}
return false;

This removes the problematic comparison and slightly simplifies the typeof/null check (we can drop cause !== null because if (!cause) break; already handles null and undefined).

No new imports or helper methods are needed.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langchain-ai/deepagentsjs/pull/256 **Author:** [@jkennedyvz](https://github.com/jkennedyvz) **Created:** 2/27/2026 **Status:** ✅ Merged **Merged:** 3/2/2026 **Merged by:** [@christian-bromann](https://github.com/christian-bromann) **Base:** `main` ← **Head:** `fix-finding-autofix-e23715e4` --- ### 📝 Commits (1) - [`3cad6af`](https://github.com/langchain-ai/deepagentsjs/commit/3cad6afc971986fd7c97aab0df58ac9bb1737857) Fix for Comparison between inconvertible types ### 📊 Changes **1 file changed** (+5 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `libs/deepagents/src/middleware/summarization.ts` (+5 -2) </details> ### 📄 Description General fix approach: Avoid comparing `cause` directly to `null` in a way that confuses static analysis when its type is a wide union. Instead, structure the loop so that `cause` is checked for truthiness (or explicitly for `undefined`/`null`) in a way that the analyzer understands, while keeping the same runtime behavior of walking the `.cause` chain until it ends. Best concrete fix here: Change the `while (cause != null)` loop into an infinite `for (;;)` or `while (true)` loop that breaks when `cause` is `null`/`undefined`. Inside the loop, first check if `cause` is falsy (`if (!cause) break;`). Then run the existing logic: if `ContextOverflowError.isInstance(cause)` return `true`; otherwise compute the next `cause` from `cause.cause` when available, otherwise set it to `undefined`. This preserves exactly the same semantics (termination when `cause` becomes `undefined` or `null`) but removes the flagged direct comparison in the loop header. Concretely, in `libs/deepagents/src/middleware/summarization.ts`, in the `isContextOverflow` function, replace: ```ts let cause: unknown = err; while (cause != null) { if (ContextOverflowError.isInstance(cause)) { return true; } cause = typeof cause === "object" && cause !== null && "cause" in cause ? (cause as { cause?: unknown }).cause : undefined; } return false; ``` with: ```ts let cause: unknown = err; for (;;) { if (!cause) { break; } if (ContextOverflowError.isInstance(cause)) { return true; } cause = typeof cause === "object" && "cause" in cause ? (cause as { cause?: unknown }).cause : undefined; } return false; ``` This removes the problematic comparison and slightly simplifies the `typeof`/null check (we can drop `cause !== null` because `if (!cause) break;` already handles `null` and `undefined`). No new imports or helper methods are needed. _Suggested fixes powered by Copilot Autofix. Review carefully before merging._ --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-06-05 17:22:34 -04:00
yindo closed this issue 2026-06-05 17:22:35 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/deepagentsjs#301