Skip to content

armgit / cogit

Public Imported from GitHub
0

Git for the intent behind agent-written code. Records what your coding agent decided and why, and links every commit to it.

fix(record): drop null notes from a side-model catch-up instead of failing the write

Erenaf20b55d8e33
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5faa194..66220cd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- A new session's first message is offered the eight most recent other sessions, each with where it left off, its branches and the message each branch ends at, instead of the last three messages of three sessions. Work from further back or the middle of a session can now be continued.
- The side model's prompt now includes what the agent did in each turn: the questions it asked with their options, the files it edited and its steps. It finds the agent's decisions and the topic of a turn in these.
+### Fixed
+- A side-model catch-up no longer fails the whole write when the model sends an empty note as `null` (for example `"why": null`); such fields are left out.
## [0.20.0] - 2026-10-28
### Added
diff --git a/packages/cli/src/commands/backfill.ts b/packages/cli/src/commands/backfill.ts
index 6e01dc8..95d2dcc 100644
--- a/packages/cli/src/commands/backfill.ts
+++ b/packages/cli/src/commands/backfill.ts
@@ -153,6 +153,29 @@ export function agentRecord(text: string): Record<string, unknown> {
return parsed as Record<string, unknown>;
}
+/**
+ * A small model writes `null` for a note it has nothing for (`"why": null`).
+ * The schema wants such a field left out, and one null would fail the whole
+ * write, so they are dropped; a node's `parent: null` (a root) and `epoch: null` stay.
+ */
+export function withoutNulls(record: Record<string, unknown>): Record<string, unknown> {
+ // `epoch: null` means "no epoch"; any other null at the top is a missing field.
+ const top = Object.fromEntries(
+ Object.entries(record).filter(([key, value]) => value !== null || key === "epoch"),
+ );
+ if (!Array.isArray(top.nodes)) return top;
+ return {
+ ...top,
+ nodes: top.nodes.map((node) =>
+ typeof node === "object" && node !== null
+ ? Object.fromEntries(
+ Object.entries(node).filter(([key, value]) => value !== null || key === "parent"),
+ )
+ : node,
+ ),
+ };
+}
+
/** The headless agent must not fire our own hooks or leave a transcript. */
export function headlessEnv(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
return { ...process.env, ...env, COGIT_DISABLE: "1" };
@@ -271,7 +294,7 @@ export async function backfillTail(
config.recorder,
);
const stdout = await runClaude(prompt, config.sideModel, io.env);
- const payload = { ...agentRecord(resultText(stdout)), sessionId };
+ const payload = { ...withoutNulls(agentRecord(resultText(stdout))), sessionId };
// Story 12.1: a side run fills empty fields and new nodes; it never rewrites
// what the main agent wrote.
await sessionWrite({ dir: root, by: "side" }, io, async () => JSON.stringify(payload));
diff --git a/packages/cli/test/backfill.test.ts b/packages/cli/test/backfill.test.ts
index 1d52bdb..6e95bf2 100644
--- a/packages/cli/test/backfill.test.ts
+++ b/packages/cli/test/backfill.test.ts
@@ -8,6 +8,7 @@ import {
catchUpPrompt,
headlessEnv,
resultText,
+ withoutNulls,
} from "../src/commands/backfill.js";
import { init } from "../src/commands/init.js";
import { sessionWrite } from "../src/commands/session.js";
@@ -159,6 +160,17 @@ describe("headless output", () => {
expect(() => agentRecord("[1]")).toThrow(/JSON object/);
});
+ it("drops the null notes a small model writes, keeping a root's null parent", () => {
+ expect(
+ withoutNulls({
+ status: null,
+ epoch: null,
+ nodes: [{ id: "m1", parent: null, why: null, decidedBy: null, title: "t" }, 3],
+ }),
+ ).toEqual({ epoch: null, nodes: [{ id: "m1", parent: null, title: "t" }, 3] });
+ expect(withoutNulls({ nodes: "x" })).toEqual({ nodes: "x" });
+ });
+
it("turns capture off in the headless run", () => {
expect(headlessEnv({ PATH: "/bin" })).toMatchObject({
PATH: "/bin",