Repository navigation
Conversation
THardy98
force-pushed
the
demo/activity-session-cache
branch
2 times, most recently
from
October 29, 2026 16:22
3db15f1 to
903ea36
Compare
Conversation workflows run turns that each need every earlier turn, which workers cache locally and otherwise fetch at a simulated cost. The workflow, activity, worker, and fleet code is shared by the sample's entrypoints. `activity_sessions.affinity` runs a batch per mode on a fresh fleet and compares turns fetched and how many workflows shared a worker: - none: ordinary task-queue routing - affinity: turns run inside `workflow.activity_session(...)` on shared session workers - single-session: the same on one single-session worker per workflow
`activity_sessions.single_session` shows both sides of single-session binding across the loss of the whole fleet: bound workers take no further work, every workflow stalls when the fleet dies, workers with new stable identities run only the unbound workflows, and the original workers resume their own workflows when restarted with the same identities. Each phase advances on an observed condition and records a check.
Shared Rich building blocks render both entrypoints: - a turn grid: one row per workflow, one cell per turn, labeled with the worker that ran it and the turns it fetched, shaded by turns fetched - stat tiles for the affinity comparison - a phase banner and workflow and worker status tables (icon, label, and status color) for the single-session lifecycle - a check list A shared runner re-renders each entrypoint's layout while it runs; --no-live prints only the summary. Adds Rich as the sample's dependency group.
Run both entrypoints end to end against a session-capable server: the affinity comparison in every mode, and the single-session lifecycle. Opt in with TEMPORAL_TEST_ACTIVITY_SESSION_SAMPLE=1.
THardy98
force-pushed
the
demo/activity-session-cache
branch
from
October 29, 2026 17:38
903ea36 to
e628529
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Add an experimental sample showing how activity sessions keep a workflow's activities on one worker, so they can reuse worker-local conversation history, and how single-session workers bind workflows to stable identities.
conversation_stepactivities. Turnnneeds every earlier turn. Each worker caches the turns it holds and fetches only the turns it is missing, with simulated latency per turn (--fetch-seconds). The workflow, activity, worker, and fleet code is shared by two entrypoints.activity_sessions.affinityruns a batch of workflows per mode on a fresh worker fleet and compares turns fetched, time spent fetching, and the most workflows any one worker served:none: ordinary task-queue routing; workers keep fetching turns they missed.affinity: turns run insideworkflow.activity_session(ActivitySessionOptions(placement=UseWorkflowSession()))on shared session workers (WorkerSessionConfig()); nothing is fetched.single-session: the same on one single-session worker per workflow (SingleSessionAdmission(stable_identity=...)); nothing is fetched and each worker serves one workflow.activity_sessions.single_sessionshows both sides of single-session binding across the loss of the whole fleet, in four phases: N workflows and M workers start, each worker binds one workflow and the rest get none; the fleet is killed and every workflow stalls; N - M workers with new stable identities run only the unbound workflows while the bound ones stay stalled; the original M workers restart with their stable identities and resume their own workflows.--no-liveprints only the summary.Requirements and scope
Requires the experimental SDK from temporalio/sdk-python#1979 and a server built from the
shivam/agentcore-single-sessionbranch of https://github.com/temporalio/temporal, with sticky activity execution enabled for the namespace. The README explains running with the feature SDK interpreter.Restarted single-session workers start with an empty cache and fetch the history once; persisting the cache across restarts is a follow-up.
Validation
TEMPORAL_TEST_ACTIVITY_SESSION_SAMPLE=1): 13 passed against the custom server.