@cubicecho/agent-core 2.0.0 → 2.0.1

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.
Files changed (2) hide show
  1. package/dist/events.js +16 -4
  2. package/package.json +1 -1
package/dist/events.js CHANGED
@@ -131,9 +131,15 @@ export async function* watch(runId) {
131
131
  // The bus caps its own backlog at `MAX_EVENTS`; without this the watcher downstream of it
132
132
  // had no cap at all, so a client too slow to keep up held every delta a run ever emitted.
133
133
  // The oldest go, which is what the backlog does, and the gap is reported once below.
134
- if (queue.length - head > MAX_EVENTS + TRIM_SLACK) {
135
- const cut = queue.length - head - MAX_EVENTS;
136
- head += cut;
134
+ //
135
+ // Dropped here means released here. Advancing the cursor alone left the dropped events in
136
+ // the slots behind it, to be freed by the compaction in the drain below — which a consumer
137
+ // that has stalled does not reach, and a stalled consumer is the whole reason for the cap.
138
+ // It read as capped and held every event anyway: 16MB where the cap promises a third of one.
139
+ const cut = queue.length - head - MAX_EVENTS;
140
+ if (cut > TRIM_SLACK) {
141
+ queue = queue.slice(head + cut);
142
+ head = 0;
137
143
  dropped += cut;
138
144
  }
139
145
  wake?.();
@@ -157,11 +163,17 @@ export async function* watch(runId) {
157
163
  if (dropped > 0) {
158
164
  // Said once per gap rather than per event, and before the event that follows it, so a
159
165
  // client reading `seq` sees why the numbers jump instead of assuming it lost its place.
166
+ //
167
+ // One short of the event it precedes, which is the last seq that went missing. Sharing
168
+ // a seq with the event behind it made the notice indistinguishable from a duplicate,
169
+ // and de-duplicating on `seq` is the one thing the sequence is documented for — so a
170
+ // client doing exactly that dropped either the gap notice or the event it explains.
171
+ // Inside the gap there is nothing to collide with: those seqs reach no watcher.
160
172
  const gap = dropped;
161
173
  dropped = 0;
162
174
  yield {
163
175
  runId,
164
- seq: event.seq,
176
+ seq: event.seq - 1,
165
177
  at: event.at,
166
178
  kind: "notice",
167
179
  text: `${gap} event(s) dropped: this watcher fell too far behind`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cubicecho/agent-core",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "The endpoint-agnostic half of an OpenAI-compatible agent loop: tool-schema compatibility, on-demand tool loading, one-shot side tasks, run events, and a pooled client.",
5
5
  "keywords": [
6
6
  "openai",