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
5 changes: 5 additions & 0 deletions .changeset/historical-relay-coverage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"grok-bot-cli": patch
---

Allow automatic messaging to establish a checkpoint over older bot outputs without run IDs while continuing to reject new outputs without correlation IDs.
7 changes: 6 additions & 1 deletion src/core/relay/intake.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ export function createIntake({
});
return;
}
const incoming = page.slice(index + 1);
if (incoming.some(entry => entry.kind === "send-message" &&
(typeof entry.requestId !== "string" || !entry.requestId))) {
await change("targets", { ...target, state: "paused", reason: "invalid-coverage" });
return;
}
const local = { ...state.read().records },
changes = [];
// Gather every nonce before classifying bot outputs, even if its user row comes later.
Expand Down Expand Up @@ -139,7 +145,6 @@ export function createIntake({
["sending", "unknown", "accepted"].includes(r.submission) &&
!r.requestId,
);
const incoming = page.slice(index + 1);
for (const entry of incoming) {
if (entry.kind !== "send-message" || own.has(entry.requestId)) continue;
const approvalNotice = grokApprovalNotice(entry, targetId);
Expand Down
5 changes: 0 additions & 5 deletions src/core/relay/records.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ export function pageEntries(payload) {
if (ids.has(id) || typeof e.kind !== "string" || !e.kind)
throw new Error("Invalid transcript coverage");
ids.add(id);
if (
e.kind === "send-message" &&
(typeof e.requestId !== "string" || !e.requestId)
)
throw new Error("Message coverage lacks requestId");
}
return page;
}
Expand Down
29 changes: 29 additions & 0 deletions test/relay-engine.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,35 @@ test("Grok approval cards notify Codex once without returning its answer as auth
assert.match(text, /explicit user decision/i);
assert.equal(f.sent.length, 0);
});
test("historical messages without requestId do not block a new tracked request", async (t) => {
const f = await fixture(t);
f.page.push({ id: "old", kind: "send-message", text: "Historical output" });
await f.engine.sendToGrok({ grokTarget: "target", codexThreadId: "thread", message: "Ask Grok", requestId: "ask" });
assert.equal(f.sent.length, 1);
f.page.push(
{ id: "user", kind: "user", clientNonce: f.sent[0].clientNonce, requestId: "run" },
{ id: "answer", kind: "send-message", requestId: "run", text: "New answer" },
);
await f.engine.tick();
await f.engine.tick();
const calls = f.fake.received.filter(r => r.method === "turn/start");
assert.equal(calls.length, 1);
assert.match(calls[0].params.input[0].text, /New answer/);
assert.doesNotMatch(calls[0].params.input[0].text, /Historical output/);
});

test("new messages without requestId pause intake without forwarding or advancing the checkpoint", async (t) => {
const f = await fixture(t);
await f.engine.sendToGrok({ grokTarget: "target", codexThreadId: "thread", message: "Ask Grok", requestId: "ask" });
f.page.push({ id: "new", kind: "send-message", text: "Uncorrelated output" });
await f.engine.tick();
assert.equal(f.fake.received.filter(r => r.method === "turn/start").length, 0);
const status = await f.engine.status();
assert.equal(status.targets[0].state, "paused");
assert.equal(status.targets[0].reason, "invalid-coverage");
assert.equal(status.targets[0].cursor, null);
});

test("tracked request uses actual requestId and never forwards another thread reply", async (t) => {
const f = await fixture(t);
const r = await f.engine.sendToGrok({
Expand Down
Loading