@runeditrun/rer 0.2.49 → 0.2.50

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/cli/errors.mjs CHANGED
@@ -14,5 +14,5 @@ export async function lifecycleError(error, store) {
14
14
  const {shared}=await import('./shared.mjs');
15
15
  const {approvedFailure}=await shared('failures.mjs');
16
16
  const approved=approvedFailure(error);
17
- return new RerError(approved?.code==='owner_conflict'?'safety_refusal':'command_failed', approved?.message ?? `${store?.state?.step ?? 'Local lifecycle'} failed. Inspect the private redacted capture log.`, approved?.exitCode ?? 1, {childExitCode:approved?.childExitCode,signal:approved?.signal});
17
+ return new RerError(['owner_conflict','machine_busy'].includes(approved?.code)?'safety_refusal':'command_failed', approved?.message ?? `${store?.state?.step ?? 'Local lifecycle'} failed. Inspect the private redacted capture log.`, approved?.exitCode ?? 1, {childExitCode:approved?.childExitCode,signal:approved?.signal});
18
18
  }
package/cli/lifecycle.mjs CHANGED
@@ -184,6 +184,8 @@ async function hostedNeeds(project) {
184
184
  // full log. A step that stopped outside a command still names the step and log.
185
185
  async function installStepError(error, store, root) {
186
186
  const { approvedFailure } = await shared('failures.mjs');
187
+ // A step the job queue never admitted is a busy machine; its message already says what to do.
188
+ if (approvedFailure(error)?.code === 'machine_busy') return error;
187
189
  const { checkoutPath, stepDiagnostic, stepFailureText } = await shared('step-failure.mjs');
188
190
  const step = approvedFailure(error)?.step ?? stepDiagnostic({ name: store.state.step, output: store.state.logs, log: store.redact(checkoutPath(root, store.logPath)) });
189
191
  // Only a RerError's message or a symbolic error code is safe to show; a native message can hold private data.
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.50
4
+
5
+ - **Seeds can declare an owner sign-in route.** The delivery producer, in Base and in each seed's vendored copy, now accepts an optional `surfaces.app.signIn.ownerSignIn` path, such as `"/auth/owner-signin"`. This is the route that accepts the platform's owner sign-in grant. The platform binds `RER_PREVIEW_OWNER_SIGNIN` to the declared path, and only when a seed declares it. The path follows the same rules as `signIn.path`, and the producer still refuses unknown keys and values such as `//evil` or `https://x` (#234).
6
+ - **`rer dev` says when the computer is busy.** When the job queue or the machine's load holds a setup step until its wait runs out, `rer dev` (and setup, build, preview, deploy and verify) now prints "Not started: this computer is busy" with the measured 1-minute load, the threshold and what to do next: run the same command again, or raise `RER_JOBS_LOAD_THRESHOLD`. It exits 4, like the server load guard. Before, the hold was reported as "Local migrations failed". A real migration failure keeps its own message and captured output. The job queue's `maxWait` now bounds only a blocked wait, so a job the machine can run is admitted even when the queue's first lock, reclaim and sample pass takes longer than `maxWait` (#221).
7
+
3
8
  ## 0.2.49
4
9
 
5
10
  - **Large imports no longer fail with D1's request limit.** The import kit sized each D1 batch from the data statements alone and left out the authority, progress, scope and return checks that `atomic()` adds to the same request. A large import could therefore build one request just over D1's limit and stop with 409 `IMPORT_D1_REQUEST_LIMIT`: Nook's 3,547-entry Slack import stopped at checkpoint 51, where the estimate said 524 statements and the request held 573 against 572 remaining. Each batch is now sized with `atomicCount()`, the same count `atomic()` sends. The apply, reverse and fenced-reversal planners share it, because undo had the same gap. Nook's import now applies all 3,547 entries in 78 saved batches (#230).
@@ -1,10 +1,12 @@
1
1
  import {array, bindingPattern, keys, string, strings} from './bindings.mjs';
2
2
 
3
3
  const pathPattern = /^\/[A-Za-z0-9/_.~-]*$/;
4
+ const signInPath = value => typeof value === 'string' && /^\/(?!\/)[a-zA-Z0-9/_-]*$/.test(value);
4
5
  const validSignIn = value => value && typeof value === 'object' && !Array.isArray(value)
5
- && Object.keys(value).every(key => ['path','loginHint'].includes(key))
6
- && typeof value.path === 'string' && /^\/(?!\/)[a-zA-Z0-9/_-]*$/.test(value.path)
7
- && typeof value.loginHint === 'boolean';
6
+ && Object.keys(value).every(key => ['path','loginHint','ownerSignIn'].includes(key))
7
+ && signInPath(value.path)
8
+ && typeof value.loginHint === 'boolean'
9
+ && (value.ownerSignIn === undefined || signInPath(value.ownerSignIn));
8
10
  const status = (value, label) => {
9
11
  if (!Number.isInteger(value) || value < 100 || value > 599) throw Error(`Invalid ${label}`);
10
12
  };
@@ -79,10 +79,8 @@ export async function createQueue(options = {}) {
79
79
  if (blockers.length) return { reason: blockers.join('; '), blockers, reasonCodes, position, ahead,
80
80
  queued: waiting.length, running: state.running.length, resources,
81
81
  limits: { slots: config.slots, loadThreshold: config.loadThreshold, minFreeMemoryBytes: config.minFreeMemoryBytes } };
82
- if (opts.maxWait > 0 && performance.now() - start >= opts.maxWait * 1000)
83
- return { reason: 'max-wait elapsed before admission', blockers: ['max-wait elapsed before admission'],
84
- reasonCodes: ['max_wait'], position, queued: waiting.length, running: state.running.length, resources,
85
- limits: { slots: config.slots, loadThreshold: config.loadThreshold, minFreeMemoryBytes: config.minFreeMemoryBytes } };
82
+ // maxWait bounds how long a blocked job waits. A job this pass finds admissible is admitted
83
+ // however long the pass itself took (lock, reclaim, sample), so a slow pass never refuses a free machine.
86
84
  state.queued = state.queued.filter(item => item.id !== job.id);
87
85
  job.startedAt = Date.now(); state.running.push(job);
88
86
  return null;
@@ -90,7 +88,7 @@ export async function createQueue(options = {}) {
90
88
  if (!result) break;
91
89
  const elapsed = performance.now() - start;
92
90
  if (opts.maxWait !== undefined && elapsed >= opts.maxWait * 1000)
93
- return { code: TIMEOUT_EXIT, timedOut: true, reason: result.reason };
91
+ return { code: TIMEOUT_EXIT, timedOut: true, reason: result.reason, reasonCodes: result.reasonCodes, resources: result.resources, limits: result.limits };
94
92
  const signature = `${result.position}:${result.reasonCodes.join(',')}`;
95
93
  const now = performance.now();
96
94
  if (!lastWaitReportAt || signature !== lastWaitSignature || now - lastWaitReportAt >= WAIT_REPORT_INTERVAL_MS) {
@@ -1,7 +1,7 @@
1
1
  import { constants } from 'node:fs';
2
2
  import { access } from 'node:fs/promises';
3
3
  import { delimiter, join } from 'node:path';
4
- import { commandFailure, approvedFailure, installationFailure, installationFailureMessage } from './failures.mjs';
4
+ import { commandFailure, approvedFailure, installationFailure, installationFailureMessage, isBusyFailure } from './failures.mjs';
5
5
  import { withoutLocalVariables } from './local/build.mjs';
6
6
  import { buildEnvironment } from './local/environment.mjs';
7
7
  import { localOperation } from './local/operation.mjs';
@@ -72,7 +72,7 @@ export function localInstaller(hooks = {}) {
72
72
  if (['installer', 'setup', 'dev'].includes(verb) && hooks.migrate) {
73
73
  try { await phase(context, hooks, 'migrate', hooks.migrate); }
74
74
  catch (error) {
75
- if (verb !== 'dev' || signal?.aborted) throw error;
75
+ if (verb !== 'dev' || signal?.aborted || isBusyFailure(error)) throw error;
76
76
  const failure = approvedFailure(error);
77
77
  throw commandFailure(`${store.redact(failure?.message ?? error.message)}\nLocal migrations failed. Fix the error and run rer setup before trying again.`, failure ?? {});
78
78
  }
@@ -124,7 +124,7 @@ function createContext(root, input, store, onApp, signal, guard) {
124
124
  async run(label, command, args = [], { step = 'setup', ...options } = {}) {
125
125
  if (guard) await guard(context);
126
126
  try { return await store.run(label, command, args, { cwd: root, signal, ...options }); } catch (error) {
127
- if (signal?.aborted || options.signal?.aborted) throw error;
127
+ if (signal?.aborted || options.signal?.aborted || isBusyFailure(error)) throw error;
128
128
  throw installationFailure('command_failed', { step, diagnostic: error });
129
129
  }
130
130
  },
@@ -0,0 +1,21 @@
1
+ import { busyFailure } from './failures.mjs';
2
+
3
+ // A queued step the job queue never admitted is a busy machine, not a failed
4
+ // command: say what held it, the limit and the next step, in the same plain form
5
+ // as the server load guard (cli/server-resources.mjs).
6
+ const commandNames = new Set(['dev', 'setup', 'preview', 'build', 'deploy', 'verify']);
7
+
8
+ function waited(seconds) {
9
+ return seconds >= 60 ? `${Math.round(seconds / 60)} minutes` : `${Math.round(seconds)} seconds`;
10
+ }
11
+
12
+ export function busyMessage(result, { verb, maxWait }) {
13
+ const command = commandNames.has(verb) ? `rer ${verb}` : 'the same command';
14
+ const load = result.resources?.load, threshold = result.limits?.loadThreshold;
15
+ if (result.reasonCodes?.includes('load') && Number.isFinite(load) && threshold !== undefined) {
16
+ return `Not started: this computer is busy. Its 1-minute load is ${load.toFixed(1)} and jobs start only at ${threshold} or below; this step waited ${waited(maxWait)} for it to drop.\nTry again in a few minutes by running ${command} again, or start it anyway with a higher threshold, for example RER_JOBS_LOAD_THRESHOLD=${Math.ceil(Math.max(threshold, load) * 2)} ${command}.`;
17
+ }
18
+ return `Not started: the job queue did not admit this step within ${waited(maxWait)}: ${result.reason}.\nTry again in a few minutes by running ${command} again.`;
19
+ }
20
+
21
+ export const busyRefusal = (result, options) => busyFailure(busyMessage(result, options));
@@ -1,4 +1,5 @@
1
- import { queuedCommand, queueLabel, commandPolicy } from './queue.mjs';
1
+ import { queuedCommand, queueLabel, commandPolicy, maxWaitSeconds } from './queue.mjs';
2
+ import { busyRefusal } from './busy.mjs';
2
3
  import { spawn as spawnChild } from 'node:child_process';
3
4
  import { writeSync } from 'node:fs';
4
5
  import { join } from 'node:path';
@@ -148,8 +149,9 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
148
149
  let queuedChild;
149
150
  const commandSignal=signal&&options.signal?AbortSignal.any([signal,options.signal]):options.signal||signal;
150
151
  const result = await queuedCommand(command,args,{...options,verb:queuePolicy.verb,signal:commandSignal,originalCI:policy.ci,
151
- label:await queueLabel(options.cwd??process.cwd(),queuePolicy.verb,options.phase??'command'),report,onWaiting,
152
+ label:await queueLabel(options.cwd??process.cwd(),queuePolicy.verb,options.phase??'command'),report,onWaiting,maxWait:queuePolicy.maxWait,queueOptions:queuePolicy.sampler?{sampler:queuePolicy.sampler}:undefined,
152
153
  spawn:(program,argv,native)=>(queuedChild=spawnCommand(label,program,argv,{...native,onChild:options.onChild,display:options.display})),cleanup:async(child,result)=>{await stopCommand(child);await options.afterCommand?.(result);}});
154
+ if(result?.timedOut)throw busyRefusal({...result,reason:redaction.redact(String(result.reason))},{verb:queuePolicy.verb,maxWait:queuePolicy.maxWait??maxWaitSeconds});
153
155
  if(result){if(result.code!==0)throw failure(label,result,captures.get(queuedChild));return result;}
154
156
  }
155
157
  let child;try{child=spawnCommand(label,command,args,options);}catch{throw failure(label,options.signal?.aborted||signal?.aborted?{reason:'cancel'}:{error:true});}
@@ -37,6 +37,13 @@ export function commandFailure(message, details = {}) {
37
37
  const error=new Error(message);approved.set(error,{code:'captured_command_failed',message,details:{...details}});return error;
38
38
  }
39
39
 
40
+ // The job queue held a step until its wait ran out. The message names the load, the
41
+ // limit and the next step; callers show it as a refusal, never as a failed command.
42
+ export function busyFailure(message) {
43
+ const error=new Error(message);approved.set(error,{code:'machine_busy',message,details:{exitCode:4}});return error;
44
+ }
45
+ export const isBusyFailure = error => approved.get(error)?.code==='machine_busy';
46
+
40
47
  // Terminal callers may expose only diagnostics approved at the capture boundary.
41
48
  // A prior diagnostic's metadata must not replace the current composed message.
42
49
  export const approvedFailure = error => { const value=approved.get(error); return value ? {...value.details,...value} : undefined; };
@@ -4,6 +4,7 @@ import { createHash } from 'node:crypto';
4
4
  import { readFile, realpath } from 'node:fs/promises';
5
5
  const portable = basename(dirname(fileURLToPath(import.meta.url))) === 'base-onboarding';
6
6
  const queueURL = new URL(portable ? '../base-cli/modules/job-queue/' : '../modules/job-queue/', import.meta.url);
7
+ export const maxWaitSeconds = 1200;
7
8
  export const heavyVerbs = new Set(['install', 'setup', 'build', 'verify', 'dev', 'preview', 'deploy', 'release', 'export', 'import', 'installer']);
8
9
  export const verificationBoundary = verb => verb === 'release' || verb === 'verify' || verb?.startsWith('verify:');
9
10
  // The seed's display name (seed.json `name`, else its folder name) for terminal lines,
@@ -43,9 +44,9 @@ export async function queuedCommand(command, args, options) {
43
44
  }
44
45
  return null;
45
46
  }
46
- const queue = await createQueue();
47
+ const queue = await createQueue(options.queueOptions);
47
48
  try {
48
- const result = await queue.run([command, ...args], { ...options, kind: 'heavy', maxWait: 1200,
49
+ const result = await queue.run([command, ...args], { ...options, kind: 'heavy', maxWait: options.maxWait ?? maxWaitSeconds,
49
50
  onWaiting: (reason, detail) => {
50
51
  const wait = { ...(detail ?? { reason }), statusCommand, statusCommandText };
51
52
  if (typeof options.onWaiting === 'function') return options.onWaiting(wait);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runeditrun/rer",
3
- "version": "0.2.49",
3
+ "version": "0.2.50",
4
4
  "description": "The rer command: install, set up, run and launch Run Edit Run checkouts.",
5
5
  "license": "MIT",
6
6
  "type": "module",