Skip to content

fix: replace generated column with partial unique index for PG logical replication - #39473

Open
rkfshakti wants to merge 4 commits into
langgenius:mainfrom
rkfshakti:fix/pg-logical-replication-39460
Open

fix: replace generated column with partial unique index for PG logical replication#39473
rkfshakti wants to merge 4 commits into
langgenius:mainfrom
rkfshakti:fix/pg-logical-replication-39460

Conversation

@rkfshakti

Copy link
Copy Markdown
Contributor

When PostgreSQL has wal_level=logical (logical replication enabled), the agents table's STORED GENERATED column (roster_unique_name) in a UniqueConstraint causes:

InvalidColumnReference: cannot update table 'agents'
DETAIL: Replica identity must not contain unpublished generated columns.

Replace the generated column + unique constraint with a partial unique index on (tenant_id, name) WHERE scope='roster' AND status='active'. This achieves the same uniqueness guarantee without a generated column.

Fixes #39460

@rkfshakti
rkfshakti requested a review from a team July 23, 2026 16:19
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 23, 2026
@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 54.99% 54.99% 0.00%
Strict coverage 54.48% 54.48% 0.00%
Typed symbols 35,658 35,658 0
Untyped symbols 29,460 29,460 0
Modules 3068 3068 0

@rkfshakti rkfshakti left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

please review to share feedback, this should be resolved now.

@rkfshakti

Copy link
Copy Markdown
Contributor Author

Friendly ping — this PR has been open for a few days with CI passing. The fix replaces a generated column on the agents table with a partial unique index so PostgreSQL logical replication doesn't fail with InvalidColumnReference. As @crazywoola noted on #39472, there's an overlapping migration file between these two PRs — I'm happy to consolidate them into a single PR if that's preferred. Let me know how you'd like to proceed.

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jul 27, 2026
rkfshakti and others added 4 commits July 27, 2026 07:22
…l replication

The agents table had a STORED GENERATED column (roster_unique_name) in a
UniqueConstraint. When PostgreSQL has wal_level=logical (logical replication
enabled), it tries to use this unique constraint for replica identity tracking,
but generated columns cannot be published, causing:

  InvalidColumnReference: cannot update table 'agents'
  DETAIL: Replica identity must not contain unpublished generated columns.

Replace the generated column + unique constraint with a partial unique index
on (tenant_id, name) WHERE scope='roster' AND status='active'. This achieves
the same uniqueness guarantee without a generated column.

Fixes langgenius#39460
… column

The tests were still checking for the old UniqueConstraint (agents_tenant_id_key)
and the roster_unique_name generated column, which were replaced with a partial
unique index to fix PostgreSQL logical replication conflicts.

Update test_agent_table_uses_partial_unique_index_for_active_roster_names to
verify the new partial unique index (agents_tenant_id_active_roster_name_key)
with its postgresql_where condition.

Update test_active_roster_agent_name_unique_constraint_allows_archived_and_workflow_only_duplicates
to verify the schema definition instead of runtime enforcement, since SQLite
does not support postgresql_where partial indexes.
ColumnCollection does not compare equal to a plain tuple, causing
AssertionError. Use the same tuple(column.name ...) pattern as the
roster index assertion.
@rkfshakti
rkfshakti force-pushed the fix/pg-logical-replication-39460 branch from b0f18b2 to 8dfa12c Compare July 27, 2026 01:52
@rkfshakti

Copy link
Copy Markdown
Contributor Author

Hi maintainers — following up again on this fix for #39460. Replaces the generated column with a partial unique index for PostgreSQL logical replication compatibility. CI is passing. Would appreciate a review when time allows. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: agents table INSERT/UPDATE fails with InvalidColumnReference on PostgreSQL with logical replication

2 participants