Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Keep the CLI fast path free of migration modules by gating the concept-input function on a version constant

garrytana2533b74af64
diff --git a/src/core/search/private-visibility.ts b/src/core/search/private-visibility.ts
index 18f3e6a3a4..3fd1f05529 100644
--- a/src/core/search/private-visibility.ts
+++ b/src/core/search/private-visibility.ts
@@ -31,7 +31,6 @@ import { ACCESS_ID_RE, hasReaders, MEMBER_PAGE_PREFIX, normalizePrincipal, reade
import { ruleCoversSql, validPrefix, validQualifiedRuleId } from '../access/folder-rules.ts';
import { holdingSlugSql } from '../facts-fence.ts';
import { atomMovedOriginPrivateSql, atomOriginSlugsSql } from '../persistence/atom-origin.ts';
-import { v311 } from '../schema-migrations/v311-concept-inputs-private.ts';
export const REMOTE_PRIVATE_PAGES_KEY = 'search.remote_private_pages';
@@ -708,13 +707,16 @@ export function privateSnapshotFilterFragment(alias: string): string {
* whose schema predates v311 or whose version was not read, the same test runs inline, as gbrain_access_origin_restricted is
* skipped inside a request on a brain that never set access.restrictions_present.
*/
+/** The schema version (migration v311) that creates gbrain_concept_inputs_private; a literal so the CLI dispatcher never loads a migration module. */
+export const CONCEPT_INPUTS_PRIVATE_SINCE = 311;
+
function derivedOriginPrivateSql(p: string, shadowedPages: boolean): string {
const privateOrigin = (atom: string, alias: string) => `EXISTS (SELECT 1 FROM pages ${alias} WHERE ${alias}.source_id = ${atom}.source_id
AND ${alias}.slug = ANY(${atomOriginSlugsSql(atom)}) AND ${alias}.frontmatter->>'visibility' = 'private')`;
const { remotePolicy } = currentCallerAccess();
const scoped = engineScopeStore.getStore();
const schema = remotePolicy ? remotePolicy.schemaVersion : scoped ? schemaVersionSeen(scoped) : undefined;
- const conceptInputsPrivate = !shadowedPages && schema !== undefined && schema >= v311.version ? `gbrain_concept_inputs_private((${p}.id)::integer)`
+ const conceptInputsPrivate = !shadowedPages && schema !== undefined && schema >= CONCEPT_INPUTS_PRIVATE_SINCE ? `gbrain_concept_inputs_private((${p}.id)::integer)`
: `EXISTS (SELECT 1 FROM links derived_input_link
JOIN pages derived_input ON derived_input.id = derived_input_link.to_page_id
WHERE derived_input_link.from_page_id = ${p}.id AND derived_input_link.link_source = 'concept-provenance'
diff --git a/test/concept-rename-history-gst2687.test.ts b/test/concept-rename-history-gst2687.test.ts
index 0bacf713fb..533b7bf54d 100644
--- a/test/concept-rename-history-gst2687.test.ts
+++ b/test/concept-rename-history-gst2687.test.ts
@@ -24,7 +24,7 @@ import { mintLegacyToken } from '../src/core/token-mint.ts';
import { parseRescopeTokenArgs, rescopeLegacyToken } from '../src/core/grants/legacy-token.ts';
import { noGrantFederatedScope } from '../src/core/source-resolver.ts';
import { dispatchToolCall } from '../src/mcp/dispatch.ts';
-import { __resetPrivateVisibilityCacheForTests, privatePagesFilterFragment, withCallerAccess, type CallerAccess } from '../src/core/search/private-visibility.ts';
+import { __resetPrivateVisibilityCacheForTests, CONCEPT_INPUTS_PRIVATE_SINCE, privatePagesFilterFragment, withCallerAccess, type CallerAccess } from '../src/core/search/private-visibility.ts';
import * as scopeRead from '../src/core/access/scope-read.ts';
import { attestedCallerAccess } from '../src/core/access/actor.ts';
import { setOwner } from '../src/core/access/owner.ts';
@@ -162,6 +162,10 @@ for (const kind of testBackends()) {
expect({ atom: await reads('granted', ATOM, 'atom'), concept: await reads('granted', CONCEPT, 'concept') }).toEqual({ atom: all, concept: all });
}, 60_000);
+ test('the read rule gates on the migration that creates the function', () => {
+ expect(CONCEPT_INPUTS_PRIVATE_SINCE).toBe(v311.version);
+ });
+
test('(g) on a brain whose schema predates v311 remote reads keep working and still hide the concept', async () => {
await engine.executeRaw('DROP FUNCTION gbrain_concept_inputs_private(integer)');
await engine.setConfig('version', String(v311.version - 1));