Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix: OpenClaw skill plugin keeps the description floor on libraries without native floor support

garrytan3d7dbee1941e
diff --git a/src/core/setup/openclaw-skill-plugin-code.ts b/src/core/setup/openclaw-skill-plugin-code.ts
index 3198f045e2..178408d65d 100644
--- a/src/core/setup/openclaw-skill-plugin-code.ts
+++ b/src/core/setup/openclaw-skill-plugin-code.ts
@@ -52,6 +52,8 @@ function rebuild(lib, catalog, dirs) {
.finally(() => { building = null; });
}
+const STRENGTHS = ['named', 'name', 'triggers', 'routing', 'description', 'body'];
+
parentPort.on('message', async (m) => {
const loaded = await ready;
if (m.type === 'warm') { parentPort.postMessage({ type: 'warm', version: loaded.lib ? loaded.lib.GBRAIN_VERSION : null, code: loaded.code || null }); return; }
@@ -70,10 +72,23 @@ parentPort.on('message', async (m) => {
for (const [id, p] of pending) if (now - p.at > 30_000) pending.delete(id);
const input = { ...m.input };
const features = Array.isArray(lib.RESOLVER_FEATURES) ? lib.RESOLVER_FEATURES : [];
- if (m.floor && features.includes('min_match_strength')) input.min_match_strength = m.floor;
+ const nativeFloor = !!m.floor && features.includes('min_match_strength');
+ if (nativeFloor) input.min_match_strength = m.floor;
+ const floorRank = STRENGTHS.indexOf(m.floor);
+ const weak = (o) => nativeFloor || floorRank < 0 ? [] : o.suggestions.filter((s) => !(STRENGTHS.indexOf(s.match_strength) >= 0 && STRENGTHS.indexOf(s.match_strength) <= floorRank));
try {
- const r = await lib.resolveSkills(input, { home, catalogs: [m.catalog], failOpen: true, deadlineMs: m.deadlineMs, env: {} });
- const out = input.shadow ? (r.shadowOutput || r.output) : r.output;
+ const opts = { home, catalogs: [m.catalog], failOpen: true, deadlineMs: m.deadlineMs, env: {} };
+ let r = await lib.resolveSkills(input, opts);
+ let out = input.shadow ? (r.shadowOutput || r.output) : r.output;
+ const below = weak(out);
+ if (below.length) {
+ const left = m.deadlineMs - (Date.now() - now);
+ const retry = below.length < out.suggestions.length && left > 5
+ ? await lib.resolveSkills({ ...input, exclude: [...(input.exclude || []), ...below.map((s) => s.id)].slice(0, 64) }, { ...opts, deadlineMs: left }) : null;
+ const retryOut = retry ? (input.shadow ? (retry.shadowOutput || retry.output) : retry.output) : null;
+ if (retryOut && retryOut.suggestions.length && !weak(retryOut).length) { r = retry; out = retryOut; }
+ else { parentPort.postMessage({ id: m.id, block: '', names: [], strengths: [], no_skill_reason: 'below_floor', deduped: 0, code: null, version: out.gbrain_version }); return; }
+ }
if (r.pending) pending.set(m.id, { key: r.pending.key, delta: r.pending.delta, at: now });
const code = out.error ? out.error.code : null;
parentPort.postMessage({ id: m.id, block: out.block, names: out.suggestions.map((s) => s.name), strengths: out.suggestions.map((s) => s.match_strength),
@@ -105,7 +120,7 @@ const GBRAIN_BIN = __BIN__;
const GBRAIN_HOME_ENV = __GBRAIN_HOME_ENV__;
const PLUGIN_VERSION = __PLUGIN_VERSION__;
const ID = 'gbrain-skill-resolver';
-const DEADLINE_MS = 50;
+const DEADLINE_MS = Number(process.env.GBRAIN_TEST_OPENCLAW_SKILL_DEADLINE_MS) || 50;
const STUCK_AFTER = 3;
const KEEP_DAYS = 14;
const MEMO_MAX = 1000;
diff --git a/test/openclaw-skill-plugin.test.ts b/test/openclaw-skill-plugin.test.ts
index 97d44a2bf6..79aef00d6d 100644
--- a/test/openclaw-skill-plugin.test.ts
+++ b/test/openclaw-skill-plugin.test.ts
@@ -109,7 +109,7 @@ await sleep(300);
console.log(JSON.stringify(out));
process.exit(0);
`);
- const r = Bun.spawnSync([NODE!, script, pluginDir(b), statePath(b), JSON.stringify(steps)], { env: { PATH: b.env.PATH!, HOME: b.home, ...(nodeOptions ? { NODE_OPTIONS: nodeOptions } : {}), ...env }, stdout: 'pipe', stderr: 'pipe', timeout: 60_000 });
+ const r = Bun.spawnSync([NODE!, script, pluginDir(b), statePath(b), JSON.stringify(steps)], { env: { PATH: b.env.PATH!, HOME: b.home, ...(nodeOptions ? { NODE_OPTIONS: nodeOptions } : {}), GBRAIN_TEST_OPENCLAW_SKILL_DEADLINE_MS: '2000', ...env }, stdout: 'pipe', stderr: 'pipe', timeout: 60_000 });
const text = r.stdout.toString().trim().split('\n').at(-1) ?? '';
try { return JSON.parse(text); } catch { throw new Error('drive failed: ' + r.stderr.toString() + text); }
}
@@ -262,6 +262,24 @@ describe.skipIf(!NODE)('the gbrain-skill-resolver plugin under Node', () => {
expect(sessions.length).toBeGreaterThan(0);
});
+ test('the description floor holds on a library without native floor support: body-only matches are never suggested', async () => {
+ const b = box();
+ const skills = join(b.state, 'workspace', 'skills');
+ mkdirSync(join(skills, 'zeta-notes'), { recursive: true });
+ writeFileSync(join(skills, 'zeta-notes', 'SKILL.md'), '---\nname: zeta-notes\ndescription: Use when you keep a journal\n---\nAlso covers quarterly xylophone tuning.\n');
+ expect((await setup(b, ['--skill-loading', 'resolve'])).exitCode).toBe(0);
+ const out = drive(b, [
+ ['turn', { text: 'xylophone tuning', id: 'm1' }],
+ ['turn', { text: 'triage the email inbox and the xylophone tuning', id: 'm2', session: 'agent:main:s2' }],
+ ]);
+ expect(out[0]).toBeNull();
+ expect(out[1].appendContext).toContain('email-triage');
+ expect(out[1].appendContext).not.toContain('zeta-notes');
+ const lines = logLines(b).filter((l) => l.agent === 'main');
+ expect(lines[0]).toMatchObject({ outcome: 'below_floor', suggested: [] });
+ expect(lines[1].strengths.every((s: string) => ['named', 'name', 'triggers', 'routing', 'description'].includes(s))).toBe(true);
+ });
+
test('rollout knobs: control arm, owner senders, first-turn pins and compaction', async () => {
const b = box();
await setup(b, ['--skill-loading', 'resolve', '--pins-route', 'first_turn', '--owner-sender', 'owner-1']);
@@ -335,7 +353,7 @@ describe.skipIf(!NODE)('the gbrain-skill-resolver plugin under Node', () => {
st.library_sha256 = sha;
writeFileSync(statePath(b), JSON.stringify(st));
const t0 = Date.now();
- drive(b, [1, 2, 3].map((i) => ['turn', { text: 'triage the email inbox ' + i, id: 'm' + i }]));
+ drive(b, [1, 2, 3].map((i) => ['turn', { text: 'triage the email inbox ' + i, id: 'm' + i }]), undefined, { GBRAIN_TEST_OPENCLAW_SKILL_DEADLINE_MS: '' });
const outcomes = logLines(b).map((l) => l.code ?? l.outcome);
expect(outcomes.filter((c) => c === 'skill_resolve_timeout').length).toBe(3);
expect(outcomes).toContain('skill_resolver_worker_stuck');