Skip to content

fix(meetings): the interlock's order on the worker's clock, the loop's passes apart, handlers before destinations, the late notice first - #388

Merged
jddunn merged 5 commits into
masterfrom
fix/meeting-channel-cleanup-2
Oct 13, 2026
Merged

jddunn merged 5 commits into
masterfrom
fix/meeting-channel-cleanup-2

Conversation

@jddunn

@jddunn jddunn commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Summary

Follow-up fixes to the meeting-participant channel (src/io/channels/meetings/), one commit each, each with the regression case that fails on the code before it:

  • The interlock's order. The notice and the stop monitor's heartbeats were stored at times bounded to one heartbeat interval past the manager's clock, each on its own, and capture opened on a heartbeat whose bounded time was at or after the notice's. With a worker clock more than an interval ahead, a heartbeat the worker made before the notice took the notice's bounded time (applied in the same millisecond) or a later one (delivered after it) and opened capture. The notice's time is now kept on the worker's clock; a heartbeat counts only once the notice is confirmed and only when the worker made it at or after the notice; a counted one is kept at its bounded time for the freshness checks; the notice's confirmation clears any heartbeat time from before it. The wait for a first heartbeat after the notice counts from no later than the notice's confirmation window after the bot entered the call, so a worker clock that runs ahead does not hold such a run in the call.
  • The loop. start() ran tick() one pass at a time, and a tick dispatches before it enforces limits, so a dispatch the provider was slow to answer (a worker pulling its image) skipped every later pass: no suspension of a quiet stop monitor, no kill, no notice, waiting-room or alone limit. A call inside the limits that never answered stopped every later pass the same way. start() now runs the dispatches and the upkeep (limits, kills, purges, eviction, the reconcile) as two passes apart, each one at a time, and a pass still running five intervals after it began is no longer waited for. tick() keeps its order.
  • Handlers before destinations. A stored event went to the destinations first and to the handlers after, and an event sent again goes to the destinations only. When the destinations step failed (the lookup or the enqueue), the handlers were never called, before or after the retry: the purge's last step lost bot:purged for every in-process handler whenever the destinations were unreachable for one pass. The handlers now receive a stored event first.
  • The late arrival's notice. A participant_joined report wrote the count and delivered the event before it posted the short notice; a failing write or delivery raised before the notice, and the worker's retry applies nothing again, so a participant who joined after the notice was never told. The notice now goes first.
  • The first finals after startCapture. The sink and recordTranscript dropped turns until captureStartedAt was written, which happens once the bot answers startCapture; a bot publishes as the command reaches it, so its first finals could be dropped. A run now takes turns once its capture has started or while the interlock holds (MeetingManager.takesTurns, read by both).

Linked issues

None.

Type of change

  • Bug fix
  • Feature
  • Performance
  • Documentation
  • Refactor
  • Tests
  • Build or CI

How this was verified

CI on this pull request: Test & Lint (build, lint, type check and the suite with coverage), Batch-1 gated tests, Browser tests and the release dry run. The regression cases: in manager-send-dispatch.test.ts, a heartbeat made before the notice by a worker an hour ahead opens no capture (same millisecond, and delivered after the notice); a run whose monitor never reports leaves within the bound under that skew; the loop's three cases (each pass one at a time with the upkeep going on beside a held dispatch; a held provider dispatch with a quiet stop monitor suspended meanwhile; a command that never answers holding the next upkeep pass back five intervals at most). In manager-lifecycle.test.ts, the handlers receive a report's event whose destinations failed, once, and bot:purged when the purge's last step failed at the destinations; a late arrival is given the short notice when the count's write or the delivery fails, once across the worker's retry; a final heard while startCapture is held is kept.

Migration notes

None: no schema change, and takesTurns is added. Behaviour a host may notice: noticePostedAt holds the worker's time again (as before the bound was introduced); the manager's event handlers are called before the outbox enqueue; a heartbeat applied before the notice is confirmed is not counted.

Checklist

  • Tests cover the changed behavior.
  • Docs are updated.
  • The title follows Conventional Commits, with ! before the colon for a change that breaks users (feat!: or feat(api)!:).
  • No secrets or private data are included.
  • Every automated review thread is settled (how).
  • I have read this change and can explain every line.

Summary by Sourcery

Harden meeting lifecycle processing against timing skew, slow operations, and partial delivery failures while preserving early capture transcripts and participant notices.

Bug Fixes:

  • Correct meeting capture interlock ordering and timeout behavior under worker clock skew.
  • Keep transcript finals received while capture startup is still in progress.
  • Post late-arrival notices before participant updates and event delivery so retries cannot lose them.
  • Deliver in-process meeting handlers before destination enqueue failures can block them.

Enhancements:

  • Separate scheduled dispatch and upkeep passes so slow or stuck provider operations do not delay meeting limits, cleanup, or reconciliation.

Documentation:

  • Update meeting bot documentation for loop scheduling, event delivery ordering, capture interlock timing, and transcript acceptance behavior.

Tests:

  • Add regression coverage for clock-skewed heartbeats, stuck loop passes, handler delivery failures, late-arrival notices, and transcript finals during capture startup.

…notice on the worker's clock

The notice's confirmation and the monitor's heartbeats were stored at times bounded to one heartbeat interval past the manager's clock, each on its own, and capture opened on a heartbeat whose bounded time was at or after the notice's. With a worker clock more than an interval ahead both bounds take the manager's clock plus the interval, so a heartbeat the worker made before the notice, applied in the same millisecond or delivered after it, counted as one after it and opened capture without a stop monitor shown to be watching the chat after the notice.

The notice's time is now kept as the worker reported it. A heartbeat counts only once the notice is confirmed and only when the worker made it at or after the notice, both on the worker's clock; a counted one is kept at its bounded time, which the freshness checks use, and the notice's confirmation clears any heartbeat time from before it. The wait for a first heartbeat after the notice counts from the notice, but from no later than the notice's confirmation window after the bot entered the call, so a worker clock that runs ahead does not hold a run without a monitor in the call.

Files: src/io/channels/meetings/MeetingManager.ts, src/io/channels/meetings/types.ts, src/io/channels/meetings/__tests__/manager-send-dispatch.test.ts, docs/features/MEETING_BOTS.md.
… a pass that does not finish stops no later one

start() ran tick() one pass at a time, and a tick dispatches the due jobs before it enforces any limit. A provider slow to answer a dispatch (a worker pulling the bot's image, a scheduler that does not reply) held that pass open, and every later pass was skipped while it waited: no stop monitor that went quiet was suspended, no armed kill fired, and no notice, waiting-room or alone limit ended a run. A call inside the limits that never answered, a command to a worker that froze, stopped every later pass the same way.

start() now runs the dispatches and the upkeep (the limits, kills, purges, eviction and the reconcile) as two passes apart, each one at a time, and a pass still running five intervals after it began is no longer waited for: the next starts beside it, with a warning. tick() runs the two in turn, as before.

Files: src/io/channels/meetings/MeetingManager.ts, src/io/channels/meetings/__tests__/manager-send-dispatch.test.ts, docs/features/MEETING_BOTS.md.
…tions

deliver() enqueued an event for each of the owner's destinations first and called the handlers after, and an event sent again goes to the destinations only, so that a handler receives it once. When the first attempt failed in the destinations step (the destination lookup or the enqueue throwing), the handlers were never called, and the retry, finding the event stored, skipped them too: the handlers never received it. The purge's last step hit this whenever the destinations were unreachable for one pass, and no in-process handler ever heard bot:purged for that run; a participant's message or a report's event went the same way.

The handlers now receive a stored event first and the destinations' deliveries are enqueued after, so a failing destination keeps the event from no handler; an event sent again still goes to the destinations only.

Files: src/io/channels/meetings/MeetingManager.ts, src/io/channels/meetings/__tests__/manager-lifecycle.test.ts, docs/features/MEETING_BOTS.md.
… before the count is written and the event delivered

A participant_joined report wrote the new count, delivered the event and only then posted the short notice to the participant who arrived. A write or a delivery that failed (the run store, the destination lookup or the enqueue) raised before the notice, and the worker's retry of the report, whose event is stored by then, applies nothing again: the participant who joined after the notice was never told the bot was taking notes, while capture went on.

The short notice now goes first, before the count's write and the event's delivery, so neither failing keeps it back; the retry still posts nothing a second time.

Files: src/io/channels/meetings/MeetingManager.ts, src/io/channels/meetings/__tests__/manager-lifecycle.test.ts, docs/features/MEETING_BOTS.md.
…bot is kept

The transcript sink and recordTranscript dropped a turn while the run's captureStartedAt was unset, and the manager writes it only once the bot has answered startCapture. A bot starts publishing as the command reaches it, so a final from its first audio could arrive before that answer, or before a slow run-store write, and was dropped without a word.

A run now takes turns once its capture has started or while the capture interlock holds (in the call, the notice confirmed, a fresh heartbeat after it, no suspension), which is when the command is sent; MeetingManager.takesTurns is that check, and the sink and recordTranscript both read it. A turn from audio a provider passed on before the interlock held is still dropped.

Files: src/io/channels/meetings/MeetingManager.ts, src/io/channels/meetings/MeetingTranscriptSink.ts, src/io/channels/meetings/__tests__/manager-lifecycle.test.ts, docs/features/MEETING_BOTS.md.
@coderabbitai

coderabbitai Bot commented Oct 13, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai

sourcery-ai Bot commented Oct 13, 2026

Copy link
Copy Markdown

Reviewer's Guide

This PR fixes meeting lifecycle races by enforcing worker-clock ordering for the capture interlock, decoupling dispatch from upkeep with stuck-pass recovery, delivering handlers before destinations, posting late-arrival notices first, and accepting transcript finals during an in-flight capture start; documentation and targeted regression tests cover each behavior.

Sequence diagram for the meeting capture interlock

sequenceDiagram
    participant Worker
    participant Manager
    participant Provider

    Worker->>Manager: processProviderEvent(providerName, ctx)
    Manager->>Manager: notice_posted
    Manager->>Manager: clear monitorSeenAt
    Manager-->>Worker: notice confirmed
    Worker->>Manager: monitor_heartbeat
    alt heartbeat at or after noticePostedAt
        Manager->>Manager: reportedAt(event.at)
        Manager->>Provider: startCapture
        Provider-->>Manager: capture started
    else heartbeat before noticePostedAt
        Manager-->>Worker: heartbeat not counted
    end
Loading

Sequence diagram for handler-first event delivery

sequenceDiagram
    participant Report as Provider report
    participant Manager
    participant Handler
    participant Destinations
    participant Outbox

    Report->>Manager: processProviderEvent(providerName, ctx)
    Manager->>Handler: MeetingManagerEvent
    Handler-->>Manager: handled
    Manager->>Destinations: destinationsFor(ownerRef)
    Destinations-->>Manager: destination refs
    Manager->>Outbox: enqueue(event delivery)
    alt destination lookup or enqueue fails
        Manager-->>Report: error after handler delivery
    end
Loading

Sequence diagram for late-arrival notice ordering

sequenceDiagram
    participant Worker
    participant Manager
    participant Provider
    participant RunStore
    participant Handler

    Worker->>Manager: participant_joined
    Manager->>Provider: postChat(lateArrivalText)
    Provider-->>Manager: notice posted
    Manager->>RunStore: updateParticipants
    RunStore-->>Manager: updated run
    Manager->>Handler: bot event
    Handler-->>Manager: handled
    Manager-->>Worker: report applied
Loading

Sequence diagram for transcript finals during capture startup

sequenceDiagram
    participant Worker
    participant Manager
    participant Sink
    participant TranscriptStore
    participant Provider

    Manager->>Provider: startCapture
    Worker->>Sink: appendNext(transcript input)
    Sink->>Manager: takesTurns(run)
    alt capture interlock holds while startCapture is in flight
        Sink->>TranscriptStore: appendNext(input)
        Sink->>Manager: recordTranscript(turn)
        Manager-->>Sink: transcript accepted
    else capture cannot start
        Manager-->>Sink: transcript dropped
    end
    Provider-->>Manager: startCapture response
    Manager->>Manager: set captureStartedAt
Loading

File-Level Changes

Change Details Files
Separates dispatch and upkeep execution while adding bounded stuck-pass overlap protection.
  • Runs dispatch and upkeep independently from start() while preserving sequential tick() ordering.
  • Tracks each pass and starts a replacement after five intervals if the prior pass remains unresolved.
  • Keeps upkeep steps progressing despite dispatch failures or slow provider calls.
src/io/channels/meetings/MeetingManager.ts
docs/features/MEETING_BOTS.md
src/io/channels/meetings/__tests__/manager-send-dispatch.test.ts
Corrects capture interlock ordering and timeout behavior across skewed worker clocks.
  • Stores notice confirmation on the worker clock and accepts only post-notice heartbeats, clearing pre-confirmation observations.
  • Continues using bounded heartbeat times for freshness and caps the no-heartbeat leave deadline relative to call entry.
  • Adds regression coverage for clock skew, same-time ordering, delayed delivery, and missing heartbeats.
src/io/channels/meetings/MeetingManager.ts
src/io/channels/meetings/types.ts
docs/features/MEETING_BOTS.md
src/io/channels/meetings/__tests__/manager-send-dispatch.test.ts
Reorders event side effects so in-process handlers are notified before destination delivery.
  • Invokes handlers once for newly stored events before destination lookup or outbox enqueue.
  • Preserves destination retries without replaying handlers.
  • Verifies handler delivery when destinations fail, including purge completion events.
src/io/channels/meetings/MeetingManager.ts
docs/features/MEETING_BOTS.md
src/io/channels/meetings/__tests__/manager-lifecycle.test.ts
Makes late-participant notices precede participant state updates and event delivery.
  • Posts the short notice before writing the participant count or delivering the event.
  • Relies on stored-event deduplication so worker retries do not repost the notice.
  • Tests failures in the run store and destination delivery paths.
src/io/channels/meetings/MeetingManager.ts
docs/features/MEETING_BOTS.md
src/io/channels/meetings/__tests__/manager-lifecycle.test.ts
Allows transcript turns during the capture-start transition when the interlock already holds.
  • Adds takesTurns() as the shared eligibility check for transcript sinks and recordTranscript().
  • Accepts first finals while startCapture is in flight, while still rejecting fenced, purging, terminal, or not-ready runs.
  • Adds a regression test for audio arriving before captureStartedAt is persisted.
src/io/channels/meetings/MeetingManager.ts
src/io/channels/meetings/MeetingTranscriptSink.ts
docs/features/MEETING_BOTS.md
src/io/channels/meetings/__tests__/manager-lifecycle.test.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@jddunn
jddunn marked this pull request as ready for review October 13, 2026 07:23
@jddunn
jddunn requested a review from Victor-Evogor as a code owner October 13, 2026 07:23
@jddunn
jddunn merged commit 16dce24 into master Oct 13, 2026
8 checks passed
@sourcery-ai

sourcery-ai Bot commented Oct 13, 2026

Copy link
Copy Markdown

Sorry @jddunn, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 4 days and 19 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@jddunn
jddunn deleted the fix/meeting-channel-cleanup-2 branch October 13, 2026 07:23
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T07:26:36.717940Z 82bac72 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 82bac722f5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +415 to +420
const began = this.passStartedAt.get(pass);
if (began !== undefined && this.loopIntervals - began < STUCK_PASS_INTERVALS) return;
if (began !== undefined) this.config.logger?.warn(`[MeetingManager] the ${pass} pass begun ${this.loopIntervals - began} intervals ago has not finished; the next one starts beside it`);
const mark = this.loopIntervals;
this.passStartedAt.set(pass, mark);
void work()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Bound stuck operations instead of spawning repeated passes

If a dependency consistently never settles—for example, every provider.command(..., { name: 'kill' }) call to a frozen worker—this starts another upkeep pass every five intervals, and each pass reaches and hangs on the same run before processing later runs. The advertised bypass therefore both leaves other bots' limits unenforced and accumulates an unbounded number of pending passes; apply a timeout/cancellation boundary to the stuck operation, or otherwise ensure replacement passes can skip the blocked run rather than merely invoking the same pass again.

Useful? React with 👍 / 👎.

github-actions Bot pushed a commit that referenced this pull request Oct 13, 2026
## [0.13.88](v0.13.87...v0.13.88) (2026-10-13)

### fix

* **guardrails:** close a blocked stream even when its refusal cannot be saved (#387) ([864941b](864941b))
* **meetings:** the follow-ups' forward fixes: the interlock's order on the worker's clock, the loop's two passes, handlers before destinations, the late notice first, finals during startCapture (#388) ([16dce24](16dce24))
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