Skip to content

Attribute the message that starts a pending thread to its sender thread (senderThreadId is dropped on first dispatch) #5010

Closed

Description

@lebryk

The workflow

One agent thread messages another with POST /threads/{id}/send and senderThreadId. bb records such a message as the sending agent's: initiator agent, a link to the sender thread, the agent message header, and permission escalation off. That works for a thread that has already started. It does not work when the send is the message that starts a thread that is still pending, for example a thread created ahead of its first turn whose first dispatch was held by a scheduled sendAt or a message.dispatch wait. Agents that open a conversation with another agent's dedicated thread hit this on every first message.

What happens today

The send goes through attemptDispatch (

const outcome = await attemptDispatch(deps, {
). The attempt resolves the sender correctly (
const author = resolveDispatchAuthor({
, and the message.dispatch hooks see it:
senderThreadId: author.senderThreadId,
). But because the thread is pending, the attempt admits it through admitPendingThread (
admitted.value = await admitPendingThread(deps, {
), which provisions the thread with only the creation's startedOnBehalfOf (
startedOnBehalfOf: startContext.startedOnBehalfOf,
). requestThreadProvision then resolves the author with senderThreadId: null ( ).

So the thread's first client/turn/requested event has initiator: "user" and senderThreadId: null, and the input has no agent message header. In the timeline the first message reads as the person's own words. Every later send into the same thread is attributed correctly.

Setting startedOnBehalfOf at creation does not help: it is accepted only with a sourceThreadId or parentThreadId (

"startedOnBehalfOf requires a sourceThreadId or parentThreadId",
), and it makes the thread seed without running.

Repro against main (fd31b75)

Server test, using the harness the dispatch-hook tests use:

  1. Install a message.dispatch hook that answers wait, then call createThreadFromRequest (codex, host environment, any input, startedOnBehalfOf: null). The thread stays pending.
  2. Remove the hook, and seed a second thread in the same project to act as the sender.
  3. Call acceptThreadSendRequest on the pending thread with { input: textInput("Please review the plan"), mode: "auto", senderThreadId: sender.id }.
  4. Read the thread's client/turn/requested event.
Actual:   initiator "user", senderThreadId null, input "Please review the plan"
Expected: initiator "agent", senderThreadId <sender id>, input with the agent message header naming the sender

The same send into an idle, started thread gives the expected result, through sendThreadMessage (

? formatAgentThreadInput({
).

Expected behaviour

The message that starts a pending thread is attributed like any other send. When the attempt carries a sender thread, the thread-start request records initiator agent and that senderThreadId, and the input carries the agent message header. Three cases stay as they are today: a send without a sender, a retry, and a creation's own startedOnBehalfOf, which still seeds a fork or child thread without running.

I'm filing this as a feature request rather than a bug because it changes what a first dispatch records.

Open question: the provisioned first run still uses the user permission escalation (ask) whatever the initiator is. An agent-sent message into a started thread gets deny. Matching that would mean persisting the initiator in the startup request. The prototype below leaves it unchanged.

Prototype

RIMTHAN-LAB@3709504 (branch thread-start-sender-attribution, on main @ fd31b75)

  • admitPendingThread receives the attempt's sender thread, null on a retry, and passes it to requestThreadProvision, which gives it to resolveDispatchAuthor. The input gets formatAgentThreadInput.
  • test/threads/thread-start-sender-attribution.test.ts covers both cases, the attributed send and the plain send. The attributed case fails on main.
  • test/threads, test/public and test/services/threads pass (118 files, 1,281 tests), and so does the server tsc.

Happy to open it as a PR once approved.

Context and alternatives

  • Alternative: let startedOnBehalfOf be set on a top-level thread. That still seeds without running, and it describes why a thread was started, not who sent a message.
  • Workaround today: the sending side writes the sender's name into the visible text of the first message. The text then says who sent it, but bb's attribution, link and policy initiator do not.

AGENT GENERATED

Activity

  1. added theissue type on Oct 6, 2026
  2. added
    threads
    confirmed-repro
    on Oct 6, 2026
  3. bb-slop-cop commented on Oct 6, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification: Bug · Priority: Medium · Effort: Medium · area: threads.
    • Report: Verified reproduction and root cause.
    • Verdict: REPRODUCED · Confidence: high · Reproduction label: confirmed-repro.
    • Root cause: Pending admission drops the resolved sender; provisioning recomputes attribution with a null sender and records unwrapped, user-attributed input.
    • Evidence: The inline regression test fails on trusted main (fd31b75fb) in two clean checkouts: one failing pending-agent case and three passing controls each. All 89 relevant existing tests pass. Captured startup options also use ask instead of the idle-agent path's deny.
    • No PR: A complete repair changes startup permission policy, which is outside this rule's simple-fix gate.

    AGENT GENERATED

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-reprothreads

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions