Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions apps/server/integration/OrchestrationEngineHarness.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ import { VcsStatusBroadcaster } from "../src/vcs/VcsStatusBroadcaster.ts";
import { GitWorkflowService } from "../src/git/GitWorkflowService.ts";
import * as VcsProcess from "../src/vcs/VcsProcess.ts";
import { ThreadSessionAdmissionPermissive } from "../src/provider/Services/ThreadSessionAdmission.ts";
import {
SecretScrubber,
type SecretScrubberShape,
makeSecretScrubber,
} from "../src/secrets/SecretScrubber.ts";

const decodeCodexSettings = Schema.decodeEffect(CodexSettings);

Expand Down Expand Up @@ -249,6 +254,8 @@ interface MakeOrchestrationIntegrationHarnessOptions {
readonly workspaceDir: string;
}) => RealProviderAdapter;
readonly serverSettings?: Parameters<typeof ServerSettingsService.layerTest>[0];
/** One registry of watched keys shared by the provider hook and ingestion. Absent: an empty one. */
readonly secretScrubber?: SecretScrubberShape;
}

const realCodexAdapter: RealProviderAdapter = {
Expand All @@ -267,6 +274,12 @@ export const makeOrchestrationIntegrationHarness = (
const fileSystem = yield* FileSystem.FileSystem;

const provider = options?.provider ?? ProviderDriverKind.make("codex");
const secretScrubberLayer = Layer.succeed(
SecretScrubber,
options?.secretScrubber ?? makeSecretScrubber(),
);
const makeProviderServiceWithScrubber = () =>
makeProviderServiceLive().pipe(Layer.provide(secretScrubberLayer));
const useRealAdapter = options?.realCodex === true || options?.realAdapter !== undefined;
const adapterHarness = useRealAdapter
? null
Expand Down Expand Up @@ -315,14 +328,14 @@ export const makeOrchestrationIntegrationHarness = (
);
const providerEventLoggersLayer = Layer.succeed(ProviderEventLoggers, NoOpProviderEventLoggers);
const providerLayer = useRealAdapter
? makeProviderServiceLive().pipe(
? makeProviderServiceWithScrubber().pipe(
Layer.provide(ThreadSessionAdmissionPermissive),
Layer.provide(providerSessionDirectoryLayer),
Layer.provide(realAdapterRegistry),
Layer.provide(AnalyticsService.layerTest),
Layer.provide(providerEventLoggersLayer),
)
: makeProviderServiceLive().pipe(
: makeProviderServiceWithScrubber().pipe(
Layer.provide(ThreadSessionAdmissionPermissive),
Layer.provide(providerSessionDirectoryLayer),
Layer.provide(fakeRegistry!),
Expand All @@ -343,6 +356,7 @@ export const makeOrchestrationIntegrationHarness = (
);
const serverSettingsLayer = ServerSettingsService.layerTest(options?.serverSettings);
const runtimeIngestionLayer = ProviderRuntimeIngestionLive.pipe(
Layer.provide(secretScrubberLayer),
// No provider publishes a page in these tests.
Layer.provideMerge(Layer.mock(AgentPages)({ assetsDirOf: () => null })),
Layer.provideMerge(Layer.mock(McpApps)({ recordCall: () => Effect.void })),
Expand Down
7 changes: 6 additions & 1 deletion apps/server/integration/providerService.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ import {
codexTurnTextFixture,
} from "./fixtures/providerRuntime.ts";
import { ThreadSessionAdmissionPermissive } from "../src/provider/Services/ThreadSessionAdmission.ts";
import { layerTest as SecretScrubberTest } from "../src/secrets/SecretScrubber.ts";

/** The provider service with an empty registry of watched keys (SecretScrubber). */
const makeProviderServiceWithScrubber = (...args: Parameters<typeof makeProviderServiceLive>) =>
makeProviderServiceLive(...args).pipe(Layer.provide(SecretScrubberTest));

const codexInstanceId = ProviderInstanceId.make("codex");

Expand Down Expand Up @@ -75,7 +80,7 @@ const makeIntegrationFixture = Effect.gen(function* () {
Layer.succeed(ProviderEventLoggers, NoOpProviderEventLoggers),
).pipe(Layer.provide(SqlitePersistenceMemory));

const layer = makeProviderServiceLive().pipe(
const layer = makeProviderServiceWithScrubber().pipe(
Layer.provide(ThreadSessionAdmissionPermissive),
Layer.provide(shared),
);
Expand Down
42 changes: 42 additions & 0 deletions apps/server/integration/replay/replay.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { makeRecorder, privateDataIn } from "./recorder.ts";
import { runReplayScenario } from "./runReplay.ts";
import { FIXTURES_DIR, fixturePath, REPLAY_SCENARIOS } from "./scenarios.ts";
import { readTranscript } from "./transcript.ts";
import { makeSecretScrubber } from "../../src/secrets/SecretScrubber.ts";

// A recording no scenario plays would rot unnoticed.
const scenarioNames = new Set(REPLAY_SCENARIOS.map((scenario) => scenario.name));
Expand Down Expand Up @@ -41,6 +42,47 @@ describe("provider replays", () => {
}
}

// Hiding a printed key (docs/design/secret-scrubbing.md), end to end through
// the real Codex adapter and ingestion: a phrase the recording streams in
// pieces, and a child's answer that ingestion joins from pieces, are
// watched. No stored event and nothing in the final thread may hold them,
// and a notice says so.
for (const [scenarioName, watched] of [
["command-approval", "run the command"],
["subagent", "ANSWER: 42"],
] as const) {
it.live(`hides a watched phrase split across stream pieces (${scenarioName}, codex)`, () =>
Effect.gen(function* () {
const scenario = REPLAY_SCENARIOS.find((entry) => entry.name === scenarioName)!;
const secretScrubber = makeSecretScrubber();
assert.isTrue(secretScrubber.watch("WATCHED_KEY", watched));
let checked = false;
yield* runReplayScenario({
provider: "codex",
scenario,
mode: { kind: "replay", transcript: readTranscript(fixturePath(scenarioName, "codex")) },
timeoutMs: 20_000,
secretScrubber,
inspect: ({ events, thread }) => {
checked = true;
for (const event of events) assert.notInclude(JSON.stringify(event), watched);
assert.notInclude(JSON.stringify(thread), watched);
assert.include(JSON.stringify(thread), "[WATCHED_KEY hidden]");
assert.isTrue(
thread.activities.some(
(activity) =>
(activity.payload as { warningKind?: string } | null)?.warningKind ===
"secret-hidden",
),
"a notice says the key was hidden",
);
},
});
assert.isTrue(checked);
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
);
}

// The repository is public: a hand-edited or older recording must not
// carry anything the recorder would have refused.
it("committed recordings hold no private data", () => {
Expand Down
17 changes: 16 additions & 1 deletion apps/server/integration/replay/runReplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* Runs a replay scenario on the integration harness, against a recorded
* transcript (replay) or the real provider with a recorder attached (record).
*/
import * as Stream from "effect/Stream";
import type { SecretScrubberShape } from "../../src/secrets/SecretScrubber.ts";
import {
ClaudeSettings,
CodexSettings,
Expand Down Expand Up @@ -114,13 +116,21 @@ export const runReplayScenario = (input: {
readonly scenario: ReplayScenario;
readonly mode: ProviderMode;
readonly timeoutMs: number;
/** Keys to watch from the start (docs/design/secret-scrubbing.md); the scenario's own check is skipped, since hiding changes its text. */
readonly secretScrubber?: SecretScrubberShape;
/** Runs on every stored event and the final thread instead of the scenario's check. */
readonly inspect?: (stored: {
readonly events: ReadonlyArray<unknown>;
readonly thread: OrchestrationThread;
}) => void;
}) =>
Effect.gen(function* () {
let cursor: ReplayCursor | null = null;
let recorder: Recorder | null = null;
const harness = yield* makeOrchestrationIntegrationHarness({
provider: ProviderDriverKind.make(input.provider),
serverSettings: REPLAY_SERVER_SETTINGS,
...(input.secretScrubber !== undefined ? { secretScrubber: input.secretScrubber } : {}),
realAdapter: (paths) =>
(input.provider === "codex" ? codexAdapter : claudeAdapter)(
input.mode,
Expand All @@ -143,7 +153,12 @@ export const runReplayScenario = (input: {
const thread = snapshot.threads.find((entry) => entry.id === THREAD_ID);
if (thread === undefined)
return yield* Effect.die(new Error("The scenario's thread is gone."));
input.scenario.check(thread, context);
if (input.inspect !== undefined) {
const events = yield* Stream.runCollect(harness.engine.readEvents(0)).pipe(Effect.orDie);
input.inspect({ events: [...events], thread });
} else {
input.scenario.check(thread, context);
}
(cursor as ReplayCursor | null)?.assertComplete();
return { thread, cursor, recorder } satisfies ScenarioOutcome;
}).pipe(Effect.ensuring(harness.dispose));
Expand Down
92 changes: 92 additions & 0 deletions apps/server/scripts/bench-secret-scrubber.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* The throughput check for hiding a printed key (docs/design/secret-scrubbing.md, "Cost").
* Runs provider events through `scrubRuntimeEvent` with 0, 1, 50 and 200 watched values
* and prints the time per event. A report for the PR, not a CI gate.
*
* node scripts/bench-secret-scrubber.ts
*/
import { performance } from "node:perf_hooks";

import { makeSecretScrubber } from "../src/secrets/SecretScrubber.ts";

const reply = (index: number, text: string) => ({
eventId: `e${index}`,
provider: "codex",
threadId: "session",
createdAt: "2026-11-19T00:00:00.000Z",
turnId: "turn",
itemId: "item",
type: "content.delta",
payload: { streamKind: "assistant_text", delta: text },
raw: {
source: "codex.app-server.notification",
method: "item/agentMessage/delta",
payload: { delta: text },
},
});

const words = "the quick brown fox jumps over a lazy dog while compiling the project ".split(" ");
const tokens = Array.from({ length: 100_000 }, (_, index) => ` ${words[index % words.length]}`);
const big = "x".repeat(64 * 1024 - 20) + " build ok, 12 passed";
const pem = `-----BEGIN KEY-----\n${"Ab9+".repeat(16 * 1024 - 10)}\n-----END KEY-----`;

function scrubberWith(count: number) {
const scrubber = makeSecretScrubber();
for (let index = 0; index < count; index += 1) {
scrubber.watch(
`KEY_${index}`,
index === 0 && count === 200 ? pem : `sk_test_${index}_Qa9Zr7Lm2Xc4`,
);
}
return scrubber;
}

function time(label: string, run: () => number) {
const started = performance.now();
const events = run();
const ms = performance.now() - started;
console.log(
`${label.padEnd(44)} ${((ms * 1000) / events).toFixed(2).padStart(9)} µs/event (${events} events, ${ms.toFixed(0)} ms)`,
);
}

for (const count of [0, 1, 50, 200]) {
console.log(`\n${count} watched`);
time("100,000 token-sized reply pieces", () => {
const scrubber = scrubberWith(count);
tokens.forEach((token, index) => scrubber.scrubRuntimeEvent(reply(index, token) as never));
return tokens.length;
});
time("2,000 command-output events of 64 KB", () => {
const scrubber = scrubberWith(count);
for (let index = 0; index < 2000; index += 1) {
scrubber.scrubRuntimeEvent({
...reply(index, big),
payload: { streamKind: "command_output", delta: big },
} as never);
}
return 2000;
});
time("holder: 200 buffers at once, 50 pieces each", () => {
const scrubber = scrubberWith(count);
const states = new Map<number, Parameters<typeof scrubber.holdPiece>[0]>();
let pieces = 0;
for (let round = 0; round < 50; round += 1) {
for (let buffer = 0; buffer < 200; buffer += 1) {
const held = scrubber.holdPiece(states.get(buffer), " sk_test_1");
states.set(buffer, held.state);
pieces += 1;
}
}
return pieces;
});
}

console.log("\n64 KB key arriving one character per piece through the holder (200 watched)");
time("one character per piece", () => {
const scrubber = scrubberWith(200);
let state: Parameters<typeof scrubber.holdPiece>[0];
const chars = [...pem];
for (const char of chars) state = scrubber.holdPiece(state, char).state;
return chars.length;
});
4 changes: 3 additions & 1 deletion apps/server/src/guide/topics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,9 @@ Settings that give agents more reach ({place:threads.agentThreads}, {place:threa
],
body: `When an agent needs an API key, token or password, it asks on a card above the message box instead of in chat. The card shows the name, the agent's reason, and, in Threadlines' own words, where the key goes: a NAME=value line in a git-ignored env file in the thread's folder (like .env.local), or a private file for the agent's commands that is removed after 24 hours. Save sends it to the thread's computer; Not now saves nothing. The agent hears the outcome, never the value.

What this promises: Threadlines doesn't put the key in the chat, its stored events, logs or other apps. What it doesn't: the agent runs as you on that computer, so it can still read the file, and if it prints the key, the model sees it. A key pasted into chat is already in the conversation; replace it if that matters. Answering needs an encrypted connection to that computer. Archiving, moving or deleting the thread removes its private files, and a saved row for a private file has Remove now.`,
What this promises: Threadlines doesn't put the key in the chat, its stored events, logs or other apps. What it doesn't: the agent runs as you on that computer, so it can still read the file, and if it prints the key, the model sees it. A key pasted into chat is already in the conversation; replace it if that matters. Answering needs an encrypted connection to that computer. Archiving, moving or deleting the thread removes its private files, and a saved row for a private file has Remove now.

If the agent later prints a saved key, or a tool reads it, Threadlines replaces it with [NAME hidden] before it stores, logs or shows that text, and a row in the thread says so. The model may still have seen it, and the provider's own transcript keeps it; replace the key if that matters. Keys under 8 characters, or made only of letters or only of digits, aren't hidden. Your terminal, files in the project and voice audio aren't covered, and a key changed by hand in the env file is hidden from the next restart.`,
},
{
id: "updates",
Expand Down
Loading
Loading