-
Notifications
You must be signed in to change notification settings - Fork 429
feat(server): implement Resource Scoping for tasks and push notifications
#709
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit
Hold shift + click to select a range
2d2d31e
feat(server): implement `resource scoping` for `tasks` and `push noti…
sokoliva 6093f7f
fix: add poolclass to allow.txt
sokoliva ce1a305
Merge branch '1.0-dev' of https://github.com/a2aproject/a2a-python in…
sokoliva 6600b47
fix: test_inmemory_task_store.py merge caused error
sokoliva a212da7
Merge branch '1.0-dev' into resource-scoping
sokoliva ea89bbb
fix: - add alembic to dev field in pyproject.toml
sokoliva 9301b8c
fix: update uv.lock
sokoliva 62dce31
fix:
sokoliva 86d769e
Merge branch '1.0-dev' into resource-scoping
sokoliva 99cf89f
fix: fix linter issues
sokoliva a11d6de
Merge branch 'resource-scoping' of https://github.com/sokoliva/a2a-py…
sokoliva feb5033
Fix: fix some more linter errors
sokoliva 212ad37
fix: more linter errors fixed
sokoliva f7b5c1c
fix: make parameter `ServerCallContext` non-optional in `PushNotifica…
sokoliva 179b21a
Merge branch '1.0-dev' into resource-scoping
sokoliva 38d7df6
fix: add ServerCallContext to tests/e2e/push_notifications/agent_app.py
sokoliva 5eeb89d
Merge branch 'resource-scoping' of https://github.com/sokoliva/a2a-py…
sokoliva c4b282a
fix: small fix
sokoliva 0090ecc
fix: fix unit test error
sokoliva 0f51ef3
fi: fix
sokoliva 00e5eac
fix: fix
sokoliva 5d65aa6
chore: distribute alembic migration files. Add helper _get_owner_push…
sokoliva cbadd5b
Merge branch '1.0-dev' of https://github.com/a2aproject/a2a-python in…
sokoliva 163c8c2
Merge branch '1.0-dev' into resource-scoping
sokoliva 44ad799
fix: linter issues
sokoliva 213ebb2
Merge branch 'resource-scoping' of https://github.com/sokoliva/a2a-py…
sokoliva 5bfccf9
fix: uv run ruff format
sokoliva bde88f1
refactor: add an edge case to test_database_task_store
sokoliva db3d050
fix: uv run ruff format
sokoliva a37efe1
fix: typo
sokoliva 782fcf7
chore: add migration for `push_notification_configs` table
sokoliva b77a4f6
Merge branch '1.0-dev' into resource-scoping
sokoliva 3428956
fix: rename README to README.md
sokoliva d90b360
feat: enhance migration CLI with table and verbose options; add owner…
sokoliva efc54a9
Merge branch '1.0-dev' into resource-scoping
sokoliva 28b6cfc
feat: enhance migration CLI with SQL mode and logging; update README …
sokoliva 591fa76
Merge branch 'resource-scoping' of https://github.com/sokoliva/a2a-py…
sokoliva 94f129d
fix: uv run ruff format
sokoliva 7f9e2bc
fix: remove user existence check in resolve_user_scope function
sokoliva 59f1fd4
feat: add CLI support for alembic in migration tool and update depend…
sokoliva 31fd9c1
fix: add ImportError handling for Alembic in CLI and migration files
sokoliva e98b578
Merge branch '1.0-dev' into resource-scoping
sokoliva 0c6d5f2
docs: update installation instructions for a2a-db migration tool
sokoliva f61eaf4
refactor: replace defaultdict with dict for in-memory task and notifi…
sokoliva 73995fa
feat: introduce a2a-db CLI for database migrations and update documen…
sokoliva 61e89fa
fix: format
sokoliva 9dc9d0c
docs: clarify error message for --owner-name flag in downgrade test
sokoliva 580d2ca
feat: update CLI flags for owner column in migrations and enhance err…
sokoliva 4164a08
feat: refactor migration tests to use direct function calls and mock …
sokoliva 874e72b
feat: enhance migration tests with importlib for coverage and refacto…
sokoliva 8317e6f
Merge branch '1.0-dev' into resource-scoping
ishymko bf7961d
feat: rename a2a-db-cli to db-cli in installation instructions and up…
sokoliva 34f3d76
Merge branch 'resource-scoping' of https://github.com/sokoliva/a2a-py…
sokoliva a041116
feat: update migration version table name to 'a2a_alembic_version'
sokoliva b7bbc17
feat: use VERSION_TABLE constant for alembic version table name in mi…
sokoliva 1e19e18
fix: change last_updated type from String to DateTime
sokoliva 55ee94e
feat: update column definitions for owner and last_updated in migrati…
sokoliva 798e455
Merge branch '1.0-dev' into resource-scoping
sokoliva 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
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,45 @@ | ||
| # A generic, single database configuration. | ||
|
|
||
| [alembic] | ||
|
|
||
| # database URL. This is consumed by the user-maintained env.py script only. | ||
| # other means of configuring database URLs may be customized within the env.py | ||
| # file. | ||
| # IMPORTANT: This is a placeholder and an example, and should be replaced with your actual database URL. | ||
| sqlalchemy.url = sqlite+aiosqlite:///./test.db | ||
|
|
||
|
|
||
| # Logging configuration | ||
| [loggers] | ||
| keys = root,sqlalchemy,alembic | ||
|
|
||
| [handlers] | ||
| keys = console | ||
|
|
||
| [formatters] | ||
| keys = generic | ||
|
|
||
| [logger_root] | ||
| level = WARNING | ||
| handlers = console | ||
| qualname = | ||
|
|
||
| [logger_sqlalchemy] | ||
| level = WARNING | ||
| handlers = | ||
| qualname = sqlalchemy.engine | ||
|
|
||
| [logger_alembic] | ||
| level = INFO | ||
| handlers = | ||
| qualname = alembic | ||
|
|
||
| [handler_console] | ||
| class = StreamHandler | ||
| args = (sys.stderr,) | ||
| level = NOTSET | ||
| formatter = generic | ||
|
|
||
| [formatter_generic] | ||
| format = %(levelname)-5.5s [%(name)s] %(message)s | ||
| datefmt = %H:%M:%S |
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,56 @@ | ||
| # Database Migrations with Alembic | ||
|
|
||
| This directory contains database migration scripts for the A2A SDK, managed by [Alembic](https://alembic.sqlalchemy.org/). | ||
|
|
||
| ## Configuration | ||
|
|
||
| - `alembic.ini`: Global configuration for Alembic, including the database URL. | ||
| - `env.py`: Python script that runs when the Alembic environment is invoked. It configures the SQLAlchemy engine and connects it to the migration context. | ||
| - `versions/`: Directory containing individual migration scripts. | ||
|
|
||
| ## Common Commands | ||
|
|
||
| All commands should be run from the project root using `uv run`. | ||
|
|
||
| ### Viewing Status | ||
| ```bash | ||
| # View current migration version of the database | ||
| uv run alembic current | ||
|
|
||
| # View migration history | ||
| uv run alembic history --verbose | ||
| ``` | ||
|
|
||
| ### Running Migrations | ||
| ```bash | ||
| # Upgrade to the latest version | ||
| uv run alembic upgrade head | ||
|
|
||
| # Downgrade by one version | ||
| uv run alembic downgrade base | ||
|
sokoliva marked this conversation as resolved.
Outdated
|
||
| ``` | ||
|
|
||
| ### Creating Migrations | ||
| ```bash | ||
| # Create a new migration manually | ||
| uv run alembic revision -m "description of changes" | ||
|
|
||
| # Create a new migration automatically (detects changes in models.py) | ||
| uv run alembic revision --autogenerate -m "description of changes" | ||
| ``` | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### "duplicate column name" error | ||
| If you see an error like `sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) duplicate column name: owner`, it usually means the column was already created (perhaps by `Base.metadata.create_all()` in tests or development) but Alembic doesn't know about it yet. | ||
|
|
||
| To fix this, "stamp" the database to tell Alembic it is already at the latest version: | ||
| ```bash | ||
| uv run alembic stamp head | ||
| ``` | ||
|
|
||
| ## How to add a new migration | ||
| 1. Modify the models in `src/a2a/server/models.py`. | ||
| 2. Run `uv run alembic revision --autogenerate -m "Add new field to Task"`. | ||
| 3. Review the generated script in `alembic/versions/`. | ||
| 4. Apply the migration with `uv run alembic upgrade head`. | ||
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,85 @@ | ||
| import asyncio | ||
|
|
||
| from logging.config import fileConfig | ||
|
|
||
| from sqlalchemy import pool | ||
| from sqlalchemy.ext.asyncio import async_engine_from_config | ||
|
|
||
| from a2a.server.models import Base | ||
| from alembic import context | ||
|
|
||
|
|
||
| # this is the Alembic Config object, which provides | ||
| # access to the values within the .ini file in use. | ||
| config = context.config | ||
|
|
||
| # Interpret the config file for Python logging. | ||
| # This line sets up loggers basically. | ||
| if config.config_file_name is not None: | ||
| fileConfig(config.config_file_name) | ||
|
|
||
| # add your model's MetaData object here for 'autogenerate' support | ||
| target_metadata = Base.metadata | ||
|
|
||
| # other values from the config, defined by the needs of env.py, | ||
| # can be acquired: | ||
| # my_important_option = config.get_main_option("my_important_option") | ||
| # ... etc. | ||
|
|
||
|
|
||
| def run_migrations_offline() -> None: | ||
| """Run migrations in 'offline' mode. | ||
|
|
||
| This configures the context with just a URL | ||
| and not an Engine, though an Engine is acceptable | ||
| here as well. By skipping the Engine creation | ||
| we don't even need a DBAPI to be available. | ||
|
|
||
| Calls to context.execute() here emit the given string to the | ||
| script output. | ||
|
|
||
| """ | ||
| url = config.get_main_option('sqlalchemy.url') | ||
| context.configure( | ||
| url=url, | ||
| target_metadata=target_metadata, | ||
| literal_binds=True, | ||
| dialect_opts={'paramstyle': 'named'}, | ||
| ) | ||
|
|
||
| with context.begin_transaction(): | ||
| context.run_migrations() | ||
|
|
||
|
|
||
| def do_run_migrations(connection): | ||
|
Check failure on line 54 in alembic/env.py
|
||
| context.configure(connection=connection, target_metadata=target_metadata) | ||
|
|
||
| with context.begin_transaction(): | ||
| context.run_migrations() | ||
|
|
||
|
|
||
| async def run_async_migrations(): | ||
| """In this scenario we need to create an Engine | ||
| and associate a connection with the context. | ||
| """ | ||
| connectable = async_engine_from_config( | ||
| config.get_section(config.config_ini_section), | ||
| prefix='sqlalchemy.', | ||
| poolclass=pool.NullPool, | ||
| ) | ||
|
|
||
| async with connectable.connect() as connection: | ||
| await connection.run_sync(do_run_migrations) | ||
|
|
||
| await connectable.dispose() | ||
|
|
||
|
|
||
| def run_migrations_online(): | ||
| """Run migrations in 'online' mode.""" | ||
| asyncio.run(run_async_migrations()) | ||
|
|
||
|
|
||
| if context.is_offline_mode(): | ||
| run_migrations_offline() | ||
| else: | ||
| run_migrations_online() | ||
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,28 @@ | ||
| """${message} | ||
|
|
||
| Revision ID: ${up_revision} | ||
| Revises: ${down_revision | comma,n} | ||
| Create Date: ${create_date} | ||
|
|
||
| """ | ||
| from typing import Sequence, Union | ||
|
|
||
| from alembic import op | ||
| import sqlalchemy as sa | ||
| ${imports if imports else ""} | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision: str = ${repr(up_revision)} | ||
| down_revision: Union[str, Sequence[str], None] = ${repr(down_revision)} | ||
| branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)} | ||
| depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)} | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| """Upgrade schema.""" | ||
| ${upgrades if upgrades else "pass"} | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| """Downgrade schema.""" | ||
| ${downgrades if downgrades else "pass"} |
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,38 @@ | ||
| """add_owner_to_task | ||
|
Check failure on line 1 in alembic/versions/6419d2d130f6_add_owner_to_task.py
|
||
|
|
||
| Revision ID: 6419d2d130f6 | ||
| Revises: | ||
| Create Date: 2026-02-17 09:23:06.758085 | ||
|
|
||
| """ | ||
|
|
||
| from collections.abc import Sequence | ||
|
|
||
| import sqlalchemy as sa | ||
|
|
||
| from alembic import op | ||
|
|
||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision: str = '6419d2d130f6' | ||
| down_revision: str | Sequence[str] | None = None | ||
| branch_labels: str | Sequence[str] | None = None | ||
| depends_on: str | Sequence[str] | None = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| """Upgrade schema.""" | ||
| op.add_column( | ||
| 'tasks', | ||
| sa.Column( | ||
| 'owner', | ||
| sa.String(255), | ||
| nullable=False, | ||
| server_default='unknown', # Set your desired default value here | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| """Downgrade schema.""" | ||
| op.drop_column('tasks', 'owner') | ||
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
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.