Skip to content

feat: add shared payment runtime - #184

Draft
parvahuja wants to merge 5 commits into
parv/stacked-pr-cifrom
parv/payment-runtime-v0.11
Draft

feat: add shared payment runtime#184
parvahuja wants to merge 5 commits into
parv/stacked-pr-cifrom
parv/payment-runtime-v0.11

Conversation

@parvahuja

@parvahuja parvahuja commented Jul 28, 2026

Copy link
Copy Markdown
Member

Stack 3 of 8 · depends on #188 · next: #189

Summary

  • add a shared PaymentRuntime with one AnyIO-owned asyncio loop
  • support borrowed methods plus sync, async, and async-context-manager factories
  • expose sync/async lifecycle contexts, credential creation, challenge matching, and events
  • defer callback-triggered close until active calls finish; external close cancels in-flight calls before method teardown

Lifecycle contract

  • direct methods= are borrowed and must be loop-independent
  • method_factories= initialize once and async context managers exit on the owned loop
  • factories and methods must finish work they spawn before returning
  • the runtime is single-use: once closed, it cannot be restarted

Why this shape

AnyIO owns the portal, loop thread, task submission, and loop cleanup. pympp only tracks runtime state, active root calls, and method teardown. The generic coroutine runner and detached-task lease model are intentionally private/out of scope.

This simplification removes 412 net lines from the previous draft. It also declares the tested AnyIO range (>=4.12,<5).

Scope

Runtime foundation only. Existing HTTP and MCP clients are unchanged; HTTPX instrumentation, origin policy, retry/outcome tracking, and MCP integration come in later PRs.

Validation

  • full suite: 805 passed, 41 skipped on Python 3.13
  • focused runtime and Tempo tests: 237 passed
  • clean-wheel smoke: Python 3.11 with minimum AnyIO 4.12.0
  • Ruff, formatting, Pyright, package build, strict Twine check, and dependency check pass

Managed as a stacked change with GitHub Stacks.

@parvahuja
parvahuja marked this pull request as ready for review July 28, 2026 03:13

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6a4c272614

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/mpp/runtime.py Outdated
try:
cleanup(self._bridge.cancel_pending)
if self._method_stack is not None:
cleanup(lambda: self._bridge.run(self._teardown_methods()))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep async context managers in their entering task context

When a factory returns an async context manager that uses task-local state, this submits _teardown_methods() as a new task even though __aenter__ ran in the earlier _initialize_methods() task. For example, an @asynccontextmanager that sets a ContextVar and resets its token in finally consistently raises ValueError: Token was created in a different Context during close(), potentially interrupting cleanup. Keep the exit stack alive in one supervisor task that performs both entry and exit rather than resubmitting teardown separately.

AGENTS.md reference: AGENTS.md:L68-L69

Useful? React with 👍 / 👎.

@parvahuja
parvahuja marked this pull request as draft July 28, 2026 17:19
@parvahuja
parvahuja force-pushed the parv/payment-runtime-v0.11 branch 2 times, most recently from 5d60b7d to b5a4293 Compare July 28, 2026 17:25
@parvahuja
parvahuja changed the base branch from main to parv/mcp-sdk-v1-compat July 28, 2026 17:25
@parvahuja
parvahuja force-pushed the parv/payment-runtime-v0.11 branch from b5a4293 to 07d5dc8 Compare July 28, 2026 18:24
@parvahuja
parvahuja force-pushed the parv/payment-runtime-v0.11 branch from 07d5dc8 to 42cfb85 Compare July 28, 2026 18:26
@parvahuja
parvahuja changed the base branch from parv/mcp-sdk-v1-compat to parv/stacked-pr-ci July 28, 2026 18:28
@parvahuja
parvahuja force-pushed the parv/payment-runtime-v0.11 branch from a9005de to 4aae448 Compare July 29, 2026 00:43
@parvahuja
parvahuja force-pushed the parv/payment-runtime-v0.11 branch from 4aae448 to 8763962 Compare July 29, 2026 01:01
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