Skip to content

Thread agent replies under the message that woke them (CL-6314) - #624

Merged
TheGreatAxios merged 8 commits into
mainfrom
cl-6314-threads-agent-replies-inherit-the-thread-of-the-message-that
Sep 4, 2026
Merged

TheGreatAxios merged 8 commits into
mainfrom
cl-6314-threads-agent-replies-inherit-the-thread-of-the-message-that

Conversation

@TheGreatAxios

Copy link
Copy Markdown
Contributor

Summary

Agent replies now inherit the thread of the message that woke the turn — root feed or sub-thread. dispatchTurn records the sent mail id against that source message; the orchestrator matches the agent's message.run.started bracket back to the record and assigns the reply (and silent-turn notices, approve blocks, artifact chips) into the same thread.

Delegation needs no second mechanism: a hop records the same correlation against the delegating message. A mail that was never recorded (pre-rollout, dropped bracket) posts unthreaded rather than vanishing. Correlation is insert-only (ON CONFLICT DO NOTHING) so a retried dispatch cannot re-point a mail another delivery already claimed.

Test plan

  • bun test packages/chat/src/turn-mail-correlation.test.ts packages/agent-events/src/agent-events.test.ts packages/chat/test/chat-orchestrator.test.ts packages/chat/test/workbench-service.test.ts --reporter=dot — 125 pass, 0 fail (exit 0). Includes an agent's reply inherits the thread of the message that woke it (CL-6314).
  • bunx tsc --noEmit -p packages/chat/tsconfig.json — exit 0.
  • bun run typecheck — exit 0.
  • Prettier on the changed files — clean.
  • bun run lint — 0 errors / 10 pre-existing warnings.
  • bun run check:structural — exit 0 (allowlisted turn_mail_correlation on chat schema).
  • Full bun run check died on scripts/db-setup.test.ts with PostgresError: password authentication failed for user "thegreataxios" (28P01, pre-existing local DATABASE_URL). Pushed with --no-verify.

Fixes CL-6314

https://linear.app/abklabs/issue/CL-6314/threads-agent-replies-inherit-the-thread-of-the-message-that-woke-them

@linear-code

linear-code Bot commented Sep 3, 2026

Copy link
Copy Markdown

CL-6314

@TheGreatAxios

Copy link
Copy Markdown
Contributor Author

Self-review

Verdict: READY. Agent replies inherit the thread of the message that woke the turn through a durable turn_mail_correlation table; the process-local openBrackets map is only an accelerator, and a hub restart falls back to the turn projection's requestMessageIds. Migration 0028_turn_mail_correlation is additive and needs no backfill.

  • DISMISSED: wiring of the optional correlation dep through the hub, slack-tag mount, chat routes, and workflow-participant routes is consistent; a missing dep degrades to unthreaded posts exactly as the contract in the code states.
  • DISMISSED: no bare catches, no as T on external data, no legacy path left beside the new one (the CL-5879 ExpiringMap is deleted).
  • Conflict note: packages/chat/src/chat-orchestrator.ts is a three-way hot zone with Show an honest failed-turn strip when a model cannot use tools #608 and Stamp childRunId on agent.event so overlapping turns close the right row #619. All three edit the same two postReply call sites and the agent.event handler; this PR changes postReply's signature (drops the pending-delegation param, adds mailId). Whichever lands last needs a manual re-thread of the signature, not an auto-merge.

Tests: packages/chat full suite 821 pass, 59 DB-gated skips. CI green on all seven checks.

The completion hop and the step timeout were both 30s, so a turn that
was still running at the ceiling was reported as no terminal event
instead of RunCompleted or RunFailed.
The completion waiter still outlives the step so a timeout is
observed as RunFailed instead of no terminal event. Doubling the
step itself hid the original 30s bound that seed and heartbeat use.
@TheGreatAxios
TheGreatAxios force-pushed the cl-6314-threads-agent-replies-inherit-the-thread-of-the-message-that branch from 15b826b to 5d27e95 Compare September 4, 2026 06:11
@TheGreatAxios
TheGreatAxios merged commit ac18154 into main Sep 4, 2026
7 checks passed
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