Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (claude): preserve intentional submodule states

Adam Eivyb6e1215a0674
diff --git a/docs/SELF_UPDATE.md b/docs/SELF_UPDATE.md
index 66880fc60a..a248c4c8ff 100644
--- a/docs/SELF_UPDATE.md
+++ b/docs/SELF_UPDATE.md
@@ -46,7 +46,7 @@ The sync step refreshes each checkout's local submodule metadata from the newly
All restart-triggering UI actions (`Update Now`, `Sync Fork & Update`, both “from Fork As-Is” variants, and the reconcile variants) launch `update.sh` or `update.ps1`, so they inherit this exact sequence. `Sync Fork Only` remains intentionally different: it only fast-forwards the GitHub fork and does not touch the local checkout.
-`GET /api/update/status` also compares recursive submodule checkouts with their pinned revisions. A mismatch or uninitialized module marks the install out of sync, making the existing Reconcile control available even when no newer release is waiting.
+`GET /api/update/status` also compares recursive submodule checkouts with their pinned revisions. An uninitialized, conflicted, behind, or divergent module marks the install out of sync, making the existing Reconcile control available even when no newer release is waiting. A checkout deliberately advanced through the Submodules tab is not treated as stale, and CoS worktrees report submodule state as unknown because they intentionally leave submodules uninitialized and cannot run the primary-checkout update flow.
To prevent that confusion, `POST /api/update/execute` rejects fork runs with **412 `FORK_SYNC_REQUIRED`** unless either:
diff --git a/server/services/installState.js b/server/services/installState.js
index 603de1bfd3..4d806d205e 100644
--- a/server/services/installState.js
+++ b/server/services/installState.js
@@ -194,7 +194,22 @@ async function detectSubmodules(rootDir, {
['submodule', 'status', '--recursive'],
rootDir,
{ ignoreExitCode: true }
- )
+ ),
+ isAheadOfPin = async ({ commit, path }) => {
+ const pinned = await execGit(
+ ['rev-parse', `HEAD:${path}`],
+ rootDir,
+ { ignoreExitCode: true }
+ );
+ const pinnedSha = pinned.exitCode === 0 ? pinned.stdout.trim() : '';
+ if (!pinnedSha) return false;
+ const ancestor = await execGit(
+ ['merge-base', '--is-ancestor', pinnedSha, commit],
+ join(rootDir, path),
+ { ignoreExitCode: true }
+ );
+ return ancestor.exitCode === 0;
+ }
} = {}) {
const result = await getStatus();
if (result?.exitCode !== 0 || typeof result?.stdout !== 'string') {
@@ -209,7 +224,17 @@ async function detectSubmodules(rootDir, {
return { stale: null, paths: null };
}
- const paths = parsed.filter(entry => entry.statusChar !== ' ').map(entry => entry.path);
+ const paths = [];
+ for (const entry of parsed) {
+ if (entry.statusChar === ' ') continue;
+ // The Submodules tab intentionally supports checking out the latest remote
+ // commit without committing the parent pointer. Git reports that as `+`,
+ // but it is not a half-finished update when the checkout descends from the
+ // pin. A behind/divergent `+`, `-` (uninitialized), or `U` (conflicted)
+ // still needs Reconcile. Comparison failures stay conservative (stale).
+ if (entry.statusChar === '+' && await isAheadOfPin(entry).catch(() => false)) continue;
+ paths.push(entry.path);
+ }
return { stale: paths.length > 0, paths };
}
@@ -241,7 +266,12 @@ export async function getInstallState({
listPending = () => isWorktreeRoot(migrationRootDir)
? Promise.resolve([])
: listPendingMigrations({ rootDir: migrationRootDir }),
- getSubmoduleState = () => detectSubmodules(rootDir),
+ // A CoS worktree cannot switch to its own main branch, and intentionally
+ // leaves submodules uninitialized. Offering Reconcile there would be a
+ // permanent false action, so preserve unknown rather than reporting stale.
+ getSubmoduleState = () => isWorktreeRoot(rootDir)
+ ? Promise.resolve({ stale: null, paths: null })
+ : detectSubmodules(rootDir),
} = {}) {
const currentCommit = await getCurrentCommit().catch(() => null);
diff --git a/server/services/installState.test.js b/server/services/installState.test.js
index 34f533cff4..c4d37cecde 100644
--- a/server/services/installState.test.js
+++ b/server/services/installState.test.js
@@ -296,12 +296,39 @@ describe('getInstallState — submodules', () => {
].join('\n')
});
- expect(await __internal.detectSubmodules(ROOT, { getStatus })).toEqual({
+ expect(await __internal.detectSubmodules(ROOT, {
+ getStatus,
+ isAheadOfPin: async () => false,
+ })).toEqual({
stale: true,
paths: ['lib/different', 'lib/missing', 'lib/conflicted']
});
});
+ it('does not flag a deliberate remote update ahead of the pinned commit', async () => {
+ const isAheadOfPin = vi.fn(async () => true);
+ const state = await __internal.detectSubmodules(ROOT, {
+ getStatus: async () => ({ exitCode: 0, stdout: '+def5678 lib/ahead (heads/main)\n' }),
+ isAheadOfPin,
+ });
+
+ expect(state).toEqual({ stale: false, paths: [] });
+ expect(isAheadOfPin).toHaveBeenCalledWith({
+ statusChar: '+',
+ commit: 'def5678',
+ path: 'lib/ahead',
+ });
+ });
+
+ it('reports submodule state as unknown in a CoS worktree', async () => {
+ const worktreeRoot = join(ROOT, 'data', 'cos', 'worktrees', 'agent-abc');
+ const { getSubmoduleState, ...opts } = syncedOpts({ rootDir: worktreeRoot });
+ const state = await getInstallState(opts);
+
+ expect(state.submodules).toEqual({ stale: null, paths: null });
+ expect(state.outOfSync).toBe(false);
+ });
+
it('returns unknown for failed or malformed git status output', async () => {
expect(await __internal.detectSubmodules(ROOT, {
getStatus: async () => ({ exitCode: 128, stdout: '' })