Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(native): add a private package boundary under native/locks (#6026)
garrytancc808c450f67
diff --git a/docs/architecture/key-files/core-persistence.md b/docs/architecture/key-files/core-persistence.mdindex d82622755a..6c4849532a 100644--- a/docs/architecture/key-files/core-persistence.md+++ b/docs/architecture/key-files/core-persistence.md@@ -36,7 +36,7 @@ Connector ingestion, item holds and checkpoint validation continue in [Core Pers- `src/core/persistence/effect-recovery-scan.ts` — bounded owner-scoped recovery selection rotates through durable effect IDs even when an earlier root has no available native lock, and wraps to retry prior roots. It never changes recovery authority or releases reservations. `test/persistence-effect-recovery-fairness.test.ts` holds two real native roots, recovers a later mirror, then verifies wraparound cleanup and exact counters on both engines.-- `src/core/persistence/native-lock.ts` + `native/locks/` — lazy portable Node-API v3 kernel locks (`flock` / `LockFileEx`) with opaque handles, retained stable lock files, cancellable asynchronous waiting and fail-closed capability errors. Eight vendored prebuilds support script-disabled source installs; pinned Zig recipes and source/artifact hashes live in `scripts/native/`. Actual competing-process, crash-handoff and compiled-executable tests run across eight platform/architecture targets and Bun 1.4.0 / 1.4.2. The compiled smoke waits for child exit before cleanup; `scripts/native/compiled-smoke-cleanup.ts` bounds retries to transient Windows `EBUSY` errors, with persistent and permission failures pinned by `test/scripts/native-compiled-cleanup.test.ts`. Windows-only `windows-ipc.h` supplies opaque Global mutex claims (same-thread recursion refused, abandoned owner handoff) and exact-handle stale AF_UNIX deletion after a verified reparse tag under a retained binding claim. CNG hashing and native casing make pipe identities independent of homes and logon sessions. Build and ownership contract: `native/locks/README.md`.+- `src/core/persistence/native-lock.ts` + `native/locks/` — lazy portable Node-API v3 kernel locks (`flock` / `LockFileEx`) with opaque handles, retained stable lock files, cancellable asynchronous waiting and fail-closed capability errors. Eight vendored prebuilds support script-disabled source installs; pinned Zig recipes and source/artifact hashes live in `scripts/native/`. Actual competing-process, crash-handoff and compiled-executable tests run across eight platform/architecture targets and Bun 1.4.0 / 1.4.2. The compiled smoke waits for child exit before cleanup; `scripts/native/compiled-smoke-cleanup.ts` bounds retries to transient Windows `EBUSY` errors, with persistent and permission failures pinned by `test/scripts/native-compiled-cleanup.test.ts`. Windows-only `windows-ipc.h` supplies opaque Global mutex claims (same-thread recursion refused, abandoned owner handoff) and exact-handle stale AF_UNIX deletion after a verified reparse tag under a retained binding claim. CNG hashing and native casing make pipe identities independent of homes and logon sessions. Build and ownership contract: `native/locks/README.md`. `native/locks/package.json` (private, no entry points, outside `buildInputs` and `prebuilds/`) is a package boundary so plugin hosts that namespace native addons by the nearest package.json do not treat the whole checkout as one package (#6026; guard `test/native-locks-package-boundary.test.ts`).- `src/core/persistence/page-input.ts` — freezes scoped subagent type normalization at durable admission, after existing-request replay. An explicit undeclared model-authored type becomes `note` with `legacy_type` retained using the then-active schema pack; a replay keeps its original normalized payload when the pack changes. Caller intent remains unchanged for idempotency checks. Raw input size is checked before normalization and malformed Markdown is left to the importer’s sanitized error contract. `test/brain-allowlist.test.ts` pins changed-pack replay, raw-size refusal, and private parse-error redaction. `undeclaredPageTypeWarning` covers every other `put_page` (not managed file imports): a type the write source's pack neither declares nor aliases is stored as written and the committed result carries `type_warning` (`code: page_type_undeclared`, cause, fix, docs), also logged; pinned by `test/put-page-type-warning.test.ts`.diff --git a/native/locks/README.md b/native/locks/README.mdindex ddebe1b268..89d23079f8 100644--- a/native/locks/README.md+++ b/native/locks/README.md@@ -200,3 +200,10 @@ bun test test/openclaw-context-engine-native.serial.test.tsThe database user needs `CREATEDB`; fixtures create/drop unique databasesrather than truncating shared rows. Real-provider recall and macOS 27 behaviorremain unverified.++`package.json` in this directory is a private package boundary, not a+package: plugin hosts that derive a native-addon namespace from the nearest+`package.json` above a `.node` file otherwise treat the whole checkout as one+package and load slowly (#6026). It declares no entry points, is not a+prebuild input, and must never move into `prebuilds/`, which holds exactly the+eight addons.diff --git a/native/locks/package.json b/native/locks/package.jsonnew file mode 100644index 0000000000..f16b24360e--- /dev/null+++ b/native/locks/package.json@@ -0,0 +1,5 @@+{+ "name": "gbrain-native-locks",+ "private": true,+ "description": "Package boundary for gbrain's prebuilt native lock addons. Internal; not published."+}diff --git a/test/native-locks-package-boundary.test.ts b/test/native-locks-package-boundary.test.tsnew file mode 100644index 0000000000..541a574611--- /dev/null+++ b/test/native-locks-package-boundary.test.ts@@ -0,0 +1,33 @@+/**+ * #6026: plugin hosts that derive a native-addon namespace from the nearest+ * package.json above a `.node` file treated the whole checkout as one+ * namespace (OpenClaw 2026.9.7+ took ~228 s to load the plugin from a+ * checkout root, ~26 s with this boundary). `native/locks/package.json` is+ * that boundary. It must stay private and inert, outside the prebuild input+ * digest, and out of `prebuilds/` (verify requires exactly the eight addons).+ */+import { describe, expect, test } from 'bun:test';+import { existsSync, readFileSync, readdirSync } from 'node:fs';+import { join } from 'node:path';+import { buildInputs } from '../scripts/native/build.ts';++const ROOT = join(import.meta.dir, '..');+const BOUNDARY = join(ROOT, 'native/locks/package.json');++describe('native/locks package boundary (#6026)', () => {+ test('exists, is private, and declares nothing that changes resolution or publishing', () => {+ expect(existsSync(BOUNDARY)).toBe(true);+ const pkg = JSON.parse(readFileSync(BOUNDARY, 'utf8')) as Record<string, unknown>;+ expect(pkg.private).toBe(true);+ for (const key of ['main', 'exports', 'type', 'module', 'imports', 'bin', 'scripts', 'dependencies', 'optionalDependencies', 'version', 'workspaces', 'files']) {+ expect(key in pkg).toBe(false);+ }+ });++ test('stays out of the prebuild input digest and out of prebuilds/', () => {+ expect(buildInputs.some((f) => f.endsWith('package.json'))).toBe(false);+ const prebuilds = readdirSync(join(ROOT, 'native/locks/prebuilds')).sort();+ expect(prebuilds.every((f) => f.endsWith('.node'))).toBe(true);+ expect(prebuilds).toHaveLength(8);+ });+});