Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(hcc): refuse unreadable state trees and non-file sqlite entries in the merge
Alfredo Lopez84465813fe8f
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.jsonindex ce2071261..36c9817a2 100644--- a/host-context-controller/package-lock.json+++ b/host-context-controller/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-host-context-controller",- "version": "0.1.385",+ "version": "0.1.386","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-host-context-controller",- "version": "0.1.385",+ "version": "0.1.386","license": "SEE LICENSE IN LICENSE","dependencies": {"@clerum/codex-catalog-projection": "file:../packages/codex-catalog-projection",diff --git a/host-context-controller/package.json b/host-context-controller/package.jsonindex 451d7351a..4963b0b4f 100644--- a/host-context-controller/package.json+++ b/host-context-controller/package.json@@ -1,6 +1,6 @@{"name": "clerum-host-context-controller",- "version": "0.1.385",+ "version": "0.1.386","description": "Host Context Controller - provides McpServer CRDs to mcp-host via REST API","main": "dist/main.js","engines": {diff --git a/host-context-controller/src/statelessDeployment.ts b/host-context-controller/src/statelessDeployment.tsindex 3948f7909..7b3f78c58 100644--- a/host-context-controller/src/statelessDeployment.ts+++ b/host-context-controller/src/statelessDeployment.ts@@ -34,8 +34,10 @@ function shellSingleQuote(value: string): string {* `workspace/`) exits 0 untouched.** Every refusal prints one line and exits 1 before the first move:- * F1 `state` or `workspace` is a symlink or not a directory, or a- * `state.db*` entry is a symlink;+ * F1 `state` or `workspace` is a symlink or not a directory, a real+ * `state/` cannot be listed and searched, a `state.db*` entry is a+ * symlink or not a regular file, or a directory that decides a+ * collision cannot be listed;* F2 more than one live database (a `state.db` main file or its journals)* across the root, `state/` and `workspace/`, except the root journals* a stopped merge leaves next to the remaining `state/state.db`;@@ -73,7 +75,9 @@ assert_managed_dir() {esac}is_empty_dir() {- [ -d "$1" ] && [ ! -L "$1" ] && [ -z "$(ls -A "$1")" ]+ [ -d "$1" ] && [ ! -L "$1" ] || return 1+ listing="$(ls -A "$1" 2>/dev/null)" || fail_merge "cannot list directory: $1"+ [ -z "$listing" ]}has_main() {present "$1/state.db"@@ -89,6 +93,9 @@ root_real="$(canonical_dir "$root")" || fail_merge "cannot resolve workspace PVC# Split-layout signature: a real state/ directory holding a state.db* entry.[ ! -L "$root/state" ] && [ -d "$root/state" ] || exit 0+# The glob below cannot see the entries of a state/ it cannot list or search.+[ -r "$root/state" ] && [ -x "$root/state" ] ||+ fail_merge "state directory is not readable and searchable: $root/state"signature=0for entry in "$root/state"/state.db*; doif present "$entry"; then signature=1; fi@@ -104,7 +111,9 @@ if present "$root/workspace"; thenfifor dir in "$root" "$root/state" "$root/workspace"; dofor entry in "$dir"/state.db*; do+ present "$entry" || continue[ ! -L "$entry" ] || fail_merge "SQLite file is a symlink: $entry"+ [ -f "$entry" ] || fail_merge "SQLite file is not a regular file: $entry"donedonediff --git a/host-context-controller/test/statelessDeployment.workspaceLayoutMerge.test.ts b/host-context-controller/test/statelessDeployment.workspaceLayoutMerge.test.tsindex 6f33afb72..77bd39b22 100644--- a/host-context-controller/test/statelessDeployment.workspaceLayoutMerge.test.ts+++ b/host-context-controller/test/statelessDeployment.workspaceLayoutMerge.test.ts@@ -255,6 +255,18 @@ describe('workspace layout merge', () => {},message: 'SQLite file is a symlink',},+ {+ name: 'a state.db entry is a directory',+ prepare: (root: string) => {+ renameSync(join(root, 'state', 'state.db-shm'), join(root, 'shm-real'))+ mkdirSync(join(root, 'state', 'state.db-shm'))+ },+ undo: (root: string) => {+ rmSync(join(root, 'state', 'state.db-shm'), { recursive: true })+ renameSync(join(root, 'shm-real'), join(root, 'state', 'state.db-shm'))+ },+ message: 'SQLite file is not a regular file',+ },{name: 'a second live database at the root (F2)',prepare: (root: string) => writeFileSync(join(root, 'state.db'), 'second database'),@@ -314,6 +326,51 @@ describe('workspace layout merge', () => {15_000)+ // A state/ that cannot be listed hides the signature from the glob; without+ // this check the merge would exit 0 and mcp-host would start on an empty+ // database next to the hidden one.+ it.each(['111', '333', '666'])(+ 'refuses a state/ directory with mode %s before the signature check',+ mode => {+ const root = splitRoot()+ const before = snapshot(root)+ chmodSync(join(root, 'state'), parseInt(mode, 8))++ const refused = merge(root)++ chmodSync(join(root, 'state'), 0o755)+ expect(refused.status).toBe(1)+ expect(refused.stderr.trim()).toBe(+ `workspace layout merge refused: state directory is not readable and searchable: ${root}/state`+ )+ expect(snapshot(root)).toEqual(before)+ // Witness: with its mode restored the same tree merges.+ expect(merge(root).status).toBe(0)+ expect(messageCount(join(root, 'state.db'))).toEqual({ rows: ROWS, check: 'ok' })+ },+ 15_000+ )++ it('refuses before the first move when a source directory cannot be listed', () => {+ const root = splitRoot()+ mkdirSync(join(root, 'cache'))+ mkdirSync(join(root, 'workspace', 'cache'))+ writeFileSync(join(root, 'workspace', 'cache', 'entry'), 'cached')+ const before = snapshot(root)+ chmodSync(join(root, 'workspace', 'cache'), 0o333)++ const refused = merge(root)++ chmodSync(join(root, 'workspace', 'cache'), 0o755)+ expect(refused.status).toBe(1)+ expect(refused.stderr.trim()).toBe(+ `workspace layout merge refused: cannot list directory: ${root}/workspace/cache`+ )+ expect(snapshot(root)).toEqual(before)+ // Witness: once listable, the non-empty source is a real collision (F3).+ expect(merge(root).stderr).toContain(`destination exists: ${root}/cache`)+ }, 15_000)+it('moves symlinks under workspace/ as links without following them', () => {const root = splitRoot()symlinkSync('/tmp/evenfire', join(root, 'workspace', 'evenfire'))