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
58 changes: 58 additions & 0 deletions apps/server/src/provider/Layers/EventNdjsonLogger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,19 @@ describe("EventNdjsonLogger", () => {
},
threadId,
);
yield* native.write(
{
event: {
type: "message.part.updated",
payload: {
properties: {
part: { type: "tool", state: { status: "running", output: "progress" } },
},
},
},
},
threadId,
);
yield* native.write({ type: "turn.completed", id: "native-final" }, threadId);
yield* store.close();

Expand All @@ -362,6 +375,51 @@ describe("EventNdjsonLogger", () => {
}),
);

it.effect("keeps OpenCode tool input, final output, and errors in native logs", () =>
Effect.gen(function* () {
const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-provider-log-"));
const basePath = NodePath.join(tempDir, "events.log");
const threadId = ThreadId.make("thread-tool-lifecycle");

try {
const store = yield* makeEventNdjsonLogStore(basePath, { batchWindowMs: 0 });
const native = store.logger("native");
const input = { command: "run-build" };
const states = [
{ status: "pending", input },
{ status: "completed", input, output: "Build complete", time: { start: 1, end: 2 } },
{ status: "error", input, error: "Build failed", time: { start: 3, end: 4 } },
{ status: "unknown", input },
null,
];
const events = states.map((state) => ({
event: {
type: "message.part.updated",
payload: { properties: { part: { type: "tool", state } } },
},
}));
for (const event of events) {
yield* native.write(event, threadId);
}
yield* store.close();

const payloads = NodeFS.readFileSync(
ownedLogPath(basePath, "thread-tool-lifecycle"),
"utf8",
)
.trim()
.split("\n")
.map((line) => parseLogLine(line).payload);
assert.deepEqual(
payloads,
events.map((event) => encodeUnknownJson(event)),
);
} finally {
NodeFS.rmSync(tempDir, { recursive: true, force: true });
}
}),
);

it.effect("contains hostile event accessors inside guarded serialization", () =>
Effect.gen(function* () {
const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-provider-log-"));
Expand Down
10 changes: 9 additions & 1 deletion apps/server/src/provider/Layers/EventNdjsonLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,15 @@ function shouldPersist(stream: EventNdjsonStream, event: unknown): boolean {
const part = Reflect.get(properties, "part");
if (typeof part !== "object" || part === null) return true;
const partType = Reflect.get(part, "type");
return partType !== "text" && partType !== "reasoning";
if (partType === "text" || partType === "reasoning") return false;
if (partType === "tool") {
// Running snapshots repeat growing output. Pending and terminal states stay in the log.
const state = Reflect.get(part, "state");
if (typeof state === "object" && state !== null) {
return Reflect.get(state, "status") !== "running";
}
}
return true;
}

return true;
Expand Down
Loading
Loading