doc/adr/0003-direct-bookmark-management-in-workflowexecutioncontext.md
Date: 2025-04-01
Accepted
Currently, ActivityExecutionContext maintains a temporary list of bookmarks created by the activity during its execution. After the activity completes, a middleware is responsible for copying these bookmarks into the WorkflowExecutionContext.Bookmarks list, which is then persisted to the database.
This architecture leads to a subtle issue upon resumption:
WorkflowExecutionContext and its Bookmarks are restored from the database.ActivityExecutionContext's temporary Bookmarks list remains empty.However, there is an existing convention that determines that if an activity created a bookmark during its execution, the activity will not automatically complete.
Specifically, this is implemented in the AutoCompleteBehavior, which is installed by the CodeActivity and possibly by custom activities.
To keep this behavior in tact, we will still maintain a private list of bookmarks, one that is explicitly purposed for maintaining new* bookmarks, temporarily for the lifetime of the ActivityExecutionContext in memory.
Eliminate the temporary Bookmarks list in ActivityExecutionContext. Instead, have activities add bookmarks directly to the WorkflowExecutionContext.Bookmarks list.
This is possible and safe because each Bookmark already contains:
ActivityIdActivityInstanceIdThese references allow accurate tracking and filtering of bookmarks, even when multiple activities are active.
Additionally, maintain a new temporary bookmarks list that explicitly stores newly created bookmarks. This list does not have to be copied into the WorkflowExecutionContext's Bookmarks property, given that this property will now be updated directly.
ActivityExecutionContext.Bookmarks list on resume. Rejected due to added complexity and duplication of state.