Skip to content

fix(delivery): wake owed agents when a Runner attaches (RIG-4166) - #1465

Merged
trunk-io[bot] merged 1 commit into
compass-server/rig-4135-archive-detected-endfrom
compass-server/rig-4166-wake-owed-on-attach
Oct 2, 2026
Merged

trunk-io[bot] merged 1 commit into
compass-server/rig-4135-archive-detected-endfrom
compass-server/rig-4166-wake-owed-on-attach

Conversation

@rigel-mintaka

@rigel-mintaka rigel-mintaka commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

This PR is part of a stack containing 4 PRs:

  1. main
  2. fix(runnerhub): scope Runner-originated binding calls to the session's tenant (RIG-4146) #1463
  3. feat(server): archive the transcript tail when a session ends without Stop (RIG-4135) #1464
  4. "fix(delivery): wake owed agents when a Runner attaches (RIG-4166)" (this PR)
  5. fix(server): run a delivery-loop wake under the agent's tenant (RIG-4167) #1466

Fixes RIG-4166. Stacked on #1464.

Problem

A mention made after a restart, before the Runner's command stream attaches, records an owed row and wakes the agent. The wake fails with Unavailable: no runner enrolled. Nothing retries it, so the agent never replies.

Change

  • New runnerhub.RunnerReadySink. Hub.fireRunnerReady calls it when a Runner's Sessions stream attaches. That is the same edge the supervisor seed uses: after the stream is live, so a wake can be served.
  • delivery.Consumer.OnRunnerReady sets a flag and notifies the loop. drainOwedRewake lists OwedMentionAccounts (a new SELECT DISTINCT agent_account_id FROM owed_mentions) and wakes each account. The wakes run off the loop, because each one is a Runner round trip. WakeAgent already skips live agents and coalesces duplicate wakes for the same agent.

Tests

  • TestMentionBeforeRunnerEnrollsWakesOnAttach (server pgtest): the consumer runs with no Runner, then @mention an agent; the wake fails and an owed row lands. A Runner then attaches, and the agent gets a session.
    • 10/10 runs pass with -race.
    • With drainOwedRewake disabled it fails: "no session started for the owed agent after the Runner attached".
  • The server and delivery suites pass (unit and pgtest, -race). sqlc drift is clean. Lint reports 0 issues.

Notes

  • Subscribed members that are not mentioned have no owed row, so this does not retry them. Their cursor keeps the message, and the next start delivers it.
  • Found while testing: a wake from the delivery loop runs under the system role, so its agent_sessions row is stamped with tenant_id ''. This predates this PR and is filed as RIG-4167.

Live check after merge: redeploy, @mention an agent within 10s, and it replies.

A mention made after a restart, before the Runner re-enrolls, failed its wake with
Unavailable and nothing retried it. When a Runner command stream attaches, the hub
now notifies the delivery consumer, which wakes every agent with an owed mention.
WakeAgent skips live agents and coalesces duplicates.

Co-authored-by: Matt Wilkinson <matt@rigel.build>
@linear-code

linear-code Bot commented Oct 2, 2026

Copy link
Copy Markdown

RIG-4166

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

Compass engineering docs preview: https://compass-server-rig-4166-wake.compass-eng-docs.pages.dev

Deployed from compass-server/rig-4166-wake-owed-on-attach at 5376bb3.

@rigel-mintaka
rigel-mintaka marked this pull request as ready for review October 2, 2026 01:59
@mattwilkinsonn
mattwilkinsonn added this pull request to stack #1467 October 2, 2026 03:19
@trunk-io
trunk-io Bot merged commit 066e46c into main Oct 2, 2026
16 checks passed
@trunk-io
trunk-io Bot deleted the compass-server/rig-4166-wake-owed-on-attach branch October 2, 2026 03:46
@trunk-io

trunk-io Bot commented Oct 2, 2026

Copy link
Copy Markdown

This pull request was merged into main as part of stacked PR 1466.

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.

2 participants