next-issue 6.6.117 → 6.6.119

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/observe.mjs +25 -4
  2. package/package.json +1 -1
package/dist/observe.mjs CHANGED
@@ -14,14 +14,27 @@ class Sink {
14
14
  level;
15
15
  file;
16
16
  listener;
17
+ /** Set once the run log fails: the run goes on, and its events reach only the listener. */
18
+ failed = false;
17
19
  constructor(stream, level, file, listener) {
18
20
  this.stream = stream;
19
21
  this.level = level;
20
22
  this.file = file;
21
23
  this.listener = listener;
24
+ // With no listener, a failed open or write (`ENOSPC`, `EIO`, `EMFILE`) would crash the process.
25
+ stream.on('error', (error) => this.fail(error));
26
+ }
27
+ fail(error) {
28
+ if (this.failed) {
29
+ return;
30
+ }
31
+ this.failed = true;
32
+ process.stderr.write(`next-issue: the run log ${this.file} cannot be written (${message(error)}); the run goes on without it\n`);
22
33
  }
23
34
  write(record) {
24
- this.stream.write(`${JSON.stringify(record)}\n`);
35
+ if (!this.failed) {
36
+ this.stream.write(`${JSON.stringify(record)}\n`);
37
+ }
25
38
  this.listener?.(record);
26
39
  }
27
40
  count(kind) {
@@ -35,7 +48,15 @@ class Sink {
35
48
  this.totals.set(role, current);
36
49
  }
37
50
  close() {
38
- return new Promise((resolve) => this.stream.end(resolve));
51
+ return new Promise((resolve) => {
52
+ if (this.stream.closed) {
53
+ resolve();
54
+ return;
55
+ }
56
+ // `close` comes after the last write is flushed, and also after an error.
57
+ this.stream.once('close', () => resolve());
58
+ this.stream.end();
59
+ });
39
60
  }
40
61
  }
41
62
  export class Recorder {
@@ -47,12 +68,12 @@ export class Recorder {
47
68
  this.base = base;
48
69
  this.runId = runId;
49
70
  }
50
- static async create(root, level, listener) {
71
+ static async create(root, level, listener, open = (file) => createWriteStream(file, { flags: 'a' })) {
51
72
  const runId = new Date().toISOString().replace(/[:.]/g, '-');
52
73
  const dir = runsDir(root);
53
74
  await mkdir(dir, { recursive: true });
54
75
  const file = join(dir, `${runId}.jsonl`);
55
- const sink = new Sink(createWriteStream(file, { flags: 'a' }), level, file, listener);
76
+ const sink = new Sink(open(file), level, file, listener);
56
77
  return new Recorder(sink, {}, runId);
57
78
  }
58
79
  get logFile() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "6.6.117",
3
+ "version": "6.6.119",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",