-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(framework): Propagate run source attribution #7998
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 all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
977c32e
refactor(framework): Simplify run-started extension hook
tanertopal 0a3209d
feat(framework): Propagate run source attribution
tanertopal d4aa97d
fix(framework): Avoid inferring HTTP run source
tanertopal a585da6
Merge main into codex/run-source-best-effort
tanertopal 83c3bf2
Potential fix for pull request finding
tanertopal 6153c40
fix(framework): Derive run sources from literal
tanertopal ce72920
Merge remote-tracking branch 'origin/codex/run-source-best-effort' in…
tanertopal 03eee2e
fix(framework): Do not infer gRPC run source
tanertopal 6be5460
Apply suggestion from @panh99
panh99 a2e3a51
Merge branch 'main' into codex/run-source-best-effort
tanertopal 445b393
Merge branch 'main' into codex/run-source-best-effort
tanertopal 5714621
Simplify run source resolution fallback
tanertopal c1900f5
Extract run source request dependency
tanertopal cf7c3ab
Merge branch 'main' into codex/run-source-best-effort
smoroso 4dc6085
Merge branch 'main' into codex/run-source-best-effort
tanertopal cc42b67
Merge branch 'main' into codex/run-source-best-effort
flwrmachine d9fed81
Update framework/py/flwr/superlink/servicer/control/control_servicer.py
tanertopal 2db4dfb
Update framework/py/flwr/superlink/servicer/control/control_servicer.py
tanertopal 20353c4
Refactor run-source attribution utilities
tanertopal f01b57c
Fix run-source import ordering
tanertopal 7864abc
Configure StartRun test metadata
tanertopal a340d11
Configure remaining StartRun test contexts
tanertopal 6554dce
Bound E2E service cleanup
tanertopal 073d50b
Narrow run-source input to strings
tanertopal 7f635e5
Format run-source test signature
tanertopal 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
|
tanertopal marked this conversation as resolved.
|
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,35 @@ | ||
| # Copyright 2026 Flower Labs GmbH. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # ============================================================================== | ||
| """FastAPI dependency for Control API run-source attribution.""" | ||
|
|
||
| from typing import Annotated | ||
|
|
||
| from fastapi import Depends, Header | ||
|
|
||
| from flwr.superlink.run_source import ( | ||
| RUN_SOURCE_METADATA_KEY, | ||
| RunStartSource, | ||
| resolve_run_start_source, | ||
| ) | ||
|
|
||
|
|
||
| def get_run_source( | ||
| run_source: Annotated[str | None, Header(alias=RUN_SOURCE_METADATA_KEY)] = None, | ||
| ) -> RunStartSource: | ||
| """Return the normalized run source from the request header.""" | ||
| return resolve_run_start_source(run_source) | ||
|
|
||
|
|
||
| RunSourceDependency = Annotated[RunStartSource, Depends(get_run_source)] |
27 changes: 27 additions & 0 deletions
27
framework/py/flwr/superlink/dependencies/run_source_test.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,27 @@ | ||
| # Copyright 2026 Flower Labs GmbH. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # ============================================================================== | ||
| """Tests for the Control API run-source dependency.""" | ||
|
|
||
| from .run_source import get_run_source | ||
|
|
||
|
|
||
| def test_get_run_source_defaults_to_unknown() -> None: | ||
| """Return unknown when the request has no source header.""" | ||
| assert get_run_source() == "unknown" | ||
|
|
||
|
|
||
| def test_get_run_source_normalizes_header_value() -> None: | ||
| """Normalize a caller-provided source header.""" | ||
| assert get_run_source("web_ui") == "web_ui" |
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
|
tanertopal marked this conversation as resolved.
|
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,36 @@ | ||
| # Copyright 2026 Flower Labs GmbH. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # ============================================================================== | ||
| """Run-start source attribution utilities.""" | ||
|
|
||
| from typing import Literal, cast, get_args | ||
|
|
||
| RunStartSource = Literal["cli", "web_ui", "automation", "unknown"] | ||
| RUN_SOURCE_METADATA_KEY = "x-flwr-run-source" | ||
| _RUN_START_SOURCES = frozenset(get_args(RunStartSource)) | ||
|
|
||
|
|
||
| def resolve_run_start_source(value: str | None) -> RunStartSource: | ||
| """Normalize a caller-provided source label for analytics. | ||
|
|
||
| Source attribution is intentionally best effort. Callers can only affect | ||
| the analytics label for their own request, so recognized values are | ||
| trusted and invalid values fall back to ``unknown``. This value is not a | ||
| security or authorization signal. | ||
| """ | ||
| if value is None: | ||
| return "unknown" | ||
| if value not in _RUN_START_SOURCES: | ||
| return "unknown" | ||
| return cast(RunStartSource, value) |
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,33 @@ | ||
| # Copyright 2026 Flower Labs GmbH. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # ============================================================================== | ||
| """Tests for run-start source attribution utilities.""" | ||
|
|
||
| from pytest import mark | ||
|
|
||
| from .run_source import RunStartSource, resolve_run_start_source | ||
|
|
||
|
|
||
| @mark.parametrize( | ||
| ("value", "expected"), | ||
| [ | ||
| (None, "unknown"), | ||
| ("web_ui", "web_ui"), | ||
| ("automation", "automation"), | ||
| ("not-a-source", "unknown"), | ||
| ], | ||
| ) | ||
| def test_resolve_run_start_source(value: str | None, expected: RunStartSource) -> None: | ||
| """Normalize best-effort caller attribution without treating it as auth.""" | ||
| assert resolve_run_start_source(value) == expected |
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
|
tanertopal marked this conversation as resolved.
|
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.