Skip to content

fix(server): run a delivery-loop wake under the agent's tenant (RIG-4167) - #1466

Merged
trunk-io[bot] merged 1 commit into
compass-server/rig-4166-wake-owed-on-attachfrom
compass-server/rig-4167-wake-tenant
Oct 2, 2026
Merged

trunk-io[bot] merged 1 commit into
compass-server/rig-4166-wake-owed-on-attachfrom
compass-server/rig-4167-wake-tenant

Conversation

@rigel-mintaka

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

Copy link
Copy Markdown
Contributor

Fixes RIG-4167. Stacked on #1465.

Problem

delivery.Consumer.Run runs under store.WithSystemRole. Every WakeAgent it calls (mention wake, lost-session wake, owed wake on attach) inherited that context. The system role sets no tenant GUC, so RecordAgentSession stamped agent_sessions.tenant_id with ''. No tenant's request path could read the woken session.

Change

  • store.AccountTenant reads accounts.tenant_id.
  • store.WithoutSystemRole clears the system-role mark.
  • lifecycleService.WakeAgent runs wakeCtx first. Under the system role it resolves the agent's tenant, then runs the wake as WithTenant(WithoutSystemRole(ctx)). If the tenant read fails, the wake is skipped and the error is logged.

Tests

  • TestMentionBeforeRunnerEnrollsWakesOnAttach now reads the woken session on the request path, under the bootstrap tenant. It passes 5/5 with -race. With wakeCtx removed it fails: "no session started for the owed agent after the Runner attached". The row exists but is stamped ''.
  • The server, store, delivery and runnerhub suites pass (unit and pgtest, -race). sqlc drift is clean. Lint reports 0 issues.

Known gap

Rows that earlier wakes already stamped '' (in agent_sessions and session_bindings) stay hidden from tenant-scoped reads. The next wake for those agents fresh-starts instead of resuming. A backfill needs a new migration, and compass-managed's #1375 currently holds 0002. The backfill is UPDATE agent_sessions s SET tenant_id = a.tenant_id FROM accounts a WHERE s.agent_account_id = a.id AND s.tenant_id = '', plus the same for bindings. It is left for after #1375 lands, to avoid a migration-number collision.

…167)

The delivery consumer runs under the system role, so WakeAgent did too, and the
agent_sessions row a fresh start records was stamped tenant_id ''. No tenant could
see the woken session. WakeAgent now resolves the agent's tenant and runs the wake
tenant-scoped.

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

linear-code Bot commented Oct 2, 2026

Copy link
Copy Markdown

RIG-4167

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

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

Deployed from compass-server/rig-4167-wake-tenant at 1aafad5.

@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 commented Oct 2, 2026 •

Copy link
Copy Markdown

😎 Stack merged successfully - details.

@trunk-io
trunk-io Bot merged commit 52681dc into main Oct 2, 2026
17 checks passed
@trunk-io
trunk-io Bot deleted the compass-server/rig-4167-wake-tenant branch October 2, 2026 03:46
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