Skip to content

refactor: replace agent frame assertions with a record guard - #18825

Closed
vansh-nagar wants to merge 1 commit into
Comfy-Org:mainfrom
vansh-nagar:refactor/checked-record-guard
Closed

vansh-nagar wants to merge 1 commit into
Comfy-Org:mainfrom
vansh-nagar:refactor/checked-record-guard

Conversation

@vansh-nagar

Copy link
Copy Markdown

Summary

Replace unchecked record assertions in agent browser-test frames with a shared runtime guard.

Changes

  • What: Added a small isRecord guard and used it in the follower host socket, wire-frame parser, and disconnect regression spec.

Review Focus

The guard preserves the existing runtime acceptance rules while letting TypeScript verify property access and returned frame data.

Fixes #18805

@vansh-nagar
vansh-nagar requested a review from a team September 25, 2026 08:56
@github-actions

Copy link
Copy Markdown
Contributor

🎉 Thank you for your contribution, we really appreciate it! 🎉

Like many open source projects, we require contributors to sign our Contributor License Agreement (CLA). A CLA makes the ownership of contributions explicit, so contributors and the project share a clear understanding of how the code can be used. By signing, you:

  • Confirm that you own your contribution.
  • Keep the right to reuse your own code.
  • Grant us a copyright license to include and share it within our projects.

CLAs are standard practice across major open source projects including those under the Apache Software Foundation and the Linux Foundation. Ours is based on the Apache Software Foundation's CLA. Most importantly, it would enable us to relicense the project under a more permissive license in the future, giving the project and its community greater flexibility.

✍ To sign, please post a new comment on this PR with exactly the following text: ✍


I have read and agree to the Contributor License Agreement


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@datadog-official

datadog-official Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Pipelines

❌ Errors

Your PR has failed checks. Please review the issues below and take necessary action before merging.

🚦 1 Pipeline job failed

CLA Assistant | cla-assistant

View in Datadog · View in GitHub Actions

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 0deddfd | Docs | View more details | Give us feedback!

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright: ⏳ Running...

🎨 Storybook: 🚧 Building...

@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: Comfy-Org/ComfyUI_frontend/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 431b29c4-ea35-48f6-b6bd-11ab4ccf6832

📥 Commits

Reviewing files that changed from the base of the PR and between bf313c7 and 0deddfd.

📒 Files selected for processing (4)
  • browser_tests/fixtures/agentFollowerHostSocket.ts
  • browser_tests/fixtures/agentWireFrame.ts
  • browser_tests/fixtures/utils/isRecord.ts
  • browser_tests/tests/agent/agentGraphOpLostOnDisconnect.spec.ts

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

Adds a shared record type guard and uses it to validate agent fixture frames. Updates the reconnect regression test to assert subscription retry timing, state-vector reuse, and node appearance.

Changes

Agent browser-test validation

Layer / File(s) Summary
Shared record guard and fixture validation
browser_tests/fixtures/utils/isRecord.ts, browser_tests/fixtures/agentFollowerHostSocket.ts, browser_tests/fixtures/agentWireFrame.ts
Adds isRecord and uses it to validate parsed frame and wire-envelope values. The existing doc_ prefix and string-type checks remain unchanged.
Reconnect subscription regression test
browser_tests/tests/agent/agentGraphOpLostOnDisconnect.spec.ts
Uses the shared guard and asserts that the node appears after a subscription retry. It also checks for two post-reconnect subscriptions with the same state vector and a delay of at least SUBSCRIBE_ACK_TIMEOUT_MS - 500.

Priority: ⬇️ Low

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

Change: Refactor

Suggested reviewers: christian-byrne

Merge Risk: ⚪ Minimal · up to 0dedd

This change only centralizes existing record checks and reuses the guard in the test. The inspected changes do not alter runtime behavior, so no material merge-readiness risk is identified.

Architecture Summary

Architecture risk: 🟡 Medium · up to 0dedd

The change affects 1 system.

Changed systems: browser_tests

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — browser_tests (service) was modified; 4 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in browser_tests/fixtures/agentFollowerHostSocket.ts: Imports the shared isRecord guard for envelope validation.
  • observed — Modified behavior in browser_tests/fixtures/agentFollowerHostSocket.ts: docFrameEnvelope now validates both the parsed frame and its data with isRecord, replacing inline object/null checks and type assertions. The doc_ prefix and string-type filter remain unchanged.
  • observed — Modified behavior in browser_tests/fixtures/agentWireFrame.ts: The fixture imports isRecord from the E2E utilities.
  • observed — Modified behavior in browser_tests/fixtures/agentWireFrame.ts: isWireEnvelopeShaped now uses isRecord as its object guard instead of checking for a non-null object and casting before destructuring.

Reliability and maintainability

  • inferred — Risk-relevant change factors for browser_tests: blast_radius_2; direct_dependents_2
🚥 Pre-merge checks | ✅ 7
✅ Passed checks (7 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: replacing agent frame assertions with a record guard.
Description check ✅ Passed The description includes the required Summary, Changes, and Review Focus sections. It explains the new isRecord guard, identifies affected areas, states the runtime behavior, and references the linked…
Linked Issues check ✅ Passed Issue #18805 requires a checked record guard for docFrameEnvelope. The PR adds isRecord under browser_tests/fixtures/utils/, uses it for the parsed frame and data, and removes both assertions.…
Out of Scope Changes check ✅ Passed All changed files support issue #18805. The shared guard enables checked narrowing, agentWireFrame.ts adopts the same guard at another fixture narrowing site, and the regression spec reuses the guar…
End-To-End Regression Coverage For Fixes ✅ Passed The PR title and commit subject use "refactor" language, not bug-fix language. The PR changes files under browser_tests/, and the listed changes do not include src/ or packages/. The failure con…
Website End-To-End Regression Coverage ✅ Passed No changed file is under apps/website/src/ or apps/website/public/. The PR changes only browser-test fixtures and a browser test, so this website-specific check does not apply.
Adr Compliance For Entity/Litegraph Changes ✅ Passed The changed files are under browser_tests/fixtures/ and browser_tests/tests/agent/. None are under src/lib/litegraph/, src/ecs/, or graph-entity-related files. The ADR compliance check does no…
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Create a new PR

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

@DrJKL DrJKL added agent Comfy Agent product, integration, tests or product documentation agent-test-only Agent tests, fixtures and test support only; no production changes agent-test-playwright Touches Agent-related Playwright tests, fixtures or configuration labels Sep 25, 2026
@christian-byrne

Copy link
Copy Markdown
Contributor

Closing this duplicate because its remaining agentWireFrame.ts use site is now included in #18816 at c109520. That carrier also has the shared guard’s unit test, so it now contains the complete union of both contributions. Your authorship is preserved with a co-author trailer on the consolidation commit.

nina-mir pushed a commit to nina-mir/ComfyUI_frontend that referenced this pull request Oct 30, 2026
…omfy-Org#21995)

## Summary

The agent follower browser fixtures each hand-rolled the same `typeof x
=== 'object' && x !== null` check before reading a parsed `doc_*` frame.
This replaces the two remaining copies with one guard under
`browser_tests/fixtures/utils/`, plus a unit test for it.

This carries the surviving part of
[Comfy-Org#18816](Comfy-Org#18816) (the
same consolidation, by @chiliec, which also absorbed Comfy-Org#18825). That PR is
conflicting against `main` on a fork branch and has been open since
September, so this is the same change re-authored on current `main`
where it can land. Two non-obvious differences, both deliberate:

**The guard excludes arrays.** `value is Record<string, unknown>` is
false for an array, so admitting one lets a caller index it by string
key with no complaint from the compiler, and three sibling guards in
`browser_tests/fixtures/customNode/` already exclude them. A shared
helper under `fixtures/utils/` is the one future callers will import, so
it should not mean the opposite of its neighbours. Both call sites
already reject an array one line later, because `type` and `op` read as
`undefined`, so no valid frame changes outcome. The only behaviour
difference is that an array `data` now returns `null` instead of being
handed back typed as a record.

**`agentGraphOpLostOnDisconnect.spec.ts` is untouched.** Comfy-Org#18816 also
removed a local copy of the guard from that spec. That copy went away
upstream along with the `subscriptionFrameOf` helper that used it, so
there is no longer a duplicate there to remove.

## Verification

- `pnpm vitest run browser_tests/fixtures/utils/isRecord.test.ts`
passes, and the array cases fail against the array-accepting version, so
the tightening is actually covered rather than assumed.
- `pnpm typecheck` and `pnpm typecheck:browser` are clean, which is what
covers the two fixture call sites narrowing correctly.
- `oxfmt --check` and `oxlint` clean on the four files.
- Not run locally: the agent Playwright specs that consume these
fixtures. They need a cloud-distribution dev server, and the change is
behaviour-preserving for every valid frame, so CI is the right place for
that leg.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent Comfy Agent product, integration, tests or product documentation agent-test-only Agent tests, fixtures and test support only; no production changes agent-test-playwright Touches Agent-related Playwright tests, fixtures or configuration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace the type assertions in agentFollowerHostSocket's docFrameEnvelope with a checked record guard

3 participants