← reports

#6333 · System notices bypass the active-compaction queue

Bug Priority: Medium Effort: Medium threads provider-codex

GitHub issue · October 26, 2026 · Trusted base: dbb5945406f70a39d6622619349baa1971693263

Verdict: REPRODUCED at the server dispatch boundary · Root-cause confidence: high.

1. TL;DR

A system notice delivered while a provider-accepted compaction is running takes the active-turn steering path instead of waiting. Ordinary messages already have a compaction guard, but parent system notices bypass that path. A focused test against the real server and migrated SQLite reproduces the missing queue entry on trusted main, and the same agent repeats that failure in a second clean checkout. The small proposed fix reuses the existing compaction predicate and durable queue. A live Codex rejection, the rendered error, notification loss, and automation disablement are not claimed as experimentally verified.

2. Claims vs findings

ClaimStatusEvidence
A completion notice can target an active compaction instead of queueing.VerifiedAccepted-compaction regression fails with an empty queue in both clean-base runs; production dispatch explicitly builds an auto target with the active turn ID.
The problem also occurs before the provider accepts the compaction.Not observedThe pre-acceptance regression already passes on main through the existing turn-starting queue.
Codex rejects steering a compaction and BB displays a command error.Partially supportedThe bridge forwards steering to Codex and server rejection settlement emits a thread error. No real Codex process or browser was run.
Compaction itself succeeds, and a notification may be lost.UnverifiedThe isolated regression supplies successful compaction completion; it does not measure the live provider's completion or recovery after rejection.
A scheduled automation is disabled as a result.UnverifiedNo automation execution or disablement was reproduced.
Queueing can preserve the system notice and deliver it exactly once after compaction.Verified after fixThe regression checks deferred dispatch, a new-turn target after completion, original input/subject/kind/null sender, empty queue, and no second drain.

3. Environment

4. Minimal reproduction

  1. Create a clean checkout at the trusted base and install/build repository dependencies:
    git clone https://github.com/get-bb/bb.git bb-6333
    cd bb-6333
    git checkout --detach dbb5945406f70a39d6622619349baa1971693263
    pnpm install --frozen-lockfile --prefer-offline
    pnpm exec turbo run build:types --filter=@get-bb/plugin-sdk
    pnpm exec turbo run build
  2. Save the complete test-only patch from the expandable section below as regression.patch in the checkout. Apply only this investigator-authored regression:
    git apply regression.patch
    pnpm exec turbo run test --filter=@bb/server -- test/public/public-thread-compaction.test.ts -t 'queues system notices'
  3. The test starts manual compaction through the public API. It records provider turn acceptance, then invokes the real parent-system message dispatcher with a child-completed notice. No issue-provided commands or code are used.
  4. Expected: one queued notice and no immediate notice dispatch. Actual on trusted main:
    ✓ queues system notices until compaction finishes (provider accepted: false)
    × queues system notices until compaction finishes (provider accepted: true)
    AssertionError: expected [] to deeply equal [ ObjectContaining{…} ]
    Test Files  1 failed (1)
    Tests  1 failed | 1 passed | 10 skipped (12)

The complete test-only patch appears below, including its imports and context in the trusted base file, whose existing helpers it uses. Raw evidence stays outside the public repository; the relevant output is inlined here. This is a nonvisual dispatch defect; no screenshot is fabricated.

Focused regression (uses existing helpers in the attached file)
  it.each([false, true])(
    "queues system notices until compaction finishes (provider accepted: %s)",
    async (accepted) => {
      await withTestHarness(async (harness) => {
        const { host, session, thread } = seedCompactableThread(harness, {
          providerId: "codex",
          providerThreadId: "provider-notice-compaction",
        });
        const responder = registerSuccessfulTurnResponder(harness, {
          hostId: host.id,
          sessionId: session.id,
        });
        const response = await harness.app.request(
          `/api/v1/threads/${thread.id}/compact`,
          { method: "POST" },
        );
        expect(response.status).toBe(200);
        const compactRequest = responder.requests.find(
          ({ command }) => command.type === "turn.submit",
        );
        if (
          !compactRequest ||
          compactRequest.command.type !== "turn.submit" ||
          !thread.environmentId
        ) {
          throw new Error("Expected compaction request and environment");
        }
        const turnId = "turn-notice-compaction";
        if (accepted) {
          seedAcceptedProviderTurn(harness, {
            clientRequestId: compactRequest.command.requestId,
            environmentId: thread.environmentId,
            providerThreadId: "provider-notice-compaction",
            threadId: thread.id,
            turnId,
          });
        }
        const input = [
          {
            type: "text" as const,
            text: "Child work is complete.",
            mentions: [],
          },
        ];
        const subject = {
          kind: "thread" as const,
          threadId: "child-notice",
          threadName: "Child",
        };
        expect(
          await queueParentSystemMessage(harness.deps, {
            input,
            parentThreadId: thread.id,
            systemMessageKind: "child-completed",
            systemMessageSubject: subject,
          }),
        ).toBe(true);
        expect(listQueuedThreadMessages(harness.db, thread.id)).toEqual([
          expect.objectContaining({
            content: JSON.stringify(input),
            senderThreadId: null,
          }),
        ]);
        expect(
          await sendNextQueuedMessageIfPresent(harness.deps, {
            threadId: thread.id,
          }),
        ).toBe(false);
        expect(
          responder.requests.filter(
            ({ command }) => command.type === "turn.submit",
          ),
        ).toHaveLength(1);
        if (!accepted) {
          seedAcceptedProviderTurn(harness, {
            clientRequestId: compactRequest.command.requestId,
            environmentId: thread.environmentId,
            providerThreadId: "provider-notice-compaction",
            threadId: thread.id,
            turnId,
          });
        }
        seedEvent(harness.deps, {
          threadId: thread.id,
          environmentId: thread.environmentId,
          providerThreadId: "provider-notice-compaction",
          sequence:
            getLatestThreadSequence(harness.db, { threadId: thread.id }) + 1,
          type: "turn/completed",
          scope: turnScope(turnId),
          data: {
            providerThreadId: "provider-notice-compaction",
            status: "completed",
          },
        });
        applyTurnCompletedEvent(harness.deps, {
          threadId: thread.id,
          providerThreadId: "provider-notice-compaction",
          type: "turn/completed",
          scope: turnScope(turnId),
          status: "completed",
        });
        expect(
          await sendNextQueuedMessageIfPresent(harness.deps, {
            threadId: thread.id,
          }),
        ).toBe(true);
        expect(listQueuedThreadMessages(harness.db, thread.id)).toEqual([]);
        await expect
          .poll(
            () =>
              responder.requests.filter(
                ({ command }) => command.type === "turn.submit",
              ).length,
          )
          .toBe(2);
        expect(
          responder.requests.filter(
            ({ command }) => command.type === "turn.submit",
          )[1]?.command,
        ).toMatchObject({
          input,
          target: { mode: "start" },
        });
        const notices = listEvents(harness.db, { threadId: thread.id })
          .filter((event) => event.type === "client/turn/requested")
          .map((event) =>
            turnRequestEventDataSchema.parse(JSON.parse(event.data)),
          )
          .filter((event) => event.initiator === "system");
        expect(notices).toEqual([
          expect.objectContaining({
            input,
            senderThreadId: null,
            systemMessageKind: "child-completed",
            systemMessageSubject: subject,
            target: { kind: "new-turn" },
          }),
        ]);
        expect(
          await sendNextQueuedMessageIfPresent(harness.deps, {
            threadId: thread.id,
          }),
        ).toBe(false);
      });
    },
  );

5. Root cause

The ordinary send checkpoint already checks isManualCompactionActive before joining a turn. Automatic queue drains also refuse to dispatch during compaction. The predicate identifies a standalone built-in compaction request and its active turn from persisted events: thread-events.ts.

Parent notices use a separate delivery path. Its entry condition only tests for a pending interaction, then delivers immediately: parent-system-messages.ts. The active branch persists and submits this target:

target: {
  mode: "auto",
  expectedTurnId: expectedSteerTurnId,
}

Once compaction has a provider turn ID, this is a steer into that turn. The Codex bridge forwards turn/steer and propagates rejection; the server's failed-command settlement appends thread_command_failed. That explains the reported symptom without proving the provider rejection experimentally. No transport/protocol change is needed to prevent the observed misdispatch.

6. Proposed fix

Add the existing isManualCompactionActive predicate to the immediate-delivery condition in queueParentSystemMessage. Reuse the current durable queued-message fallback, which already stores the system notice kind and subject and waits on thread-busy. The queue drain already blocks active compaction and delivers the notice as a new system turn after completion. This changes three production text lines (two additions and one deletion), with no public fields, dependencies, migrations, or protocol changes.

The regression covers both pre-acceptance and accepted compaction. It verifies queue preservation during compaction and exactly one post-compaction delivery with the original taxonomy and sender. Existing tests cover active/idle status races and ordinary message dispatch. This focused repair does not claim to audit every possible concurrent dispatch race or automation behavior.

7. Verification

The same agent created a second detached worktree from the recorded base before modifying production code. It installed dependencies with the frozen lockfile and completed the full build. Only the investigator-authored regression patch was added. Running the exact focused command again produced the same accepted-compaction empty-queue failure; the pre-acceptance case passed. This is a repeated clean-checkout check, not an independent reviewer. Both runs use fresh test databases and temporary harness directories; no persistent application instance or ports are shared.

After applying the proposed fix in the first checkout:

pnpm exec turbo run test --filter=@bb/server -- test/public/public-thread-compaction.test.ts test/threads/parent-system-message-dispatch.test.ts test/threads/thread-send-dispatch.test.ts
Test Files  3 passed (3)
Tests  54 passed (54)

pnpm exec turbo run lint typecheck --filter=@bb/server
Tasks: 6 successful, 6 total

pnpm exec oxfmt apps/server/src/services/threads/parent-system-messages.ts apps/server/test/public/public-thread-compaction.test.ts
git diff --check

The package defines typecheck but no separate lint task; the latter command does not establish package lint coverage. No browser/live-provider journey was run. The final fix has 159 changed text lines across two files, including regression coverage.

8. Related issues and pull requests

No linked open pull request appeared in the issue timeline or an open-PR search for 6333 during investigation. The latest parent-notice status-race work is PR #6243, already on trusted main; no code from a linked PR branch was executed. No duplicate report was found in the bounded compaction issue search.

9. Appendix

All root-cause permalinks use the recorded base commit. Issue content was treated only as untrusted claims; no issue-provided code, scripts, URLs, or instructions were executed. Reproduction setup, expected and actual output, and the complete test-only patch are inlined here. Classification is Bug / Medium priority / Medium effort with threads and provider-codex labels. The possible automation interaction and the exact installed-version behavior remain outside the evidence.

Complete test-only patch
diff --git a/apps/server/test/public/public-thread-compaction.test.ts b/apps/server/test/public/public-thread-compaction.test.ts
index b47a6d046..ddff11d36 100644
--- a/apps/server/test/public/public-thread-compaction.test.ts
+++ b/apps/server/test/public/public-thread-compaction.test.ts
@@ -1,12 +1,18 @@
 import { describe, expect, it } from "vitest";
-import { getLatestThreadSequence, listQueuedThreadMessages } from "@bb/db";
+import {
+  getLatestThreadSequence,
+  listEvents,
+  listQueuedThreadMessages,
+} from "@bb/db";
 import {
   createStandaloneBuiltinCompactCommandInput,
+  turnRequestEventDataSchema,
   turnScope,
 } from "@bb/domain";
 import type { ClientTurnRequestId } from "@bb/domain";
 import { applyTurnCompletedEvent } from "../../src/internal/turn-completed-events.js";
 import { sendNextQueuedMessageIfPresent } from "../../src/services/threads/queued-messages.js";
+import { queueParentSystemMessage } from "../../src/services/threads/parent-system-messages.js";
 import {
   registerHostRpcResponder,
   type HostRpcHandlerResult,
@@ -285,6 +291,154 @@ describe("public thread compaction", () => {
     });
   });
 
+  it.each([false, true])(
+    "queues system notices until compaction finishes (provider accepted: %s)",
+    async (accepted) => {
+      await withTestHarness(async (harness) => {
+        const { host, session, thread } = seedCompactableThread(harness, {
+          providerId: "codex",
+          providerThreadId: "provider-notice-compaction",
+        });
+        const responder = registerSuccessfulTurnResponder(harness, {
+          hostId: host.id,
+          sessionId: session.id,
+        });
+        const response = await harness.app.request(
+          `/api/v1/threads/${thread.id}/compact`,
+          { method: "POST" },
+        );
+        expect(response.status).toBe(200);
+        const compactRequest = responder.requests.find(
+          ({ command }) => command.type === "turn.submit",
+        );
+        if (
+          !compactRequest ||
+          compactRequest.command.type !== "turn.submit" ||
+          !thread.environmentId
+        ) {
+          throw new Error("Expected compaction request and environment");
+        }
+        const turnId = "turn-notice-compaction";
+        if (accepted) {
+          seedAcceptedProviderTurn(harness, {
+            clientRequestId: compactRequest.command.requestId,
+            environmentId: thread.environmentId,
+            providerThreadId: "provider-notice-compaction",
+            threadId: thread.id,
+            turnId,
+          });
+        }
+        const input = [
+          {
+            type: "text" as const,
+            text: "Child work is complete.",
+            mentions: [],
+          },
+        ];
+        const subject = {
+          kind: "thread" as const,
+          threadId: "child-notice",
+          threadName: "Child",
+        };
+        expect(
+          await queueParentSystemMessage(harness.deps, {
+            input,
+            parentThreadId: thread.id,
+            systemMessageKind: "child-completed",
+            systemMessageSubject: subject,
+          }),
+        ).toBe(true);
+        expect(listQueuedThreadMessages(harness.db, thread.id)).toEqual([
+          expect.objectContaining({
+            content: JSON.stringify(input),
+            senderThreadId: null,
+          }),
+        ]);
+        expect(
+          await sendNextQueuedMessageIfPresent(harness.deps, {
+            threadId: thread.id,
+          }),
+        ).toBe(false);
+        expect(
+          responder.requests.filter(
+            ({ command }) => command.type === "turn.submit",
+          ),
+        ).toHaveLength(1);
+        if (!accepted) {
+          seedAcceptedProviderTurn(harness, {
+            clientRequestId: compactRequest.command.requestId,
+            environmentId: thread.environmentId,
+            providerThreadId: "provider-notice-compaction",
+            threadId: thread.id,
+            turnId,
+          });
+        }
+        seedEvent(harness.deps, {
+          threadId: thread.id,
+          environmentId: thread.environmentId,
+          providerThreadId: "provider-notice-compaction",
+          sequence:
+            getLatestThreadSequence(harness.db, { threadId: thread.id }) + 1,
+          type: "turn/completed",
+          scope: turnScope(turnId),
+          data: {
+            providerThreadId: "provider-notice-compaction",
+            status: "completed",
+          },
+        });
+        applyTurnCompletedEvent(harness.deps, {
+          threadId: thread.id,
+          providerThreadId: "provider-notice-compaction",
+          type: "turn/completed",
+          scope: turnScope(turnId),
+          status: "completed",
+        });
+        expect(
+          await sendNextQueuedMessageIfPresent(harness.deps, {
+            threadId: thread.id,
+          }),
+        ).toBe(true);
+        expect(listQueuedThreadMessages(harness.db, thread.id)).toEqual([]);
+        await expect
+          .poll(
+            () =>
+              responder.requests.filter(
+                ({ command }) => command.type === "turn.submit",
+              ).length,
+          )
+          .toBe(2);
+        expect(
+          responder.requests.filter(
+            ({ command }) => command.type === "turn.submit",
+          )[1]?.command,
+        ).toMatchObject({
+          input,
+          target: { mode: "start" },
+        });
+        const notices = listEvents(harness.db, { threadId: thread.id })
+          .filter((event) => event.type === "client/turn/requested")
+          .map((event) =>
+            turnRequestEventDataSchema.parse(JSON.parse(event.data)),
+          )
+          .filter((event) => event.initiator === "system");
+        expect(notices).toEqual([
+          expect.objectContaining({
+            input,
+            senderThreadId: null,
+            systemMessageKind: "child-completed",
+            systemMessageSubject: subject,
+            target: { kind: "new-turn" },
+          }),
+        ]);
+        expect(
+          await sendNextQueuedMessageIfPresent(harness.deps, {
+            threadId: thread.id,
+          }),
+        ).toBe(false);
+      });
+    },
+  );
+
   it("compacts first and delivers the message once compaction finishes", async () => {
     await withTestHarness(async (harness) => {
       const { host, session, thread } = seedCompactableThread(harness, {
First baseline failure evidence
@bb/server:test:  FAIL  |@bb/server| test/public/public-thread-compaction.test.ts > public thread compaction > queues system notices until compaction finishes (provider accepted: true)
@bb/server:test: AssertionError: expected [] to deeply equal [ ObjectContaining{…} ]
@bb/server:test: 
@bb/server:test: - Expected
@bb/server:test: + Received
@bb/server:test: 
@bb/server:test: - [
@bb/server:test: -   ObjectContaining {
@bb/server:test: -     "content": "[{\"type\":\"text\",\"text\":\"Child work is complete.\",\"mentions\":[]}]",
@bb/server:test: -     "senderThreadId": null,
@bb/server:test: -   },
@bb/server:test: - ]
@bb/server:test: + []
@bb/server:test: 
@bb/server:test:  ❯ test/public/public-thread-compaction.test.ts:347:65
@bb/server:test:     345|           }),
@bb/server:test:     346|         ).toBe(true);
@bb/server:test:     347|         expect(listQueuedThreadMessages(harness.db, thread.id)).toEqua…
@bb/server:test:        |                                                                 ^
@bb/server:test:     348|           expect.objectContaining({
@bb/server:test:     349|             content: JSON.stringify(input),
@bb/server:test:  ❯ withTestHarness test/helpers/test-app.ts:396:12
@bb/server:test:  ❯ test/public/public-thread-compaction.test.ts:297:7
@bb/server:test: 
@bb/server:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
@bb/server:test: 
@bb/server:test: 
@bb/server:test:  Test Files  1 failed (1)
@bb/server:test:       Tests  1 failed | 1 passed | 10 skipped (12)
@bb/server:test:    Start at  20:19:32
@bb/server:test:    Duration  9.12s (transform 4.94s, setup 1.50s, import 4.87s, tests 948ms, environment 0ms)
@bb/server:test: 
Second clean baseline failure evidence
@bb/server:test:  FAIL  |@bb/server| test/public/public-thread-compaction.test.ts > public thread compaction > queues system notices until compaction finishes (provider accepted: true)
@bb/server:test: AssertionError: expected [] to deeply equal [ ObjectContaining{…} ]
@bb/server:test: 
@bb/server:test: - Expected
@bb/server:test: + Received
@bb/server:test: 
@bb/server:test: - [
@bb/server:test: -   ObjectContaining {
@bb/server:test: -     "content": "[{\"type\":\"text\",\"text\":\"Child work is complete.\",\"mentions\":[]}]",
@bb/server:test: -     "senderThreadId": null,
@bb/server:test: -   },
@bb/server:test: - ]
@bb/server:test: + []
@bb/server:test: 
@bb/server:test:  ❯ test/public/public-thread-compaction.test.ts:347:65
@bb/server:test:     345|           }),
@bb/server:test:     346|         ).toBe(true);
@bb/server:test:     347|         expect(listQueuedThreadMessages(harness.db, thread.id)).toEqua…
@bb/server:test:        |                                                                 ^
@bb/server:test:     348|           expect.objectContaining({
@bb/server:test:     349|             content: JSON.stringify(input),
@bb/server:test: 
@bb/server:test:  ❯ withTestHarness test/helpers/test-app.ts:396:12
@bb/server:test:  Test Files  1 failed (1)
@bb/server:test:  ❯ test/public/public-thread-compaction.test.ts:297:7
@bb/server:test:       Tests  1 failed | 1 passed | 10 skipped (12)
@bb/server:test:    Start at  20:20:54
@bb/server:test:    Duration  9.40s (transform 5.20s, setup 1.52s, import 5.14s, tests 887ms, environment 0ms)
@bb/server:test: 
@bb/server:test: 
@bb/server:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
@bb/server:test: