Skip to content

Fix: clear the discrete observation-buffer slot when an emitter is unsubscribed - #83

Open
docxology wants to merge 1 commit into
ReactiveBayes:mainfrom
docxology:fix/unsubscribe-clear-discrete-buffer
Open

Fix: clear the discrete observation-buffer slot when an emitter is unsubscribed#83
docxology wants to merge 1 commit into
ReactiveBayes:mainfrom
docxology:fix/unsubscribe-clear-discrete-buffer

Conversation

@docxology

Copy link
Copy Markdown

Summary

When Rocket.unsubscribe!(emitter, receiver) severs an emitter from a discrete receiver, the receiver's
Observations.buffer still holds the emitter's slot (nothing after a clear, or a stale Observation). The
discrete forwarder (src/markovblanket.jl:73-80) requires all buffer slots to be filled before emitting, so
the removed emitter's dead slot blocks all future observations — the environment silently stops emitting to the
surviving agents.

Change

src/abstractentity.jl — in Rocket.unsubscribe!(emitter::AbstractEntity, receiver::AbstractEntity), when the
receiver is discrete, delete the emitter from the receiver's observation buffer:

function Rocket.unsubscribe!(emitter::AbstractEntity, receiver::AbstractEntity)
    Rocket.unsubscribe!(sensors(receiver)[emitter])
    delete!(sensors(receiver), emitter)
    delete!(actuators(emitter), receiver)
    # A discrete receiver buffers one observation per emitter; drop the removed
    # emitter's slot so the "wait for all emitters" check can still complete.
    if receiver isa AbstractEntity{T,DiscreteEntity} where {T}
        delete!(observations(receiver).buffer, emitter)
    end
end

How to verify

Add/run the discrete unsubscribe regression:

env = RxEnvironment(MockEnvironment(); is_discrete=true)
a1 = add!(env, MockEntity()); a2 = add!(env, MockEntity())
obs = keep(Any); subscribe_to_observations!(a1, obs)
send!(env, a1, 0.0); send!(env, a2, 0.0)   # obs.length == 1
unsubscribe!(a2, env)
send!(env, a1, 0.0)                          # obs.length == 2  (was stuck at 1)

Run julia --project=. -e 'using Pkg; Pkg.test()' — discrete entity tests remain green.

Notes

The continuous path is unaffected. This is a focused one-line-class fix; a follow-up could also add a
clear_buffer!-style reset on unsubscribe for robustness.

When a discrete receiver unsubscribes an emitter, the emitter's per-source
observation buffer slot was left behind. The discrete forwarder only emits an
ObservationCollection once every buffered source has contributed, so the stale
empty slot permanently blocked all further observations to surviving agents.
Drop the emitter's buffer slot on unsubscribe.
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