Skip to content

fix: don't drop deferred custom events in ops.testing - #2811

Draft
tonyandrewmeyer wants to merge 2 commits into
canonical:mainfrom
tonyandrewmeyer:fix/scenario-deferred-custom-events
Draft

tonyandrewmeyer wants to merge 2 commits into
canonical:mainfrom
tonyandrewmeyer:fix/scenario-deferred-custom-events

Conversation

@tonyandrewmeyer

@tonyandrewmeyer tonyandrewmeyer commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

State.deferred only picks up a notice if its event's handle path matches ops' event regex, which needs an on/. A deferred custom event from an ObjectEvents created with a key (MyCharm/on[key]/event[n]), or from an EventSource directly on the charm (MyCharm/event[n]), is silently dropped, so its handler never runs again, although ops itself re-emits every notice whatever the path. The same snapshot also shows up in State.stored_states as a bogus StoredState.

This reads every notice instead, as ops does, and leaves anything with a notice out of the stored states.

Hyrum has one newly failing test and none newly passing. Valkey's test_start_primary defers unit_fully_started (an EventSource on its BaseEvents object) in one start run and asserts the status after the next. With this change the deferred event is re-emitted before that start, as it would be in Juju, so the status differs. I think that's the test relying on the bug rather than a reason to keep it, so I think we should make this change, but open a PR to fix things there.

It turned up in a multi-charm test of Valkey, where the dropped event meant its start lock was never released.

claude and others added 2 commits October 9, 2026 15:43
State.deferred only picked up notices whose event snapshot matched ops'
event regex, which needs an 'on/' in the handle path. A custom event from
an ObjectEvents created with a key ('MyCharm/on[key]/event[n]') or from an
EventSource directly on the charm ('MyCharm/event[n]') doesn't have one,
so the deferral was silently dropped and the event never ran again, while
ops itself re-emits every notice. The same snapshot then showed up in
State.stored_states as a bogus StoredState.

Read every notice instead, and leave anything with a notice out of the
stored states.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011NfZieBLjUD8cULjqRQpHm

This branch has not been deployed

No deployments
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.

2 participants