Skip to content

Isolate concurrent Agent sessions#68

Draft
hi-michael-li wants to merge 1 commit into
mainfrom
michael-li/stirrup-07-session-isolation
Draft

Isolate concurrent Agent sessions#68
hi-michael-li wants to merge 1 commit into
mainfrom
michael-li/stirrup-07-session-isolation

Conversation

@hi-michael-li

@hi-michael-li hi-michael-li commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Why

Concurrent sessions could share provider, logger, skill, output, and lifecycle state. One session could leak data into or prematurely close another.

What

  • Give every session a detached runtime with session-local tools, output/finish/cache state, skills, provider lifecycle, and logger lifecycle.
  • Support overlapping sessions for exact built-in providers and loggers through private reconstruction rather than a public cloning protocol.
  • Keep custom providers, custom loggers, and built-in subclasses usable sequentially; reject overlapping use of the same configured object before resource entry.
  • Resolve the built-in ViewImage/code-backend dependency explicitly.
  • Require SessionAgent.run() and run_tool() to execute only inside their own active context.
  • Keep independent nested roots isolated and require delegated sub-agent tools to have an active parent session.
  • Shield teardown from cancellation, preserve primary exceptions, and restore task-local state on every exit path.
  • Keep signal handling main-thread/ref-count safe and reserve identical cache-enabled tasks through teardown.
  • Preserve intentional Slack coordination objects while isolating each run's lifecycle.
  • Require Rich 14.1 or newer for concurrent built-in live displays.

Deliberate limits

  • Custom providers, custom loggers, and built-in subclasses are sequential-only when they share the same configured object; use separate instances for concurrency.
  • A custom ViewImage/backend pair cannot borrow a different parent execution environment.
  • Concurrent identical cache-enabled root runs are rejected; cache durability itself is handled by the cache PR.

Testing

  • Focused session coverage: 27 passed.
  • Full suite: 190 passed.
  • Ruff, formatting, strict docs, package build, and diff checks pass. Type checking reports only the existing Slack optional-API warning.

@hi-michael-li
hi-michael-li force-pushed the michael-li/stirrup-07-session-isolation branch from 13dc308 to 9641abc Compare July 14, 2026 06:27
@hi-michael-li
hi-michael-li force-pushed the michael-li/stirrup-06-terminal-finish branch 2 times, most recently from 1c538c0 to 9132046 Compare July 14, 2026 13:24
@hi-michael-li
hi-michael-li force-pushed the michael-li/stirrup-07-session-isolation branch 2 times, most recently from 6a7d499 to dda2ee1 Compare July 16, 2026 02:18
@hi-michael-li
hi-michael-li force-pushed the michael-li/stirrup-06-terminal-finish branch from 9132046 to b0090ab Compare July 16, 2026 02:18
@hi-michael-li
hi-michael-li force-pushed the michael-li/stirrup-07-session-isolation branch from dda2ee1 to 325206a Compare July 16, 2026 10:33
@hi-michael-li
hi-michael-li force-pushed the michael-li/stirrup-06-terminal-finish branch 2 times, most recently from 78a368a to c0d46ea Compare July 17, 2026 05:08
@hi-michael-li
hi-michael-li force-pushed the michael-li/stirrup-07-session-isolation branch from 325206a to 27b6e2d Compare July 17, 2026 05:08
@hi-michael-li
hi-michael-li force-pushed the michael-li/stirrup-06-terminal-finish branch from c0d46ea to 4a2912b Compare July 17, 2026 06:17
@hi-michael-li
hi-michael-li force-pushed the michael-li/stirrup-07-session-isolation branch from 27b6e2d to ecf0b18 Compare July 17, 2026 06:17
@hi-michael-li
hi-michael-li force-pushed the michael-li/stirrup-06-terminal-finish branch from 4a2912b to 3f73c63 Compare July 17, 2026 07:10
@hi-michael-li
hi-michael-li force-pushed the michael-li/stirrup-07-session-isolation branch from ecf0b18 to 87a411e Compare July 17, 2026 07:10
@hi-michael-li
hi-michael-li changed the base branch from michael-li/stirrup-06-terminal-finish to main July 17, 2026 10:48
@hi-michael-li

Copy link
Copy Markdown
Contributor Author

Planned simplification

I’m going to narrow session isolation by removing the generic recursive provider/logger cloning framework:

  • concurrent sessions remain supported for exact built-in providers and the built-in logger;
  • custom providers, custom loggers, and built-in subclasses remain usable sequentially but overlapping use is rejected clearly;
  • retain one task-local session context and explicit built-in dependency handling;
  • reduce tests that only pin the generic cloning protocol.

This deliberately trades unsupported custom concurrency for a smaller, clearer ownership model.

@hi-michael-li
hi-michael-li force-pushed the michael-li/stirrup-07-session-isolation branch from 4f69eff to 61ae468 Compare July 17, 2026 17:01
@hi-michael-li hi-michael-li changed the title [7/9] Isolate concurrent Agent sessions Isolate concurrent Agent sessions Jul 17, 2026
@hi-michael-li

Copy link
Copy Markdown
Contributor Author

Simplification complete

  • Head: 61ae468
  • Scope: 41 files (+4852/-689) → 12 files (+1987/-228)
  • Rebuilt directly on main without a public provider/logger cloning protocol.
  • Concurrent exact built-ins are supported; shared custom providers/loggers/subclasses are deliberately sequential-only and overlap-safe.
  • Added explicit cancellation cleanup, session ownership, cache-task reservation, nested-root/subagent boundaries, and Rich 14.1 minimum support.
  • Validation: 27 focused session tests; 190 full-suite tests; Ruff, formatting, strict docs, package build, type and diff checks pass (apart from the existing Slack type warning).

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