Skip to content

refactor: replace hand-rolled utilities and dead code with the shared forms - #7016

Closed
waleedlatif1 wants to merge 3 commits into
deslop-codebasefrom
deslop-mechanical
Closed

refactor: replace hand-rolled utilities and dead code with the shared forms#7016
waleedlatif1 wants to merge 3 commits into
deslop-codebasefrom
deslop-mechanical

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Stacked on #7015. Review that first; this PR's base is deslop-codebase, and it should be retargeted to staging once #7015 merges.

What

Sites that hand-roll something the repo already mandates, plus the dead code around them. Each was verified equivalent before changing, not pattern-matched:

Replaced With Where
Object.fromEntries(Object.entries(x).filter(...)) omit() blocks/blocks/{stt,fireflies,grain}.ts
error instanceof Error ? error.message : String(error) getErrorMessage() executor/utils/errors.ts:53
getAllBlocks().find((b) => b.type === x) getBlock() tool-input.tsx ×2, agent-handler.ts
.find()-by-id in a loop a Map index skill-input.tsx ×3, display.ts
15 * 1000 ×3 SELECTOR_SEARCH_STALE {jira,google,webflow}/selectors.ts
static inline style Tailwind classes {plus,skills}-menu-dropdown.tsx
catch (e) {} catch {} api-handler.ts, executor/utils.ts ×2

omit() also recovers the Omit<T, K> typing that Object.fromEntries erases to a bare index signature.

getAllBlocks() is not memoised — each call built a fresh 336-element array before scanning it. getBlock is an O(1) registry index. agent-handler's call ran per tool during execution; tool-input's ran inside a loop over selected tools.

panel.tsx loses a TODO-stubbed const hasValidationErrors = false and the isWorkflowBlocked term built on it. That term was dead twice over — it reduced to isExecuting, and the enclosing expression is already guarded by !isExecuting, so the disjunct could only ever be reached as false.

Two things the review caught

getBlock is not a drop-in for .find(). It normalizes via type.replace(...), so it throws on undefined where .find() returned undefined harmlessly. Both call sites are reachable without a type — tool-input reads state.blocks[blockId]?.type, undefined once the block is deleted while the panel is mounted. Record indexing hid that from the compiler; it would have thrown during render. Both are now guarded. The compiler did catch the agent-handler one.

providers/utils.ts:683 deliberately keeps its getAllBlocks().find(...). It takes the registry as an injected dependency so a client-reachable module never imports it. Reaching for getBlock there would cross that boundary, so it was left alone.

Scope

Behavior-preserving throughout — no user-visible change intended. The SELECTOR_SEARCH_STALE constant preserves the three sites' existing 15s window rather than folding them into the 60s SELECTOR_STALE; its doc describes what those three callers share rather than asserting a rule about search, since several other search-backed selectors still sit on the longer window.

Testing

  • 7019 tests passing across executor, blocks, hooks, lib/workflows/subblocks, app/workspace
  • bun run type-check clean; bun run check:api-validation passes

Provenance

Found by running mattpocock/skills over the codebase. Worth noting what the audit did not find: the repo's mandated-utility rules are already ~95% enforced — zero @ts-ignore, zero JSON.parse(JSON.stringify(, and 52 of 60 non-test double-casts already carry their required annotation.

… forms

Each of these has a mandated helper or an established accessor in the repo that
the site predates or missed. All are behavior-preserving:

- `omit()` for the three `Object.fromEntries(Object.entries(x).filter(...))`
  block-input filters, which also recovers the `Omit<T, K>` typing that
  `Object.fromEntries` erases to an index signature.
- `getErrorMessage()` for the inline `instanceof Error` message ternary.
- `getBlock()` for two `getAllBlocks().find((b) => b.type === x)` scans, one of
  them inside a loop over selected tools. The same file already resolves the
  same values through `getBlock`.
- A memoised `Map` for three `.find()`-by-id scans over the workspace skill
  list, one of them inside a render `.map()`.
- `SELECTOR_SEARCH_STALE` for three copy-pasted `15 * 1000` literals. They are
  deliberately shorter than `SELECTOR_STALE`, so this is a new named constant
  rather than a fold into the existing one.
- Tailwind classes for the static half of two duplicated anchor styles, keeping
  only the genuinely dynamic `left`/`top` inline.
- Dropped the unused `catch` bindings on three intentional JSON-parse swallows.

`panel.tsx`'s run-button gate loses a `TODO`-stubbed `hasValidationErrors =
false` and the `isWorkflowBlocked` term built on it. That term was dead twice
over: it reduced to `isExecuting`, and the enclosing expression is already
guarded by `!isExecuting`.
…s callers

`getBlock` normalizes its argument with `type.replace(...)`, so it throws on
`undefined` where the `getAllBlocks().find(...)` it replaced returned
`undefined` harmlessly. Both call sites can be reached without a type:
`tool-input` reads `state.blocks[blockId]?.type`, which is undefined once the
block is deleted while the panel is mounted — and `Record` indexing hides that
from the compiler, so it would have thrown during render. `agent-handler`'s
`tool.type` is optional and the compiler did catch it.

Also index the skill lookup in `resolveSkillsLabel`, which runs a `.find()`
inside a `.map()` for every block on the canvas — the case the memoised map in
`skill-input` addressed for one component while leaving the hot path.

`providers/utils.ts` keeps its `getAllBlocks().find(...)`: it takes the
registry as an injected dependency precisely so a client-reachable module never
imports it, and reaching for `getBlock` there would cross that boundary.

The new constant's doc claimed search-backed selectors take a shorter window.
Several still sit on `SELECTOR_STALE`, so it now describes the value its three
callers share rather than asserting a rule the tree does not follow.
@vercel

vercel Bot commented Aug 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Aug 23, 2026 7:53pm

Request Review

@cursor

cursor Bot commented Aug 23, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Intended as equivalent refactors. The only behavioral risk is getBlock vs .find(), which is now guarded at the previously unsafe call sites.

Overview
Behavior-preserving cleanup that swaps ad-hoc patterns for existing helpers: omit() for v2 block input stripping, getErrorMessage(), getBlock() instead of scanning getAllBlocks(), Map-indexed skill lookups, and a shared SELECTOR_SEARCH_STALE (15s) for Drive/Jira/Webflow selectors.

getBlock is guarded where blockType can be missing (deleted block still mounted). Dead hasValidationErrors / isWorkflowBlocked wiring is removed from the run button. Dropdown anchors use Tailwind classes; unused catch bindings are dropped.

Reviewed by Cursor Bugbot for commit 15d9368. Configure here.

@greptile-apps

greptile-apps Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR consolidates hand-rolled utilities around shared helpers and removes dead logic without intending behavioral changes.

  • Replaces repeated filtering, error formatting, block lookup, and array-search patterns with shared utilities or indexed maps.
  • Centralizes the 15-second selector-search stale interval.
  • Moves static dropdown-anchor styles to Tailwind while retaining runtime-measured coordinates inline.
  • Guards getBlock calls whose type can disappear while the editor remains mounted.
  • Removes dead workflow-run state and redundant catch bindings.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/plus-menu-dropdown/plus-menu-dropdown.tsx Moves fixed, size, and pointer-event declarations to Tailwind while correctly retaining runtime anchor coordinates inline.
apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/skills-menu-dropdown/skills-menu-dropdown.tsx Applies the same behavior-preserving anchor-style consolidation as the plus menu.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/tool-input.tsx Replaces repeated block-catalog scans with guarded registry lookups, including the newly added guard for potentially absent tool types.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/skill-input/skill-input.tsx Builds a memoized skill index and uses it consistently for editing, naming, and rendering lookups.
apps/sim/executor/handlers/agent/agent-handler.ts Uses the shared block registry lookup in the agent execution path.
apps/sim/hooks/selectors/providers/shared.ts Introduces the shared selector-search stale-time constant used by the affected providers.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/panel.tsx Removes validation placeholders and a blocked-state term that reduced to existing execution-state behavior.

Reviews (2): Last reviewed commit: "fix: guard the second registry lookup in..." | Re-trigger Greptile

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 15d9368. Configure here.

`selectedTools` validates only `value[0]?.type` and then casts the whole array,
so a persisted workflow whose later rows lost their `type` yields `undefined`
here — the cast is what makes the compiler believe otherwise. `getBlock`
normalizes with `type.replace`, so that throws during render.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile-apps the summary is a commit behind — last reviewed 15d936801d, head is 53b4dfdc71. The unguarded getBlock(tool.type) behind the 4/5 was fixed in that newer commit. Please re-review.

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