Skip to content

feat(runtime): native_session skips a2a_queue — primitive #5 of 6 - #2144

Merged
hongmingwang-moleculeai merged 1 commit into
stagingfrom
feat/native-session-skip-queue
Apr 27, 2026
Merged

feat(runtime): native_session skips a2a_queue — primitive #5 of 6#2144
hongmingwang-moleculeai merged 1 commit into
stagingfrom
feat/native-session-skip-queue

Conversation

@HongmingWang-Rabbit

Copy link
Copy Markdown
Contributor

Summary

Capability primitive #5 of 6 (task #117). The consumer that validates the template-side declarations already shipped in claude-code template PR #12 and hermes template PR #25.

When a target workspace has declared `provides_native_session=True`, the SDK owns its own queue/session state (claude-agent-sdk's streaming session, hermes-agent's in-container event log). Adding the platform's `a2a_queue` layer on top double-buffers the same in-flight state — and worse, the platform queue's drain timing has no relationship to the SDK's actual readiness, so the queued request might dispatch while the SDK is still busy.

Behavior change: in `handleA2ADispatchError`, when `isUpstreamBusyError(err)` fires and the target declared native_session, return 503 + Retry-After directly without enqueueing. The caller's adapter handles retry on its own schedule, and the SDK's own queue absorbs the request when ready. Response body carries `native_session=true` so callers can distinguish this from queue-failure 503s.

Observability preserved: `logA2AFailure` still runs; broadcaster still fires; activity_logs records the busy event same as the platform-fallback path.

End-to-end validation

This is the FIRST primitive consumer that validates the priority adapters' declarations:

Declares Effect after #2143 + template PRs land
claude-code `provides_native_session=True` (PR #12) busy → 503 (no queue), adapter retries via SDK
hermes `provides_native_session=True` (PR #25) busy → 503 (no queue), adapter retries via SDK
langgraph / crewai / deepagents False (default) busy → enqueue (today's behavior, unchanged)

Tests (2 new)

  • NativeSession_SkipsEnqueue — cache pre-populated; sqlmock has NO `INSERT INTO a2a_queue` expected (regression cover via sqlmock's unexpected-query failure). Asserts 503 + Retry-After + `native_session=true` marker.
  • NoNativeSession_StillEnqueues — negative pin: empty cache, same busy error → falls through to EnqueueA2A (preserves today's behavior for non-native runtimes).

Verification

  • All Go handlers tests pass (2 new + existing)
  • `go build ./...` + `go vet ./...` clean

Stacked

Standalone PR off latest staging — primitives 1-3 are merged, this only depends on the cache (handlers.runtimeOverrides) which lives in #2139.

🤖 Generated with Claude Code

…of 6

When a target workspace's adapter has declared
provides_native_session=True (claude-code SDK's streaming session,
hermes-agent's in-container event log), the SDK owns its own queue/
session state. Adding the platform's a2a_queue layer on top would
double-buffer the same in-flight state — and worse, the platform
queue's drain timing has no relationship to the SDK's actual readiness,
so the queued request might dispatch while the SDK is STILL busy.

Behavior change: in handleA2ADispatchError, when isUpstreamBusyError(err)
fires and the target declared native_session, return 503 + Retry-After
directly without enqueueing. The caller's adapter handles retry on
its own schedule, and the SDK's own queue absorbs the request when
ready. Response body carries native_session=true so callers can
distinguish this from queue-failure 503s.

Observability is preserved: logA2AFailure still runs above; the
broadcaster still fires; the activity_logs row records the busy event
just like the platform-fallback path.

This is the consumer that validates the template-side declarations
already shipped in:
  - molecule-ai-workspace-template-claude-code PR #12
  - molecule-ai-workspace-template-hermes PR #25
Once those merge + image tags bump, claude-code + hermes workspaces'
busy 503s skip the platform queue end-to-end. End-to-end validation
of capability primitive #5.

Tests (2 new):
  - NativeSession_SkipsEnqueue: cache pre-populated, deliberate
    sqlmock with NO INSERT INTO a2a_queue expected — implicit
    regression cover (sqlmock fails on unexpected queries). Asserts
    503 + Retry-After + native_session=true marker in body.
  - NoNativeSession_StillEnqueues: negative pin — empty cache, same
    busy error → falls through to EnqueueA2A (which fails in this
    test, falls through to legacy 503 without native_session marker).

Verification:
  - All Go handlers tests pass (2 new + existing)
  - go build + go vet clean

See project memory `project_runtime_native_pluggable.md`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Merged via the queue into staging with commit 34b92c3 Apr 27, 2026
15 checks passed
@molecule-ai
molecule-ai Bot deleted the feat/native-session-skip-queue branch May 20, 2026 06:21
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