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
22 changes: 22 additions & 0 deletions src/perf/active-turn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Process-wide open-turn id for nesting permission.wait / subagent outside the
* reactor observer.
*
* Single-primary assumption: one run-sink observer owns the slot. A second
* concurrent observer overwrites the parent used by gate/task spans — not
* supported. `clear()`, observer `reset()`, and `closeTurn` null the slot.
*/

let activeTurnId: string | null = null;

export function getActiveTurnId(): string | null {
return activeTurnId;
}

export function setActiveTurnId(id: string | null): void {
activeTurnId = id;
}

export function clearActiveTurnId(): void {
activeTurnId = null;
}
8 changes: 8 additions & 0 deletions src/perf/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ describe("sanitizeTags", () => {
provider_id: "openai",
model_id: "gpt-5.4",
transport: "ws",
decision: "allow",
duration_ms: 12.5,
bytes: 1024,
payload_bytes: 2048,
Expand All @@ -257,6 +258,7 @@ describe("sanitizeTags", () => {
provider_id: "openai",
model_id: "gpt-5.4",
transport: "ws",
decision: "allow",
duration_ms: 12.5,
bytes: 1024,
payload_bytes: 2048,
Expand All @@ -269,6 +271,12 @@ describe("sanitizeTags", () => {
});
});

test("keeps decision allow/deny and strips free-text decisions", () => {
expect(sanitizeTags({ decision: "allow" })).toEqual({ decision: "allow" });
expect(sanitizeTags({ decision: "deny" })).toEqual({ decision: "deny" });
expect(sanitizeTags({ decision: "maybe" })).toBeUndefined();
});

test("strips free-text, paths, prompts, and unknown keys", () => {
const tags = sanitizeTags({
prompt: "system: you are a helpful assistant",
Expand Down
4 changes: 4 additions & 0 deletions src/perf/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
*/

import { isOpaqueId, sanitizeTags, type PerfTags } from "./sanitize.js";
import { clearActiveTurnId } from "./active-turn.js";

export {
sanitizeTags,
isOpaqueId,
OPAQUE_ID_RE,
ALLOWED_TAG_KEYS,
type AllowedTagKey,
type DecisionKind,
type PerfTags,
type TransportKind,
} from "./sanitize.js";
Expand Down Expand Up @@ -243,4 +245,6 @@ export function clear(): void {
ringWrite = 0;
ringCount = 0;
nextId = 0;
clearActiveTurnId();
}

Loading
Loading