billion-context-omp 0.3.2-pr.138.5 → 0.3.2-pr.140.6

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/dist/index.js CHANGED
@@ -4970,6 +4970,14 @@ function createRuntime(adapter) {
4970
4970
  coreSlots.set(sid, slot);
4971
4971
  lcp = 0;
4972
4972
  }
4973
+ if (lcp === 0 && slot.state.blocks.length > 0) {
4974
+ const presentIds = new Set(ids);
4975
+ const surviving = slot.state.blocks.filter((b) => b.active === false || b.effectiveMessageIds.some((id) => presentIds.has(id)));
4976
+ if (surviving.length < slot.state.blocks.length) {
4977
+ debug.event("fold-purge-stale-blocks", { sid, before: slot.state.blocks.length, after: surviving.length });
4978
+ slot.state = { ...slot.state, blocks: surviving };
4979
+ }
4980
+ }
4973
4981
  const coreMessages = stream;
4974
4982
  const config = configFor(ctx);
4975
4983
  const names = toolCallNames(stream);
@@ -5105,17 +5113,31 @@ ${acp}`);
5105
5113
  logInfo("fold", { sid, event: "fold-restore-empty" });
5106
5114
  return false;
5107
5115
  }
5116
+ const byId = /* @__PURE__ */ new Map();
5117
+ for (const b of r.state.blocks) {
5118
+ const prev = byId.get(b.blockId);
5119
+ if (!prev || b.createdAt > prev.createdAt) byId.set(b.blockId, b);
5120
+ }
5121
+ const blocks = [...byId.values()];
5122
+ if (blocks.length < r.state.blocks.length) {
5123
+ logInfo("fold", { sid, event: "fold-restore-dedup", before: r.state.blocks.length, after: blocks.length });
5124
+ }
5125
+ const maxId = blocks.reduce((m, b) => {
5126
+ const n = /^b(\d+)$/i.exec(b.blockId);
5127
+ return n ? Math.max(m, Number.parseInt(n[1], 10)) : m;
5128
+ }, 0);
5129
+ const state = { ...r.state, blocks, nextBlockId: Math.max(r.state.nextBlockId ?? 1, maxId + 1) };
5108
5130
  coreSlots.set(sid, {
5109
5131
  identities: r.identities,
5110
5132
  foldedLen: r.foldedLen,
5111
5133
  preview: false,
5112
5134
  live: true,
5113
- state: r.state,
5135
+ state,
5114
5136
  coreMessages: r.coreMessages,
5115
5137
  appliedCallIds: r.appliedCallIds,
5116
5138
  rejectStreak: r.rejectStreak
5117
5139
  });
5118
- logInfo("fold", { sid, event: "fold-restore", blocks: r.state.blocks.length, foldedLen: r.foldedLen });
5140
+ logInfo("fold", { sid, event: "fold-restore", blocks: state.blocks.length, foldedLen: r.foldedLen, nextBlockId: state.nextBlockId });
5119
5141
  return true;
5120
5142
  }
5121
5143
  function snapshotOf(slot) {