bailinghub 0.9.1 → 0.9.3
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/README.en.md +6 -6
- package/README.md +6 -6
- package/docker-compose.images.yml +2 -2
- package/docs/CHANGELOG.en.md +23 -1
- package/docs/CHANGELOG.md +23 -1
- package/docs/CORE_RELIABILITY.en.md +79 -0
- package/docs/CORE_RELIABILITY.md +79 -0
- package/docs/DEPLOYMENT_DIAGNOSTICS.en.md +78 -0
- package/docs/DEPLOYMENT_DIAGNOSTICS.md +78 -0
- package/docs/IMPLEMENTATION_STATUS.en.md +27 -15
- package/docs/IMPLEMENTATION_STATUS.md +27 -15
- package/docs/INDEPENDENT_VALIDATION.en.md +4 -4
- package/docs/INDEPENDENT_VALIDATION.md +4 -4
- package/docs/KERNEL_HOST_API.en.md +2 -0
- package/docs/KERNEL_HOST_API.md +2 -0
- package/docs/MODEL_BILLING.en.md +4 -0
- package/docs/MODEL_BILLING.md +4 -0
- package/docs/MODEL_PROCESS_RECOVERY.en.md +32 -0
- package/docs/MODEL_PROCESS_RECOVERY.md +37 -0
- package/docs/OPERATIONS.en.md +13 -0
- package/docs/OPERATIONS.md +12 -0
- package/docs/README.en.md +7 -0
- package/docs/README.md +7 -0
- package/docs/RELEASE_NOTES_v0.9.2.en.md +45 -0
- package/docs/RELEASE_NOTES_v0.9.2.md +45 -0
- package/docs/RELEASE_NOTES_v0.9.3.en.md +51 -0
- package/docs/RELEASE_NOTES_v0.9.3.md +51 -0
- package/docs/TOOLS_DESIGN.md +1 -0
- package/docs/UPGRADE_v0.9.2.en.md +62 -0
- package/docs/UPGRADE_v0.9.2.md +62 -0
- package/docs/UPGRADE_v0.9.3.en.md +63 -0
- package/docs/UPGRADE_v0.9.3.md +63 -0
- package/package.json +7 -3
- package/scripts/check-doc-links.mjs +4 -0
- package/scripts/check-image-tags.sh +1 -1
- package/scripts/check-release-consistency.test.mjs +2 -2
- package/scripts/doctor-deployment.test.ts +419 -0
- package/scripts/doctor-deployment.ts +357 -0
- package/scripts/doctor.ts +8 -1
- package/scripts/install-secrets.test.mjs +185 -0
- package/scripts/install.sh +10 -6
- package/scripts/publish-images.sh +1 -1
- package/scripts/release-audit.mjs +8 -0
- package/scripts/verify-github-repo.mjs +8 -0
- package/security/dependency-audit-exceptions.json +1 -1
- package/sql/065_usage_reconciliation_scan.sql +4 -0
- package/sql/066_approval_continuations.sql +15 -0
- package/sql/067_delivery_dlq_replay.sql +10 -0
- package/sql/README.en.md +6 -0
- package/sql/README.md +15 -0
- package/src/adapters/llm/file.test.ts +59 -0
- package/src/adapters/llm/file.ts +11 -4
- package/src/app/agent-tool-invocations.test.ts +3 -1
- package/src/app/approval-continuations.mysql.test.ts +138 -0
- package/src/app/approval-continuations.test.ts +351 -0
- package/src/app/approval-continuations.ts +148 -0
- package/src/app/channels-attachments.test.ts +63 -0
- package/src/app/channels.ts +7 -4
- package/src/app/delivery-dlq-replay.mysql.test.ts +139 -0
- package/src/app/delivery-dlq-replay.test.ts +75 -0
- package/src/app/delivery-dlq-replay.ts +41 -0
- package/src/app/delivery.ts +3 -2
- package/src/app/http-server.ts +3 -0
- package/src/app/kernel-model-process-crash.mysql.test.ts +377 -0
- package/src/app/kernel-notification-lifecycle.test.ts +49 -0
- package/src/app/kernel.ts +22 -0
- package/src/app/notification-outbound.test.ts +53 -0
- package/src/app/operational-metrics.test.ts +37 -1
- package/src/app/operational-metrics.ts +25 -2
- package/src/app/outbound.ts +13 -2
- package/src/app/runtime-evidence-maintenance.test.ts +55 -0
- package/src/app/runtime-lifecycle-default.ts +7 -0
- package/src/app/runtime-lifecycle.test.ts +89 -0
- package/src/app/runtime-lifecycle.ts +52 -11
- package/src/app/tool-approvals.ts +2 -1
- package/src/core/contracts/approval-continuation.ts +43 -0
- package/src/core/contracts/delivery-replay.ts +41 -0
- package/src/core/contracts/tools-idempotency.test.ts +121 -5
- package/src/core/contracts/tools.ts +21 -11
- package/src/core/contracts/types.ts +4 -0
- package/src/core/observability/openmetrics.test.ts +28 -0
- package/src/core/observability/openmetrics.ts +91 -0
- package/src/core/platform/http-body.test.ts +185 -0
- package/src/core/platform/http-body.ts +58 -0
- package/src/core/runtime/finish-runtime.test.ts +2 -0
- package/src/core/runtime/finish-runtime.ts +10 -7
- package/src/core/runtime/notification-background-work.test.ts +50 -0
- package/src/core/runtime/notification-background-work.ts +101 -0
- package/src/core/state/approval-continuation.ts +22 -0
- package/src/core/state/delivery-replay.ts +19 -0
- package/src/core/state/state-codec.ts +2 -0
- package/src/core/state/state-contracts.ts +6 -0
- package/src/infrastructure/config/config-approval-ledger.ts +75 -0
- package/src/infrastructure/config/config-delivery-dlq-ledger.ts +36 -10
- package/src/infrastructure/config/configstore.ts +4 -3
- package/src/infrastructure/state/state-jsonl.ts +56 -11
- package/src/infrastructure/state/state-mysql.ts +54 -0
- package/src/modules/usage/background-work.test.ts +28 -0
- package/src/modules/usage/background-work.ts +43 -7
- package/src/modules/usage/billing-reconciliation.mysql.test.ts +163 -0
- package/src/modules/usage/billing-reconciliation.test.ts +85 -0
- package/src/modules/usage/billing-repository.ts +63 -11
- package/src/modules/usage/maintenance.test.ts +78 -0
- package/src/modules/usage/maintenance.ts +39 -0
- package/src/modules/usage/model-gateway.ts +2 -1
- package/src/routes/admin-default.ts +2 -2
- package/src/routes/admin-runtime-default.ts +2 -2
- package/src/routes/admin-runtime.test.ts +1 -1
- package/src/routes/admin-runtime.ts +39 -18
- package/src/routes/admin.ts +1 -1
- package/src/routes/approvals-default.ts +2 -2
- package/src/routes/approvals.ts +30 -33
- package/src/routes/critical-routes.test.ts +16 -3
- package/src/test-support/approval-continuation-crash-child.ts +24 -0
- package/src/test-support/model-process-crash-child.ts +78 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/** Test-only process entrypoint. Configuration arrives over IPC, never from a deployment file. */
|
|
2
|
+
import { createServer } from 'node:http';
|
|
3
|
+
import type { AddressInfo } from 'node:net';
|
|
4
|
+
import type { PoolConnection } from 'mysql2/promise';
|
|
5
|
+
import type { AppConfig } from '../core/config/config';
|
|
6
|
+
import { UsageRepository } from '../modules/usage/repository';
|
|
7
|
+
import { createBailingHubKernel } from '../app/kernel';
|
|
8
|
+
|
|
9
|
+
export type CrashStage = 'admitted' | 'dispatch' | 'result' | 'settlement';
|
|
10
|
+
export type CrashPoint = `${CrashStage}:${'before' | 'after'}`;
|
|
11
|
+
export interface CrashChildInit { type: 'init'; config: AppConfig; instanceKey: string; point?: CrashPoint }
|
|
12
|
+
|
|
13
|
+
export function transactionStage(sql: string): CrashStage | undefined {
|
|
14
|
+
if (/INSERT INTO bz_usage_billing_requests\(/i.test(sql)) return 'admitted';
|
|
15
|
+
if (/UPDATE bz_usage_billing_requests SET state='dispatch_committed'/i.test(sql)) return 'dispatch';
|
|
16
|
+
if (/UPDATE bz_usage_billing_requests SET state=\?,result_state=\?,result_json=\?/i.test(sql)) return 'result';
|
|
17
|
+
if (/INSERT INTO bz_usage_billing_ledger\(/i.test(sql)) return 'settlement';
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function installCrashBarrier(point: CrashPoint) {
|
|
22
|
+
const transaction = UsageRepository.prototype.withTransaction;
|
|
23
|
+
let entered = false;
|
|
24
|
+
const pause = async () => {
|
|
25
|
+
entered = true;
|
|
26
|
+
process.send?.({ type: 'fault', point, pid: process.pid });
|
|
27
|
+
await new Promise<void>(() => { /* Only SIGKILL may cross this test barrier. */ });
|
|
28
|
+
};
|
|
29
|
+
UsageRepository.prototype.withTransaction = function<T>(fn: (c: PoolConnection) => Promise<T>): Promise<T> {
|
|
30
|
+
return transaction.call(this, async (connection: PoolConnection) => {
|
|
31
|
+
const originalQuery = connection.query, originalCommit = connection.commit, originalRelease = connection.release;
|
|
32
|
+
let stage: CrashStage | undefined;
|
|
33
|
+
connection.query = (async (...args: unknown[]) => {
|
|
34
|
+
const result = await (originalQuery as (...args: unknown[]) => Promise<unknown>).apply(connection, args);
|
|
35
|
+
if (typeof args[0] === 'string') stage = transactionStage(args[0]) ?? stage;
|
|
36
|
+
return result;
|
|
37
|
+
}) as PoolConnection['query'];
|
|
38
|
+
connection.commit = async () => {
|
|
39
|
+
if (!entered && point === `${stage}:before`) await pause();
|
|
40
|
+
await originalCommit.call(connection);
|
|
41
|
+
if (!entered && point === `${stage}:after`) await pause();
|
|
42
|
+
};
|
|
43
|
+
connection.release = () => {
|
|
44
|
+
connection.query = originalQuery;
|
|
45
|
+
connection.commit = originalCommit;
|
|
46
|
+
connection.release = originalRelease;
|
|
47
|
+
originalRelease.call(connection);
|
|
48
|
+
};
|
|
49
|
+
return fn(connection);
|
|
50
|
+
}) as Promise<T>;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let initialized = false;
|
|
55
|
+
process.on('message', (message: CrashChildInit | { type: 'shutdown' }) => {
|
|
56
|
+
if (message.type !== 'init' || initialized) return;
|
|
57
|
+
initialized = true;
|
|
58
|
+
void (async () => {
|
|
59
|
+
if (message.point) installCrashBarrier(message.point);
|
|
60
|
+
const kernel = createBailingHubKernel({ instanceKey: message.instanceKey, config: message.config,
|
|
61
|
+
schedulerMode: 'managed', bootstrapLocalAdmin: false, logger: { log() {}, warn() {}, error() {} } });
|
|
62
|
+
await kernel.initialize();
|
|
63
|
+
const server = createServer((req, res) => { void kernel.handle(req, res).catch(error => res.destroy(error)); });
|
|
64
|
+
await new Promise<void>(resolve => server.listen(0, '127.0.0.1', resolve));
|
|
65
|
+
process.send?.({ type: 'ready', base: `http://127.0.0.1:${(server.address() as AddressInfo).port}`, pid: process.pid });
|
|
66
|
+
process.on('message', next => {
|
|
67
|
+
if ((next as { type?: string }).type !== 'shutdown') return;
|
|
68
|
+
void (async () => {
|
|
69
|
+
server.close(); server.closeAllConnections();
|
|
70
|
+
await kernel.close(5000);
|
|
71
|
+
process.exit(0);
|
|
72
|
+
})().catch(() => process.exit(1));
|
|
73
|
+
});
|
|
74
|
+
})().catch(error => {
|
|
75
|
+
process.send?.({ type: 'error', message: error instanceof Error ? error.message : 'Synthetic child failed' });
|
|
76
|
+
process.exit(1);
|
|
77
|
+
});
|
|
78
|
+
});
|