@decocms/sandbox-controller 0.8.3 → 0.8.5

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.d.ts CHANGED
@@ -3783,6 +3783,15 @@ declare class FreestyleSandboxProvider implements SandboxProvider {
3783
3783
  private run;
3784
3784
  ensure(id: SandboxId, opts?: EnsureOptions): Promise<Sandbox>;
3785
3785
  private resume;
3786
+ /**
3787
+ * The bearer this VM was claimed with lives in daemon memory. A cold boot
3788
+ * (Freestyle restarts a guest it finds wedged) brings the daemon back on the
3789
+ * snapshot's sentinel with no config, so every call signed with the VM's own
3790
+ * token gets 401. Offer the claim again: a daemon that still holds its token
3791
+ * refuses the sentinel. One whose writes hang, while /health still answers, is
3792
+ * the wedged guest itself, so reboot it and claim the fresh daemon.
3793
+ */
3794
+ private reclaim;
3786
3795
  private create;
3787
3796
  /**
3788
3797
  * The fork's first config: swap the snapshot's sentinel bearer for this
package/dist/index.js CHANGED
@@ -6759,7 +6759,7 @@ var Freestyle = class {
6759
6759
  // ../sandbox/package.json
6760
6760
  var package_default = {
6761
6761
  name: "@decocms/sandbox",
6762
- version: "1.89.2",
6762
+ version: "1.89.4",
6763
6763
  private: true,
6764
6764
  type: "module",
6765
6765
  description: "Sandbox runtime for isolated Studio tool execution",
@@ -7077,9 +7077,12 @@ running`).digest("hex").slice(0, 16)}`;
7077
7077
  });
7078
7078
  }
7079
7079
  async resume(found, opts) {
7080
- const { state } = await found.vm.data();
7080
+ const { state, sourceSnapshotSlugAtCreate } = await found.vm.data();
7081
7081
  if (state !== "running") await found.vm.start();
7082
7082
  await this.waitForDaemon(found.daemon.url);
7083
+ if (sourceSnapshotSlugAtCreate) {
7084
+ await this.reclaim(found, sourceSnapshotSlugAtCreate, opts);
7085
+ }
7083
7086
  if (opts.orgFsConfigJson) {
7084
7087
  await postOrgFsConfig(
7085
7088
  found.daemon.url,
@@ -7096,6 +7099,35 @@ running`).digest("hex").slice(0, 16)}`;
7096
7099
  );
7097
7100
  }
7098
7101
  }
7102
+ /**
7103
+ * The bearer this VM was claimed with lives in daemon memory. A cold boot
7104
+ * (Freestyle restarts a guest it finds wedged) brings the daemon back on the
7105
+ * snapshot's sentinel with no config, so every call signed with the VM's own
7106
+ * token gets 401. Offer the claim again: a daemon that still holds its token
7107
+ * refuses the sentinel. One whose writes hang, while /health still answers, is
7108
+ * the wedged guest itself, so reboot it and claim the fresh daemon.
7109
+ */
7110
+ async reclaim(found, snapshotSlug, opts) {
7111
+ const { url, token } = found.daemon;
7112
+ const sentinel = this.sentinelToken(snapshotSlug);
7113
+ const payload = this.configPayload(opts) ?? {};
7114
+ try {
7115
+ await postConfig(url, sentinel, payload, { rotateToken: token });
7116
+ console.log(`[${LOG_LABEL2}] reclaimed ${url} after a reboot`);
7117
+ return;
7118
+ } catch (err) {
7119
+ if (err instanceof ConfigRequestError) {
7120
+ if (err.status === 401) return;
7121
+ throw err;
7122
+ }
7123
+ }
7124
+ console.warn(
7125
+ `[${LOG_LABEL2}] ${url} answers /health but not writes; rebooting`
7126
+ );
7127
+ await found.vm.exec({ command: "reboot -f", timeoutMs: 1e4 }).catch(() => {
7128
+ });
7129
+ await this.claimDaemon(url, sentinel, token, payload);
7130
+ }
7099
7131
  async create(handle, opts) {
7100
7132
  if (opts.env && Object.keys(opts.env).length > 0) {
7101
7133
  throw new Error(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decocms/sandbox-controller",
3
- "version": "0.8.3",
3
+ "version": "0.8.5",
4
4
  "description": "Runs Studio agent sandboxes on Kubernetes, and serves them to a remote Studio.",
5
5
  "repository": {
6
6
  "type": "git",