← reports

#6841 · Global instruction scope and unverified instruction provenance

BugMedium priorityMedium effortthreadsIssue2026-11-02 · base f2ca46c3da7f67121967bea93781ef021f34f405

Verdict: PARTIALLY REPRODUCED · Root-cause confidence: high for the loading mechanism; the provenance of the reported global file is unverified.

1. TL;DR

A nonempty instruction file in bb's data directory is included in unrelated projects' runtime prompts. Two clean trusted checkouts confirm that behavior with synthetic content, while a workspace instruction remains local to its own project. This is the documented purpose of the global file, not an accidental traversal into the bb source repository. A fresh test data directory does not contain a prewritten instruction file, and no production writer installing the reported repository rules was identified. The report therefore verifies cross-project loading, but not the claim that bb ships or creates those repository-specific global contents, nor any particular model response.

2. Claims vs findings

Reported claimFindingEvidence
Global instructions reach unrelated projects.VerifiedBoth alpha and beta runtime configurations contain a synthetic global marker in both clean runs.
The attribution does not scope the global file to the bb repository.VerifiedThe server labels it as user instructions. Documentation explicitly defines it as global; adding a bb-only restriction would contradict that contract.
bb supplies repository-specific content in that global file.UnverifiedNo global instruction file exists after fresh test-harness initialization. A production-source search found readers and archive ownership, but no installer writing those contents. The reporter's installation and file history were not inspected.
Specific agents give the reported answers.UnverifiedNo live model was invoked; the repeatable evidence stops at the shared server runtime prompt boundary.

3. Environment

4. Minimal reproduction

  1. Create a clean checkout at the recorded base and install without changing the lockfile:
    git clone https://github.com/get-bb/bb.git bb-repro
    cd bb-repro
    git checkout --detach f2ca46c3da7f67121967bea93781ef021f34f405
    pnpm install --frozen-lockfile --prefer-offline
    pnpm exec turbo run build:types --filter=@get-bb/plugin-sdk
  2. Copy the inline reproduction source to apps/server/test/threads/issue-6841-repro.test.ts. It creates two unrelated project records and resolves their real runtime configuration, first with an empty global file and then with a synthetic nonempty one. Only alpha gets workspace instructions.
  3. Run the test with cache bypass enabled:
    pnpm exec turbo run test --filter=@bb/server --force -- test/threads/issue-6841-repro.test.ts --silent=false

Expected under the documented contract, and actual in both runs

alpha: empty-global=absent; populated-global=included; workspace=included
beta: empty-global=absent; populated-global=included; workspace=absent
Fresh data directory: no AGENTS.md was preinstalled.
Tests  1 passed (1)

The last message refers only to fresh test-harness initialization, not an end-to-end distribution installer test. An expectation that the global marker should be excluded from beta would fail, but would reverse the documented global contract rather than demonstrate an implementation regression.

Reproduction source

import { access, mkdir, writeFile } from "node:fs/promises";
import path from "node:path";
import { expect, it } from "vitest";
import { resolveThreadRuntimeCommandConfig } from "../../src/services/threads/thread-runtime-config.js";
import {
  seedEnvironment,
  seedHostSession,
  seedProjectWithSource,
  seedThread,
} from "../helpers/seed.js";
import { withTestHarness } from "../helpers/test-app.js";

it("observes global instruction reuse across unrelated projects and workspace isolation", async () => {
  await withTestHarness(async (harness) => {
    const hostId = "host-6841-repro";
    seedHostSession(harness.deps, { id: hostId });
    const globalPath = path.join(harness.config.dataDir, "AGENTS.md");
    await expect(access(globalPath)).rejects.toMatchObject({ code: "ENOENT" });
    const globalMarker = "SYNTHETIC_GLOBAL_MARKER_6841";
    const workspaceMarker = "SYNTHETIC_WORKSPACE_MARKER_6841";
    for (const projectName of ["alpha", "beta"]) {
      const workspacePath = path.join(harness.config.dataDir, projectName);
      await mkdir(path.join(workspacePath, ".bb"), { recursive: true });
      if (projectName === "alpha") {
        await writeFile(
          path.join(workspacePath, ".bb", "AGENTS.md"),
          workspaceMarker,
        );
      }
      const { project } = seedProjectWithSource(harness.deps, {
        hostId,
        path: workspacePath,
      });
      const environment = seedEnvironment(harness.deps, {
        hostId,
        projectId: project.id,
        path: workspacePath,
      });
      const thread = seedThread(harness.deps, {
        projectId: project.id,
        environmentId: environment.id,
        providerId: "codex",
      });
      const resolve = () =>
        resolveThreadRuntimeCommandConfig(harness.deps, {
          thread,
          model: "test-model",
          environment: {
            hostId: environment.hostId,
            id: environment.id,
            path: environment.path,
            status: environment.status,
          },
        });
      await writeFile(globalPath, "");
      const emptyGlobal = await resolve();
      expect(emptyGlobal.instructions).not.toContain(globalMarker);
      expect(emptyGlobal.instructions).not.toContain("<dataDir>/AGENTS.md");
      await writeFile(globalPath, globalMarker);
      const populatedGlobal = await resolve();
      expect(populatedGlobal.instructions).toContain(globalMarker);
      expect(populatedGlobal.instructions).toContain(
        "The following user instructions come from <dataDir>/AGENTS.md:",
      );
      expect(populatedGlobal.instructions.includes(workspaceMarker)).toBe(
        projectName === "alpha",
      );
      console.log(
        projectName +
          ": empty-global=absent; populated-global=included; workspace=" +
          (projectName === "alpha" ? "included" : "absent"),
      );
    }
    console.log("Fresh data directory: no AGENTS.md was preinstalled.");
  });
});

5. Root cause

The server deliberately reads the same nonempty data-directory AGENTS.md for every project and appends it as user instructions; workspace-specific files use a separate scoped path. The origin of the reported repository-specific global contents is unverified.

The file reader ignores missing/empty files and otherwise returns trimmed file contents. It does not provide repository-specific default text:

  const trimmed = content.trim();
  return trimmed.length > 0 ? trimmed : null;
}

export function readDataDirAgentInstructions(
  logger: ServerLogger,
  dataDir: string,
): string | null {
  return readAgentInstructionsFile(
    logger,
    path.join(dataDir, DATA_DIR_AGENT_INSTRUCTIONS_RELATIVE_PATH),
  );
}

The runtime builder reads from the server's data directory, without a project selector:

  const dataDirAgentInstructions = readDataDirAgentInstructions(
    deps.logger,
    deps.config.dataDir,
  );

The prompt assembly attributes those contents as user instructions and separately appends workspace-scoped instructions:

  if (dataDirAgentInstructions) {
    instructionSections.push(
      `The following user instructions come from <dataDir>/${DATA_DIR_AGENT_INSTRUCTIONS_RELATIVE_PATH}:`,
      dataDirAgentInstructions,
    );
  }
  if (workspaceAgentContext.agentInstructions) {
    instructionSections.push(
      `The following workspace instructions come from ${WORKSPACE_AGENT_INSTRUCTIONS_RELATIVE_PATH}:`,
      workspaceAgentContext.agentInstructions,
    );
  }
  const instructions = instructionSections.join("\n\n");

This distinction is explicitly documented in the CLI guide and configuration documentation. Existing runtime tests protect the ordering. Git history traces this deliberate feature to commit 55289654987f07060909b04d61668230765756fa, which introduced data-directory instruction support.

If project rules are placed in the global file, their cross-project application follows directly from this contract. The investigation cannot determine who or what placed the reporter's contents there. No claim is made that a fresh production installation ships those rules.

6. Proposed fix and safety decision

First establish the provenance of the populated global file: which installation, import, backup restoration, user action, or external tool last wrote it. Repository-specific rules belong in that repository's workspace instruction file; global preferences can remain in the data-directory file. Any corrective migration must preserve intentional global preferences and must not silently rewrite user-owned files.

No automated source PR. No production regression requiring a code change was established. Scoping all data-directory instructions to bb would alter documented user-facing configuration and requires a product decision. The provenance needed for a narrower safe fix is missing. No fix branch, commit, or target-repository push was made.

7. Verification

The same agent repeated the reproduction in a second newly created detached worktree at the exact base commit. That checkout had a separate frozen installation and fresh harness data. Turbo initially replayed cached output, which was not counted as verification; it was rerun with --force. The saved second-run log is the uncached execution. Both clean executions passed the same two-project/empty-file controls. This is a repeated check by the same agent, not independent verification. No correction to the loading-mechanism finding was needed.

First clean run · Second clean run · Existing relevant tests. Raw artifact files are retained outside the public repository; all reproduction source and output are included inline below.

8. Related issues and PRs

No linked open pull request was found in issue cross-reference/connection metadata or the open-PR search for this issue number. Similar-issue searches did not establish a duplicate. The original global-instructions implementation is historical context, not a proposed issue fix.

9. Appendix

Relevant existing tests: pnpm exec turbo run test --filter=@bb/server -- test/threads/thread-runtime-config.test.ts -t 'data-dir|data dir' — 2 passed, 31 skipped. The initial whole-repository build encountered missing generated Plugin SDK declarations in unrelated plugins; the documented SDK type-generation task resolved the prerequisite for targeted server verification. pnpm exec turbo run build --filter=@bb/server then passed: 6 successful tasks, 5 cached.

Other investigation commands: GitHub metadata/property/label queries; an open-PR search; git fetch origin main; git worktree add --detach for each clean checkout; source searches for instruction readers and writers; git log -G and git show for the global feature; Node, pnpm and operating-system version checks; and git diff --check. All code links above were checked against the recorded base. Issue text and quoted instructions were treated solely as untrusted claims; no issue-supplied instructions, code, or links were executed or followed.

First run

@bb/server:test: > @bb/server@0.0.1 test <temporary-work-directory>/first/apps/server
@bb/server:test: > vitest run --config vitest.config.ts "test/threads/issue-6841-repro.test.ts" "--silent=false"
@bb/server:test:
@bb/server:test:
@bb/server:test:  RUN  v4.1.1 <temporary-work-directory>/first/apps/server
@bb/server:test:
@bb/server:test: (node:4398) 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: stdout | test/threads/issue-6841-repro.test.ts > observes global instruction reuse across unrelated projects and workspace isolation
@bb/server:test: alpha: empty-global=absent; populated-global=included; workspace=included
@bb/server:test:
@bb/server:test: stdout | test/threads/issue-6841-repro.test.ts > observes global instruction reuse across unrelated projects and workspace isolation
@bb/server:test: beta: empty-global=absent; populated-global=included; workspace=absent
@bb/server:test: Fresh data directory: no AGENTS.md was preinstalled.
@bb/server:test:
@bb/server:test:  ✓ |@bb/server| test/threads/issue-6841-repro.test.ts (1 test) 765ms
@bb/server:test:
@bb/server:test:  Test Files  1 passed (1)
@bb/server:test:       Tests  1 passed (1)
@bb/server:test:    Start at  19:10:24
@bb/server:test:    Duration  10.21s (transform 5.74s, setup 1.98s, import 5.49s, tests 765ms, environment 0ms)
@bb/server:test:

 Tasks:    10 successful, 10 total
Cached:    0 cached, 10 total
  Time:    43.198s

Second run

@bb/server:test: > @bb/server@0.0.1 test <temporary-work-directory>/second/apps/server
@bb/server:test: > vitest run --config vitest.config.ts "test/threads/issue-6841-repro.test.ts" "--silent=false"
@bb/server:test:
@bb/server:test:
@bb/server:test:  RUN  v4.1.1 <temporary-work-directory>/second/apps/server
@bb/server:test:
@bb/server:test: (node:5626) 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: stdout | test/threads/issue-6841-repro.test.ts > observes global instruction reuse across unrelated projects and workspace isolation
@bb/server:test: alpha: empty-global=absent; populated-global=included; workspace=included
@bb/server:test:
@bb/server:test: stdout | test/threads/issue-6841-repro.test.ts > observes global instruction reuse across unrelated projects and workspace isolation
@bb/server:test: beta: empty-global=absent; populated-global=included; workspace=absent
@bb/server:test: Fresh data directory: no AGENTS.md was preinstalled.
@bb/server:test:
@bb/server:test:  ✓ |@bb/server| test/threads/issue-6841-repro.test.ts (1 test) 753ms
@bb/server:test:
@bb/server:test:  Test Files  1 passed (1)
@bb/server:test:       Tests  1 passed (1)
@bb/server:test:    Start at  19:12:00
@bb/server:test:    Duration  9.24s (transform 5.19s, setup 1.48s, import 5.12s, tests 753ms, environment 0ms)
@bb/server:test:

 Tasks:    10 successful, 10 total
Cached:    0 cached, 10 total
  Time:    39.599s

Existing tests

@bb/server:test: > @bb/server@0.0.1 test <trusted-checkout>/apps/server
@bb/server:test: > vitest run --config vitest.config.ts "test/threads/thread-runtime-config.test.ts" "-t" "data-dir|data dir"
@bb/server:test:
@bb/server:test:
@bb/server:test:  RUN  v4.1.1 <trusted-checkout>/apps/server
@bb/server:test:
@bb/server:test: (node:3750) 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/threads/thread-runtime-config.test.ts (33 tests | 31 skipped) 844ms
@bb/server:test:
@bb/server:test:  Test Files  1 passed (1)
@bb/server:test:       Tests  2 passed | 31 skipped (33)
@bb/server:test:    Start at  19:08:37
@bb/server:test:    Duration  9.85s (transform 5.53s, setup 1.61s, import 5.43s, tests 844ms, environment 0ms)
@bb/server:test:

 Tasks:    10 successful, 10 total
Cached:    0 cached, 10 total
  Time:    44.466s