@systemfsoftware/effect-daemon-spec 3.0.14 → 4.0.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @systemfsoftware/effect-daemon-spec
2
2
 
3
+ ## 4.0.0
4
+
5
+ ### Patch Changes
6
+
7
+ - A supervisor whose restart decision cannot read its own restart command now logs the error and cools down, the same as when its restart budget runs out. It used to die and take its children down with it.
8
+
3
9
  ## 3.0.14
4
10
 
5
11
  ### Patch Changes
package/dist/index.mjs CHANGED
@@ -521,8 +521,8 @@ const DecideInputBase = Schema.Struct({
521
521
  }).check(Schema.makeFilter(failedIndexAddressesAChild, { message: BOUND_MESSAGE }));
522
522
  /**
523
523
  * The restart command. A `Schema.Class` rather than a `Schema.Struct` because `Workflow.make`
524
- * takes the command's class as its first argument, and a struct carries no `identifier` and
525
- * no `extend` — the constraint refuses it. Every field schema and the cross-field check are
524
+ * constrains its `command` on the class itself — a struct carries no `identifier` and no
525
+ * `extend`, and the constraint refuses it. Every field schema and the cross-field check are
526
526
  * the ones the struct carried.
527
527
  *
528
528
  * Class-level `toCodecArbitrary` is what `Arbitrary.schema(DecideInput)` compiles. The
@@ -535,7 +535,7 @@ var DecideInput = class DecideInput extends Schema.Class("DecideInput")(DecideIn
535
535
  decode: SchemaGetter.transform((generated) => new DecideInput(commandFromGenerated(generated))),
536
536
  encode: SchemaGetter.transform(generatedFromCommand)
537
537
  }) }) {
538
- static [Workflow.InstrumentationBrand] = ["strategy"];
538
+ static [Workflow.InstrumentationBrand] = { strategy: "daemon.restart.strategy" };
539
539
  };
540
540
  //#endregion
541
541
  //#region src/internal/choose-restart-strategy.workflow.ts
@@ -560,11 +560,23 @@ var RestartDecisionRestart = class extends S.TaggedClass()("Restart", { indices:
560
560
  var RestartDecisionExhausted = class extends S.TaggedError()("Exhausted", {}) {
561
561
  [RestartDecisionTypeId] = RestartDecisionTypeId;
562
562
  };
563
+ /**
564
+ * The decision channel: the two outcomes a cooldown-or-restart choice is made between, as
565
+ * one schema the workflow declares. The error channel carries `RestartDecisionExhausted`, so
566
+ * the compiler holds the three-way dispatch over the encoded tags of both channels.
567
+ */
563
568
  /** @internal */
564
- const chooseRestartStrategy = Workflow.make(DecideInput, (command) => Match$1.value(command).pipe(Match$1.when({ exitSuccess: true }, () => Result$1.succeed(RestartDecisionContinue.make())), Match$1.when({
565
- exitSuccess: false,
566
- intensityExceeded: true
567
- }, () => Result$1.fail(RestartDecisionExhausted.make())), Match$1.orElse(() => Result$1.succeed(RestartDecisionRestart.make({ indices: restartIndicesFor(command.strategy, command.failedIndex, command.totalChildren) })))));
569
+ const RestartDecision = S.Union([RestartDecisionContinue, RestartDecisionRestart]);
570
+ /** @internal */
571
+ const chooseRestartStrategy = Workflow.make({
572
+ command: DecideInput,
573
+ decision: RestartDecision,
574
+ error: RestartDecisionExhausted,
575
+ decide: (command) => Match$1.value(command).pipe(Match$1.when({ exitSuccess: true }, () => Result$1.succeed(RestartDecisionContinue.make())), Match$1.when({
576
+ exitSuccess: false,
577
+ intensityExceeded: true
578
+ }, () => Result$1.fail(RestartDecisionExhausted.make())), Match$1.orElse(() => Result$1.succeed(RestartDecisionRestart.make({ indices: restartIndicesFor(command.strategy, command.failedIndex, command.totalChildren) }))))
579
+ });
568
580
  //#endregion
569
581
  //#region src/internal/IntensityWindow.ts
570
582
  /** @internal */
@@ -718,25 +730,35 @@ const handleRestart = (ctx, cause, onSignal) => Effect.gen(function* () {
718
730
  * The read is a bump-and-report: recording a restart is how the current rate is obtained, so
719
731
  * the mutation is a product gathered across the read's interior rather than a write standing
720
732
  * before a decision. That is what keeps this one layer instead of two, and it is why
721
- * `intensity.record` sits where it does.
733
+ * `intensity.record` sits where it does. The read is also where the command's encoded form is
734
+ * gathered, so the library decodes it through the workflow's command schema before `decide`
735
+ * runs and encodes the decision or the refusal the workflow returns.
722
736
  *
723
- * `encode` is the identity because nothing needs shaping — the decision is already what the
724
- * write consumes — and the write only dispatches over the tags the decision produced.
737
+ * The write dispatches one handler per encoded tag, and each handler answers with the epoch
738
+ * step that follows: a decision to continue stops the epoch, a decision to restart reports and
739
+ * reboots, and the `Exhausted` refusal cools down. A command the supervisor built that fails its
740
+ * own schema is a regression in this module, so it is logged and treated as exhausted: the
741
+ * supervisor cools down instead of dying and taking every child with it.
725
742
  *
726
743
  * A description is built per failure because the write needs that failure's context, and the
727
744
  * phase signatures hand the command to the read alone. Restarts are rare, so the allocation is
728
745
  * paid only when a supervised child has actually died.
729
746
  */
730
- const restartDescription = (spec) => Sandwich.named("supervisor.restart-description")((intensity) => Effect.andThen(intensity.record, intensity.isExceeded)).decode(Sandwich.pure((intensityExceeded) => Result.succeed({
747
+ const restartDescription = (spec) => Sandwich.named("supervisor.restart-description")((intensity) => Effect.map(Effect.andThen(intensity.record, intensity.isExceeded), (intensityExceeded) => ({
731
748
  strategy: spec.strategy,
732
749
  totalChildren: spec.totalChildren,
733
750
  failedIndex: spec.failedIndex,
734
751
  exitSuccess: false,
735
752
  intensityExceeded
736
- }))).decide(chooseRestartStrategy).encode(Sandwich.pure((outcome) => Result.succeed(outcome))).write((outcome) => Result.match(outcome, {
737
- onFailure: () => handleExhausted(spec.ctx, spec.cause),
738
- onSuccess: (right) => Match.value(right).pipe(Match.tag("Continue", () => Effect.succeed(StopEpoch.make())), Match.tag("Restart", (decision) => handleRestart(spec.ctx, spec.cause, spec.onRestart(decision))), Match.exhaustive)
739
- }));
753
+ }))).decide(chooseRestartStrategy).write({
754
+ Continue: () => Effect.succeed(StopEpoch.make()),
755
+ Restart: (decision) => handleRestart(spec.ctx, spec.cause, spec.onRestart(decision)),
756
+ Exhausted: () => handleExhausted(spec.ctx, spec.cause),
757
+ CommandRejected: (rejected) => Effect.andThen(Effect.logError("supervisor restart command failed its own schema; cooling down", {
758
+ daemon: spec.ctx.name,
759
+ issue: String(rejected.issue)
760
+ }), handleExhausted(spec.ctx, spec.cause))
761
+ });
740
762
  const reopenHealthyAfterCooldown = (ctx) => Effect.andThen(ctx.health.healthy.open, Metric.update(Metric.withAttributes(healthStateGauge, {
741
763
  daemon: ctx.name,
742
764
  latch: "healthy"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@systemfsoftware/effect-daemon-spec",
3
3
  "license": "Apache-2.0",
4
- "version": "3.0.14",
4
+ "version": "4.0.0",
5
5
  "author": "Ryan Lee <drdgvhbh@gmail.com>",
6
6
  "repository": {
7
7
  "type": "git",
@@ -37,17 +37,17 @@
37
37
  "dist"
38
38
  ],
39
39
  "dependencies": {
40
- "@systemfsoftware/effect-cell-types": "^9.0.0"
40
+ "@systemfsoftware/effect-cell-types": "^10.0.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@effect/vitest": "4.0.0-rc.116",
44
44
  "@microsoft/api-extractor": "^7.59.1",
45
45
  "@systemfsoftware/arethetypeswrong-cli": "^4.2.0",
46
- "@systemfsoftware/stryker-ignorer-effect-schema-declarations": "^0.1.0",
47
- "@systemfsoftware/stryker-ignorer-in-source-vitest-block": "^0.1.0",
48
- "@systemfsoftware/stryker-js": "^10.0.1",
49
- "@systemfsoftware/stryker-js-typescript-checker": "^7.0.4",
50
- "@systemfsoftware/stryker-js-vitest-runner": "^7.0.1",
46
+ "@systemfsoftware/stryker-ignorer-effect-schema-declarations": "^0.1.1",
47
+ "@systemfsoftware/stryker-ignorer-in-source-vitest-block": "^0.1.1",
48
+ "@systemfsoftware/stryker-js": "^10.1.1",
49
+ "@systemfsoftware/stryker-js-typescript-checker": "^7.0.5",
50
+ "@systemfsoftware/stryker-js-vitest-runner": "^7.1.1",
51
51
  "@systemfsoftware/stryker-test-contribution": "^3.0.3",
52
52
  "@types/node": "^26",
53
53
  "@vitest/coverage-v8": "^5",
@@ -58,14 +58,14 @@
58
58
  "tsdown": "^0.23.0",
59
59
  "typescript": "^7",
60
60
  "vitest": "^5",
61
- "@systemfsoftware/effect-gherkin-spec": "^4.2.2",
61
+ "@systemfsoftware/effect-gherkin-spec": "^4.2.3",
62
+ "@systemfsoftware/effect-schema-vite": "^2.2.1",
62
63
  "@systemfsoftware/effect-schema-law": "^2.2.1",
63
- "@systemfsoftware/oxlint-config-recommended": "^1.1.0",
64
+ "@systemfsoftware/oxlint-config-recommended": "^1.1.1",
64
65
  "@systemfsoftware/stryker-config": "^0.1.0",
65
- "@systemfsoftware/tsconfig": "^1.3.6",
66
+ "@systemfsoftware/vitest-config": "^0.1.0",
66
67
  "@systemfsoftware/tsdown-config": "^0.1.0",
67
- "@systemfsoftware/effect-schema-vite": "^2.2.1",
68
- "@systemfsoftware/vitest-config": "^0.1.0"
68
+ "@systemfsoftware/tsconfig": "^1.3.6"
69
69
  },
70
70
  "peerDependencies": {
71
71
  "effect": "4.0.0-rc.116"