Skip to content

feat: introduce SSE (ref AI-984) - #28

Merged
toddbaert merged 13 commits into
mainfrom
feat/sse
Nov 16, 2026
Merged

toddbaert merged 13 commits into
mainfrom
feat/sse

Conversation

@leakonvalinka

@leakonvalinka leakonvalinka commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor
  • introduces SSE functionality to enable real-time notifications for flag config changes

References

https://dt-rnd.atlassian.net/browse/AI-984

@leakonvalinka leakonvalinka changed the title feat: introduce SSE feat: introduce SSE (ref AI-984) Oct 22, 2026
@toddbaert

Copy link
Copy Markdown
Collaborator

Heads up: harness v1.4.0 adds a scenario for polling at 10s after a failed fetch, even with SSE connected. Only a successful fetch while SSE is connected relaxes to 10m; connect alone no longer does. Spec: https://github.com/Dynatrace-Internal/feature-management-knowledge-base/pull/177; Java: Dynatrace/openfeature-provider-java#44; Node: Dynatrace/openfeature-provider-js#46.

Comment thread src/dynatrace/openfeature/_sse.py Resolved
@leakonvalinka
leakonvalinka marked this pull request as ready for review November 5, 2026 10:49
Copilot AI balanced review requested due to automatic review settings November 5, 2026 10:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved SSE and polling defects can block reconnection indefinitely, discard needed refetches, miss stream URL changes, and delay recovery after fetch failures.

5 open issues
What changed in this PR

Adds server-sent events (SSE) support to the Dynatrace OpenFeature provider so flag-change notifications trigger configuration refreshes, with polling as a fallback.

Changes:

  • Adds stream discovery, message parsing, reconnection, and shutdown handling.
  • Integrates SSE-triggered refreshes with single-flight polling and configurable polling intervals.
  • Adds unit and end-to-end coverage, dependencies, and user documentation.
File Description
uv.lock Locks the new SSE client dependency.
tests/​test_sse.py Tests stream lifecycle, callbacks, and logging.
tests/​test_sse_message.py Tests message parsing and invalid payload handling.
tests/​test_provider_sse.py Tests provider-level SSE integration and lifecycle.
tests/​test_polling.py Tests interval changes and deferred refresh coalescing.
tests/​test_cdn_config.py Tests advertised SSE URL extraction.
tests/​sse_server.py Adds a local SSE server for socket-based tests.
tests/​e2e/​test_e2e.py Adds SSE acceptance steps and event assertions.
tests/​e2e/​mock_server.py Adds SSE controls to the mock-server client.
tests/​e2e/​conftest.py Enables previously skipped single-flight scenarios.
tests/​conftest.py Provides the local SSE server fixture.
src/​dynatrace/​openfeature/​provider.py Connects SSE notifications to provider refresh and polling.
src/​dynatrace/​openfeature/​_sse.py Implements streaming, reconnection, and shutdown.
src/​dynatrace/​openfeature/​_sse_message.py Parses flat and wrapped SSE messages.
src/​dynatrace/​openfeature/​_polling.py Supports dynamic cadence and coalesced immediate refreshes.
src/​dynatrace/​openfeature/​_cdn.py Exposes Last-Modified timestamps for refresh deduplication.
src/​dynatrace/​openfeature/​_cdn_config.py Extracts SSE endpoints from configuration.
README.md Documents SSE behavior and the disable option.
pyproject.toml Declares the SSE dependency and typing override.
.gitignore Excludes IDE and macOS artifacts.

Review effort: Balanced

Comment thread src/dynatrace/openfeature/_polling.py Resolved
Comment thread src/dynatrace/openfeature/_sse.py Resolved
Comment thread src/dynatrace/openfeature/provider.py Resolved
Comment thread src/dynatrace/openfeature/provider.py Resolved
Comment thread tests/sse_server.py Resolved
Comment thread src/dynatrace/openfeature/_sse.py Resolved
Comment thread fm-provider-test-harness Resolved
Comment thread src/dynatrace/openfeature/provider.py Resolved
Comment thread src/dynatrace/openfeature/_sse.py Resolved
Comment thread src/dynatrace/openfeature/_polling.py Resolved
Comment thread src/dynatrace/openfeature/_polling.py Resolved
Comment thread src/dynatrace/openfeature/_polling.py Resolved
Comment thread src/dynatrace/openfeature/provider.py Resolved
Comment thread src/dynatrace/openfeature/provider.py Resolved
Comment thread src/dynatrace/openfeature/provider.py Resolved
Comment thread src/dynatrace/openfeature/provider.py Resolved
Copilot AI balanced review requested due to automatic review settings November 16, 2026 12:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

An SSE callback race can submit a fetch after stop() returns, allowing a CDN request to start after shutdown unless the stop event is rechecked under the condition lock.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Prevent SSE callbacks from submitting fetches after poller shutdown

src/​dynatrace/​openfeature/​_polling.py:97

An SSE callback can pass the stop check, pause, and acquire _cond after stop() has returned, then submit a new fetch on the stopped poller. Because _poll() invokes the fetcher before checking cancellation, this can start a CDN request after shutdown. Recheck _stop_event under _cond before deferring or submitting work.

4 resolved since last review

Review effort: Balanced

@leakonvalinka

Copy link
Copy Markdown
Contributor Author

@toddbaert I made the variable-name adjustments you proposed, but when looking at the other languages, they use different ones entirely (for example, looking at the polling manager in java and .net). They both use inFlightSseRefetch instead inFlightLastModified or issuedFor instead of previousInFlight, for example. I think it makes sense to re-adjust them here to match the others.

# Conflicts:
#	uv.lock
Copilot AI balanced review requested due to automatic review settings November 16, 2026 13:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

An SSE trigger can race with stop() and submit a fetch after shutdown because the stop flag is not rechecked under the condition lock.

2 open issues

Review effort: Balanced

Comment thread src/dynatrace/openfeature/_polling.py Resolved
Copilot AI balanced review requested due to automatic review settings November 16, 2026 13:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

A race between the stop check and condition-lock acquisition allows an SSE callback to submit a fetch after shutdown, potentially issuing a CDN request despite cancellation.

2 open issues

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 16, 2026 15:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human assessment is needed to evaluate timezone-dependent suppression of newer SSE notifications and an initialization race that can make rotation tests fail despite correct behavior.

1 open issue
1 resolved since last review

Review effort: Balanced

Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
Copilot AI balanced review requested due to automatic review settings November 16, 2026 19:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the SSE refresh and polling-fallback changes.

1 open issue

Review effort: Balanced

Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
Copilot AI balanced review requested due to automatic review settings November 16, 2026 19:52
@toddbaert

Copy link
Copy Markdown
Collaborator

@toddbaert I made the variable-name adjustments you proposed, but when looking at the other languages, they use different ones entirely (for example, looking at the polling manager in java and .net). They both use inFlightSseRefetch instead inFlightLastModified or issuedFor instead of previousInFlight, for example. I think it makes sense to re-adjust them here to match the others.

agree, done.

Signed-off-by: Todd Baert <todd.baert@dynatrace.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

A re-initialization race can commit a rejected poll response’s validators alongside a different configuration body, enabling later 304 responses for a configuration that was never applied.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment on lines +104 to +107
pending = self._pending_cache
if pending is not None:
self._cache = pending
self._pending_cache = None

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A repeated initialize() is now a no-op (6387831), so there's no second fetch to race with the running poller. Tracked across providers in AI-1639.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The shutdown + re-initialize variant from the latest review is real but narrow (a poll has to finish between its stop check and its apply while the lifecycle is replaced). Same gap exists in all our providers, so we'll fix it consistently there: poll callbacks name the poller they came from and the provider drops them unless it's still current, like the SSE callbacks. Tracked in AI-1639.

Copilot AI balanced review requested due to automatic review settings November 16, 2026 19:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Concurrent initialization and polling can commit validators from a rejected configuration, causing subsequent requests to return 304 indefinitely while an older configuration remains loaded.

1 open issue

Review effort: Balanced

Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
Copilot AI balanced review requested due to automatic review settings November 16, 2026 20:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human assessment is needed for a critical lifecycle race that can let a stale fetch worker apply flags and close or replace the new lifecycle’s SSE stream after shutdown and reinitialization.

1 open issue

Review effort: Balanced

@toddbaert
toddbaert merged commit 6b5fedc into main Nov 16, 2026
18 checks passed
@toddbaert
toddbaert deleted the feat/sse branch November 16, 2026 21:06
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.

3 participants