@poncho-ai/harness 0.59.1 → 0.59.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +5 -5
- package/CHANGELOG.md +28 -0
- package/dist/index.d.ts +39 -118
- package/dist/index.js +37 -327
- package/package.json +1 -1
- package/src/index.ts +3 -11
- package/src/orchestrator/entries-dual-write.ts +20 -209
- package/src/orchestrator/index.ts +1 -6
- package/src/orchestrator/orchestrator.ts +22 -115
- package/src/orchestrator/run-conversation-turn.ts +0 -108
- package/src/state.ts +3 -1
- package/src/storage/entries.ts +47 -182
- package/src/storage/memory-engine.ts +2 -2
- package/src/storage/sql-dialect.ts +27 -7
- package/test/entries-dual-write.test.ts +21 -144
- package/test/entries-store.test.ts +43 -53
- package/test/entries.test.ts +37 -105
package/dist/index.js
CHANGED
|
@@ -2780,55 +2780,6 @@ import { randomUUID as randomUUID3 } from "crypto";
|
|
|
2780
2780
|
// src/storage/entries.ts
|
|
2781
2781
|
import { createLogger as createLogger2 } from "@poncho-ai/sdk";
|
|
2782
2782
|
var entriesReadLog = createLogger2("entries-read");
|
|
2783
|
-
function buildLlmContext(entries) {
|
|
2784
|
-
let latestCompaction;
|
|
2785
|
-
for (const e of entries) {
|
|
2786
|
-
if (e.type === "compaction" && (!latestCompaction || e.seq > latestCompaction.seq)) {
|
|
2787
|
-
latestCompaction = e;
|
|
2788
|
-
}
|
|
2789
|
-
}
|
|
2790
|
-
const harnessMsgs = entries.filter(
|
|
2791
|
-
(e) => e.type === "harness_message"
|
|
2792
|
-
);
|
|
2793
|
-
if (latestCompaction) {
|
|
2794
|
-
const kept = harnessMsgs.filter((e) => e.seq >= latestCompaction.firstKeptSeq).map((e) => e.message);
|
|
2795
|
-
return [latestCompaction.summaryMessage, ...kept];
|
|
2796
|
-
}
|
|
2797
|
-
return harnessMsgs.map((e) => e.message);
|
|
2798
|
-
}
|
|
2799
|
-
function buildDisplaySnapshot(entries, tailN) {
|
|
2800
|
-
const amendmentsByTarget = /* @__PURE__ */ new Map();
|
|
2801
|
-
for (const e of entries) {
|
|
2802
|
-
if (e.type === "assistant_amendment") {
|
|
2803
|
-
const list = amendmentsByTarget.get(e.targetEntryId) ?? [];
|
|
2804
|
-
list.push(e);
|
|
2805
|
-
amendmentsByTarget.set(e.targetEntryId, list);
|
|
2806
|
-
}
|
|
2807
|
-
}
|
|
2808
|
-
const built = [];
|
|
2809
|
-
for (const e of entries) {
|
|
2810
|
-
if (e.type === "user_message") {
|
|
2811
|
-
if (e.hidden) continue;
|
|
2812
|
-
built.push({ seq: e.seq, message: e.message });
|
|
2813
|
-
} else if (e.type === "assistant_message") {
|
|
2814
|
-
let content = typeof e.message.content === "string" ? e.message.content : "";
|
|
2815
|
-
const amendments = amendmentsByTarget.get(e.id);
|
|
2816
|
-
if (amendments) {
|
|
2817
|
-
for (const a of amendments.sort((x, y) => x.seq - y.seq)) {
|
|
2818
|
-
if (a.appendText) content += a.appendText;
|
|
2819
|
-
}
|
|
2820
|
-
}
|
|
2821
|
-
built.push({ seq: e.seq, message: { ...e.message, content } });
|
|
2822
|
-
}
|
|
2823
|
-
}
|
|
2824
|
-
const total = built.length;
|
|
2825
|
-
const tail = tailN >= total ? built : built.slice(total - tailN);
|
|
2826
|
-
return {
|
|
2827
|
-
messages: tail.map((b) => b.message),
|
|
2828
|
-
totalMessages: total,
|
|
2829
|
-
headSeq: tail.length > 0 ? tail[0].seq : null
|
|
2830
|
-
};
|
|
2831
|
-
}
|
|
2832
2783
|
function getPendingSubagentResults(entries) {
|
|
2833
2784
|
const consumed = /* @__PURE__ */ new Set();
|
|
2834
2785
|
for (const e of entries) {
|
|
@@ -2908,7 +2859,7 @@ var InMemoryEngine = class {
|
|
|
2908
2859
|
if (!c) return void 0;
|
|
2909
2860
|
return rebuildConversationFromEntries(
|
|
2910
2861
|
{ ...c },
|
|
2911
|
-
(id) => this.conversations.readEntries(id)
|
|
2862
|
+
(id) => this.conversations.readEntries(id, { types: ["subagent_result", "callback_started"] })
|
|
2912
2863
|
);
|
|
2913
2864
|
},
|
|
2914
2865
|
// In-memory storage has no separate archive blob, so both variants
|
|
@@ -2918,7 +2869,7 @@ var InMemoryEngine = class {
|
|
|
2918
2869
|
if (!c) return void 0;
|
|
2919
2870
|
return rebuildConversationFromEntries(
|
|
2920
2871
|
{ ...c },
|
|
2921
|
-
(id) => this.conversations.readEntries(id)
|
|
2872
|
+
(id) => this.conversations.readEntries(id, { types: ["subagent_result", "callback_started"] })
|
|
2922
2873
|
);
|
|
2923
2874
|
},
|
|
2924
2875
|
getStatusSnapshot: async (conversationId) => {
|
|
@@ -3797,7 +3748,7 @@ var SqlStorageEngine = class {
|
|
|
3797
3748
|
}
|
|
3798
3749
|
return rebuildConversationFromEntries(
|
|
3799
3750
|
conv,
|
|
3800
|
-
(id) => this.conversations.readEntries(id)
|
|
3751
|
+
(id) => this.conversations.readEntries(id, { types: ["subagent_result", "callback_started"] })
|
|
3801
3752
|
);
|
|
3802
3753
|
},
|
|
3803
3754
|
getStatusSnapshot: async (conversationId) => {
|
|
@@ -3850,7 +3801,7 @@ var SqlStorageEngine = class {
|
|
|
3850
3801
|
}
|
|
3851
3802
|
return rebuildConversationFromEntries(
|
|
3852
3803
|
conv,
|
|
3853
|
-
(id) => this.conversations.readEntries(id)
|
|
3804
|
+
(id) => this.conversations.readEntries(id, { types: ["subagent_result", "callback_started"] })
|
|
3854
3805
|
);
|
|
3855
3806
|
},
|
|
3856
3807
|
create: async (ownerId, title, tenantId, init) => {
|
|
@@ -3966,11 +3917,16 @@ var SqlStorageEngine = class {
|
|
|
3966
3917
|
);
|
|
3967
3918
|
},
|
|
3968
3919
|
rename: async (conversationId, title) => {
|
|
3969
|
-
const
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3920
|
+
const normalized = normalizeTitle2(title);
|
|
3921
|
+
const dataExpr = this.dialect.tag === "sqlite" ? `json_set(data, '$.title', $2)` : `jsonb_set(data, '{title}', to_jsonb($2::text))`;
|
|
3922
|
+
await this.executor.run(
|
|
3923
|
+
rewrite(
|
|
3924
|
+
`UPDATE conversations SET title = $1, data = ${dataExpr}, updated_at = $3 WHERE id = $4`,
|
|
3925
|
+
this.dialect
|
|
3926
|
+
),
|
|
3927
|
+
[normalized, normalized, (/* @__PURE__ */ new Date()).toISOString(), conversationId]
|
|
3928
|
+
);
|
|
3929
|
+
return this.conversations.get(conversationId);
|
|
3974
3930
|
},
|
|
3975
3931
|
delete: async (conversationId) => {
|
|
3976
3932
|
const row = await this.executor.get(
|
|
@@ -12245,7 +12201,10 @@ var InMemoryConversationStore = class {
|
|
|
12245
12201
|
this.purgeExpired();
|
|
12246
12202
|
const c = this.conversations.get(conversationId);
|
|
12247
12203
|
if (!c) return void 0;
|
|
12248
|
-
return rebuildConversationFromEntries(
|
|
12204
|
+
return rebuildConversationFromEntries(
|
|
12205
|
+
{ ...c },
|
|
12206
|
+
(id) => this.readEntries(id, { types: ["subagent_result", "callback_started"] })
|
|
12207
|
+
);
|
|
12249
12208
|
}
|
|
12250
12209
|
// In-memory stores already hold the full conversation object, so there's
|
|
12251
12210
|
// no separate archive blob to load. Both variants return the same data.
|
|
@@ -12704,12 +12663,10 @@ var CALLBACK_LOCK_STALE_MS = 5 * 60 * 1e3;
|
|
|
12704
12663
|
var STALE_SUBAGENT_THRESHOLD_MS = 5 * 60 * 1e3;
|
|
12705
12664
|
|
|
12706
12665
|
// src/orchestrator/orchestrator.ts
|
|
12707
|
-
import { createLogger as createLogger8, getTextContent as
|
|
12666
|
+
import { createLogger as createLogger8, getTextContent as getTextContent3 } from "@poncho-ai/sdk";
|
|
12708
12667
|
|
|
12709
12668
|
// src/orchestrator/entries-dual-write.ts
|
|
12710
12669
|
import { randomUUID as randomUUID6 } from "crypto";
|
|
12711
|
-
import { getTextContent as getTextContent3 } from "@poncho-ai/sdk";
|
|
12712
|
-
var entriesParityEnabled = () => process.env.PONCHO_VERIFY_ENTRIES === "1";
|
|
12713
12670
|
var appendEntriesSafe = async (store, conversation, entries, log2) => {
|
|
12714
12671
|
if (entries.length === 0) return [];
|
|
12715
12672
|
try {
|
|
@@ -12724,123 +12681,21 @@ var appendEntriesSafe = async (store, conversation, entries, log2) => {
|
|
|
12724
12681
|
);
|
|
12725
12682
|
} catch (err) {
|
|
12726
12683
|
log2.error(
|
|
12727
|
-
`[entries-
|
|
12684
|
+
`[entries-queue] append failed for ${conversation.conversationId}: ${err instanceof Error ? err.message : String(err)}`
|
|
12728
12685
|
);
|
|
12729
12686
|
return [];
|
|
12730
12687
|
}
|
|
12731
12688
|
};
|
|
12732
|
-
var userMessageEntry = (message, turnId, opts) => ({
|
|
12733
|
-
type: "user_message",
|
|
12734
|
-
message,
|
|
12735
|
-
turnId,
|
|
12736
|
-
...opts?.hidden ? { hidden: true } : {}
|
|
12737
|
-
});
|
|
12738
|
-
var assistantMessageEntry = (message, turnId, runId) => ({
|
|
12739
|
-
type: "assistant_message",
|
|
12740
|
-
message,
|
|
12741
|
-
turnId,
|
|
12742
|
-
runId
|
|
12743
|
-
});
|
|
12744
|
-
var harnessMessageEntries = (messages, turnId) => messages.map((message) => ({ type: "harness_message", message, turnId }));
|
|
12745
|
-
var compactionEntry = (summaryMessage, firstKeptSeq, opts) => ({
|
|
12746
|
-
type: "compaction",
|
|
12747
|
-
summaryMessage,
|
|
12748
|
-
firstKeptSeq,
|
|
12749
|
-
...opts?.tokensBefore !== void 0 ? { tokensBefore: opts.tokensBefore } : {},
|
|
12750
|
-
...opts?.tokensAfter !== void 0 ? { tokensAfter: opts.tokensAfter } : {}
|
|
12751
|
-
});
|
|
12752
12689
|
var subagentResultEntry = (result) => ({ type: "subagent_result", result });
|
|
12753
12690
|
var callbackStartedEntry = (consumedSeqs) => ({
|
|
12754
12691
|
type: "callback_started",
|
|
12755
12692
|
consumedSeqs
|
|
12756
12693
|
});
|
|
12757
|
-
var assistantAmendmentEntry = (targetEntryId, appendText) => ({
|
|
12758
|
-
type: "assistant_amendment",
|
|
12759
|
-
targetEntryId,
|
|
12760
|
-
...appendText ? { appendText } : {}
|
|
12761
|
-
});
|
|
12762
|
-
var newHarnessMessagesThisTurn = (prev, next) => {
|
|
12763
|
-
const prevArr = prev ?? [];
|
|
12764
|
-
const nextArr = next ?? [];
|
|
12765
|
-
if (nextArr.length === 0) return { messages: [], approximate: false };
|
|
12766
|
-
if (prevArr.length === 0) return { messages: nextArr, approximate: false };
|
|
12767
|
-
if (nextArr.length >= prevArr.length) {
|
|
12768
|
-
return { messages: nextArr.slice(prevArr.length), approximate: false };
|
|
12769
|
-
}
|
|
12770
|
-
return { messages: nextArr, approximate: true };
|
|
12771
|
-
};
|
|
12772
|
-
var projectText = (m) => {
|
|
12773
|
-
const role = m.role;
|
|
12774
|
-
const text = getTextContent3(m).replace(/\s+/g, " ").trim();
|
|
12775
|
-
return `${role}:${text}`;
|
|
12776
|
-
};
|
|
12777
|
-
var projectAll = (msgs) => msgs.map(projectText);
|
|
12778
|
-
var countMismatch = (label, a, b) => a === b ? null : `${label} length ${a} (entries) vs ${b} (blob)`;
|
|
12779
|
-
var verifyEntriesParity = async (store, conversationId, blob, log2) => {
|
|
12780
|
-
if (!entriesParityEnabled()) return;
|
|
12781
|
-
try {
|
|
12782
|
-
const entries = await store.readEntries(conversationId);
|
|
12783
|
-
const mismatches = [];
|
|
12784
|
-
if (blob.harnessMessages) {
|
|
12785
|
-
const llm = buildLlmContext(entries);
|
|
12786
|
-
const lenMismatch = countMismatch(
|
|
12787
|
-
"llmContext",
|
|
12788
|
-
llm.length,
|
|
12789
|
-
blob.harnessMessages.length
|
|
12790
|
-
);
|
|
12791
|
-
if (lenMismatch) mismatches.push(lenMismatch);
|
|
12792
|
-
const entriesProj = projectAll(llm);
|
|
12793
|
-
const blobProj = projectAll(blob.harnessMessages);
|
|
12794
|
-
const tail = Math.min(entriesProj.length, blobProj.length, 5);
|
|
12795
|
-
for (let i = 1; i <= tail; i++) {
|
|
12796
|
-
const ep = entriesProj[entriesProj.length - i];
|
|
12797
|
-
const bp = blobProj[blobProj.length - i];
|
|
12798
|
-
if (ep !== bp) {
|
|
12799
|
-
mismatches.push(
|
|
12800
|
-
`llmContext tail[-${i}] differs: entries=${JSON.stringify(ep).slice(0, 120)} blob=${JSON.stringify(bp).slice(0, 120)}`
|
|
12801
|
-
);
|
|
12802
|
-
}
|
|
12803
|
-
}
|
|
12804
|
-
}
|
|
12805
|
-
if (blob.displayMessages) {
|
|
12806
|
-
const snap = buildDisplaySnapshot(entries, Number.MAX_SAFE_INTEGER);
|
|
12807
|
-
const lenMismatch = countMismatch(
|
|
12808
|
-
"display",
|
|
12809
|
-
snap.totalMessages,
|
|
12810
|
-
blob.displayMessages.length
|
|
12811
|
-
);
|
|
12812
|
-
if (lenMismatch) mismatches.push(lenMismatch);
|
|
12813
|
-
const entriesProj = projectAll(snap.messages);
|
|
12814
|
-
const blobProj = projectAll(blob.displayMessages);
|
|
12815
|
-
const tail = Math.min(entriesProj.length, blobProj.length, 5);
|
|
12816
|
-
for (let i = 1; i <= tail; i++) {
|
|
12817
|
-
const ep = entriesProj[entriesProj.length - i];
|
|
12818
|
-
const bp = blobProj[blobProj.length - i];
|
|
12819
|
-
if (ep !== bp) {
|
|
12820
|
-
mismatches.push(
|
|
12821
|
-
`display tail[-${i}] differs: entries=${JSON.stringify(ep).slice(0, 120)} blob=${JSON.stringify(bp).slice(0, 120)}`
|
|
12822
|
-
);
|
|
12823
|
-
}
|
|
12824
|
-
}
|
|
12825
|
-
}
|
|
12826
|
-
if (mismatches.length > 0) {
|
|
12827
|
-
log2.warn(
|
|
12828
|
-
`[entries-parity] ${conversationId} MISMATCH (${mismatches.length}): ${mismatches.join(" | ")}`
|
|
12829
|
-
);
|
|
12830
|
-
} else {
|
|
12831
|
-
log2.info(`[entries-parity] ${conversationId} OK`);
|
|
12832
|
-
}
|
|
12833
|
-
} catch (err) {
|
|
12834
|
-
log2.error(
|
|
12835
|
-
`[entries-parity] ${conversationId} checker threw (ignored): ${err instanceof Error ? err.message : String(err)}`
|
|
12836
|
-
);
|
|
12837
|
-
}
|
|
12838
|
-
};
|
|
12839
12694
|
|
|
12840
12695
|
// src/orchestrator/orchestrator.ts
|
|
12841
|
-
var
|
|
12696
|
+
var entriesQueueLog = createLogger8("orchestrator:entries");
|
|
12842
12697
|
var assistantMessageText = (message) => {
|
|
12843
|
-
const raw =
|
|
12698
|
+
const raw = getTextContent3(message).trim();
|
|
12844
12699
|
if (raw.startsWith("{") && raw.includes('"tool_calls"')) {
|
|
12845
12700
|
try {
|
|
12846
12701
|
const parsed = JSON.parse(raw);
|
|
@@ -13149,8 +13004,6 @@ var AgentOrchestrator = class {
|
|
|
13149
13004
|
if (!checkpointedRun) {
|
|
13150
13005
|
const conv = await this.conversationStore.get(conversationId);
|
|
13151
13006
|
if (conv) {
|
|
13152
|
-
let amendmentText;
|
|
13153
|
-
let pushedAssistant;
|
|
13154
13007
|
const hasAssistantContent = draft.assistantResponse.length > 0 || draft.toolTimeline.length > 0 || draft.sections.length > 0;
|
|
13155
13008
|
if (hasAssistantContent) {
|
|
13156
13009
|
const prevMessages = conv.messages;
|
|
@@ -13178,14 +13031,15 @@ var AgentOrchestrator = class {
|
|
|
13178
13031
|
}
|
|
13179
13032
|
}
|
|
13180
13033
|
];
|
|
13181
|
-
amendmentText = draft.assistantResponse;
|
|
13182
13034
|
} else {
|
|
13183
|
-
|
|
13184
|
-
|
|
13185
|
-
|
|
13186
|
-
|
|
13187
|
-
|
|
13188
|
-
|
|
13035
|
+
conv.messages = [
|
|
13036
|
+
...prevMessages,
|
|
13037
|
+
{
|
|
13038
|
+
role: "assistant",
|
|
13039
|
+
content: draft.assistantResponse,
|
|
13040
|
+
metadata: buildAssistantMetadata(draft)
|
|
13041
|
+
}
|
|
13042
|
+
];
|
|
13189
13043
|
}
|
|
13190
13044
|
}
|
|
13191
13045
|
applyTurnMetadata(conv, {
|
|
@@ -13195,54 +13049,6 @@ var AgentOrchestrator = class {
|
|
|
13195
13049
|
harnessMessages: execution?.runHarnessMessages
|
|
13196
13050
|
}, { shouldRebuildCanonical: true });
|
|
13197
13051
|
await this.conversationStore.update(conv);
|
|
13198
|
-
if (amendmentText !== void 0 || pushedAssistant) {
|
|
13199
|
-
const finalConv = conv;
|
|
13200
|
-
const amendText = amendmentText;
|
|
13201
|
-
const pushed = pushedAssistant;
|
|
13202
|
-
void (async () => {
|
|
13203
|
-
try {
|
|
13204
|
-
if (pushed) {
|
|
13205
|
-
await appendEntriesSafe(
|
|
13206
|
-
this.conversationStore,
|
|
13207
|
-
finalConv,
|
|
13208
|
-
[assistantMessageEntry(pushed, `resume-${conversationId}`, latestRunId)],
|
|
13209
|
-
dualWriteLog
|
|
13210
|
-
);
|
|
13211
|
-
} else if (amendText !== void 0) {
|
|
13212
|
-
const existing = await this.conversationStore.readEntries(
|
|
13213
|
-
conversationId,
|
|
13214
|
-
{ types: ["assistant_message"] }
|
|
13215
|
-
);
|
|
13216
|
-
const target = existing[existing.length - 1];
|
|
13217
|
-
if (target) {
|
|
13218
|
-
await appendEntriesSafe(
|
|
13219
|
-
this.conversationStore,
|
|
13220
|
-
finalConv,
|
|
13221
|
-
[assistantAmendmentEntry(target.id, amendText)],
|
|
13222
|
-
dualWriteLog
|
|
13223
|
-
);
|
|
13224
|
-
} else {
|
|
13225
|
-
dualWriteLog.warn(
|
|
13226
|
-
`[entries-dual-write] resume amendment for ${conversationId}: no assistant_message entry to target; skipped`
|
|
13227
|
-
);
|
|
13228
|
-
}
|
|
13229
|
-
}
|
|
13230
|
-
await verifyEntriesParity(
|
|
13231
|
-
this.conversationStore,
|
|
13232
|
-
conversationId,
|
|
13233
|
-
{
|
|
13234
|
-
harnessMessages: finalConv._harnessMessages,
|
|
13235
|
-
displayMessages: finalConv.messages
|
|
13236
|
-
},
|
|
13237
|
-
dualWriteLog
|
|
13238
|
-
);
|
|
13239
|
-
} catch (err) {
|
|
13240
|
-
dualWriteLog.error(
|
|
13241
|
-
`[entries-dual-write] resume finalize append failed for ${conversationId}: ${err instanceof Error ? err.message : String(err)}`
|
|
13242
|
-
);
|
|
13243
|
-
}
|
|
13244
|
-
})();
|
|
13245
|
-
}
|
|
13246
13052
|
}
|
|
13247
13053
|
} else {
|
|
13248
13054
|
const conv = await this.conversationStore.get(conversationId);
|
|
@@ -13778,7 +13584,6 @@ ${resultBody}`,
|
|
|
13778
13584
|
conversation.updatedAt = Date.now();
|
|
13779
13585
|
await this.conversationStore.update(conversation);
|
|
13780
13586
|
if (pendingResults.length > 0) {
|
|
13781
|
-
const turnId = `callback-${callbackCount}-${conversation.conversationId}`;
|
|
13782
13587
|
void (async () => {
|
|
13783
13588
|
try {
|
|
13784
13589
|
const resultEntries = await this.conversationStore.readEntries(
|
|
@@ -13792,17 +13597,12 @@ ${resultBody}`,
|
|
|
13792
13597
|
await appendEntriesSafe(
|
|
13793
13598
|
this.conversationStore,
|
|
13794
13599
|
conversation,
|
|
13795
|
-
[
|
|
13796
|
-
|
|
13797
|
-
...injectedCallbackMessages.map(
|
|
13798
|
-
(m) => userMessageEntry(m, turnId, { hidden: true })
|
|
13799
|
-
)
|
|
13800
|
-
],
|
|
13801
|
-
dualWriteLog
|
|
13600
|
+
[callbackStartedEntry(consumedSeqs)],
|
|
13601
|
+
entriesQueueLog
|
|
13802
13602
|
);
|
|
13803
13603
|
} catch (err) {
|
|
13804
|
-
|
|
13805
|
-
`[entries-
|
|
13604
|
+
entriesQueueLog.error(
|
|
13605
|
+
`[entries-queue] callback_started append failed for ${conversation.conversationId}: ${err instanceof Error ? err.message : String(err)}`
|
|
13806
13606
|
);
|
|
13807
13607
|
}
|
|
13808
13608
|
})();
|
|
@@ -13888,25 +13688,6 @@ ${resultBody}`,
|
|
|
13888
13688
|
}, { shouldRebuildCanonical: true, clearApprovals: false });
|
|
13889
13689
|
freshConv.runningCallbackSince = void 0;
|
|
13890
13690
|
await this.conversationStore.update(freshConv);
|
|
13891
|
-
if (callbackAssistantMsg) {
|
|
13892
|
-
const finalMsg = callbackAssistantMsg;
|
|
13893
|
-
void appendEntriesSafe(
|
|
13894
|
-
this.conversationStore,
|
|
13895
|
-
freshConv,
|
|
13896
|
-
[assistantMessageEntry(finalMsg, `callback-${conversationId}`, execution.latestRunId)],
|
|
13897
|
-
dualWriteLog
|
|
13898
|
-
).then(
|
|
13899
|
-
() => verifyEntriesParity(
|
|
13900
|
-
this.conversationStore,
|
|
13901
|
-
conversationId,
|
|
13902
|
-
{
|
|
13903
|
-
harnessMessages: freshConv._harnessMessages,
|
|
13904
|
-
displayMessages: freshConv.messages
|
|
13905
|
-
},
|
|
13906
|
-
dualWriteLog
|
|
13907
|
-
)
|
|
13908
|
-
);
|
|
13909
|
-
}
|
|
13910
13691
|
if (freshConv.channelMeta && execution.draft.assistantResponse.length > 0) {
|
|
13911
13692
|
this.hooks?.onMessagingNotify?.(conversationId, execution.draft.assistantResponse);
|
|
13912
13693
|
}
|
|
@@ -14319,11 +14100,11 @@ ${resultBody}`,
|
|
|
14319
14100
|
this.conversationStore,
|
|
14320
14101
|
parent,
|
|
14321
14102
|
[subagentResultEntry(result)],
|
|
14322
|
-
|
|
14103
|
+
entriesQueueLog
|
|
14323
14104
|
);
|
|
14324
14105
|
} catch (err) {
|
|
14325
|
-
|
|
14326
|
-
`[entries-
|
|
14106
|
+
entriesQueueLog.error(
|
|
14107
|
+
`[entries-queue] subagent_result append failed for ${parentConversationId}: ${err instanceof Error ? err.message : String(err)}`
|
|
14327
14108
|
);
|
|
14328
14109
|
}
|
|
14329
14110
|
})();
|
|
@@ -14514,8 +14295,6 @@ var runConversationTurn = async (opts) => {
|
|
|
14514
14295
|
conversation.updatedAt = Date.now();
|
|
14515
14296
|
await opts.conversationStore.update(conversation);
|
|
14516
14297
|
};
|
|
14517
|
-
const preTurnHarnessMessages = conversation._harnessMessages ? [...conversation._harnessMessages] : void 0;
|
|
14518
|
-
const turnId = assistantId;
|
|
14519
14298
|
conversation.messages = [...historyMessages, userMessage];
|
|
14520
14299
|
conversation.subagentCallbackCount = 0;
|
|
14521
14300
|
conversation._continuationCount = void 0;
|
|
@@ -14525,12 +14304,6 @@ var runConversationTurn = async (opts) => {
|
|
|
14525
14304
|
`failed to persist user turn: ${err instanceof Error ? err.message : String(err)}`
|
|
14526
14305
|
);
|
|
14527
14306
|
});
|
|
14528
|
-
void appendEntriesSafe(
|
|
14529
|
-
opts.conversationStore,
|
|
14530
|
-
conversation,
|
|
14531
|
-
[userMessageEntry(userMessage, turnId)],
|
|
14532
|
-
log
|
|
14533
|
-
);
|
|
14534
14307
|
try {
|
|
14535
14308
|
const execution = await executeConversationTurn({
|
|
14536
14309
|
harness: opts.harness,
|
|
@@ -14578,34 +14351,6 @@ var runConversationTurn = async (opts) => {
|
|
|
14578
14351
|
...existingHistory,
|
|
14579
14352
|
...preRunMessages.slice(0, removedCount)
|
|
14580
14353
|
];
|
|
14581
|
-
const summaryMessage = event.compactedMessages[0];
|
|
14582
|
-
const keptCount = Math.max(0, event.compactedMessages.length - 1);
|
|
14583
|
-
if (summaryMessage) {
|
|
14584
|
-
void (async () => {
|
|
14585
|
-
try {
|
|
14586
|
-
const existing = await opts.conversationStore.readEntries(
|
|
14587
|
-
opts.conversationId,
|
|
14588
|
-
{ types: ["harness_message"] }
|
|
14589
|
-
);
|
|
14590
|
-
const harnessSeqs = existing.map((e) => e.seq);
|
|
14591
|
-
const firstKeptSeq = harnessSeqs.length >= keptCount && keptCount > 0 ? harnessSeqs[harnessSeqs.length - keptCount] : (harnessSeqs[harnessSeqs.length - 1] ?? 0) + 1;
|
|
14592
|
-
await appendEntriesSafe(
|
|
14593
|
-
opts.conversationStore,
|
|
14594
|
-
conversation,
|
|
14595
|
-
[
|
|
14596
|
-
compactionEntry(summaryMessage, firstKeptSeq, {
|
|
14597
|
-
tokensBefore: conversation.contextTokens
|
|
14598
|
-
})
|
|
14599
|
-
],
|
|
14600
|
-
log
|
|
14601
|
-
);
|
|
14602
|
-
} catch (err) {
|
|
14603
|
-
log.error(
|
|
14604
|
-
`[entries-dual-write] compaction append failed: ${err instanceof Error ? err.message : String(err)}`
|
|
14605
|
-
);
|
|
14606
|
-
}
|
|
14607
|
-
})();
|
|
14608
|
-
}
|
|
14609
14354
|
}
|
|
14610
14355
|
}
|
|
14611
14356
|
if (event.type === "step:completed") {
|
|
@@ -14739,36 +14484,6 @@ var runConversationTurn = async (opts) => {
|
|
|
14739
14484
|
{ shouldRebuildCanonical }
|
|
14740
14485
|
);
|
|
14741
14486
|
await opts.conversationStore.update(conversation);
|
|
14742
|
-
const finalAssistant = conversation.messages[conversation.messages.length - 1];
|
|
14743
|
-
const { messages: newHarness, approximate } = newHarnessMessagesThisTurn(
|
|
14744
|
-
preTurnHarnessMessages,
|
|
14745
|
-
conversation._harnessMessages
|
|
14746
|
-
);
|
|
14747
|
-
if (approximate) {
|
|
14748
|
-
log.warn(
|
|
14749
|
-
`[entries-dual-write] ${opts.conversationId} harness-message diff approximate (blob array shrank this turn \u2014 likely compaction); appended full context`
|
|
14750
|
-
);
|
|
14751
|
-
}
|
|
14752
|
-
const finalizeEntries = [
|
|
14753
|
-
...harnessMessageEntries(newHarness, turnId),
|
|
14754
|
-
...finalAssistant && finalAssistant.role === "assistant" ? [assistantMessageEntry(finalAssistant, turnId, latestRunId)] : []
|
|
14755
|
-
];
|
|
14756
|
-
void appendEntriesSafe(
|
|
14757
|
-
opts.conversationStore,
|
|
14758
|
-
conversation,
|
|
14759
|
-
finalizeEntries,
|
|
14760
|
-
log
|
|
14761
|
-
).then(
|
|
14762
|
-
() => verifyEntriesParity(
|
|
14763
|
-
opts.conversationStore,
|
|
14764
|
-
opts.conversationId,
|
|
14765
|
-
{
|
|
14766
|
-
harnessMessages: conversation._harnessMessages,
|
|
14767
|
-
displayMessages: conversation.messages
|
|
14768
|
-
},
|
|
14769
|
-
log
|
|
14770
|
-
)
|
|
14771
|
-
);
|
|
14772
14487
|
}
|
|
14773
14488
|
return {
|
|
14774
14489
|
latestRunId,
|
|
@@ -14891,8 +14606,6 @@ export {
|
|
|
14891
14606
|
buildAgentDirectoryName,
|
|
14892
14607
|
buildApprovalCheckpoints,
|
|
14893
14608
|
buildAssistantMetadata,
|
|
14894
|
-
buildDisplaySnapshot,
|
|
14895
|
-
buildLlmContext,
|
|
14896
14609
|
buildSkillContextWindow,
|
|
14897
14610
|
buildToolCompletedText,
|
|
14898
14611
|
cloneSections,
|
|
@@ -14929,7 +14642,6 @@ export {
|
|
|
14929
14642
|
deleteOpenAICodexSession,
|
|
14930
14643
|
deriveUploadKey,
|
|
14931
14644
|
ensureAgentIdentity,
|
|
14932
|
-
entriesParityEnabled,
|
|
14933
14645
|
estimateTokens,
|
|
14934
14646
|
estimateTotalTokens,
|
|
14935
14647
|
executeConversationTurn,
|
|
@@ -14955,7 +14667,6 @@ export {
|
|
|
14955
14667
|
loadSkillMetadataFromDirs,
|
|
14956
14668
|
loadVfsSkillMetadata,
|
|
14957
14669
|
mergeSkills,
|
|
14958
|
-
newHarnessMessagesThisTurn,
|
|
14959
14670
|
normalizeApprovalCheckpoint,
|
|
14960
14671
|
normalizeOtlp,
|
|
14961
14672
|
normalizeScriptPolicyPath,
|
|
@@ -14979,7 +14690,6 @@ export {
|
|
|
14979
14690
|
runConversationTurn,
|
|
14980
14691
|
slugifyStorageComponent,
|
|
14981
14692
|
startOpenAICodexDeviceAuth,
|
|
14982
|
-
verifyEntriesParity,
|
|
14983
14693
|
verifyTenantToken,
|
|
14984
14694
|
withToolResultArchiveParam,
|
|
14985
14695
|
writeOpenAICodexSession
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -21,23 +21,15 @@ export * from "./telemetry.js";
|
|
|
21
21
|
export * from "./secrets-store.js";
|
|
22
22
|
export * from "./storage/index.js";
|
|
23
23
|
export * from "./storage/store-adapters.js";
|
|
24
|
-
//
|
|
25
|
-
// appendEntries/readEntries are reachable on the
|
|
26
|
-
// StorageEngine.conversations surfaces
|
|
24
|
+
// Subagent delivery queue (append-only conversation_entries): types + the
|
|
25
|
+
// pending-results rebuild. appendEntries/readEntries are reachable on the
|
|
26
|
+
// ConversationStore / StorageEngine.conversations surfaces exported above.
|
|
27
27
|
export {
|
|
28
|
-
buildLlmContext,
|
|
29
|
-
buildDisplaySnapshot,
|
|
30
28
|
getPendingSubagentResults,
|
|
31
29
|
type ConversationEntry,
|
|
32
30
|
type NewConversationEntry,
|
|
33
|
-
type UserMessageEntry,
|
|
34
|
-
type AssistantMessageEntry,
|
|
35
|
-
type AssistantAmendmentEntry,
|
|
36
|
-
type HarnessMessageEntry,
|
|
37
|
-
type CompactionEntry,
|
|
38
31
|
type SubagentResultEntry,
|
|
39
32
|
type CallbackStartedEntry,
|
|
40
|
-
type DisplaySnapshot,
|
|
41
33
|
} from "./storage/entries.js";
|
|
42
34
|
export {
|
|
43
35
|
PonchoFsAdapter,
|