Skip to content

Conversation

@icecrasher321
Copy link
Collaborator

@icecrasher321 icecrasher321 commented Jun 30, 2025

Description

  • Special Subblock Selectors now use collab hooks correctly for updates
  • Race condition between edge and block addition for autoconnect fixed

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • All tests pass locally and in CI (bun run test)
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules
  • I have updated version numbers as needed (if needed)
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Security Considerations:

  • My changes do not introduce any new security vulnerabilities
  • I have considered the security implications of my changes

icecrasher321 and others added 3 commits June 30, 2025 15:56
…g issues (#587)

* fix(variable-resolution): don't inject stringified json, use var refs

* fix lint

* remove unused var

---------

Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@vikhyaths-air.lan>
* fix(knowledge-base-selector): should trigger sockets event for persistence

* fix subblock value updates for non useSubblockValue components

* fix lint

---------

Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@Vikhyaths-MacBook-Air.local>
…dge + block (#582)

* auto connect race condition

* fix lint

* Update apps/sim/hooks/use-collaborative-workflow.ts

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* Update apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* fix lint

---------

Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@Vikhyaths-Air.attlocal.net>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@Vikhyaths-MacBook-Air.local>
@vercel
Copy link

vercel bot commented Jun 30, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sim (staging) ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 30, 2025 11:57pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
docs ⬜️ Skipped (Inspect) Jun 30, 2025 11:57pm

@icecrasher321 icecrasher321 merged commit f4e627a into main Jun 30, 2025
6 of 8 checks passed
@delve-auditor
Copy link

delve-auditor bot commented Jun 30, 2025

No security or compliance issues detected. Reviewed everything up to 1a78dd5.

Security Overview
  • 🔎 Scanned files: 11 changed file(s)
Detected Code Changes
Change Type Relevant files
Bug Fix ► use-collaborative-workflow.ts
    Fix auto-connect race condition between adding edge and block
► workflow.tsx
    Fix race condition handling

Reply to this PR with @delve-auditor followed by a description of what change you want and we'll auto-submit a change to this PR to implement it.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR fixes race conditions and synchronization issues in collaborative workflow features, focusing on autoconnect edges and subblock selectors.

  • Enhanced validation with new AutoConnectEdgeSchema in apps/sim/socket-server/validation/schemas.ts for atomic block+edge operations
  • Refactored subblock selectors (document, file, knowledge-base, project) to use useCollaborativeWorkflow hooks instead of direct store mutations
  • Added insertAutoConnectEdge helper in apps/sim/socket-server/database/operations.ts to handle edge creation synchronously with blocks
  • Implemented atomic block addition with autoconnect edges in apps/sim/hooks/use-collaborative-workflow.ts
  • Cleaned up verbose logging in apps/sim/app/api/function/execute/route.ts

11 files reviewed, 9 comments
Edit PR Review Bot Settings | Greptile

Comment on lines 175 to 177
if (!isPreview) {
setValue(blockId, subBlock.id, document.id)
collaborativeSetSubblockValue(blockId, subBlock.id, document.id)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: redundant isPreview check - the parent if statement on line 170 already guards against preview mode

Suggested change
if (!isPreview) {
setValue(blockId, subBlock.id, document.id)
collaborativeSetSubblockValue(blockId, subBlock.id, document.id)
}
collaborativeSetSubblockValue(blockId, subBlock.id, document.id)

Comment on lines +303 to 304
collaborativeSetSubblockValue(blockId, subBlockId, newFiles)
useWorkflowStore.getState().triggerUpdate()
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider awaiting the collaborative update to ensure synchronization completes before triggering workflow update

Comment on lines +40 to +44
tx: any,
workflowId: string,
autoConnectEdge: any,
logger: any
) {
Copy link
Contributor

Choose a reason for hiding this comment

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

style: avoid using any types for database transaction, edge data, and logger - specify proper types

Comment on lines 418 to 420
setStoreValue(null)
useSubBlockStore.getState().setValue(blockId, subBlockId, null)
collaborativeSetSubblockValue(blockId, subBlockId, null)
useWorkflowStore.getState().triggerUpdate()
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Early UI state clear could cause inconsistency if file deletion fails. Consider moving this after successful deletion

Comment on lines +627 to +628
// Handle auto-connect edge if present
await insertAutoConnectEdge(tx, workflowId, payload.autoConnectEdge, logger)
Copy link
Contributor

Choose a reason for hiding this comment

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

style: code duplication with 'add' case - consider extracting error handling for auto-connect edge

Comment on lines 94 to 97
if (!isPreview) {
setValue(blockId, subBlock.id, knowledgeBase.id)
// Use collaborative update for both local store and persistence
collaborativeSetSubblockValue(blockId, subBlock.id, knowledgeBase.id)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: redundant isPreview check since it's already checked at the start of the function

Suggested change
if (!isPreview) {
setValue(blockId, subBlock.id, knowledgeBase.id)
// Use collaborative update for both local store and persistence
collaborativeSetSubblockValue(blockId, subBlock.id, knowledgeBase.id)
}
// Use collaborative update for both local store and persistence
collaborativeSetSubblockValue(blockId, subBlock.id, knowledgeBase.id)

}

const { type } = event.detail
console.log('🛠️ Adding block from toolbar:', type)
Copy link
Contributor

Choose a reason for hiding this comment

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

style: consider using an established logger instead of console.log

Suggested change
console.log('🛠️ Adding block from toolbar:', type)
logger.info('Adding block from toolbar:', { type })

type: 'workflowEdge',
})
}
console.log('✅ Auto-connect edge created:', autoConnectEdge)
Copy link
Contributor

Choose a reason for hiding this comment

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

style: remove debug log in production

Comment on lines 73 to 78
if (subBlock.id === 'teamId') {
setValue(blockId, 'teamId', projectId)
setValue(blockId, 'projectId', '')
collaborativeSetSubblockValue(blockId, 'teamId', projectId)
collaborativeSetSubblockValue(blockId, 'projectId', '')
} else if (subBlock.id === 'projectId') {
setValue(blockId, 'projectId', projectId)
collaborativeSetSubblockValue(blockId, 'projectId', projectId)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider extracting Linear-specific project/team ID handling into a separate function for better maintainability

waleedlatif1 pushed a commit that referenced this pull request Jul 1, 2025
* fix(variable resolution): use variable references to not have escaping issues (#587)

* fix(variable-resolution): don't inject stringified json, use var refs

* fix lint

* remove unused var

---------

Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@vikhyaths-air.lan>

* fix(subblock updates): special selectors persistence (#591)

* fix(knowledge-base-selector): should trigger sockets event for persistence

* fix subblock value updates for non useSubblockValue components

* fix lint

---------

Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@Vikhyaths-MacBook-Air.local>

* fix(race-cond): for auto-connect rare race condition between adding edge + block (#582)

* auto connect race condition

* fix lint

* Update apps/sim/hooks/use-collaborative-workflow.ts

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* Update apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* fix lint

---------

Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@Vikhyaths-Air.attlocal.net>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@Vikhyaths-MacBook-Air.local>

---------

Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@vikhyaths-air.lan>
Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@Vikhyaths-MacBook-Air.local>
Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@Vikhyaths-Air.attlocal.net>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
arenadeveloper02 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Sep 19, 2025
* fix(variable resolution): use variable references to not have escaping issues (simstudioai#587)

* fix(variable-resolution): don't inject stringified json, use var refs

* fix lint

* remove unused var

---------

Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@vikhyaths-air.lan>

* fix(subblock updates): special selectors persistence (simstudioai#591)

* fix(knowledge-base-selector): should trigger sockets event for persistence

* fix subblock value updates for non useSubblockValue components

* fix lint

---------

Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@Vikhyaths-MacBook-Air.local>

* fix(race-cond): for auto-connect rare race condition between adding edge + block (simstudioai#582)

* auto connect race condition

* fix lint

* Update apps/sim/hooks/use-collaborative-workflow.ts

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* Update apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* fix lint

---------

Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@Vikhyaths-Air.attlocal.net>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@Vikhyaths-MacBook-Air.local>

---------

Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@vikhyaths-air.lan>
Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@Vikhyaths-MacBook-Air.local>
Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@Vikhyaths-Air.attlocal.net>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
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.

2 participants