Skip to content

POC: Bind AgentCore sessions to one ACS instance using a stable identity - #12770

Draft
Shivs11 wants to merge 17 commits into
shivam/sticky-activitiesfrom
shivam/agentcore-single-session
Draft

Shivs11 wants to merge 17 commits into
shivam/sticky-activitiesfrom
shivam/agentcore-single-session

Conversation

@Shivs11

@Shivs11 Shivs11 commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

What changed?

Adds initial server support for keeping one AgentCore session dedicated to one workflow execution. Builds on #12630.

A starts on shared queue foo → session S acquires A
Later work for A             → sticky queue S
Replacement worker using S   → A's next tasks
  • Workflow tasks and activities that request the workflow's session use the sticky queue named by the stable identity. Activities do not join the session automatically and are opt-in right now using activity session options!
  • The assignment survives queue reload, so a replacement worker using the same stable identity can receive the original workflow's tasks. Assigned workflow queue records are kept after workflow completion to prevent reuse.

Why?

An AgentCore run needs to keep its own session even when its worker stops and is later replaced. Spare worker capacity should not cause that session to pick up another run.

How did you test it?

  • added four new server tests in tests/single_session_taskpoller_test.go and then ran the existing suites.

Pending work and limits

This is an initial happy-path POC for review. The following needs more pondering upon honestly:

  • Versioning and AU workflows: : do not have tests for this; however, pinned workflows with sessions works.
  • Uncertain acquisition outcomes: for example --> History may start A without Matching learning that it succeeded; a later poll could then acquire B for the same S. Isolation in these cases is not guaranteed by this POC.
  • Queue name collisions: this POC assumes session queue names are not also used as normal queue names. The server does not reserve those names or validate the workflow owner of every task sent directly to S.
  • Later scope: Continue-As-New, child workflows, and starting/stopping AgentCore compute.

Suggested review order

This PR is stacked on #12630.

  1. Saved assignment: persistence proto fields, db.go, and queue-record retention.
  2. History binding: RecordWorkflowTaskStarted, mutable-state sticky setters/reset paths, completion/failure/timeouts, and task routing.
  3. Matching: acquisition coordination in task_queue_partition_manager.go; direct initial polling and assignment methods in physical_task_queue_manager.go; the shared request builder in pri_forwarder.go; and assignment persistence in db.go. An empty forwarding source lets the Matching client choose a normal read partition, while the generated client copy preserves session options. Ordinary sticky forwarding remains unchanged. The shared backlog callback still preserves notices received during queue initialization.
  4. Tests: the corresponding owner test files, then tests/single_session_taskpoller_test.go. Read generated files last.

@Shivs11 Shivs11 changed the title POC: Bind AgentCore sessions to one workflow using a stable identity POC: Bind AgentCore sessions to one ACS instance using a stable identity Oct 27, 2026
Serialize initial polls for the same stable identity, then serve the assigned
sticky queue locally. Reuse existing backlog forwarding and retain the first
backlog notification while the sticky queue initializes.

Keep receiver methods and tests in their owning files, preserve review comments,
and document that acquisition failure recovery remains outside this POC.
Comment thread AGENTS.md
- Update API proto: `make update-go-api`
- Always include `-tags test_dep` when running tests. Include the `integration` tag only for integration tests.

## Code Conventions

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just something that i observed an agent do :)

@Shivs11 Shivs11 Oct 28, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the main change that i have added over here is that i have allowed sessionOptions to be sendable on matching poll RPC's for the sole purpose of being able to send the first sticky session poll to a normal task queue partition (and use matching's load balancing)


// Create corresponding WorkflowTaskScheduled event for speculative WT.
// Transient and speculative tasks need a scheduled event before their timeout is recorded.
if workflowTask.Type == enumsspb.WORKFLOW_TASK_TYPE_SPECULATIVE || m.ms.IsTransientWorkflowTask() {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be debatable but the main reason why this has been added is because now, for session based s2s timeouts, we want to not clear stickiness and just place the task back on the sticky task queue. Earlier, for non session based tasks, we were clearing the stickiness of these tasks and then having transient tasks being picked up from the normal task queue without any s2s timeouts. That changes here imo

@ShahabT ShahabT left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed all history side and half of matching side. Thanks for the great work, and sorry for the big list of comments! this is a big change, hence these is much to comment :)

Comment thread service/matching/db.go Resolved
Comment thread service/matching/db.go Resolved
Comment thread service/matching/matching_engine.go Resolved
Comment thread service/matching/matching_engine.go Resolved
Comment thread service/matching/matching_engine.go Resolved
Store the binding policy and stable destination together, keep the sticky
destination synchronized, and reuse a cloned session state in query responses.

Stop creating schedule-to-start timers for ordinary exclusive workflow tasks
while preserving speculative task recovery. Align Matching assignment names
and simplify metadata expiry without duplicating assignment fields.

Update unit and server tests. Acquisition-error, versioning, and offline-query
follow-ups remain deferred.
Comment thread service/matching/matching_engine.go Resolved
Comment thread service/matching/pri_forwarder.go Resolved
Preserve matcher-owned acquisition and exclusive-worker validation while incorporating internal activity session state and updated sticky activity routing. Regenerate the combined persistence protobufs.

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