@replayci/replay 0.1.0 → 0.1.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.
package/dist/index.cjs CHANGED
@@ -108,7 +108,11 @@ var CaptureBuffer = class {
108
108
  if (this.flushPromise) {
109
109
  return this.flushPromise;
110
110
  }
111
- const flushPromise = this.flushOnce().catch(() => {
111
+ const flushPromise = this.flushOnce().catch((err) => {
112
+ emitDiagnostics(this.diagnostics, {
113
+ type: "flush_error",
114
+ error: err instanceof Error ? err.message : String(err)
115
+ });
112
116
  }).finally(() => {
113
117
  if (this.flushPromise === flushPromise) {
114
118
  this.flushPromise = void 0;
@@ -122,9 +126,18 @@ var CaptureBuffer = class {
122
126
  return;
123
127
  }
124
128
  this.closed = true;
125
- this.queue.length = 0;
126
129
  this.clearTimer();
127
- unregisterBuffer(this);
130
+ if (this.queue.length > 0) {
131
+ this.closed = false;
132
+ this.flush().catch(() => {
133
+ }).finally(() => {
134
+ this.closed = true;
135
+ this.queue.length = 0;
136
+ unregisterBuffer(this);
137
+ });
138
+ } else {
139
+ unregisterBuffer(this);
140
+ }
128
141
  }
129
142
  async flushOnce() {
130
143
  if (this.closed || this.remoteDisabled || this.queue.length === 0) {
@@ -186,6 +199,17 @@ var CaptureBuffer = class {
186
199
  this.failureCount += 1;
187
200
  if (this.failureCount >= CIRCUIT_BREAKER_FAILURE_LIMIT) {
188
201
  this.circuitOpenUntil = this.now() + CIRCUIT_BREAKER_MS;
202
+ emitDiagnostics(this.diagnostics, {
203
+ type: "circuit_open",
204
+ failures: this.failureCount,
205
+ backoffMs: CIRCUIT_BREAKER_MS
206
+ });
207
+ try {
208
+ console.warn(
209
+ `[replayci] Capture buffer circuit breaker open after ${this.failureCount} consecutive failures. Captures will be dropped for ${CIRCUIT_BREAKER_MS / 6e4} minutes.`
210
+ );
211
+ } catch {
212
+ }
189
213
  this.failureCount = 0;
190
214
  }
191
215
  }
package/dist/index.d.cts CHANGED
@@ -26,6 +26,13 @@ type ObserveDiagnosticEvent = {
26
26
  } | {
27
27
  type: "buffer_overflow";
28
28
  dropped: number;
29
+ } | {
30
+ type: "flush_error";
31
+ error: string;
32
+ } | {
33
+ type: "circuit_open";
34
+ failures: number;
35
+ backoffMs: number;
29
36
  };
30
37
  type ObserveOptions = {
31
38
  agent?: string;
package/dist/index.d.ts CHANGED
@@ -26,6 +26,13 @@ type ObserveDiagnosticEvent = {
26
26
  } | {
27
27
  type: "buffer_overflow";
28
28
  dropped: number;
29
+ } | {
30
+ type: "flush_error";
31
+ error: string;
32
+ } | {
33
+ type: "circuit_open";
34
+ failures: number;
35
+ backoffMs: number;
29
36
  };
30
37
  type ObserveOptions = {
31
38
  agent?: string;
package/dist/index.js CHANGED
@@ -80,7 +80,11 @@ var CaptureBuffer = class {
80
80
  if (this.flushPromise) {
81
81
  return this.flushPromise;
82
82
  }
83
- const flushPromise = this.flushOnce().catch(() => {
83
+ const flushPromise = this.flushOnce().catch((err) => {
84
+ emitDiagnostics(this.diagnostics, {
85
+ type: "flush_error",
86
+ error: err instanceof Error ? err.message : String(err)
87
+ });
84
88
  }).finally(() => {
85
89
  if (this.flushPromise === flushPromise) {
86
90
  this.flushPromise = void 0;
@@ -94,9 +98,18 @@ var CaptureBuffer = class {
94
98
  return;
95
99
  }
96
100
  this.closed = true;
97
- this.queue.length = 0;
98
101
  this.clearTimer();
99
- unregisterBuffer(this);
102
+ if (this.queue.length > 0) {
103
+ this.closed = false;
104
+ this.flush().catch(() => {
105
+ }).finally(() => {
106
+ this.closed = true;
107
+ this.queue.length = 0;
108
+ unregisterBuffer(this);
109
+ });
110
+ } else {
111
+ unregisterBuffer(this);
112
+ }
100
113
  }
101
114
  async flushOnce() {
102
115
  if (this.closed || this.remoteDisabled || this.queue.length === 0) {
@@ -158,6 +171,17 @@ var CaptureBuffer = class {
158
171
  this.failureCount += 1;
159
172
  if (this.failureCount >= CIRCUIT_BREAKER_FAILURE_LIMIT) {
160
173
  this.circuitOpenUntil = this.now() + CIRCUIT_BREAKER_MS;
174
+ emitDiagnostics(this.diagnostics, {
175
+ type: "circuit_open",
176
+ failures: this.failureCount,
177
+ backoffMs: CIRCUIT_BREAKER_MS
178
+ });
179
+ try {
180
+ console.warn(
181
+ `[replayci] Capture buffer circuit breaker open after ${this.failureCount} consecutive failures. Captures will be dropped for ${CIRCUIT_BREAKER_MS / 6e4} minutes.`
182
+ );
183
+ } catch {
184
+ }
161
185
  this.failureCount = 0;
162
186
  }
163
187
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@replayci/replay",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "ReplayCI SDK for deterministic tool-call validation and observation.",
5
5
  "license": "ISC",
6
6
  "author": "ReplayCI",