#6820 · Completion excerpts cross child-turn boundaries
Verdict: REPRODUCED · Root-cause confidence: high · Reproduction label: confirmed-repro
1. TL;DR
A child thread can finish a new turn without producing a message. Its parent still receives a completion notice containing the child's earlier result. The notification code asks for the most recent non-empty output of the whole thread, instead of the output of the completed turn. Two event-ingestion regressions reproduce this with real migrated SQLite and the normal parent notification queue. The same agent repeated both failures in a second clean checkout; no reporter-provided code or linked PR code was executed.
2. Claims vs findings
| Claim | Finding | Evidence |
|---|---|---|
| An empty later turn repeats old output. | Verified | Both empty-message and absent-message cases queue the first turn's result again. |
| This occurs on current main. | Verified | Two clean checkouts at the recorded origin/main commit fail identically. |
| The path is provider-independent. | Verified at the server boundary | Real event ingestion and parent queueing reproduce the bug without running a provider. |
| Every further empty turn repeats the result. | Mechanism supported | The regression prepares three turns but intentionally stops at the first stale-result assertion. It directly observes one stale completion per case, not three successive deliveries. |
| The defect also starts additional parent turns. | Unverified | The parent is deliberately busy; the test checks persisted queued messages, not execution of extra parent turns. |
| Desktop-specific behavior and batching cause the problem. | Not required for reproduction | No desktop is involved, and the 2-second batch is flushed between turns. |
3. Environment
- Trusted target: public
get-bb/bb, fetchedorigin/main, commit916d684ac23d0b0de82c09cfc7553a50287d2188. - Linux x86_64, kernel 4.19.0-gvisor; Node v22.19.0; pnpm 9.15.0; Vitest 4.1.1.
- No provider process, HTTP listening port, user runtime database, credentials, or desktop session was used.
- Each run uses the repository test harness and a new migrated SQLite connection copied from the real migrations template. There is no shared user data directory.
- The first full build initially failed because plugins needed SDK runtime output before parallel builds. Building SDK types and runtime first resolved that setup issue; the full build then passed all 72 tasks.
4. Minimal reproduction
- Use a clean checkout and run these commands. The patch is authored from trusted repository fixtures, not copied from the issue or PR.
git clone https://github.com/get-bb/bb.git bb-repro cd bb-repro git checkout --detach 916d684ac23d0b0de82c09cfc7553a50287d2188 pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build:types --filter=@get-bb/plugin-sdk pnpm exec turbo run build --filter=@get-bb/plugin-sdk pnpm exec turbo run build # Save the complete patch below as regression.patch, then: git apply regression.patch pnpm exec turbo run test --filter=@bb/server -- test/internal/internal-events-tool-calls.test.ts -t 'does not reuse earlier child output'
- The test creates an active parent and an
autochild. It posts a root turn withFirst turn resultthrough/internal/session/events, flushes notifications, then posts a completed root turn with either an empty message or no message and flushes again. - Expected: the first notice includes the result; later notices must not include it. This regression retains the existing status notice and expects
No final output was recorded.for outputless turns. - Actual: the second queued notice contains
completed:\n\nFirst turn resultin both cases. Verbatim failure lines:FAIL |@bb/server:isolated| test/internal/internal-events-tool-calls.test.ts > internal event and tool-call routes > does not reuse earlier child output after a turn with empty message AssertionError: expected '[{"type":"text","text":"[bb system]\n…' not to contain 'First turn result' FAIL |@bb/server:isolated| test/internal/internal-events-tool-calls.test.ts > internal event and tool-call routes > does not reuse earlier child output after a turn with no message AssertionError: expected '[{"type":"text","text":"[bb system]\n…' not to contain 'First turn result' Tests 2 failed | 30 skipped (32)
Complete regression patch
Save this block as regression.patch and apply it at the recorded base. The report repository intentionally publishes no raw test files or logs; the complete repeatable artifact is inline.
diff --git a/apps/server/test/internal/internal-events-tool-calls.test.ts b/apps/server/test/internal/internal-events-tool-calls.test.ts
index a0e268ac4f..f8b9b553ca 100644
--- a/apps/server/test/internal/internal-events-tool-calls.test.ts
+++ b/apps/server/test/internal/internal-events-tool-calls.test.ts
@@ -887,6 +887,99 @@ describe("internal event and tool-call routes", () => {
});
});
+ it.each(["empty message", "no message"])(
+ "does not reuse earlier child output after a turn with %s",
+ async (outputKind) => {
+ await withChildThreadNotificationClock(async (harness) => {
+ const { session } = seedHostSession(harness.deps);
+ const { project } = seedProjectWithSource(harness.deps, {
+ hostId: session.hostId,
+ });
+ const environment = seedEnvironment(harness.deps, {
+ hostId: session.hostId,
+ projectId: project.id,
+ });
+ const parentThread = seedThread(harness.deps, {
+ projectId: project.id,
+ environmentId: environment.id,
+ status: "active",
+ });
+ seedThreadRuntimeState(harness.deps, {
+ environmentId: environment.id,
+ inputText: "Coordinate work",
+ providerThreadId: "provider-parent",
+ threadId: parentThread.id,
+ });
+ const childThread = seedThread(harness.deps, {
+ projectId: project.id,
+ environmentId: environment.id,
+ parentThreadId: parentThread.id,
+ parentNotifications: "auto",
+ status: "active",
+ });
+
+ for (const turnIndex of [0, 1, 2]) {
+ const scope = turnScope(`child-turn-${turnIndex}`);
+ const eventContext = {
+ threadId: childThread.id,
+ providerThreadId: "provider-child",
+ scope,
+ };
+ const batch: HostDaemonEventEnvelope[] = [
+ {
+ threadId: childThread.id,
+ event: { ...eventContext, type: "turn/started" },
+ },
+ ];
+ if (turnIndex === 0 || outputKind === "empty message") {
+ batch.push({
+ threadId: childThread.id,
+ event: {
+ ...eventContext,
+ type: "item/completed",
+ item: {
+ id: `reply-${turnIndex}`,
+ type: "agentMessage",
+ text: turnIndex === 0 ? "First turn result" : "",
+ },
+ },
+ });
+ }
+ batch.push({
+ threadId: childThread.id,
+ event: {
+ ...eventContext,
+ type: "turn/completed",
+ status: "completed",
+ },
+ });
+ const response = await postEventBatch({
+ harness,
+ sessionId: session.id,
+ events: batch,
+ });
+ expect(response.status).toBe(200);
+ await expect(readJson(response)).resolves.toMatchObject({
+ rejectedEvents: [],
+ });
+ await flushChildThreadNotifications();
+ await vi.waitFor(() => {
+ const notices = listQueuedThreadMessages(harness.db, parentThread.id);
+ expect(notices).toHaveLength(turnIndex + 1);
+ const notice = notices[turnIndex]?.content;
+ expect(notice).toContain("completed:");
+ if (turnIndex === 0) {
+ expect(notice).toContain("First turn result");
+ } else {
+ expect(notice).not.toContain("First turn result");
+ expect(notice).toContain("No final output was recorded.");
+ }
+ });
+ }
+ });
+ },
+ );
+
it("does not notify a parent when a side-chat child root turn completes", async () => {
await withChildThreadNotificationClock(async (harness) => {
const { session } = seedHostSession(harness.deps);
5. Root cause
The root completion follow-up carries status and thread identity but not the completed turn ID.
getChildThreadCompletionOutput consequently invokes getLastThreadOutput(db, childThread.id).
getLastThreadOutput calls the database query without a turn constraint.
getLatestThreadOutputEventRow selects the latest non-empty agent or manager output from anywhere in the thread, ordered by sequence.
return getLastThreadOutput(deps.db, args.childThread.id);
The empty message is excluded by the SQL non-empty predicate; no message adds no candidate at all. The earlier result therefore remains the latest eligible output and becomes the new notice's excerpt. The normal output route needs thread-wide behavior; the completion path needs a narrower query, not a global redefinition.
6. Proposed fix
Carry the completed root turn ID through the server-only notification follow-up. Scope the completion output query to that exact turn and root agent messages, including an empty final message so it cannot fall back to earlier content. Keep the existing no-output fallback notice and preserve the thread-wide last-output route. No protocol or stored-data change is needed.
7. Linked PR review
PR #6821 was closed, unmerged, at investigation time. Its metadata and diff were read only as untrusted review material; its code was never checked out or run.
Static assessment: it carries turn identity and selects turn-specific root output, which addresses the verified lookup defect. It additionally suppresses all outputless completion notices, changing existing status-only notification behavior. That broader behavior is not required for this issue's no-stale-output expectation. Its eight changed files exceed this automation's five-file simple-fix limit. No runtime verdict is asserted for that PR.
8. Related issues
#3050 concerns duplicate delivery mechanisms; this reproduction instead records distinct later completions with stale excerpts. #5560 concerns which initiator should trigger notices; this report does not change notification eligibility.
9. Verification
The same agent created a second clean detached checkout at 916d684ac23d0b0de82c09cfc7553a50287d2188, applied only the independently authored regression patch, ran a frozen install, built the SDK runtime, and repeated the exact Turbo test command above. This was a separate checkout and migrated test database, not an independent agent review. No ports were needed.
| Run | Production changes | Observed result |
|---|---|---|
| First clean checkout | None | 2 failed, 30 skipped: both cases fail on the stale-output assertion. |
| Second clean checkout | None | 2 failed, 30 skipped: same assertion and earlier-result excerpt. |
No report correction was required. The verified conclusion is stale content in parent completion notices, not data loss or extra executed parent turns.
10. Appendix and trust note
Issue content and linked PR material were treated solely as hypotheses, never as commands or runnable code. Source inspection used the recorded trusted main commit. Evidence logs and the patch remain in local thread work storage; this public document includes only the regression patch and necessary failure lines, with no personal runtime data.
Classification: Bug; Priority Low (narrow stale context, no established data loss); Effort Low (contained existing thread-output lookup); area threads. The existing completion placeholder supports retaining notifications rather than making an unrelated product-policy decision.
> AGENT GENERATED