Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

managed worktrees: sources push refusal, verify push_probe and skill hints name the managed route (#5606)

garrytane807efcd5043
diff --git a/src/commands/doctor/skill-checks.ts b/src/commands/doctor/skill-checks.ts
index cfeb33ddaa..1113a4554f 100644
--- a/src/commands/doctor/skill-checks.ts
+++ b/src/commands/doctor/skill-checks.ts
@@ -4,6 +4,7 @@
* symbol (tests and scripts/live-brain-first-check.ts import them from
* doctor.ts) and buildChecks consumes them.
*/
+import { isManagedFilesystemPath } from '../../core/persistence/filesystem-guard.ts';
import { join, resolve as resolvePath } from 'path';
import { existsSync, readFileSync, readdirSync } from 'fs';
import type { BrainEngine } from '../../core/engine.ts';
@@ -173,7 +174,10 @@ export function skillCurrencyCheck(skillsDir: string): Check {
status: 'warn',
message:
`${counts.new} new built-in skill(s) available that this workspace hasn't installed: ${sample('new')}. ` +
- `Add them with \`gbrain skillpack sync\`.` +
+ (isManagedFilesystemPath(skillsDir)
+ // #5606: on a managed canonical worktree skillpack sync is refused; name the route that works there.
+ ? 'This is a managed canonical worktree, where `gbrain skillpack sync` is refused: publish each reviewed bundle through `gbrain call --source <source> import_skill_proposal` (docs/guides/shared-brain-skills.md#publish-reviewed-filesystem-edits).'
+ : `Add them with \`gbrain skillpack sync\`.`) +
(counts.drifted > 0 ? ` (${counts.drifted} drifted from the bundle — local edits are fine.)` : ''),
details: {
new: skills.filter(k => k.status === 'new').map(k => k.slug),
diff --git a/src/core/bootstrap/verify.ts b/src/core/bootstrap/verify.ts
index 3f44bdace8..c0c517fcdf 100644
--- a/src/core/bootstrap/verify.ts
+++ b/src/core/bootstrap/verify.ts
@@ -28,6 +28,7 @@
*/
import { managedPersistenceEnabled } from '../persistence/ownership.ts';
+import { managedFilesystemRootFor } from '../persistence/filesystem-guard.ts';
import { submitPageMutation } from '../persistence/page-mutations.ts';
import { withCoordinatedWrite } from '../persistence/context.ts';
import { maintenanceAttribution } from '../persistence/attribution.ts';
@@ -1010,9 +1011,16 @@ async function checkHooksSmoke(engine: BrainEngine, ws: string, sourceId: string
}
}
-function checkPushProbe(ws: string): VerifyCheck {
+export function checkPushProbe(ws: string): VerifyCheck {
const id = 'push_probe';
try {
+ // #5606: a managed canonical worktree is pushed by the persistence owner's Git effect; sources push is refused there, so never recommend it.
+ const managed = managedFilesystemRootFor(ws);
+ if (managed) {
+ const source = managed.sourceId ?? '<source>';
+ return { id, ok: true, detail: `managed canonical worktree${managed.sourceId ? ` (source ${managed.sourceId})` : ''} — page writes are committed and pushed by the persistence owner's Git effect, not by sources push; `
+ + `check \`gbrain sources writer status ${source} --json\` (git_durability) and enable with \`gbrain sources writer git-durability ${source} --enable --dry-run\` if it is off` };
+ }
// Read through the shared per-root reader [D8/D13] — a v0.45.8+ push
// writes push-status-<roothash>.json, not the legacy single file, so the
// old direct read reported "no push recorded" on every fresh install.
diff --git a/src/core/skillpack/writer-guard.ts b/src/core/skillpack/writer-guard.ts
index e34eac8d56..51f97f9ac4 100644
--- a/src/core/skillpack/writer-guard.ts
+++ b/src/core/skillpack/writer-guard.ts
@@ -6,8 +6,12 @@ import type { SqlEngine } from '../persistence/model.ts';
function refuse(error: unknown): never {
if (error instanceof OperationError && error.code === 'writer_coordinator_required') {
- throw new OperationError('skill_bundle_required', 'Legacy skill writers cannot change a managed canonical worktree.',
- 'Use put_skill with the catalog expected_revision and complete approved file bundle; an existing pack requires host-authorized adoptSharedSkillpack adoption. Run legacy optimization in an unmanaged working copy, then submit the reviewed result through put_skill.');
+ // #5606: name the exact managed route, so the refusal is not a dead end for skillpack sync / reference --apply-clean-hunks.
+ throw new OperationError('skill_bundle_required', 'Legacy skill writers (skillpack sync, reference --apply-clean-hunks, copy) cannot change a managed canonical worktree.',
+ 'Preview the drift read-only with gbrain skillpack reference <slug> (no --apply-clean-hunks). To converge, publish the reviewed bundle through the coordinator: '
+ + 'gbrain call --source <source> import_skill_proposal "$(cat <private reviewed-proposal.json>)" with the current expected_revision, a unique request_id, the complete files and expected_hashes '
+ + '(docs/guides/shared-brain-skills.md#publish-reviewed-filesystem-edits), or put_skill with the catalog expected_revision; an existing pack requires host-authorized adoptSharedSkillpack adoption. '
+ + 'Run legacy optimization in an unmanaged working copy and submit the reviewed result the same way.');
}
throw error;
}
diff --git a/src/core/workspace-push.ts b/src/core/workspace-push.ts
index 647ebce48c..a336488fe8 100644
--- a/src/core/workspace-push.ts
+++ b/src/core/workspace-push.ts
@@ -1,4 +1,4 @@
-import { assertManagedFilesystemWrite } from './persistence/filesystem-guard.ts';
+import { assertManagedFilesystemWrite, managedFilesystemRootFor } from './persistence/filesystem-guard.ts';
import { OperationError } from './ops/contract.ts';
/**
* workspace-push.ts — the `gbrain sources push` core: scan-gated
@@ -665,6 +665,27 @@ export function aheadCount(root: string, branch: string): number | undefined {
return Number.isFinite(n) ? n : undefined;
}
+/**
+ * #5606: `sources push` on a managed canonical worktree is refused with the
+ * managed equivalent named, not a bare "submit through the coordinator": the
+ * persistence owner's Git effect is the writer for page files, the writer
+ * verbs check and enable it, and files that are not pages are the operator's
+ * to push with plain git. Same code, so every surface that keys on it still does.
+ */
+export function managedPushRefusal(dir: string, root: string | null | undefined, cause: OperationError): OperationError {
+ const managed = managedFilesystemRootFor(root ?? dir) ?? managedFilesystemRootFor(dir);
+ const source = managed?.sourceId;
+ const name = source ?? '<source>';
+ const error = new OperationError('writer_coordinator_required',
+ `${managed?.root ?? root ?? dir} is the managed canonical worktree${source ? ` of source ${source}` : ''}; gbrain sources push is not its Git writer.`,
+ `Page writes there are committed and pushed by the persistence owner's Git effect, not by sources push. Check it with gbrain sources writer status${source ? ` ${source}` : ''} --json `
+ + `(git_durability, parked effects). If git_durability is off or unknown, enable it with gbrain sources writer git-durability ${name} --enable --dry-run, then the apply command it prints; `
+ + `after a push credential change, gbrain sources writer git-durability ${name} --pat-file <path> re-wires it and retries the parked pushes. `
+ + 'Files that are not gbrain pages (MEMORY.md, daily notes) are not published by the owner: review the diff and push them with plain git; the sources push secret scan does not run then.');
+ error.detail = cause.detail;
+ return error;
+}
+
export async function workspacePush(opts: WorkspacePushOpts): Promise<WorkspacePushResult> {
const log = (line: string) => opts.logger?.(line);
@@ -678,10 +699,11 @@ export async function workspacePush(opts: WorkspacePushOpts): Promise<WorkspaceP
// status surface calls a push that can never run "stale" instead of failing.
// No lock winner can be in flight here: the same guard refuses every legacy
// push of this root.
- if (root && e instanceof OperationError) {
- writePushStatus({ ts: new Date().toISOString(), ok: false, code: e.code, reason: `${e.code}: ${e.message}`, repoRoot: root });
+ const refusal = e instanceof OperationError && e.code === 'writer_coordinator_required' ? managedPushRefusal(opts.dir, root, e) : e;
+ if (root && refusal instanceof OperationError) {
+ writePushStatus({ ts: new Date().toISOString(), ok: false, code: refusal.code, reason: `${refusal.code}: ${refusal.message}`, repoRoot: root });
}
- throw e;
+ throw refusal;
}
if (!root) {
return { ok: false, status: 'error', reason: `not a git repository: ${opts.dir}` };
diff --git a/test/doctor-skill-checks.test.ts b/test/doctor-skill-checks.test.ts
index 81a7f1ee1e..e8e9d2539b 100644
--- a/test/doctor-skill-checks.test.ts
+++ b/test/doctor-skill-checks.test.ts
@@ -24,6 +24,7 @@ import {
skillCurrencyCheck,
skillPreconditionsCheck,
} from '../src/commands/doctor/skill-checks.ts';
+import { assertLegacySkillFilesystemWrite } from '../src/core/skillpack/writer-guard.ts';
import {
SKILLS_MANIFEST_FILENAME,
computeSkillsManifest,
@@ -133,6 +134,23 @@ describe('skillCurrencyCheck', () => {
const details = check.details as { new: string[]; drifted: string[] };
expect(details.new.length).toBeGreaterThan(0);
});
+
+ // #5606: on a managed canonical worktree `skillpack sync` is refused, so the hint names the coordinator route instead.
+ test('a managed workspace is pointed at import_skill_proposal, never at `gbrain skillpack sync`', () => {
+ const workspace = makeDir('gbrain-currency-managed-');
+ const skillsDir = join(workspace, 'skills');
+ mkdirSync(skillsDir, { recursive: true });
+ writeFileSync(join(workspace, '.gbrain-managed'), JSON.stringify({ managed: true, version: 1 }));
+ const check = skillCurrencyCheck(skillsDir);
+ expect(check.status).toBe('warn');
+ expect(check.message).toContain('managed canonical worktree');
+ expect(check.message).toContain('import_skill_proposal');
+ expect(check.message).not.toContain('Add them with `gbrain skillpack sync`');
+ let refusal: unknown;
+ try { assertLegacySkillFilesystemWrite(join(skillsDir, 'brain-ops', 'SKILL.md')); } catch (error) { refusal = error; }
+ expect(refusal).toMatchObject({ code: 'skill_bundle_required', suggestion: expect.stringContaining('gbrain call --source <source> import_skill_proposal') });
+ expect((refusal as { message: string }).message).toContain('reference --apply-clean-hunks');
+ });
});
describe('skillPreconditionsCheck', () => {
diff --git a/test/managed-push-remedy.serial.test.ts b/test/managed-push-remedy.serial.test.ts
index d724f2e509..6c33bb3e5b 100644
--- a/test/managed-push-remedy.serial.test.ts
+++ b/test/managed-push-remedy.serial.test.ts
@@ -26,6 +26,7 @@ import { join } from 'node:path';
import { assessBackupRepository } from '../src/core/backup/repository.ts';
import { pushStatusPathForRoot, workspacePush } from '../src/core/workspace-push.ts';
import { bootstrapDoctorChecks } from '../src/commands/doctor/bootstrap-checks.ts';
+import { checkPushProbe } from '../src/core/bootstrap/verify.ts';
import { makeGitFixture } from './helpers/git-fixture.ts';
import { withEnv } from './helpers/with-env.ts';
@@ -132,4 +133,31 @@ describe('the managed guard refusal record (#6083)', () => {
expect(record.ok).toBe(false);
expect(record.code).toBe('writer_coordinator_required');
});
+
+ // #5606: the refusal names the managed equivalent instead of a bare "submit through the coordinator".
+ test('names the managed Git writer, its status and enable verbs, and plain git for non-page files', async () => {
+ const root = await repository();
+ manage(root);
+ const refusal = await workspacePush({ dir: root }).catch(error => error);
+ expect(refusal).toMatchObject({ code: 'writer_coordinator_required' });
+ expect(refusal.message).toContain('gbrain sources push is not its Git writer');
+ expect(refusal.suggestion).toContain('gbrain sources writer status');
+ expect(refusal.suggestion).toContain('gbrain sources writer git-durability');
+ expect(refusal.suggestion).toContain('--pat-file');
+ expect(refusal.suggestion).toContain('plain git');
+ expect(refusal.suggestion).not.toContain('Submit the change through the persistence coordinator');
+ });
+
+ test('bootstrap verify push_probe never recommends sources push on a managed worktree', async () => {
+ const root = await repository();
+ const before = checkPushProbe(root);
+ expect(before.detail).toContain('gbrain sources push');
+ manage(root);
+ const probe = checkPushProbe(root);
+ expect(probe).toMatchObject({ id: 'push_probe', ok: true });
+ expect(probe.warn).toBeFalsy();
+ expect(probe.detail).toContain('managed canonical worktree');
+ expect(probe.detail).toContain('gbrain sources writer git-durability');
+ expect(probe.detail).not.toContain('gbrain sources push');
+ });
});