Skip to content

refactor: Enforce ServerCallContext in all TaskStore operations#882

Open
sokoliva wants to merge 3 commits intoa2aproject:1.0-devfrom
sokoliva:Server-Call-Context-Mandatory
Open

refactor: Enforce ServerCallContext in all TaskStore operations#882
sokoliva wants to merge 3 commits intoa2aproject:1.0-devfrom
sokoliva:Server-Call-Context-Mandatory

Conversation

@sokoliva
Copy link
Member

Description

Make ServerCallContext a mandatory parameter across all TaskStore implementations (TaskStore interface, DatabaseTaskStore, and InMemoryTaskStore) and update tests.

Previously, context defaulted to None, which could allow callers to bypass authorization scoping if the context was set to None. By requiring the context, we guarantee that the owner_resolver always has the necessary request context to determine scope boundaries.

Fixes #718 🦕

@sokoliva sokoliva requested a review from guglielmo-san March 20, 2026 16:57
@sokoliva sokoliva requested a review from a team as a code owner March 20, 2026 16:57
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the TaskStore operations to enforce the use of ServerCallContext as a mandatory parameter. This change significantly enhances the security posture by ensuring that all task-related operations are consistently performed within a defined authorization scope, preventing scenarios where context could be inadvertently omitted. The update promotes a more robust and predictable interaction with task storage mechanisms across the application.

Highlights

  • Mandatory ServerCallContext: The ServerCallContext parameter is now mandatory across all TaskStore operations, including the TaskStore interface, DatabaseTaskStore, and InMemoryTaskStore implementations. This change removes the possibility of None being passed as a context, ensuring proper authorization scoping.
  • Enhanced Security and Consistency: By requiring ServerCallContext, the system guarantees that the owner_resolver always has the necessary request context to determine scope boundaries, preventing potential bypasses of authorization scoping that could occur when the context defaulted to None.
  • Updated Owner Resolver: The OwnerResolver type definition and the resolve_user_scope function in owner_resolver.py have been updated to explicitly require ServerCallContext, removing the None option and the associated None check.
  • Comprehensive Test Updates: All relevant test cases in test_database_task_store.py, test_inmemory_task_store.py, and test_owner_resolver.py have been updated to reflect the mandatory ServerCallContext parameter, including the introduction of a TEST_CONTEXT constant for consistent testing.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link

🧪 Code Coverage (vs 1.0-dev)

⬇️ Download Full Report

No coverage changes.

Generated by coverage-comment.yml

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the TaskStore interface and its implementations (DatabaseTaskStore and InMemoryTaskStore) to enforce the use of ServerCallContext in all operations. This change ensures that the owner_resolver always has the necessary request context for determining scope boundaries, addressing a potential authorization bypass. The tests have also been updated to reflect this change.

Comment on lines +29 to +31
def test_resolve_user_default_context():
"""Test resolve_user_scope with default context."""
assert resolve_user_scope(ServerCallContext()) == ''
Copy link
Contributor

Choose a reason for hiding this comment

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

low

The test test_resolve_user_default_context asserts that resolve_user_scope(ServerCallContext()) returns an empty string. This aligns with the change in resolve_user_scope where a missing user in the context results in an empty string. This test validates the behavior of the function when the context is initialized without a user.

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.

1 participant