-
Notifications
You must be signed in to change notification settings - Fork 0
fix(retrieval): widen outbox aggregate IDs #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
777genius
wants to merge
1
commit into
main
Choose a base branch
from
fix/retrieval-profile-outbox-width
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
...s/infinity_context_adapters/postgres/migrations/0060_memory_outbox_aggregate_id_width.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| SET LOCAL lock_timeout = '5s'; | ||
| SET LOCAL statement_timeout = '30s'; | ||
|
|
||
| ALTER TABLE public.memory_outbox | ||
| ALTER COLUMN aggregate_id TYPE VARCHAR(120); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
tests/e2e/test_memory_outbox_aggregate_id_width_postgres.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import asyncio | ||
| import os | ||
|
|
||
| import pytest | ||
| from infinity_context_adapters.postgres import build_async_engine, upgrade_schema | ||
| from postgres_test_database import PostgresTestDatabase | ||
| from postgres_versioned_schema_fixtures import install_versioned_schema_through | ||
| from sqlalchemy import text | ||
|
|
||
|
|
||
| def test_memory_outbox_width_upgrade_when_postgres_is_configured() -> None: | ||
| database_url = os.getenv("INFINITY_CONTEXT_TEST_POSTGRES_URL") | ||
| if not database_url: | ||
| pytest.skip("INFINITY_CONTEXT_TEST_POSTGRES_URL is not configured") | ||
| asyncio.run(_assert_width_upgrade(database_url)) | ||
|
|
||
|
|
||
| async def _assert_width_upgrade(database_url: str) -> None: | ||
| asyncpg = pytest.importorskip("asyncpg") | ||
| database = PostgresTestDatabase.from_url( | ||
| database_url, prefix="outbox_width_0060", asyncpg=asyncpg | ||
| ) | ||
| await database.recreate() | ||
| try: | ||
| await install_versioned_schema_through(database, "0059_") | ||
| existing_id = "e" * 80 | ||
| raw = await database.connect() | ||
| try: | ||
| await raw.execute( | ||
| "INSERT INTO memory_outbox " | ||
| "(event_type,aggregate_type,aggregate_id,payload_json,status," | ||
| "attempt_count,next_attempt_at,created_at,updated_at) " | ||
| "VALUES ('probe.existing','locator_profile',$1,'{}','pending',0," | ||
| "CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP)", | ||
| existing_id, | ||
| ) | ||
| finally: | ||
| await raw.close() | ||
|
|
||
| engine = build_async_engine(database.app_url) | ||
| try: | ||
| result = await upgrade_schema(engine) | ||
| assert result.applied == ("0060_memory_outbox_aggregate_id_width",) | ||
| aggregate_id = "p" * 120 | ||
| async with engine.begin() as connection: | ||
| assert await connection.scalar( | ||
| text( | ||
| "SELECT character_maximum_length FROM information_schema.columns " | ||
| "WHERE table_schema='public' AND table_name='memory_outbox' " | ||
| "AND column_name='aggregate_id'" | ||
| ) | ||
| ) == 120 | ||
| assert await connection.scalar( | ||
| text("SELECT aggregate_id FROM memory_outbox WHERE aggregate_id=:id"), | ||
| {"id": existing_id}, | ||
| ) == existing_id | ||
| await connection.execute( | ||
| text( | ||
| "INSERT INTO memory_outbox " | ||
| "(event_type,aggregate_type,aggregate_id,payload_json,status," | ||
| "attempt_count,next_attempt_at,created_at,updated_at) " | ||
| "VALUES ('vector.upsert_locator_profile','locator_profile',:id," | ||
| "'{}','pending',0,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP," | ||
| "CURRENT_TIMESTAMP)" | ||
| ), | ||
| {"id": aggregate_id}, | ||
| ) | ||
| finally: | ||
| await engine.dispose() | ||
| finally: | ||
| await database.drop() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| from datetime import UTC, datetime | ||
| from pathlib import Path | ||
|
|
||
| from infinity_context_adapters.postgres import migration_runner | ||
| from infinity_context_adapters.postgres.outbox_models import MemoryOutboxRow | ||
| from sqlalchemy import create_engine | ||
|
|
||
| MIGRATION = ( | ||
| Path(__file__).resolve().parents[2] | ||
| / "packages/infinity_context_adapters/infinity_context_adapters/postgres/migrations" | ||
| / "0060_memory_outbox_aggregate_id_width.sql" | ||
| ) | ||
|
|
||
|
|
||
| def test_0060_widens_only_the_outbox_aggregate_id() -> None: | ||
| migrations = migration_runner._load_migrations() | ||
| assert migrations[-2].migration_id == "0059_locator_parent_lifecycle" | ||
| assert migrations[-1].migration_id == "0060_memory_outbox_aggregate_id_width" | ||
| assert MIGRATION.read_text(encoding="utf-8") == ( | ||
| "SET LOCAL lock_timeout = '5s';\n" | ||
| "SET LOCAL statement_timeout = '30s';\n" | ||
| "\n" | ||
| "ALTER TABLE public.memory_outbox\n" | ||
| " ALTER COLUMN aggregate_id TYPE VARCHAR(120);\n" | ||
| ) | ||
|
|
||
|
|
||
| def test_outbox_model_accepts_a_120_character_aggregate_id_on_sqlite() -> None: | ||
| aggregate_id = "p" * 120 | ||
| assert MemoryOutboxRow.__table__.c.aggregate_id.type.length == 120 | ||
|
|
||
| engine = create_engine("sqlite://") | ||
| MemoryOutboxRow.__table__.create(engine) | ||
| now = datetime(2026, 9, 15, tzinfo=UTC) | ||
| with engine.begin() as connection: | ||
| connection.execute( | ||
| MemoryOutboxRow.__table__.insert(), | ||
| { | ||
| "event_type": "vector.upsert_locator_profile", | ||
| "aggregate_type": "locator_profile", | ||
| "aggregate_id": aggregate_id, | ||
| "payload_json": {}, | ||
| "next_attempt_at": now, | ||
| "created_at": now, | ||
| "updated_at": now, | ||
| }, | ||
| ) | ||
| assert connection.scalar( | ||
| MemoryOutboxRow.__table__.select().with_only_columns( | ||
| MemoryOutboxRow.aggregate_id | ||
| ) | ||
| ) == aggregate_id |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Expand the applied-migration slice.
The migration runner appends pending migration IDs to
appliedand returns them as a tuple. The expected tuple contains 22 IDs, including both0052migrations.upgraded.applied[-21:]selects only 21 IDs, so the assertion can fail after a successful clean upgrade.Change the slice to
[-22:].Proposed fix
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yu
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yy