Skip to content

Add on_change callbacks for managed variables#1699

Open
dmontagu wants to merge 21 commits intomainfrom
managed-variables-on-change
Open

Add on_change callbacks for managed variables#1699
dmontagu wants to merge 21 commits intomainfrom
managed-variables-on-change

Conversation

@dmontagu
Copy link
Contributor

@dmontagu dmontagu commented Feb 10, 2026

Opened as a separate PR to iterate on the API for this a bit. @alexmojaki had some objections on the design in the other PR #1691

Summary

  • Adds Variable.on_change() method to register callbacks that fire when a variable's remote configuration changes
  • Adds VariableProvider.set_on_config_change() / _notify_config_change() for provider-level change detection
  • Change detection in LogfireRemoteVariableProvider.refresh() compares old/new configs and notifies on differences
  • LocalVariableProvider notifies on create_variable, update_variable, and delete_variable
  • Wires up change notifications in Logfire.var() and handles re-wiring on logfire.configure() reconfiguration

Test plan

  • Tests for on_change callback firing on variable updates, creates, and deletes
  • Tests for decorator usage and return value
  • Tests for exception handling in callbacks (caught and logged, doesn't break provider)
  • Tests for multiple callbacks on the same variable
  • Tests for selective notification (only changed variables fire)
  • Tests for reconfigure re-wiring
  • Tests for remote provider change detection
  • Tests for unknown variable names in callbacks

dmontagu and others added 19 commits February 5, 2026 11:09
Add comprehensive tests covering uncovered lines across the variables
module: is_resolve_function edge cases, variant deserialization errors,
remote provider change detection, force refresh, variant diffing,
variable type operations, push_variable_types, and more. Add pragmas
for genuinely untestable code paths (fork handler, unreachable fallback).
Covers: resolve function default without type, duplicate variable name,
on_config_change with unknown variable, and multiple keyword-only params.
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Add a `timeout` field to `RemoteVariablesConfig` (default `(10, 10)`) so
that both the polling thread and the blocking first-resolve path use a
bounded `Session.get` call. Also propagate `timeout_millis` through
`VariableProvider.shutdown()` so thread joins respect the shutdown budget.
…sion optional

- Remove `enabled` field from VariableConfig (disabled variables are now modeled by pointing labels to code_default)
- Add `code_default` handling in `follow_ref` - returns (None, None) to trigger code default fallthrough
- Make `LabelRef.version` optional (None for code_default and label-to-label refs)
- Update `_validate_labels` to skip code_default refs in label validation
- Update tests to use code_default pattern instead of enabled=False
- Remove `enabled` field from VariableConfig reference table
- Document `code_default` as a LabelRef target
- Note that LabelRef.version is optional
- Add explanations for when to use each ref target type
Extract on_change callback functionality into a separate PR to keep
the managed-variables branch focused on the core feature.
Add support for registering callbacks that fire when a variable's
configuration changes, enabling reactive patterns like cache
invalidation and feature flag updates.
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 10, 2026

Deploying logfire-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: cd4d77d
Status: ✅  Deploy successful!
Preview URL: https://45d68fc6.logfire-docs.pages.dev
Branch Preview URL: https://managed-variables-on-change.logfire-docs.pages.dev

View logs

Base automatically changed from managed-variables to main February 13, 2026 20:02
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