Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(hcc): match only base-init backup names in the merge signature (R3-H1)

Alfredo Lopez3158019a522e
diff --git a/docs/architecture/host-storage-layout.md b/docs/architecture/host-storage-layout.md
index 60f929598..cafe9c06a 100644
--- a/docs/architecture/host-storage-layout.md
+++ b/docs/architecture/host-storage-layout.md
@@ -75,9 +75,12 @@ SQLite.
**Trigger.** It acts only on the split-layout signature the earlier init
leaves: `state/` and `workspace/` are both real directories (not symlinks),
and `state/` holds a file that init writes: `state.db`, `state.db-wal`,
-`state.db-shm` or a `state.db*.pre-<ts>.bak` copy. Every other tree exits 0
+`state.db-shm` or a `.pre-<ts>.bak` copy of one of those three
+(`state.db.pre-<ts>.bak`, `state.db-wal.pre-<ts>.bak`,
+`state.db-shm.pre-<ts>.bak`). Every other tree exits 0
unchanged, including an agent folder named `workspace/` or `state/` alone, a
-`state/` holding other `state.db*` names (`state.db.json`, `state.dbx`), and a
+`state/` holding other `state.db*` names (`state.db.json`, `state.dbx`,
+`state.dbX.pre-1.bak`), and a
`state` or `workspace` that is a symlink or not a directory. An agent can
create those on a stateful Host, so they must not stop it from starting. A
stateful or desktop tree changes only if it carries the signature, which only
@@ -118,7 +121,7 @@ Host). Recovery, with the Host stopped and the PVC mounted in a helper Pod:
1. every entry of `workspace/`, dotfiles and symlinks included, to the root
(`mv` renames a symlink and never follows it);
2. every entry of `state/` except `state.db`, including journals and
- `state.db*.pre-<ts>.bak` backups;
+ `.pre-<ts>.bak` backups;
3. `state/state.db` last, so an interrupted merge still carries the
signature and completes on the next start;
4. remove the empty `state/` and `workspace/`, then `sync`.
@@ -235,7 +238,7 @@ forced by a deploy.
zero, rename the new root `state.db*` files from a helper Pod (keep them),
and move `workspace/state.db*` to the root.
- The second exception is the same cut when `state/` already holds a
- `state.db*.pre-<ts>.bak` from an earlier start. The tree then carries the
+ `.pre-<ts>.bak` backup from an earlier start. The tree then carries the
signature, and the merge moves `workspace/` entries in name order:
`state.db` before `state.db-shm` and `state.db-wal`. Resume covers only
journals at the root next to `state/state.db`, so a merge cut after
@@ -255,7 +258,7 @@ forced by a deploy.
backup. A Pod in this window is Pending with the merge init still running,
not in `Init:Error`, so the rule below names it explicitly.
- After a rollback, the previous init moves every root entry into
- `workspace/`, including `state.db*.pre-<ts>.bak` backups, and moves back to
+ `workspace/`, including `.pre-<ts>.bak` backups, and moves back to
`state/` only the exact names `state.db`, `state.db-wal` and `state.db-shm`.
The backups stay under `workspace/`, the agent's workspace on a stateless
Host, where the previous mcp-host (which protects only those three exact
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.json
index 62d2d01a8..4dee08dce 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.394",
+ "version": "0.1.395",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-host-context-controller",
- "version": "0.1.394",
+ "version": "0.1.395",
"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.json
index 30e935205..e6dd2198e 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.394",
+ "version": "0.1.395",
"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.ts
index 1249378f6..3641a75ec 100644
--- a/host-context-controller/src/statelessDeployment.ts
+++ b/host-context-controller/src/statelessDeployment.ts
@@ -31,8 +31,8 @@ function shellSingleQuote(value: string): string {
*
* The merge runs only on the signature the earlier init leaves: `state/`
* and `workspace/` are both real directories and `state/` holds a file the
- * init writes (`state.db`, `state.db-wal`, `state.db-shm` or a
- * `state.db*.pre-*.bak` copy). Any other tree exits 0 untouched: stateful,
+ * init writes (`state.db`, `state.db-wal`, `state.db-shm` or a `.pre-*.bak`
+ * copy of one of those three). Any other tree exits 0 untouched: stateful,
* desktop, empty, a user folder named `state/` or `workspace/`, a `state/`
* holding other `state.db*` names, and a `state` or `workspace` that is a
* symlink or not a directory (an agent can create those on a stateful Host,
@@ -104,9 +104,10 @@ root_real="$(canonical_dir "$root")" || fail_merge "cannot resolve workspace PVC
[ -r "$root/state" ] && [ -x "$root/state" ] ||
fail_merge "state directory is not readable and searchable: $root/state"
# Only the names the earlier init writes count: the database, its journals
-# and the .pre-<ts>.bak copies it keeps of an older source.
+# and the .pre-<ts>.bak copy it keeps of each of them from an older source.
signature=0
-for entry in "$root/state"/state.db "$root/state"/state.db-wal "$root/state"/state.db-shm "$root/state"/state.db*.pre-*.bak; do
+for entry in "$root/state"/state.db "$root/state"/state.db-wal "$root/state"/state.db-shm \\
+ "$root/state"/state.db.pre-*.bak "$root/state"/state.db-wal.pre-*.bak "$root/state"/state.db-shm.pre-*.bak; do
if present "$entry"; then signature=1; fi
done
[ "$signature" -eq 1 ] || exit 0
@@ -118,7 +119,8 @@ assert_managed_dir "$root/workspace" workspace
[ -r "$root/workspace" ] && [ -x "$root/workspace" ] ||
fail_merge "workspace directory is not readable and searchable: $root/workspace"
for dir in "$root" "$root/state" "$root/workspace"; do
- for entry in "$dir"/state.db "$dir"/state.db-wal "$dir"/state.db-shm "$dir"/state.db*.pre-*.bak; do
+ for entry in "$dir"/state.db "$dir"/state.db-wal "$dir"/state.db-shm \\
+ "$dir"/state.db.pre-*.bak "$dir"/state.db-wal.pre-*.bak "$dir"/state.db-shm.pre-*.bak; 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"
diff --git a/host-context-controller/test/statelessDeployment.workspaceLayoutMerge.test.ts b/host-context-controller/test/statelessDeployment.workspaceLayoutMerge.test.ts
index a47ec924f..cc390f9ef 100644
--- a/host-context-controller/test/statelessDeployment.workspaceLayoutMerge.test.ts
+++ b/host-context-controller/test/statelessDeployment.workspaceLayoutMerge.test.ts
@@ -604,6 +604,20 @@ describe('workspace layout merge', () => {
mkdirSync(join(root, 'workspace'))
writeFileSync(join(root, 'workspace', 'README.md'), 'user file')
},
+ // Its backups are state.db.pre-<ts>.bak, state.db-wal.pre-<ts>.bak and
+ // state.db-shm.pre-<ts>.bak; any other .pre-*.bak name is a user file.
+ 'user state/ folder with .pre-*.bak names the base init never writes': root => {
+ mkdirSync(join(root, 'state'))
+ for (const name of [
+ 'state.dbX.pre-1.bak',
+ 'state.db.x.pre-1.bak',
+ 'state.db-journal.pre-1.bak',
+ ]) {
+ writeFileSync(join(root, 'state', name), 'user file')
+ }
+ mkdirSync(join(root, 'workspace'))
+ writeFileSync(join(root, 'workspace', 'README.md'), 'user file')
+ },
// A desktop PVC never held the database before v1; a user project in
// state/ must not be adopted as the conversation store.
'desktop project state/{state.db,app.yml} without workspace/': root => {