@ours.network/install 1.2.1-nightly.51 → 1.2.1-nightly.52
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/assets/release.json +1 -1
- package/assets/sources.json +1 -1
- package/lib/effects.mjs +4 -21
- package/lib/gateway.mjs +68 -0
- package/package.json +1 -1
package/assets/release.json
CHANGED
package/assets/sources.json
CHANGED
package/lib/effects.mjs
CHANGED
|
@@ -25,7 +25,7 @@ import { dirname, join, resolve } from 'node:path';
|
|
|
25
25
|
import { connect as netConnect } from 'node:net';
|
|
26
26
|
import { clientPackageNames, maintenanceServices, installationPaths, validateInstallation, consumerServiceState, unitNameForStateDir, launchdLabelForStateDir, messengerServicePlan, selectSourcePackages, resolveSourcePolicy, SERVER_SERVICES } from './plan.mjs';
|
|
27
27
|
import { validateHostProfile, validateGatewayClientProfile } from './target.mjs';
|
|
28
|
-
import { serverBase, validateGatewayDiscovery, gatewayCompose, gatewayNginx, gatewayAddress } from './gateway.mjs';
|
|
28
|
+
import { serverBase, validateGatewayDiscovery, gatewayCompose, gatewayNginx, gatewayAddress, gatewayReadinessScript, describeGatewayReadiness } from './gateway.mjs';
|
|
29
29
|
import { createServerOnboarding, retainedCredentialRefused } from './server-onboarding.mjs';
|
|
30
30
|
import { atomicWriteConfig, snapshotConfig, restoreConfig } from './config.mjs';
|
|
31
31
|
import { select as selectOnTty, multiselect as multiselectOnTty, askLine as askLineOnTty } from './prompt.mjs';
|
|
@@ -855,28 +855,11 @@ export function networkEffects(effects) {
|
|
|
855
855
|
async removeGatewayContainer(record) { await compose(record, ['rm', '-f', 'gateway']); },
|
|
856
856
|
async verifyGateway(record) {
|
|
857
857
|
const { prefix } = gatewayAddress(record);
|
|
858
|
-
const script =
|
|
859
|
-
const base=${JSON.stringify('http://gateway:8080' + prefix)};
|
|
860
|
-
const get=async(path,options={})=>{const r=await fetch(base+path,{...options,redirect:'error',signal:AbortSignal.timeout(5000)});if(!r.ok)throw Error('Gateway readiness HTTP '+r.status);return r.json();};
|
|
861
|
-
const selection=await get('/daemon/selection');
|
|
862
|
-
if(selection.instanceId!==${JSON.stringify(record.instanceId)})throw Error('Gateway daemon instance mismatch');
|
|
863
|
-
stage='unauthenticated-management';
|
|
864
|
-
const denied=await fetch(base+'/cowork/management/rpc',{method:'POST',redirect:'error',signal:AbortSignal.timeout(5000),headers:{'content-type':'application/json'},body:'{}'});
|
|
865
|
-
await denied.body?.cancel();if(denied.status!==401)throw Error('Gateway management does not reject unauthenticated requests');
|
|
866
|
-
stage='credential';
|
|
867
|
-
const token=fs.readFileSync('/var/lib/ours/daemon-token','utf8').trim();
|
|
868
|
-
const headers={'x-ours-api-token':token,'content-type':'application/json'};
|
|
869
|
-
stage='authenticated-daemon';
|
|
870
|
-
const identities=await get('/daemon/identities',{headers});
|
|
871
|
-
if(!Array.isArray(identities.identities))throw Error('Gateway daemon API invalid');
|
|
872
|
-
stage='authenticated-management';
|
|
873
|
-
const result=await get('/cowork/management/rpc',{method:'POST',headers,body:JSON.stringify({version:1,id:'installer-readiness',method:'room.list',params:{}})});
|
|
874
|
-
if(result.version!==1||result.id!=='installer-readiness'||!Array.isArray(result.result)||result.error)throw Error('Gateway Cowork management unavailable');
|
|
875
|
-
})().catch(error=>{const code=error.cause?.code;process.stdout.write('gateway-readiness:'+stage+':'+(['EAI_AGAIN','ENOTFOUND','ECONNREFUSED','ETIMEDOUT'].includes(code)?code:'CHECK_FAILED'));process.exitCode=1;});`;
|
|
858
|
+
const script = gatewayReadinessScript({ base: 'http://gateway:8080' + prefix, instanceId: record.instanceId });
|
|
876
859
|
const result = await compose(record, ['exec', '-T', 'daemon', 'node', '-e', script], { sensitive: true, allowCodes: [1] });
|
|
877
860
|
if (result.code === 1) {
|
|
878
|
-
const
|
|
879
|
-
const detail =
|
|
861
|
+
const described = describeGatewayReadiness(result.stdout);
|
|
862
|
+
const detail = described ? ` (${described})` : '';
|
|
880
863
|
throw new Error(`Gateway readiness failed${detail}. Keep installation state intact; check the managed gateway startup and network connection, then retry setup.`);
|
|
881
864
|
}
|
|
882
865
|
},
|
package/lib/gateway.mjs
CHANGED
|
@@ -157,3 +157,71 @@ http {
|
|
|
157
157
|
}
|
|
158
158
|
`;
|
|
159
159
|
}
|
|
160
|
+
|
|
161
|
+
/** How long the gateway readiness probe keeps retrying a dependency that is still starting. */
|
|
162
|
+
export const GATEWAY_READINESS_WAIT_MS = 60_000;
|
|
163
|
+
const GATEWAY_READINESS_RETRY_MS = 1_000;
|
|
164
|
+
const READINESS_KIND = /^(EAI_AGAIN|ENOTFOUND|ECONNREFUSED|ECONNRESET|ETIMEDOUT|EPIPE|UND_ERR_SOCKET|UND_ERR_CONNECT_TIMEOUT|TIMEOUT|HTTP_[1-5][0-9][0-9]|INVALID|RPC_ERROR|CHECK_FAILED)$/;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Node script the installer runs inside the daemon container to prove the
|
|
168
|
+
* gateway serves the daemon and Cowork management with the installation's
|
|
169
|
+
* credential. Services restored by an update may still be starting, so a
|
|
170
|
+
* transient result (a 502/503/504 without an RPC error body, a request
|
|
171
|
+
* timeout, a refused, reset or dropped connection — including one dropped
|
|
172
|
+
* while the body is read — or a name not yet resolvable) is
|
|
173
|
+
* retried until one total `deadlineMs` across every stage and attempt; each
|
|
174
|
+
* request is capped to the time left. Anything else — a wrong instance,
|
|
175
|
+
* 401/403, a well-formed RPC error under any status, any other status or an
|
|
176
|
+
* invalid body — fails at once. The probe only reads; nothing else is retried. Output carries stage and a fixed kind only,
|
|
177
|
+
* never the token or a response body.
|
|
178
|
+
*/
|
|
179
|
+
export function gatewayReadinessScript({ base, instanceId, tokenPath = '/var/lib/ours/daemon-token',
|
|
180
|
+
deadlineMs = GATEWAY_READINESS_WAIT_MS, retryMs = GATEWAY_READINESS_RETRY_MS }) {
|
|
181
|
+
return `const fs=require('node:fs');const base=${JSON.stringify(base)};const instanceId=${JSON.stringify(instanceId)};
|
|
182
|
+
const tokenPath=${JSON.stringify(tokenPath)};const deadline=Date.now()+${Number(deadlineMs)};const retryMs=${Number(retryMs)};
|
|
183
|
+
const NET=['EAI_AGAIN','ENOTFOUND','ECONNREFUSED','ECONNRESET','ETIMEDOUT','EPIPE','UND_ERR_SOCKET','UND_ERR_CONNECT_TIMEOUT'];
|
|
184
|
+
class Check extends Error{constructor(kind,transient){super(kind);this.kind=kind;this.transient=transient;}}
|
|
185
|
+
const status=s=>new Check('HTTP_'+s,s===502||s===503||s===504);
|
|
186
|
+
const request=async(path,options)=>{const left=Math.max(1,Math.min(5000,deadline-Date.now()));
|
|
187
|
+
try{return await fetch(base+path,{...options,redirect:'error',signal:AbortSignal.timeout(left)});}
|
|
188
|
+
catch(e){const code=e?.cause?.code;if(NET.includes(code))throw new Check(code,true);if(e?.name==='TimeoutError'||e?.cause?.name==='TimeoutError')throw new Check('TIMEOUT',true);throw new Check('CHECK_FAILED',false);}};
|
|
189
|
+
const json=async(path,options={})=>{const r=await request(path,options);
|
|
190
|
+
if(!r.ok){let body;try{body=await r.json();}catch{}
|
|
191
|
+
// A well-formed RPC error is the service's answer, whatever the status: never retried.
|
|
192
|
+
if(body&&typeof body==='object'&&body.version===1&&body.error)throw new Check('RPC_ERROR',false);throw status(r.status);}
|
|
193
|
+
// The request signal also bounds the body: a stalled body is a timeout, not an invalid answer.
|
|
194
|
+
// A connection dropped mid-body is transport, not content; only a parse failure is invalid.
|
|
195
|
+
try{return await r.json();}catch(e){if(e?.name==='TimeoutError'||e?.name==='AbortError')throw new Check('TIMEOUT',true);
|
|
196
|
+
const code=e?.cause?.code;if(NET.includes(code))throw new Check(code,true);throw new Check('INVALID',false);}};
|
|
197
|
+
let stage='selection';
|
|
198
|
+
const attempt=async()=>{
|
|
199
|
+
stage='selection';const selection=await json('/daemon/selection');
|
|
200
|
+
if(selection?.instanceId!==instanceId)throw new Check('INVALID',false);
|
|
201
|
+
stage='unauthenticated-management';
|
|
202
|
+
const denied=await request('/cowork/management/rpc',{method:'POST',headers:{'content-type':'application/json'},body:'{}'});
|
|
203
|
+
await denied.body?.cancel();if(denied.status!==401)throw status(denied.status);
|
|
204
|
+
stage='credential';let token;try{token=fs.readFileSync(tokenPath,'utf8').trim();}catch{throw new Check('CHECK_FAILED',false);}
|
|
205
|
+
const headers={'x-ours-api-token':token,'content-type':'application/json'};
|
|
206
|
+
stage='authenticated-daemon';const identities=await json('/daemon/identities',{headers});
|
|
207
|
+
if(!Array.isArray(identities?.identities))throw new Check('INVALID',false);
|
|
208
|
+
stage='authenticated-management';
|
|
209
|
+
const result=await json('/cowork/management/rpc',{method:'POST',headers,body:JSON.stringify({version:1,id:'installer-readiness',method:'room.list',params:{}})});
|
|
210
|
+
if(result?.version!==1||result.id!=='installer-readiness'||!Array.isArray(result.result)||result.error)throw new Check('INVALID',false);
|
|
211
|
+
};
|
|
212
|
+
(async()=>{let attempts=0;for(;;){attempts++;try{await attempt();return;}catch(e){
|
|
213
|
+
const c=e instanceof Check?e:new Check('CHECK_FAILED',false);
|
|
214
|
+
if(!c.transient||Date.now()+retryMs>=deadline){process.stdout.write('gateway-readiness:'+stage+':'+c.kind+':'+attempts+(c.transient?':transient':''));process.exitCode=1;return;}
|
|
215
|
+
await new Promise(r=>setTimeout(r,retryMs));}}})();`;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** Operator text for a failed readiness probe; `undefined` when the output is not the probe's. */
|
|
219
|
+
export function describeGatewayReadiness(stdout) {
|
|
220
|
+
const match = /^gateway-readiness:(selection|unauthenticated-management|credential|authenticated-daemon|authenticated-management):([A-Z0-9_]+):([0-9]{1,6})(:transient)?$/.exec(String(stdout).trim());
|
|
221
|
+
if (!match || !READINESS_KIND.test(match[2])) return undefined;
|
|
222
|
+
const [, stage, kind, attempts, transient] = match;
|
|
223
|
+
const what = kind.startsWith('HTTP_') ? `HTTP ${kind.slice(5)}` : kind;
|
|
224
|
+
return transient
|
|
225
|
+
? `${stage}, ${what}; still not ready after ${attempts} attempts over ${GATEWAY_READINESS_WAIT_MS / 1000}s`
|
|
226
|
+
: `${stage}, ${what}`;
|
|
227
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ours.network/install",
|
|
3
|
-
"version": "1.2.1-nightly.
|
|
3
|
+
"version": "1.2.1-nightly.52",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The all-in-one ours.network installer: one shared daemon, MCP, cowork, Telegram, Fleet initialization, harness plugins, Human identity, progress UI, and guided next steps.",
|
|
6
6
|
"type": "module",
|