Skip to content

feat(runtime): add canonical turn dispatch boundary - #941

Closed
Neonforge98 wants to merge 1 commit into
codex/durable-turn-receiptsfrom
codex/turn-dispatch-service
Closed

feat(runtime): add canonical turn dispatch boundary#941
Neonforge98 wants to merge 1 commit into
codex/durable-turn-receiptsfrom
codex/turn-dispatch-service

Conversation

@Neonforge98

Copy link
Copy Markdown
Collaborator

Problem

Frontend turn producers independently combined lifecycle reservation, optimistic status, transport dispatch, idempotency, and terminal waiting. That made IPC response loss look like rejection even when the backend had already accepted the exact turn, let WorkItem composer intent X lose attribution when execution became WorkItemRun Y, and allowed a delayed terminal to be confused with a newer generation.

Solution

  • Add one TurnDispatchService that synchronously reserves intent plus generation, sends through SessionService, reconciles durable receipts, and exposes exact-generation finality waits.
  • Return typed acknowledgements from native and CLI adapters and share one Zod turn-intent status contract across both CLI receipts and agent_turn_intent_status.
  • Alias backend-selected effective identities to the original frontend generation without overwriting conflicts.
  • Retain bounded exact-generation terminals while preventing old terminals from changing a newer turn phase.
  • Keep active intent mappings out of the recent-history LRU and retire them on terminal, dead-man, or session cleanup.
  • Preserve rollout compatibility for legacy producers: backend-minted unknown intents are accepted only when the session has no active canonical mapping.

Potential risks

  • This is a stacked PR and requires fix(runtime): make turn acceptance retry-safe #940; its base is codex/durable-turn-receipts so the typed backend receipt/status command is present first.
  • Effective WorkItemRun and ambiguous response-loss receipts start a bounded-backoff local status monitor. It stops on exact terminal, generation supersession, session cleanup, or test reset; queued/running execution is intentionally not failed by elapsed time alone.
  • Existing producers are not migrated in this PR. Their behavior remains compatible, and migration is isolated in the next PR.
  • No Team Chat payload, Work Item UI, conversation plane, continuation store, cloud API, or database schema changes are included.

Verification

  • 100 focused Vitest cases passed across TurnDispatchService, exact lifecycle, intent aliases, native receipt parsing/terminal attribution, CLI transport receipts, and shared schemas.
  • pnpm typecheck
  • ESLint and Prettier on all 21 changed files
  • Focused madge traversal: 973 files, no circular dependency
  • Normal pre-commit lint-staged, TypeScript, and commit-stats hooks passed

Architecture audit: SessionService remains the transport/context owner; TurnDispatchService owns only intent reservation, receipt reconciliation, and finality. UI transcript writes and conversation-plane projection remain outside it.

Map composer and backend-selected turn identities onto one exact lifecycle generation, and reconcile lost responses through durable receipts.

Return typed native and CLI acknowledgements while preserving legacy terminal handling until producer migration completes.
@Harry19081 Harry19081 added enhancement New feature or request agent Agent runtime, behavior, memory, providers, or orchestration sessions Sessions, history, replay, sidebar, workspace, or worktrees labels Aug 25, 2026
@Neonforge98

Copy link
Copy Markdown
Collaborator Author

Superseded by the final two-PR design: #844 removes the Work Item-specific remote continuation bridge, and stacked #939 keeps the reusable audience routing plus sender-local provider-native continuation. This dispatcher/store/handoff stack is intentionally retired.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent Agent runtime, behavior, memory, providers, or orchestration enhancement New feature or request sessions Sessions, history, replay, sidebar, workspace, or worktrees

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants