fix(core): consistently generated session ids #531
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.
Proposed Changes
Summary of the Problem
Internally, the uAgents have a concept of an Internal and external context variants. The internal one was created and cached inside the agent object.
Due to the nature of the cached internal context, this would leads to some interesting outcomes specifically for the session id. In some cases (like a startup event) the session id can be
None
. Additionally, some session ids values are cached depending on the order of how handlers are called.All of the above means that being able to reliable use the session id for chaining is difficult.
Consistent Generation of Session IDs
Semantically, this change ensures that the following rule is always applied:
The session id is always taken from the triggering envelope, when this is not possible a new session id is always generated
As a result of this, the code is updated so that the context is always built before it is used. This was always the case for the external context, but now is true for the internal context as well. This consistency eliminates some of the quirky cached behaviour that we had beforehand.
More importantly, however, this ensures that the session id can be used by the agent code to track responses from chained sessions.
Linked Issues
n/a
Types of changes
What type of change does this pull request make (put an
x
in the boxes that apply)?Checklist
Put an
x
in the boxes that apply:If applicable
Further comments
[if this is a relatively large or complex change, kick off a discussion by explaining why you chose the solution you did, what alternatives you considered, etc...]