Skip to content

fix(connectors): name the answering turn in legacy /replies drains - #50275

Merged
nwparker merged 1 commit into
stablyai:mainfrom
LuisQin01:investigate/49891-slack-progress
Nov 27, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
LuisQin01:investigate/49891-slack-progress

Conversation

@LuisQin01

@LuisQin01 LuisQin01 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When Orca restarts and then sends a saved bot answer back to Slack through the older delivery route, it labelled the answer with the time the answer was written instead of the conversation turn it belongs to. The cloud could not match the answer to its turn, so it could not credit it to the person who asked or cancel a duplicate fallback post. Now the answer carries the right turn label, the same way the newer route already does.

What Changed

  • src/main/connector-cloud/connector-reply-outbox.ts: the kill-switch /replies drain (ConnectorReplyOutbox.post, used when the hello does not list replies.outbox) now sends turnId: turnStartedAt ?? filledAt instead of turnId: filledAt. turnStartedAt is the start time already saved on the fill by fix(connectors): name the answering turn on a reply, and settle requests by the turn that answered them #47320, and replyEventsOf (the outbox route) already sends it.
    • Before: after a restart, every drained reply was labelled with its fill time.
    • After: each reply is labelled with the turn that answered it. Rows with no known turn start (for example, fills made by boot recovery) still fall back to filledAt.
    • The reply ID (from deliveryId) and answerDeliveryId are unchanged, so retries across the upgrade stay idempotent. No schema or migration change.
  • src/main/external-conversations/connector-reply-restart-matrix.test.ts: a new case in describe('the reply names the turn that answered it'). It uses a real SQLite journal with real admission and fillTurn, closes and reopens the DB, then drains through the real outbox with outbox: false and captures the post at the network boundary. It covers one row with a known turn start and one row that uses the fallback.

Why

The /replies contract defines turnId as the at time of the answering turn-started event. The orca reply RPC and the reply-events route both follow it. Only the legacy drain sent the fill time. Reusing the field that is already saved fixes the mismatch without another migration or a new way to attribute replies.

Linked Issue

Fixes #50267

Refs #49891 (related investigation; not closed by this PR, because its real transport route and the hosted Working-message cleanup are still unverified).

Visual Proof

N/A. This changes the payload sent by a background main-process drain, not the renderer or any interaction. The before/after evidence is the regression test:

  • On main: expected [['d1', 1800000000000], …] to deeply equal [['d1', 1799999970000], …]. The fill time was sent instead of the turn start.
  • With the fix: both rows pass. d1 gets its turn start and d2 gets the fill-time fallback.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • Every added test fails without this change and avoids the test anti-patterns

  • pnpm exec vitest run src/main/external-conversations/connector-reply-restart-matrix.test.ts src/main/connector-cloud/: 15 files, 190 tests passed.

  • With only the outbox line reverted to main, the new case fails as shown above. A separate 4-row probe got the fill time for every row on main, and the correct start times with the fix.

  • oxlint, oxfmt --check, the anti-slop and native code-quality oxlint configs, ast-grep, and the changed-code quality gate are all clean on both files.

  • Platform: macOS, local modules and SQLite. The change is pure data with no paths or shells. The real Slack/cloud round trip was not exercised.

Performance

None, because this is one extra field read with ?? on the kill-switch drain. That is a cold path that makes one awaited network post per row. Microbench over a 200-row page: about 0.12 us before and 0.35 us after, against at least one network round trip per row. No new I/O, timers, polling or sync work.

Risk

Level: Low

On Slack, a reply drained through the kill-switch route after a restart can now get the asker's member stamp. That stamp can wake other bots in the thread, and it lets the cloud cancel the duplicate turn-end fallback post. This matches what the reply-events route already does, but it is a visible change in behaviour. Several rows from one turn now share a turnId, which the orca reply RPC already does. Both routes validate turnId with the same EpochMsSchema, so the change cannot cause a new 400. A plain revert backs this out; no migration is involved.

Review

One production line plus one regression case. No UI, auth, schema, path or platform-specific code. The same outbox runs on local and remote hosts, and the payload shape is unchanged, so mixed-version peers are unaffected.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Original fix by @LuisQin01 in #50275. Their authorship is preserved on the commit. The maintainer folded the regression test into the existing restart matrix (the separate connector-reply-turn-identity.test.ts file was dropped) and destructured turnStartedAt alongside the other fill fields.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The legacy /replies payload now uses the persisted turnStartedAt as turnId when available. If it is absent, the payload uses filledAt. A restart test checks both cases after reopening the journal and draining the outbox.

Severity of issue fixed: Low

Merge Risk: Minimal · up to 4ea28

The legacy /replies payload now reports the answering turn's start time as turnId, with the fill time as the fallback when none was recorded. No schema or identifier changes accompany it, and the change adds no performance cost. No merge-blocking risk remains beyond normal CI approval.

Pre-merge checks: Passed 4

Check name Status Explanation
Linked Issues check Passed Directly linked issue #50267 requires legacy /replies to send the persisted answering turn start as turnId when known, and to keep the filledAt fallback otherwise. At the current head 4ea2804, t…
Out of Scope Changes check Passed The production change is a single-line payload change in the outbox that directly implements #50267, and the destructuring addition supports it. The test change is confined to the reply-restart matrix…
Title check Passed The title names the change: the legacy /replies drain now sends the answering turn as turnId instead of the fill time. It is specific and matches the main change in the changeset. The fix: connector-r…
Description check Passed The description follows the repository template and fills every required section: ELI5, What Changed, Why, Linked Issue (Fixes #50267), Visual Proof (N/A with reason), Testing, Performance, Risk with …
Full details: Linked Issues check

Explanation

Directly linked issue #50267 requires legacy /replies to send the persisted answering turn start as turnId when known, and to keep the filledAt fallback otherwise. At the current head 4ea2804, the whole-PR diff against merge base 33dfd04 changes src/main/connector-cloud/connector-reply-outbox.ts in the client.post payload from turnId: filledAt to turnId: turnStartedAt ?? filledAt. The destructuring now reads turnStartedAt from row.fill. This implements both the known-start and fallback behavior. The added regression in src/main/external-conversations/connector-reply-restart-matrix.test.ts fills one reply with a known TURN_AT and one without a start, closes and reopens the SQLite journal, drains through ConnectorReplyOutbox with a captured client.post, and asserts [answerDeliveryId, turnId] equals [d1, TURN_AT] and [d2, NOW]. Schemas, reply IDs, and delivery IDs are unchanged in the diff. #49891 is context only and is correctly not closed. Residual uncertainty: the PR description names connector-reply-turn-identity.test.ts, which is absent at head; the regression is in the restart-matrix file instead. Live Slack/cloud behavior is not verified, and the issue does not require it.

Full details: Out of Scope Changes check

Explanation

The production change is a single-line payload change in the outbox that directly implements #50267, and the destructuring addition supports it. The test change is confined to the reply-restart matrix test file and adds one regression case covering the same objective. It adds the ConnectorReplyOutbox and ConnectorReplyBody imports it needs. No schema, UI, authentication, file path, or migration change appears in the inspected diffs. Documentation gap only: the PR description cites src/main/external-conversations/connector-reply-turn-identity.test.ts, which does not exist at head. This is a traceability mismatch, not an out-of-scope change.

Full details: Title check

Explanation

The title names the change: the legacy /replies drain now sends the answering turn as turnId instead of the fill time. It is specific and matches the main change in the changeset. The fix: connector-reply-outbox.ts uses turnStartedAt ?? filledAt, with a regression test in the restart matrix.

Full details: Description check

Explanation

The description follows the repository template and fills every required section: ELI5, What Changed, Why, Linked Issue (Fixes #50267), Visual Proof (N/A with reason), Testing, Performance, Risk with level, Review, the upstream boundary checkbox, Notes, and Checklist. It gives a concrete before/after and a regression-test failure output. Gaps: the AI Disclosure section is left as the template comment, which the template says to skip for internal contributors. The final checklist item for pnpm lint/typecheck/test/build is unchecked, and the Testing section says the changed-file gate passed but does not confirm the full suite.

  • 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

Recent 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: 83414f70-0efb-4431-999c-a5c1ccb8fd1e
Commits

Reviewing files that changed from the base of the PR and between 30a77b2 and 4ea2804.

Files selected for processing: 2

  • src/main/connector-cloud/connector-reply-outbox.ts
  • src/main/external-conversations/connector-reply-restart-matrix.test.ts

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

@LuisQin01

Copy link
Copy Markdown
Contributor Author

Could a maintainer approve the fork workflow runs for this head (30a77b2eefbb95ab583da8f5262e33de2d852615)? PR Checks, Headless Node server, PR test LoC and PR description currently report action_required with no jobs run; for example: https://github.com/stablyai/orca/actions/runs/45931007945 .

The local changed-file gate passed all 28 checks after rebasing, and CodeRabbit completed successfully with no actionable comments. Those results do not substitute for Actions. The PR remains limited to #50267; the new NO_REPLY observation in #49891 is being investigated separately.

The kill-switch /replies drain sent turnId: filledAt, but the contract
defines turnId as the answering turn-started time. Send the persisted
fill.turnStartedAt, as the reply-events route already does, and fall
back to filledAt when no turn start was recorded (boot-recovery fills).

Fixes stablyai#50267

Co-authored-by: Neil <[email protected]>
@nwparker
nwparker force-pushed the investigate/49891-slack-progress branch from 30a77b2 to 4ea2804 Compare November 27, 2026 03:57
@nwparker nwparker changed the title fix(connectors): preserve answering turn identity in legacy replies fix(connectors): name the answering turn in legacy /replies drains Nov 27, 2026
@nwparker
nwparker merged commit 7ae7618 into stablyai:main Nov 27, 2026
55 of 56 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.

[Bug]: Legacy connector replies lose the persisted answering turn identity

2 participants