Skip to content

fix(connector): reply rows can be owed to a continuation, and a stamped Slack turn never also sends its full end - #46044

Merged
Jinwoo-H merged 6 commits into
mainfrom
jinwoo/connector-reply-claims
Nov 21, 2026
Merged

Jinwoo-H merged 6 commits into
mainfrom
jinwoo/connector-reply-claims

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Phase 1 of the connector reply fixes after a restart, desktop part 1. Stacked on #46032.

What changes now

  • Stamped Slack turns end state-only. A turn whose stamps name its Slack conversation now always sends a state-only end. Before, if recovery had already filled, sent and deleted its rows, or the fill threw, the live end found no rows and also sent the full legacy end. The cloud then posted the same answer twice. Sources outside the outbox (GitHub, Linear) keep their full end.
  • Group head. The group's answer key is now its earliest stamp per conversation, not the first row still unfilled, so a partial fill or a deleted row can't move it.

Groundwork for continuations (nothing produces it yet)

  • Row columns. journal_connector_replies gets cut_turn_id, cut_kind and claim_message_id. They are in the fresh schema and added to older tables like took_ms, with no user_version change.
  • Conditional writers. Every write states the row state it expects (open, claimed by message M, or owed by cut C and unclaimed), so a stale writer changes nothing.
    • fill takes that expectation.
    • New writers: cut, recut and releaseClaim.
    • Withdraw, rewind-clear and forget also clear a cut's kept failure.
    • A rewind that removes a continuation gives its rows back to their cut.
  • connectorClaim message field. It names the cut a continuation answers and that cut's deliveries.
    • It is host-written, decoded from storage, and stripped from the provider payload like connectorDelivery.
    • The continuation's admission claims the cut's unclaimed rows in the same transaction.
    • connectorReplyTurnStamps includes the claimed origin, so fill, recovery and attribution all read it through one helper.
    • A continuation turn fills only the rows its own admission claimed.

Review round 2

  • A queued continuation's claim moves from its card id to the send the card is handed over as, in the handover's transaction, so that send's turn fills the rows. A send admitted again after its claim was released claims again.
  • The admission claim also takes the still-open rows its connectorClaim.origin names. A launch continuation is admitted before classification cuts them. The claim records its cut kind.

Rollback

  • The columns are safe to roll back: an older build lists its insert columns, reads with SELECT *, and fills with WHERE outcome IS NULL.
  • Once a later PR writes a connectorClaim, that chat is unreadable to an older build, because journal storage is strict. This is the same trade-off as connectorDelivery.
  • This PR writes no claim, so it is safe to roll back on its own.

Tests

  • journal-connector-replies.test.ts: only the claiming continuation fills; a second claim, the cut turn's own late fill and another cut's close change nothing; recut and release; a rewind of the continuation; the kept failure is dropped on other ends.
  • external-conversation-turn-ends.test.ts: state-only end when rows are gone or the fill throws; GitHub keeps its full end.
  • external-conversation-reply-fill.test.ts: a continuation fills only its claimed rows, under the original head.

Design: Phase 1 r3, approved. The next PR adds the producers: restart and usage-limit classification and the continuation's claim.

Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​260 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​260
Prod 14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​337 $\color{#cf222e}{\Huge{\mathbf{−}}}$​30 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​307

…onfirmed outcome

Adds the replies.paused feature, turn-ended's optional resumes, and the
unconfirmed failure category. Inert: nothing sends or reads them yet. The
failure contract moves to its own module to keep the cloud contract mirror
under its size cap.
…ed Slack turn never also sends its full end

Adds cut and claim columns to the reply outbox rows, conditional writers
that state the state they expect (a stale fill, a second claim or another
cut's close changes nothing), and the connectorClaim message field a
continuation's admission uses to claim its cut's rows in the same
transaction. A continuation turn's stamps include the deliveries it
claimed, and its group answers under the cut group's own head. Nothing
cuts or claims rows yet.

A Slack turn whose stamps name its conversation now ends state-only even
when its rows were already sent and deleted, or the fill failed, so its
answer can't also go out as a legacy full end.
…kes its cut's still-open rows

The admission claim also takes the open rows its claim names (a launch
continuation is admitted before classification cuts them), records which
kind of cut it is, and a card's claim moves to the send it is handed over
as, so that send's turn fills them. A send admitted again after its claim
was released claims again.
@Jinwoo-H
Jinwoo-H changed the base branch from jinwoo/connector-reply-contract to main November 21, 2026 04:43
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

The change adds cut and claim state for connector replies, stores that state in the journal, and adds journal operations for managing it. Queued submissions transfer claims to dispatched messages. Turn stamps include claimed connector deliveries, and turn reply filling checks claim or cut state before updating rows.

Merge Risk: Low · up to b672f

This change adds groundwork for connector reply continuations, but nothing produces cuts or claims yet, so users see no impact today. Before a later change starts writing claims, release the claims held by withdrawn continuations and decide how a steered claim-bearing send is handled.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names two changes: reply rows can be owed to a continuation, and a stamped Slack turn sends only a state-only end. The changeset matches both. The title is long (112 characters, 20 words) bu…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description is mostly complete for a stacked, internal Phase 1 change. It covers what changes now (stamped Slack turns end state-only, and the group head rule), the groundwork for continuations (r…
Full details: Title check

Explanation

The title names two changes: reply rows can be owed to a continuation, and a stamped Slack turn sends only a state-only end. The changeset matches both. The title is long (112 characters, 20 words) but still specific and accurate. The Slack end change is the user-visible fix, and the cut/claim groundwork is the other main part.

Full details: Description check

Explanation

The description is mostly complete for a stacked, internal Phase 1 change. It covers what changes now (stamped Slack turns end state-only, and the group head rule), the groundwork for continuations (row columns, conditional writers, the connectorClaim field), rollback behavior, and the tests added. It also states the design approval status. The template sections ELI5, Visual Proof, Risk level, and AI Disclosure are missing or only partly filled. The Linked Issue section is not filled, and the checklist and the agent skill upstream boundary checkbox are not marked. The Testing section lists automated tests but does not say whether the change was manually tested or on which platforms. The Review section and Notes are empty. The author gives a rollback plan, but the template's Risk level is not stated. These gaps are non-critical for the core change, so the check passes.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f51ac06d-1832-43c8-accb-0d969134371e
Commits

Reviewing files that changed from the base of the PR and between d556484 and b672f04.

Files selected for processing: 17

  • src/main/connector-cloud/connector-reply-outbox.ts
  • src/main/external-conversations/external-conversation-reply-fill.test.ts
  • src/main/external-conversations/external-conversation-reply-fill.ts
  • src/main/external-conversations/external-conversation-reply-recovery.ts
  • src/main/external-conversations/external-conversation-turn-ends.test.ts
  • src/main/external-conversations/external-conversation-turn-ends.ts
  • src/main/native-chat/agent-session-journal/connector-replies/journal-connector-replies-schema.ts
  • src/main/native-chat/agent-session-journal/connector-replies/journal-connector-replies.test.ts
  • src/main/native-chat/agent-session-journal/connector-replies/journal-connector-replies.ts
  • src/main/native-chat/agent-session-journal/connector-replies/journal-sql-connector-replies.ts
  • src/main/native-chat/agent-session-journal/durable-rows/journal-storage-schema.ts
  • src/main/native-chat/agent-session-journal/journal-domain-submission-admission.ts
  • src/main/native-chat/agent-session-journal/journal-sql-maintenance.ts
  • src/shared/agent-session/journal/agent-journal-bot-message-fields.ts
  • src/shared/agent-session/journal/journal-connector-reply-turn.ts
  • src/shared/agent-session/journal/journal-connector-reply.ts
  • src/shared/agent-session/requests/structured-agent-session-send-mutation.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

): void {
const withdraw = db.prepare(`UPDATE journal_connector_replies
SET outcome='withdrawn',answer_delivery_id=delivery_id,filled_at=?
SET outcome='withdrawn',answer_delivery_id=delivery_id,failure_json=NULL,filled_at=?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Major · Functional Correctness · Quick win

Release connector claims held by withdrawn continuations.

withdrawJournalConnectorReplies marks only the withdrawn card's own rows. It does not release rows that the withdrawn card claimed for a cut. Those rows keep claim_message_id set to the withdrawn card. A replacement continuation cannot claim them, so the cut's replies can stay unfilled. Release each withdrawn message's claim in the same call. The release keeps the cut and its kept failure.

Suggested fix

   for (const messageId of messageIds) {
     withdraw.run(now, target.sessionId, target.epoch, messageId)
+    releaseJournalConnectorClaim(db, messageId)
   }

recordJournalConnectorReplies(db, target, input.clientMessageId, false, input.body)
} else {
repointJournalConnectorClaim(db, target, familyId, input.clientMessageId)
claimJournalConnectorReplies(db, target, input.clientMessageId, input.body)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Data Integrity & Integration · Quick win

Stamp and fill the claim for a continuation that is steered into another turn.

A continuation that is steered into a turn opened by another message is not handled. connectorReplyTurnStamps adds a claim's origin only when the opener carries the claim. A steered continuation contributes only its own connectorDelivery. conversationReplyFill skips any row whose claimMessageId does not match the turn's opener. The rows that the continuation claimed therefore stay unanswered when that turn ends.

Choose one behavior and make it explicit. Either a claim-bearing send must not join a turn opened by another message, or the turn that it joins must stamp the claim's origin and fill the claimed rows. The current code supports neither behavior for this case.

@Jinwoo-H
Jinwoo-H merged commit 151f776 into main Nov 21, 2026
73 of 104 checks passed
AmethystLiang added a commit that referenced this pull request Nov 21, 2026
…k DM

- A bot's reply to a Slack DM with words before NO_REPLY now posts those words, the trailing
  marker stripped; a reply that is only the marker stays quiet. Threads the bot follows, mail,
  items and automations keep today's rule. Decided per reply row (connectorReplyTurnOutcome),
  so the live outbox fill and boot recovery agree. A DM is read from the conversation id the
  cloud sets (Slack source only), never from message text.
- endRepliedTurn reports 'told' | 'not-covered' | 'unsafe'. The legacy turn end posts a DM's
  stripped words only when the journal stamps prove the turn answered that DM and no outbox
  row can also post them (mostly defensive since #46044 ends stamped Slack turns state-only).
- The merged-quiet fallback (#46062) no longer fires for a DM whose words now post, so the DM
  gets one post.
AmethystLiang added a commit that referenced this pull request Nov 21, 2026
…k DM

- A bot's reply to a Slack DM with words before NO_REPLY now posts those words, the trailing
  marker stripped; a reply that is only the marker stays quiet. Threads the bot follows, mail,
  items and automations keep today's rule. Decided per reply row (connectorReplyTurnOutcome),
  so the live outbox fill and boot recovery agree. A DM is read from the conversation id the
  cloud sets (Slack source only), never from message text.
- endRepliedTurn reports 'told' | 'not-covered' | 'unsafe'. The legacy turn end posts a DM's
  stripped words only when the journal stamps prove the turn answered that DM and no outbox
  row can also post them (mostly defensive since #46044 ends stamped Slack turns state-only).
- The merged-quiet fallback (#46062) no longer fires for a DM whose words now post, so the DM
  gets one post.
AmethystLiang added a commit that referenced this pull request Nov 21, 2026
…k DM (#46182)

* fix(connectors): NO_REPLY can't silence a bot's real answer to a Slack DM

- A bot's reply to a Slack DM with words before NO_REPLY now posts those words, the trailing
  marker stripped; a reply that is only the marker stays quiet. Threads the bot follows, mail,
  items and automations keep today's rule. Decided per reply row (connectorReplyTurnOutcome),
  so the live outbox fill and boot recovery agree. A DM is read from the conversation id the
  cloud sets (Slack source only), never from message text.
- endRepliedTurn reports 'told' | 'not-covered' | 'unsafe'. The legacy turn end posts a DM's
  stripped words only when the journal stamps prove the turn answered that DM and no outbox
  row can also post them (mostly defensive since #46044 ends stamped Slack turns state-only).
- The merged-quiet fallback (#46062) no longer fires for a DM whose words now post, so the DM
  gets one post.

* fix(connectors): only the owner's own DM hears words before NO_REPLY, and only the protocol marker goes

- C1-3: the marker loses its silence only for a delivery the bot's owner sent (the journal's asker
  role, marked on the turn's stamps); a member's DM, even one steered into item or worker mail,
  keeps today's rule. The preamble tells the bot the owner's DM posts the words before the marker.
- C1-1/C1-2: addressedBotWords strips every trailing marker but keeps a quoted mention ending a
  sentence (Use `NO_REPLY`), and a rest with no letter or digit (`> NO_REPLY`, `- NO_REPLY`) stays
  quiet.
- C1-4: the legacy DM-words branch is owner-gated too and documented as reachable only without a
  reply outbox; a test pins that with an outbox it never posts the words.

* fix(connectors): a continuation's claimed owner-DM row keeps its owner proof

A continuation (usage-limit pause, restart) answers rows its claim names, and those stamps carry no
asker, so the owner's DM answer ending in NO_REPLY was filled quiet again on the resume leg. The
fill now reads an unmarked DM row's admitting message (journalReads.submissionBody(row.messageId))
for its asker, with nothing new persisted, so live fill and boot recovery decide alike. A delivery
seen twice in a turn's stamps keeps the owner's mark (stamps are copies, never journal objects), and
rows that answered with words get no merged-quiet stand-in.

* fix(connectors): a queued owner DM keeps its owner proof after a pause, and askers are read only when needed

- A delivery to a busy chat is queued: its outbox row keeps the queue card's id, and the card is
  handed over as a new send. submissionBody gains an opt-in `family` read (the current send whose
  admission family is that card), used only by the fill's owner read, so a queued owner DM is
  answered after a pause and continue too; a member's queued DM stays quiet.
- journalAskedByOwner is the one production adapter (install and the restart matrix both use it).
- The fill reads askers only for a successful bot turn whose prose ends with the marker.
- Tests: queued owner/member through pause and continue on the real journal, the adapter, a
  member duplicate never marked owner, a quiet answer not counted as answered.

* fix(connectors): rows an earlier fill answered for the same turn count as answered

When boot recovery fills a turn's owner-DM row before its live end, the live fill skips that row,
so its conversation was missing from 'answered' and a merged-quiet stand-in could go out beside the
words. Rows whose stored fill is this turn's answered outcome now count too.

* fix(connectors): a turn's live end knows its answer after recovery's row was sent

Boot recovery and the live end fill through the same function, and a sent row is deleted, so the
live end could miss an answer recovery already sent and post the merged-quiet stand-in beside it.
The fill keeps, in memory and bounded to recent turns, the conversations each turn answered with
words, and seeds 'answered' from it.
AmethystLiang added a commit that referenced this pull request Nov 25, 2026
…uietly, and a restart continuation answers with the whole reply

Follow-up to the restart reply recovery that landed in #46044, #46068 and
#47898, carrying the two parts of #46048 main does not have.

- A fill recovery makes from a turn that ended over an hour ago, or any
  recovery or restart-continuation fill of a request admitted over a day
  ago, closes the request quietly (no post) instead of posting it. Rows now
  record when they were admitted (admitted_at) and, locally, why a fill
  closed quietly (expired_reason); each such close logs a warn line and
  counts. A row with no date, and a request a usage-limit pause told its
  thread to wait for, are never closed this way.
- A restart continuation's claimed requests are answered with the reply
  the restart cut partway (each cut of a chain, oldest first, up to four),
  then the continuation's own. A turn cut inside a tool call adds nothing,
  and a failed read leaves the continuation's answer alone.
- The reply matrix harness reads cut replies as the app does, and its rows
  carry real clock times.
AmethystLiang added a commit that referenced this pull request Nov 25, 2026
…uietly, and a restart continuation answers with the whole reply

Follow-up to the restart reply recovery that landed in #46044, #46068 and
#47898, carrying the two parts of #46048 main does not have.

- A fill recovery makes from a turn that ended over an hour ago (a held
  empty-turn answer judged by when its turn ended), or a fill of a request
  admitted before this process started and over a day old, closes the
  request quietly (no post). A live turn's request, a hidden retry's
  included, never starts the request clock; a row with no admission date
  never ages by it on any path; a row a usage-limit pause ever owed keeps
  a paused mark through later cuts, claims and retry holds, and never
  ages by it either.
- A quiet close fills under its own delivery id, and the answer of the
  requests filled with it never keys on that id, so the outbox sends
  disjoint events. Rows record admitted_at and, locally, expired_reason;
  each close is counted and logged only once the journal shows it written.
- A restart continuation's claimed requests, and every request it answers
  in that thread, get the whole reply: each cut of the chain's partial
  prose, oldest first, then its own. The prose rides on the continuation's
  claim, built from the read that already builds the claim, so the fill
  reads no journal; over the answer cap the earlier part is cut with the
  existing note.
- A recovery pass still reading when the host changes or connectors stop
  writes, watches and schedules nothing once its read returns.
- The reply matrix harness carries real clock times and a process start.
AmethystLiang added a commit that referenced this pull request Nov 25, 2026
…uietly

Follow-up to the restart reply recovery that landed in #46044, #46068 and
#47898 (refs #46048).

- A fill recovery makes from a turn that ended over an hour ago (a held
  empty-turn answer judged by when its turn ended), or a fill of a request
  admitted before this process started and over a day old, closes the
  request quietly (no post). A live turn's request, a hidden retry's
  included, never starts the request clock; a row with no admission date
  never ages by it on any path; a row a usage-limit pause ever owed keeps
  a paused mark through later cuts, claims and retry holds, and never
  ages by it either.
- A quiet close fills under its own delivery id, and the answer of the
  requests filled with it never keys on that id, so the outbox sends
  disjoint events. Rows record admitted_at and, locally, expired_reason.
- Each quiet close is written in its own call, so its own commit result
  says whether it closed; it is counted and logged only then. A call that
  threw is looked up once by key, and an unconfirmed close is logged as
  such, never counted.
- Recovery work begun before a dispose (another host, connectors off)
  writes, watches and schedules nothing once it resumes: boot's first
  read, each pass, a fill nested in it and a claim are bound to the
  generation they began in, and a reply write queued on the journal's
  lane asks whether it is still current when the writer takes it. A boot
  asking to open a chat while a pass runs gets its pass run again opened.
- The reply matrix harness carries real clock times and a process start.
AmethystLiang added a commit that referenced this pull request Nov 25, 2026
…uietly

Follow-up to the restart reply recovery that landed in #46044, #46068 and
#47898 (refs #46048).

- A fill recovery makes from a turn that ended over an hour ago (a held
  empty-turn answer judged by when its turn ended), or a fill of a request
  admitted before this process started and over a day old, closes the
  request quietly (no post). A live turn's request, a hidden retry's
  included, never starts the request clock; a row with no admission date
  never ages by it on any path; a row a usage-limit pause ever owed keeps
  a paused mark through later cuts, claims and retry holds, and never
  ages by it either.
- A quiet close fills under its own delivery id, and the answer of the
  requests filled with it never keys on that id, so the outbox sends
  disjoint events. Rows record admitted_at and, locally, expired_reason.
- A fill's rows are written as one command in one writer transaction that
  returns each row's result, so a batch commits whole or not at all. A
  quiet close is counted and logged only when its row changed. A call that
  fails probes its quiet closes once by key: one this attempt wrote wakes
  the sender before the error is rethrown. A failed recovery pass is
  settled again, and a live fill that throws still hands its rows to
  recovery.
- Work begun before a dispose (another host, connectors off), and a live
  turn end since reset, writes, holds, asks, watches, schedules and wakes
  nothing: boot, each pass and nested fill, claims, the live fill and its
  retry hold and send, the turn-end and retry callbacks, and the reply
  write's admit, asked just before it is posted to the writer worker.
AmethystLiang added a commit that referenced this pull request Nov 25, 2026
…uietly

Follow-up to the restart reply recovery that landed in #46044, #46068 and
#47898 (refs #46048).

- A fill recovery makes from a turn that ended over an hour ago (a held
  empty-turn answer judged by when its turn ended), or a fill of a request
  admitted before this process started and over a day old, closes the
  request quietly (no post). A live turn's request, a hidden retry's
  included, never starts the request clock; a row with no admission date
  never ages by it on any path; a row a usage-limit pause ever owed keeps
  a paused mark through later cuts, claims and retry holds, and never
  ages by it either.
- A quiet close fills under its own delivery id, and the answer of the
  requests filled with it never keys on that id, so the outbox sends
  disjoint events. Rows record admitted_at and, locally, expired_reason.
- A fill's rows are written as one command in one writer transaction that
  returns each row's result, so a batch commits whole or not at all. A
  quiet close is counted and logged only when its row changed. A call that
  fails probes its quiet closes once by key: one this attempt wrote wakes
  the sender before the error is rethrown. A failed recovery pass is
  settled again, and a live fill that throws still hands its rows to
  recovery.
- Work begun before a dispose (another host, connectors off), and a live
  turn end since reset, writes, holds, asks, watches, schedules and wakes
  nothing: boot, each pass and nested fill, claims, the live fill and its
  retry hold and send, the turn-end and retry callbacks, and the reply
  write's admit, asked just before it is posted to the writer worker.
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