Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

OpenClaw skill plugin: write daily log lines in event order

garrytan9b3b59e30527
diff --git a/src/core/setup/openclaw-skill-plugin-code.ts b/src/core/setup/openclaw-skill-plugin-code.ts
index d43631ff99..89da7abed7 100644
--- a/src/core/setup/openclaw-skill-plugin-code.ts
+++ b/src/core/setup/openclaw-skill-plugin-code.ts
@@ -143,10 +143,14 @@ function readState() {
function day(t) { return new Date(t).toISOString().slice(0, 10); }
+let logTail = Promise.resolve();
+
function log(line) {
try {
const at = Date.now();
- appendFile(join(LOG_DIR, 'openclaw-' + day(at) + '.jsonl'), JSON.stringify({ at: new Date(at).toISOString(), ...line }) + '\n', { mode: 0o600 }).catch(() => {});
+ const file = join(LOG_DIR, 'openclaw-' + day(at) + '.jsonl');
+ const text = JSON.stringify({ at: new Date(at).toISOString(), ...line }) + '\n';
+ logTail = logTail.then(() => appendFile(file, text, { mode: 0o600 })).catch(() => {});
} catch { /* logging never fails a turn */ }
}
diff --git a/test/openclaw-skill-plugin.test.ts b/test/openclaw-skill-plugin.test.ts
index 55a38a1845..8a4469d7e8 100644
--- a/test/openclaw-skill-plugin.test.ts
+++ b/test/openclaw-skill-plugin.test.ts
@@ -282,6 +282,20 @@ describe.skipIf(!NODE)('the gbrain-skill-resolver plugin under Node', () => {
expect(sessions.length).toBeGreaterThan(0);
});
+ test('the daily log keeps event order when a skill read follows a turn at once', async () => {
+ const b = box();
+ await setup(b, ['--skill-loading', 'resolve']);
+ const steps: unknown[] = [];
+ const want: string[] = [];
+ for (let i = 0; i < 4; i++) {
+ steps.push(['turn', { text: 'triage the email inbox', id: 'm' + i, session: 'agent:main:o' + i }]);
+ want.push('suggested');
+ for (let j = 0; j < 40; j++) { steps.push(['read', { name: 'skill-' + i + '-' + j }]); want.push('skill-' + i + '-' + j); }
+ }
+ drive(b, steps);
+ expect(logLines(b).filter((l) => l.agent === 'main').map((l) => l.skill ?? l.outcome)).toEqual(want);
+ });
+
test('the description floor holds: body-only matches are never suggested', async () => {
const b = box();
const skills = join(b.state, 'workspace', 'skills');