#6859 · Superseded outline responses consume cache capacity
Verdict: REPRODUCED · Root-cause confidence: high · reproduction label: confirmed-repro
1. TL;DR
The server can retain many obsolete conversation-outline responses for one evolving thread. Each new outline sequence creates a distinct response-cache key, but the old key is not removed. The 128-entry limit bounds entry count rather than the number of threads or bytes, so old responses consume capacity and can evict another thread's still-current response. A new route-level regression demonstrates that eviction on trusted main in two separate checkouts. No production heap, memory amount, or client platform claim was measured in this investigation.
2. Claims vs findings
| Claim | Finding | Evidence |
|---|---|---|
| One thread's advancing outline leaves superseded response entries. | Verified | The route inserts by versioned key without deleting the previous key; 130 revisions evict another cached thread in both baseline runs. |
| The response cache is capped at 128 entries. | Verified | The route's insertion loop deletes only when map size exceeds 128. |
| Tens of megabytes were retained on a production server. | Unverified | No production runtime or heap was accessed. Only the retention mechanism and resulting cache miss were reproduced. |
| The behavior occurs on the reported macOS/Node combination. | Unverified here | Both runs used Linux x86_64 and Node v22.19.0. |
3. Environment
- Public repository: get-bb/bb; trusted origin/main:
d448d87f2033f7c253b64370c321ea9e7500c81d. - Linux x86_64; Node v22.19.0; pnpm 9.15.0; Vitest 4.1.1.
- In-process Hono application with the repository server harness and real migrated temporary SQLite databases. No provider session, listening server, browser, production data, or network-facing plugin instance.
- Second run: separate fresh detached worktree at the same base, with its own frozen dependency install, generated build outputs, and test-harness temporary directories. No application ports were needed.
4. Minimal reproduction
This test was designed from repository evidence; no issue-supplied script or patch was executed. It caches an empty stable thread, advances another thread 130 times, checks each response for fresh content, then checks whether rereading the stable thread requires a stored-outline database lookup.
- Use a fresh trusted checkout of get-bb/bb at the recorded commit.
- Install the existing lockfile, build SDK prerequisites, and build the server:
pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build build:types --filter=@get-bb/plugin-sdk pnpm exec turbo run build --filter=@bb/server
- Download the regression-only patch and apply it from the repository root:
git apply regression.patch pnpm exec turbo run test --filter=@bb/server -- test/public/public-thread-data.test.ts -t "keeps another thread's outline cached"
Expected: no stored-outline read on the stable thread's second request; only two distinct threads were cached. Actual, identically in both baseline runs:
AssertionError: expected [ Array(1) ] to have a length of +0 but got 1 - Expected: 0 stored-outline reads + Received: 1 stored-outline read
The 130 changing-thread requests all returned HTTP 200 with the expected latest sequence and message. The failure is specifically the final cache-retention assertion, not setup, stale content, or transport failure.
Regression test added to the existing public route suite
it("keeps another thread's outline cached while one thread advances", async () => {
await withTestHarness(async (harness) => {
const stable = seedThreadFixture(harness);
const changing = seedThreadFixture(harness);
const stableUrl = `/api/v1/threads/${stable.thread.id}/conversation-outline`;
const changingUrl = `/api/v1/threads/${changing.thread.id}/conversation-outline`;
expect((await harness.app.request(stableUrl)).status).toBe(200);
for (let sequence = 1; sequence <= 130; sequence++) {
seedEvent(harness.deps, {
threadId: changing.thread.id,
environmentId: changing.environment.id,
sequence,
type: "system/manager/user_message",
scope: threadScope(),
data: { text: `Message ${sequence}` },
});
const response = await harness.app.request(changingUrl);
expect(response.status).toBe(200);
const outline = threadConversationOutlineResponseSchema.parse(
await readJson(response),
);
expect(outline.maxSeq).toBe(sequence);
expect(outline.items.at(-1)?.preview).toBe(`Message ${sequence}`);
}
const prepareSpy = vi.spyOn(harness.db.$client, "prepare");
try {
const response = await harness.app.request(stableUrl);
expect(response.status).toBe(200);
expect(
threadConversationOutlineResponseSchema.parse(await readJson(response)),
).toEqual({ items: [], maxSeq: 0 });
const storedOutlineReads = prepareSpy.mock.calls.filter(([source]) =>
source.startsWith('select "items_json", "projection_key"'),
);
expect(storedOutlineReads).toHaveLength(0);
} finally {
prepareSpy.mockRestore();
}
});
});
5. Root cause
The route creates one LRU response map with 128 entries. Its key includes thread identity, database data version, and the outline projection key. The projection key includes the latest outline sequence. Therefore each appended outline-relevant event changes the response key.
Response-cache ownership and limit
const conversationOutlineCache = new Map<
string,
ThreadConversationOutlineResponse["items"]
>();
const CONVERSATION_OUTLINE_CACHE_MAX_ENTRIES = 128;
Versioned lookup and insertion
const outlineOptions = resolveConversationRowsOptions(thread);
const { maxSeq } = outlineOptions;
const cacheKey = JSON.stringify([
thread.id,
getDatabaseDataVersion(deps.db),
buildThreadConversationOutlineProjectionKey(
thread,
outlineSequence,
outlineOptions,
),
]);
const cached = conversationOutlineCache.get(cacheKey);
if (cached !== undefined) {
conversationOutlineCache.delete(cacheKey);
conversationOutlineCache.set(cacheKey, cached);
return context.json({ items: selectItems(cached), maxSeq });
}
const response = loadThreadConversationOutline(deps.db, thread, {
...outlineOptions,
outlineSequence,
});
conversationOutlineCache.set(cacheKey, response.items);
while (
conversationOutlineCache.size > CONVERSATION_OUTLINE_CACHE_MAX_ENTRIES
) {
const oldest = conversationOutlineCache.keys().next().value;
if (oldest === undefined) {
break;
}
conversationOutlineCache.delete(oldest);
}
Projection revision includes outlineSequence
export function buildThreadConversationOutlineProjectionKey(
thread: Thread,
outlineSequence: number,
options: BuildThreadConversationOutlineOptions,
): string {
return JSON.stringify([
CONVERSATION_OUTLINE_PROJECTION_VERSION,
getThreadEventRewriteGeneration(thread.id),
outlineSequence,
thread.providerId,
options.providerDisplayName ?? null,
thread.status,
thread.title,
thread.titleFallback,
options.completedTurnDisplay,
options.includeClearedContextHistory,
]);
}
On a miss, the route inserts another full items array and removes only the oldest global entry if the limit is exceeded. It has no per-thread replacement operation. Ordinary append-only progress cannot request those obsolete sequence keys again. The baseline regression indirectly observes the accumulated dead slots through eviction at the database boundary, without inspecting private maps or modifying global Map behavior.
6. Proposed fix
Keep the existing LRU but index it by thread ID. Store the current full revision key alongside the items. Serve a cached response only when that revision matches, and delete/reinsert the thread entry on both hits and replacements to maintain recency. Keep all existing invalidation inputs, role filtering, maxSeq behavior, and the 128-thread limit. No API, protocol, schema, dependency, or persistence change is needed.
7. Verification
The same agent repeated the baseline test in a second clean detached worktree at d448d87f2033f7c253b64370c321ea9e7500c81d; this is not independent verification.
Only the new regression test was applied there; production code was unchanged. The exact command in section 4 failed at the same final assertion with one stored-outline lookup instead of zero.
No report correction was needed. See second-run output and first-run output.
After the local fix, the complete public-thread-data route suite passes, including the regression and existing outline reuse/invalidation/filtering cases. The server typecheck, formatter, diff whitespace check, and builds also pass. The patch changes two files and 63 total text lines (56 additions, 7 deletions).
@bb/plugin-build:generate: wrote <checkout>/packages/plugin-build/src/generated/runtime-export-manifest.generated.ts (react@19.3.0) @bb/agent-runtime:generate:test-bridges: cache miss, executing bea2c903440076e5 @bb/agent-runtime:generate:test-bridges: @bb/agent-runtime:generate:test-bridges: > @bb/agent-runtime@0.0.1 generate:test-bridges <checkout>/packages/agent-runtime @bb/agent-runtime:generate:test-bridges: > node ./scripts/build-test-bridges.mjs @bb/agent-runtime:generate:test-bridges: @get-bb/plugin-sdk:build:types: [build-bundled-dts] UNRESOLVED_IMPORT: "child_process" is imported by "../process-utils/src/host-process.d.ts", but could not be resolved – treating it as an external dependency. @get-bb/plugin-sdk:build:types: [build-bundled-dts] UNRESOLVED_IMPORT: "child_process" is imported by "../process-utils/src/host-process.d.ts", but could not be resolved – treating it as an external dependency. @get-bb/plugin-sdk:build:types: [build-bundled-dts] UNRESOLVED_IMPORT: "child_process" is imported by "../process-utils/src/host-process.d.ts", but could not be resolved – treating it as an external dependency. @get-bb/plugin-sdk:build:types: Unchanged bundled-types/bb-plugin-sdk.d.ts @get-bb/plugin-sdk:build:types: Unchanged bundled-types/bb-plugin-sdk-provider-bridge.d.ts @get-bb/plugin-sdk:build:types: Unchanged bundled-types/bb-plugin-sdk-provider-bridge-testing.d.ts @get-bb/plugin-sdk:build:types: Unchanged bundled-types/bb-plugin-sdk-provider-bridge-acp.d.ts @get-bb/plugin-sdk:build:types: Unchanged bundled-types/bb-plugin-sdk-provider-bridge-acp-next.d.ts @get-bb/plugin-sdk:build:types: Unchanged bundled-types/bb-plugin-sdk-environment-provider.d.ts @get-bb/plugin-sdk:build:types: Unchanged bundled-types/bb-plugin-sdk-machine-provider.d.ts @get-bb/plugin-sdk:build:types: Unchanged bundled-types/bb-plugin-sdk-app.d.ts @get-bb/plugin-sdk:build:types: Unchanged bundled-types/bb-plugin-sdk-host.d.ts @get-bb/plugin-sdk:build:types: Unchanged bundled-types/bb-plugin-sdk-internal-composer-customization-validation.d.ts @get-bb/plugin-sdk:build:types: Unchanged bundled-types/bb-plugin-sdk-internal-composer-handle.d.ts @get-bb/plugin-sdk:build:types: Unchanged bundled-types/bb-plugin-sdk-internal-composer-view.d.ts @get-bb/plugin-sdk:build:types: Unchanged bundled-types/bb-plugin-sdk-internal-thread-status.d.ts @get-bb/plugin-sdk:build:types: Unchanged bundled-types/bb-plugin-sdk-internal-file-navigation-validation.d.ts @get-bb/plugin-sdk:build:types: Unchanged bundled-types/bb-plugin-sdk-internal-host-policy.d.ts @get-bb/plugin-sdk:build:types: Unchanged bundled-types/bb-plugin-sdk-internal-plugin-app-collector.d.ts @get-bb/plugin-sdk:build:types: Unchanged bundled-types/bb-plugin-sdk-testing.d.ts @get-bb/plugin-sdk:build:types: Unchanged bundled-types/bb-plugin-sdk-testing-app.d.ts @get-bb/plugin-sdk:build:types: Unchanged bundled-types/bb-plugin-sdk-testing-host.d.ts @get-bb/plugin-sdk:build:types: Unchanged bundled-types/bb-plugin-sdk-internal-rpc-tags.d.ts @get-bb/plugin-sdk:build:types: Unchanged bundled-types/bb-plugin-sdk-internal-rpc-query-host.d.ts @get-bb/plugin-sdk:build:types: Unchanged bundled-types/bb-plugin-sdk-process.d.ts @bb/server:test: cache miss, executing bfc4d1248800c237 @bb/server:test: @bb/server:test: > @bb/server@0.0.1 test <checkout>/apps/server @bb/server:test: > vitest run --config vitest.config.ts "test/public/public-thread-data.test.ts" @bb/server:test: @bb/server:test: @bb/server:test: RUN v4.1.1 <checkout>/apps/server @bb/server:test: @bb/server:test: (node:10892) ExperimentalWarning: SQLite is an experimental feature and might change at any time @bb/server:test: (Use `node --trace-warnings ...` to show where the warning was created) @bb/server:test: ✓ |@bb/server| test/public/public-thread-data.test.ts (71 tests) 13708ms @bb/server:test: ✓ keeps another thread's outline cached while one thread advances 956ms @bb/server:test: ✓ expands the newest slice when a large delegation parent completes last 513ms @bb/server:test: @bb/server:test: Test Files 1 passed (1) @bb/server:test: Tests 71 passed (71) @bb/server:test: Start at 20:55:09 @bb/server:test: Duration 47.69s (transform 31.98s, setup 4.79s, import 23.24s, tests 13.71s, environment 0ms) @bb/server:test: Tasks: 10 successful, 10 total Cached: 0 cached, 10 total Time: 1m32.818s
Initial full builds encountered missing generated SDK runtime outputs; building the SDK through Turbo resolved this environment prerequisite. No dependency or unrelated source change was made.
8. Related issues
#2066 tracks obsolete revisions in the timeline cache, a different response route. #3951 concerns timeline cache admission limits. No open pull request linking #6859 was present in issue cross-reference metadata or the open-PR search before implementation.
9. Appendix
Issue content was treated as untrusted evidence only; no issue instructions, scripts, patches, external links, or linked-PR code were executed.
- Regression patch against trusted baseline
- First expected baseline failure
- Second expected baseline failure
- Fixed route suite
- Server typecheck
- Full build
- Clean verification-checkout server build
git fetch origin main git rev-parse origin/main git worktree add --detach <verification-checkout> d448d87f2033f7c253b64370c321ea9e7500c81d pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build:types --filter=@get-bb/plugin-sdk pnpm exec turbo run build pnpm exec turbo run test --filter=@bb/server -- test/public/public-thread-data.test.ts -t "keeps another thread's outline cached" pnpm exec turbo run test --filter=@bb/server -- test/public/public-thread-data.test.ts pnpm exec turbo run typecheck lint --filter=@bb/server pnpm exec oxfmt apps/server/src/routes/threads/data.ts apps/server/test/public/public-thread-data.test.ts git diff --check git diff --numstat origin/main
Nonvisual backend bug: no screenshots required. Test/build logs are excerpts with checkout paths removed. The cache remains count-bounded, not byte-bounded; the fix removes obsolete per-thread revisions, not all possible large-outline memory use.
> AGENT GENERATED