Skip to content

fix(agent): scope nested tool canonical-mode overrides by instance, not type#5534

Merged
waleedlatif1 merged 1 commit into
stagingfrom
worktree-fix-table-canonical-mode-shared
Jul 9, 2026
Merged

fix(agent): scope nested tool canonical-mode overrides by instance, not type#5534
waleedlatif1 merged 1 commit into
stagingfrom
worktree-fix-table-canonical-mode-shared

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Fixes a bug where two tool entries of the same type in an Agent block's tool-input array (e.g. two Table tools) shared one canonical-mode override, so switching basic/advanced mode on a field in one instance silently switched it for every other instance of the same tool type
  • The override key was ${toolType}:${canonicalId} (shared across every instance of a type); it's now ${toolIndex}:${canonicalId}, scoped to the tool's position in its own tool-input array
  • Threaded the tool's array index through every consumer of this key: the editor (tool-input.tsx read + write), execution (agent-handler.ts / providers/utils.ts transformBlockTool), the search index (search-replace/indexer.ts), and fork/promote remapping (dependent-reconfigs.ts)
  • This was also a correctness bug at execution time, not just the editor UI — the wrong basic/advanced value could be resolved for the second tool instance when running the workflow

Type of Change

  • Bug fix

Testing

  • Added a dedicated scopeCanonicalModesForTool test suite in visibility.test.ts covering the instance-scoping behavior directly
  • Added a regression test in providers/utils.test.ts with two Table tool instances resolving independent canonical modes
  • Added a regression test in dependent-reconfigs.test.ts covering two same-type nested tools in the fork/promote remap path
  • Updated existing tests that referenced the old ${toolType}:${canonicalId} key format to the new ${toolIndex}:${canonicalId} format
  • Full repo test suite (2864 tests, 175 files) passes; bun run type-check, bun run lint, and bun run check:api-validation all pass

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Jul 9, 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 Jul 9, 2026 6:15pm

Request Review

@cursor

cursor Bot commented Jul 9, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes how canonical modes are keyed and resolved at execution, in realtime persistence, and during fork copy; regression risk is mitigated by broad tests and legacy key fallback.

Overview
Fixes nested tool-input basic/advanced overrides so each tool instance has its own mode instead of sharing one key per tool type.

Override keys move from ${toolType}:${canonicalId} to ${toolIndex}:${canonicalId}. That index is threaded through the editor, transformBlockTool / agent execution, search indexing, and fork/promote remapping. Legacy ${toolType}: keys still work until the user toggles again.

Reindexing keeps overrides aligned when the tools array changes: remove, drag-reorder, and MCP bulk add in tool-input; dropping unresolved custom/MCP tools during fork copy. New helpers reindexToolCanonicalModes / reindexCanonicalModesByPosition produce a full replacement map.

Collaboration adds REPLACE_CANONICAL_MODES (store, socket persistence, permissions) so reindex can atomically replace canonicalModes without stale keys or swap clobbering from per-key merges.

Reviewed by Cursor Bugbot for commit e197014. Configure here.

@greptile-apps

greptile-apps Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR scopes nested tool canonical-mode overrides to each tool instance. The main changes are:

  • Index-based canonical-mode keys for Agent tool-input entries.
  • Reindexing when tools are removed, reordered, or filtered during editor and fork flows.
  • Whole-map canonicalModes replacement for collaborative updates.
  • Updated execution, search, and fork/remap consumers to pass tool indexes.
  • Regression tests for same-type tools, legacy fallback, and stale-key removal.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/tool-input.tsx Rekeys tool canonical-mode reads and writes by tool index and reindexes overrides for editor mutations that change tool order or length.
apps/sim/lib/workflows/subblocks/visibility.ts Adds index-scoped override extraction, legacy fallback handling, and helpers for reindexing or dropping stale tool override keys.
apps/sim/hooks/use-collaborative-workflow.ts Adds a collaborative operation that replaces the full canonicalModes map instead of merging individual keys.
apps/sim/ee/workspace-forking/lib/remap/remap-references.ts Threads tool indexes through fork and promote remapping and carries reindexed canonicalModes after dropped nested tools.
apps/sim/executor/handlers/agent/agent-handler.ts Preserves original tool-input positions across filtering before formatting non-MCP tools for execution.
apps/sim/providers/utils.ts Resolves canonical resource params from the scoped tool-instance override map.
apps/realtime/src/database/operations.ts Persists the replace-canonical-modes block operation while preserving other block data.
packages/realtime-protocol/src/constants.ts Adds the replace-canonical-modes operation constant.
packages/realtime-protocol/src/schemas.ts Allows the new replace-canonical-modes operation through protocol validation.

Reviews (6): Last reviewed commit: "fix(agent): scope nested tool canonical-..." | Re-trigger Greptile

Comment thread apps/sim/lib/workflows/subblocks/visibility.ts
Comment thread apps/sim/lib/workflows/subblocks/visibility.ts Outdated
@waleedlatif1 waleedlatif1 force-pushed the worktree-fix-table-canonical-mode-shared branch from 9f47896 to 5e84b2c Compare July 9, 2026 15:45
@waleedlatif1 waleedlatif1 force-pushed the worktree-fix-table-canonical-mode-shared branch from 5e84b2c to 5fc1245 Compare July 9, 2026 16:06
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

Addressed both findings — thanks Greptile and Bugbot, these were real:

  1. Legacy ${toolType}: keys silently ignoredscopeCanonicalModesForTool now falls back to the legacy type-scoped prefix when no index-scoped key matches, so an override saved before this fix keeps applying (shared across same-type tools, the old behavior) until the user explicitly re-toggles that specific instance, at which point it's rewritten under the new index-scoped key. No more silent data loss.

  2. Index instability on reorder/delete — added reindexToolCanonicalModes (in tool-input/utils.ts, unit tested) and wired it into every mutation site that changes tool order/length in the editor (remove, remove-all-from-server, delete custom tool, drag-reorder, "use all MCP tools"). Diffs old vs. new tool arrays by object identity and re-emits each surviving tool's overrides under its new index before the array mutation is committed.

Pushed as a new commit (rebased + amended). Re-triggering review.

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@waleedlatif1 waleedlatif1 force-pushed the worktree-fix-table-canonical-mode-shared branch from 5fc1245 to eb7106f Compare July 9, 2026 17:05
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/lib/workflows/subblocks/visibility.ts
@waleedlatif1 waleedlatif1 force-pushed the worktree-fix-table-canonical-mode-shared branch from eb7106f to 9912b52 Compare July 9, 2026 17:26
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/ee/workspace-forking/lib/remap/remap-references.ts
@waleedlatif1 waleedlatif1 force-pushed the worktree-fix-table-canonical-mode-shared branch from 9912b52 to 0c9c314 Compare July 9, 2026 17:58
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/ee/workspace-forking/lib/copy/copy-workflows.ts Outdated
…ot type

Two tool entries of the same type inside an Agent block's tool-input array
(e.g. two Table tools) shared a single canonical-mode override keyed by
${toolType}:${canonicalId}, so switching basic/advanced mode on one field
silently switched it on every other instance of the same tool type -
including at execution time, where the wrong basic/advanced value could be
resolved for the second tool.

Rescope the override key to the tool's position in its tool-input array
(${toolIndex}:${canonicalId}) instead of its type, and thread that index
through every consumer: the editor (read + write), execution
(agent-handler/providers), search-index, and fork/promote remapping.
@waleedlatif1 waleedlatif1 force-pushed the worktree-fix-table-canonical-mode-shared branch from 0c9c314 to e197014 Compare July 9, 2026 18:15
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit e197014. Configure here.

@waleedlatif1 waleedlatif1 merged commit b117758 into staging Jul 9, 2026
18 checks passed
@waleedlatif1 waleedlatif1 deleted the worktree-fix-table-canonical-mode-shared branch July 9, 2026 18:22
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