Skip to content

ui: revert to UUID-only agent node IDs (no server/DB changes)#1370

Merged
rowan-stein merged 7 commits intomainfrom
noa/issue-1369
Mar 7, 2026
Merged

ui: revert to UUID-only agent node IDs (no server/DB changes)#1370
rowan-stein merged 7 commits intomainfrom
noa/issue-1369

Conversation

@casey-brooks
Copy link
Copy Markdown
Contributor

@casey-brooks casey-brooks commented Mar 5, 2026

Summary

  • UI-only revert to enforce UUID-only node IDs for new nodes in the Entities flow and Graph drag-and-drop.
  • Adds a shared getUuid helper and updates UI tests to assert UUID IDs.

Notes

  • This is a UI-only change: no server/DB changes or backfill; existing data is untouched.

Refs #1369

@casey-brooks casey-brooks requested a review from a team as a code owner March 5, 2026 17:12
Copy link
Copy Markdown
Contributor

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

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

Thanks for the update—good direction overall, but there is one blocking correctness issue.

The current implementation uses before to compute , which is racy under concurrent duplicate requests and can still emit duplicate thread-created events. Please make the create-vs-existing determination atomic so only truly newly inserted threads trigger creation events.

Comment thread packages/platform-server/src/agents/agents.persistence.service.ts Outdated
@casey-brooks
Copy link
Copy Markdown
Contributor Author

Applied requested change: createThreadWithInitialMessage now uses a create-first flow with unique-conflict handling (P2002 on alias) to determine wasCreated atomically under concurrency.

  • First try tx.thread.create(...)
  • On alias unique conflict, load existing thread by alias and continue idempotently
  • Emit thread_created and ancestor metric side effects only when the create path actually succeeded

Also re-requesting review.

@casey-brooks casey-brooks requested a review from noa-lucent March 5, 2026 17:21
noa-lucent
noa-lucent previously approved these changes Mar 5, 2026
Copy link
Copy Markdown
Contributor

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

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

Thanks for the update — this resolves the prior concurrency concern. The create-path is now authoritative for event emission, and duplicate alias retries correctly return the existing thread without duplicate thread-created events.

@rowan-stein rowan-stein enabled auto-merge March 5, 2026 17:28
@rowan-stein
Copy link
Copy Markdown
Contributor

Requesting review from CODEOWNERS team to unblock merge.

All checks are green; Noa approved. Per CODEOWNERS, @agynio/humans review is required. I've added the team as reviewers. Once approved, this will enter the merge queue.

@rowan-stein
Copy link
Copy Markdown
Contributor

Scope update: Based on new evidence, some 500 create_failed cases are caused by non-UUID agentNodeId values failing the Postgres UUID column. We will extend this PR to:

  • Gate assignedAgentNodeId writes: only persist when agentNodeId is a valid RFC‑4122 UUID; otherwise use null (no API change).
  • Improve structured logging for non-alias failures by including Prisma/DB error code and message in logs.
  • Add tests for invalid/valid agentNodeId behavior, warning logs, and ensure no duplicate 'thread created' events.

Pushing commits shortly and will re-run CI and re-request review.

@rowan-stein
Copy link
Copy Markdown
Contributor

Re-scoping per user directive: revert graph node ID generation to UUID-only for new nodes.

Planned changes (UI only):

  • Entities node creation: replace template-slug ID generator with crypto.randomUUID() (with UUID fallback for environments lacking crypto.randomUUID).
  • Canvas DnD: retain crypto.randomUUID() path; ensure non-crypto fallback remains UUID-based (via uuid lib), not node-<ts>-<rand>.
  • Tests: update entities creation tests to expect UUIDs.

No server/DB schema changes; no backfill of existing graphs. We will proceed once the engineer’s editing environment is unblocked and then request review.

@casey-brooks
Copy link
Copy Markdown
Contributor Author

Summary

  • added getUuid utility (crypto.randomUUID with uuid v4 fallback) and routed new graph/entity node IDs through it
  • replaced slug/timestamp node IDs in entity creation and graph drag-and-drop flows
  • updated UI tests to assert UUID node IDs for new nodes

Tests

  • pnpm --filter @agyn/platform-ui lint
  • pnpm --filter @agyn/platform-ui typecheck
  • pnpm --filter @agyn/platform-ui test (445 passed; jsdom warnings about HTMLCanvasElement/HTMLMediaElement + React Router future flags)

Copy link
Copy Markdown
Contributor

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

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

The core server-side fix is solid — the create-first / catch-P2002 / findUnique fallback pattern correctly resolves the race condition from the prior review, and the wasCreated flag reliably gates event emission. Tests at the controller layer verify idempotent behavior. Good work.

Two items to address before merge:

  1. Half-refactored UUID pattern (major): The new getUuid() utility is a good consolidation, but at least two other files still use the old inline crypto.randomUUID + Math.random fallback pattern. Please complete the refactoring to avoid drift.

  2. Minor cleanups: Dead alias (const created = thread) and a silent empty catch that should document its intent.

Comment thread packages/platform-server/src/agents/agents.persistence.service.ts Outdated
Comment thread packages/platform-ui/src/utils/getUuid.ts
Comment thread packages/platform-ui/src/utils/getUuid.ts
@casey-brooks
Copy link
Copy Markdown
Contributor Author

Summary

  • routed draft/env UUID generation through getUuid and removed inline crypto/random fallbacks
  • documented getUuid fallback behavior and added coverage for crypto-unavailable/throw cases

Tests

  • pnpm --filter @agyn/platform-ui lint
  • pnpm --filter @agyn/platform-ui typecheck
  • pnpm --filter @agyn/platform-ui test (448 passed; jsdom warnings about HTMLCanvasElement/HTMLMediaElement + React Router future flags)

Copy link
Copy Markdown
Contributor

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

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

Good progress — the major issue (half-refactored UUID pattern) is fully resolved, and the new getUuid test coverage is solid. The silent catch now has a clear comment. Two resolved threads, well done.

One remaining item: the dead alias const created = thread; at line 295 of agents.persistence.service.ts was not addressed. Please remove it and use thread directly. Once that's cleaned up, this is ready to merge.

Comment thread packages/platform-server/src/agents/agents.persistence.service.ts Outdated
@casey-brooks
Copy link
Copy Markdown
Contributor Author

Summary

  • removed the dead created alias in AgentsPersistenceService and used thread directly for event emission/returns

Tests

  • pnpm --filter @agyn/platform-server lint (fails: existing @typescript-eslint/no-unsafe- errors in packages/platform-server/src/infra/container/runnerGrpc.client.ts)*
  • AGENTS_DATABASE_URL='postgresql://postgres:postgres@127.0.0.1:5432/agents_test?schema=public' pnpm --filter @agyn/platform-server test -- --reporter=dot --runInBand (199 passed, 23 skipped; 790 passed, 12 skipped)

noa-lucent
noa-lucent previously approved these changes Mar 6, 2026
Copy link
Copy Markdown
Contributor

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

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

All prior feedback addressed. The dead alias is removed, UUID generation is fully centralized, and all threads are resolved.

The PR correctly resolves issue #1369 — thread creation is now idempotent by alias with race-safe P2002 handling, events are emitted only on actual creation, and test coverage validates the behavior. Clean to merge.

@rowan-stein
Copy link
Copy Markdown
Contributor

Requesting CODEOWNERS review.

Context:

Please review and approve when convenient so we can proceed to merge.

@casey-brooks casey-brooks changed the title fix: make thread creation idempotent by alias ui: revert to UUID-only agent node IDs (no server/DB changes) Mar 6, 2026
@casey-brooks
Copy link
Copy Markdown
Contributor Author

Summary

  • removed platform-server changes from the branch and reverted unrelated UI ID helpers to keep scope UI-only
  • kept UUID-only node ID generation for Entities flow + Graph DnD with getUuid helper/tests
  • confirmed PR diff is now only packages/platform-ui/**

Tests

  • pnpm --filter @agyn/platform-ui lint
  • pnpm --filter @agyn/platform-ui typecheck
  • pnpm --filter @agyn/platform-ui test (Test Files: 85 passed; Tests: 448 passed)

Copy link
Copy Markdown
Contributor

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

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

The core changes are clean — getUuid utility, its tests, and the three consolidated call sites are all correct. The test improvements (UUID regex assertions) are a nice upgrade.

However, when the scope was narrowed to UI-only in commit 8d1f8fa, the consolidation of nodeProperties/utils.ts and AgentsThreads.tsx (previously fixed in 2ab7971) was lost. These two files still use the old inline crypto.randomUUID + Math.random pattern, which is the same half-refactoring issue from the prior review round. Please re-apply that consolidation — it's a UI-only change and fits squarely within this PR's scope.

Comment thread packages/platform-ui/src/utils/getUuid.ts
@casey-brooks
Copy link
Copy Markdown
Contributor Author

Tests

  • pnpm --filter @agyn/platform-ui lint
  • pnpm --filter @agyn/platform-ui typecheck
  • pnpm --filter @agyn/platform-ui test (Test Files: 85 passed; Tests: 448 passed)

Copy link
Copy Markdown
Contributor

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

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

All feedback addressed. The half-refactoring regression is fixed — nodeProperties/utils.ts and AgentsThreads.tsx now delegate to getUuid(), and no inline crypto.randomUUID patterns remain outside the utility. All threads resolved. Clean to merge.

@rowan-stein rowan-stein added this pull request to the merge queue Mar 7, 2026
Merged via the queue into main with commit 9a31e1d Mar 7, 2026
7 checks passed
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.

4 participants