Skip to content

Unify new and resumed turns in the conversation worker #876

Closed

Description

@dcramer

Objective

Run new and resumed asynchronous turns through one conversation-owned worker workflow under the existing mailbox and lease.

This is not an exercise in designing a generic runtime API. The boundary should emerge by consolidating the two real Slack paths while preserving behavior, then be proven by agent-dispatch in #882.

Current state

  • processConversationWork already owns mailbox, lease, check-in, yield, redelivery, and wake recovery.
  • AgentRunner already owns agent execution and resumable session-record mechanics.
  • New Slack turns use SlackTurnRuntime + reply-executor.ts.
  • Resumed turns re-enter the same queue but use agent-continue-runner.ts + slack-resume.ts for a separate restoration, outcome, delivery, and terminalization lifecycle.

Scope

  • Reduce the signed queue wake payload to conversationId; destination and source are loaded from durable conversation work rather than supplied by the queue callback.
  • Add one worker decision loop that, under the conversation lease, either resumes the active durable turn or starts the next mailbox turn.
  • Route authorization completion back through conversation work: OAuth callbacks persist the completed authorization attempt and send a wake-up hint instead of calling the agent resume lifecycle directly.
  • Share durable restoration, AgentRunner request construction, outcome handling, completion ordering, and terminalization between new and resumed work where their behavior is actually the same.
  • Keep provider concerns in Slack-owned code: message/thread parsing, installation hydration, actor lookup, status/reactions, authorization UX, formatting, and reply delivery.
  • Keep conversationId, turnId, actor, credential subject, destination, source, model/reasoning configuration, artifacts, sandbox state, and history explicit across slices.
  • Preserve steering/defer behavior when new mailbox input arrives while a turn is resumable or active.
  • Make input handling explicit enough to preserve the current distinction between steerable Slack messages and ordered future work; do not treat every pending mailbox item as active-turn steering.
  • Preserve completion policy differences without separate lifecycles: interactive auth pause versus non-interactive blocking, Slack no-reply versus required visible output, and provider reply versus future internal result delivery.
  • Establish one delivery fence rule: after the completion target accepts output, retries may repair durable state but cannot deliver again.
  • Keep local CLI synchronous.

Completion

  • One leased worker path chooses start versus resume for Slack conversations.
  • Queue wake payloads contain only conversationId, and stale or forged callback data cannot change durable routing.
  • Initial and resumed slices use the same turn restoration and outcome/terminalization rules.
  • OAuth completion cannot execute an agent slice outside the conversation lease.
  • Slack-specific code is limited to provider input, UX, and delivery responsibilities.
  • Timeout, cooperative yield, auth pause, no-reply, success, recoverable failure, and terminal failure preserve current durable behavior.
  • Ordered mailbox work is not accidentally injected as steering into the active turn.
  • Post-delivery persistence failure remains repairable without producing a duplicate reply/result.
  • Queue redelivery, stale session versions, duplicate wakes, and hard-worker recovery cannot advance or deliver a turn twice.
  • Model profile, reasoning, actor, authority, artifacts, sandbox, and history survive continuation.
  • The separate Slack continuation lifecycle is deleted or reduced to provider adaptation with no independent turn ownership.
  • Integration coverage proves new turn, timeout resume, yield resume, auth resume, worker recovery, duplicate wake, and delivery fencing.

Non-goals

Implementation checkpoints

Each checkpoint should be independently mergeable and behavior-preserving. Do not start the next checkpoint by introducing abstractions that the current checkpoint does not need.

1. Conversation-id wake-up

  • Add an owning runtime schema for the queue payload and infer its TypeScript type from that schema.
  • Remove destination from queue producers, signatures, callbacks, and worker inputs; queue messages carry only conversationId.
  • Load destination and routing from durable conversation work after callback verification.
  • Switch readers and writers together. Vercel push queues are partitioned by deployment and deliver messages to the same deployment that published them, so old deployments drain their old payloads while the new deployment uses the new contract.
  • Keep first-contact ingress responsible for atomically establishing or validating the durable conversation route when it appends the first mailbox item.
  • Update queue, signature, callback, heartbeat, and worker tests before changing turn behavior.

2. One leased Slack decision loop

  • Under the acquired conversation lease, inspect durable active-turn/session state first.
  • Resume valid active work; otherwise start the next pending mailbox input.
  • Preserve the existing input-commit rule: durably checkpoint the prompt and any required active-task reference before acknowledging the mailbox item.
  • Preserve the current rules for a pending Slack message that may steer, must defer, or starts a later turn.
  • Do not choose resume behavior from conversation.source alone; resource-event conversations already use Slack execution behavior.
  • Treat completed authorization as durable state that makes the active turn runnable; the callback wakes the conversation and the leased worker performs the resume.

3. Consolidate Slack start/resume ownership

  • Move only behavior proven identical by the two paths: durable restoration, AgentRunner request materialization, session outcomes, delivery fencing, and terminalization.
  • Leave Slack provider hydration, status/reactions, auth UX, formatting, backfill, attachments, and delivery in Slack-owned modules.
  • Delete the independent continuation lifecycle only after focused parity tests pass.
  • Remove direct resumeSlackTurn / resumeAuthorizedRequest execution from OAuth handlers after queue-driven auth resume parity is proven.

Validation map

  • Queue payload, idempotency, lease, wake, stale delivery, and recovery behavior: tests/component/task-execution/conversation-work.test.ts and tests/component/vercel-queue-dev.test.ts.
  • Slack mailbox reconstruction, ack, steering, defer, and worker-result behavior: tests/component/task-execution/slack-conversation-work.test.ts.
  • Timeout/yield session-record mechanics: tests/integration/runtime/agent-run-agent-continue.test.ts.
  • Slack automatic continuation, hard-worker recovery, actor restoration, and delivery fencing: tests/integration/agent-continue-slack.test.ts.
  • OAuth status, auth re-pause, reply formatting, and failure behavior: tests/integration/oauth-resume-slack.test.ts plus the OAuth handler unit tests.
  • Missing-wake and expired-lease repair: tests/integration/heartbeat.test.ts.

Activity

  1. added 13 commits that reference this issue on Jul 13, 2026
    706b40b
    d7335fa
    357081f
    046eddd
    f092a44
    90749e7
    2fbf44f
    0d3db15
    9932d6d
    032b8ca
    17641a7
    3bf94fa
    e78f8b3
  2. 18 remaining items

  3. changed the title [-]Extract a conversation-neutral turn runtime[/-] [+]Unify new and resumed turns in the conversation worker[/+] on Jul 23, 2026
  4. dcramer commented on Jul 23, 2026

    @dcramer
    MemberAuthor

    Checkpoint 1 reader-side implementation is now complete locally: queue contracts are runtime-schema-owned, verification accepts signed v1 destination-bearing payloads and signed v2 conversation-id-only wakes, callback/worker code normalizes both to conversationId, and the worker loads destination from persisted conversation work. Production queue writers intentionally remain on v1 for the expand-first rollout. Typecheck and targeted lint pass; 113 queue/work, Slack worker, steering, and heartbeat tests pass. The checkpoint should not be marked complete until the dual reader is deployed before switching writers.

  5. dcramer commented on Jul 23, 2026

    @dcramer
    MemberAuthor

    Correction to the earlier reader-first rollout note: Vercel push queue messages are deployment-scoped and are delivered to the same deployment that published them. Production uses the deployment-aware QueueClient default, so there is no old-reader/new-writer overlap to protect here. PR #1019 now switches producers and consumers to the conversation-ID-only payload together and removes the compatibility layer.

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions