Skip to content

Commit e23ba84

Browse files
committed
fix(review): keep runtime vocabulary out of persistent-data findings
Recut the persistent-data classifier boundary accepted on #983 onto the active post-#993 change-detection module. The content regexes in dataModelSurfacesFromPatch ran over the joined patch text with no reference to the file path, so ordinary runtime, test, fixture, telemetry, docs, and workflow vocabulary - metadata, cache, upgrade, JSON.parse, vector, dimension, repair - was enough to raise a persistent data-model surface. That set data_model_change, cost the pull request pass and automerge eligibility, and published a migration-proof demand on changes that touch no stored state. Exclude test, fixture, and snapshot paths from the candidate set, narrow the migration, cache, and vector content regexes, require explicit storage APIs or nearby file I/O plus JSON plus a persistence noun for serialized state, and anchor the migration filename path hint. pathHint, unknown-data-model-change, unknown-truncated-pull-files, truncation detection, and pullFilesTruncated fail-closed behavior are unchanged.
1 parent 81c23be commit e23ba84

2 files changed

Lines changed: 220 additions & 15 deletions

File tree

‎src/clawsweeper-change-detection.ts‎

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ export function dataModelChangeFromContext(repo: string, context: ItemContext):
8080
const previousPath =
8181
typeof file.previous_filename === "string" ? file.previous_filename.trim() : "";
8282
const candidates = [path, previousPath].filter(Boolean);
83-
const likelyPath = candidates.find(isLikelyOpenClawDataModelPath) ?? "";
83+
const productionCandidates = candidates.filter(
84+
(candidate) => !isOpenClawDataModelTestPath(candidate),
85+
);
86+
const likelyPath = productionCandidates.find(isLikelyOpenClawDataModelPath) ?? "";
8487
const patch = typeof file.patch === "string" ? file.patch : null;
8588
const lines = patch === null ? [] : changedPatchLines(patch);
8689

@@ -91,7 +94,7 @@ export function dataModelChangeFromContext(repo: string, context: ItemContext):
9194
surfaces.add(dataModelSurfaceLabel(likelyPath, "unknown-data-model-change"));
9295
}
9396

94-
for (const candidate of candidates) {
97+
for (const candidate of productionCandidates) {
9598
if (isDocsPath(candidate)) {
9699
if (patch !== null && !configSurfacePatchIsTruncated(patch)) {
97100
dataModelSurfacesFromPatch(candidate, lines, { docsOnly: true }).forEach((surface) =>
@@ -312,7 +315,7 @@ function dataModelSurfacesFromPatch(
312315
) {
313316
add("database schema");
314317
}
315-
if (/\b(?:migration|migrate|upgrade|backfill|doctor|repair|reindex|rehydrat\w*)\b/i.test(text)) {
318+
if (/\b(?:migrations?|migrat(?:e|ed|es|ing)|backfill\w*)\b/i.test(text)) {
316319
add("migration/backfill/repair");
317320
}
318321
if (
@@ -322,22 +325,26 @@ function dataModelSurfacesFromPatch(
322325
) {
323326
add("durable storage schema");
324327
}
325-
if (
326-
/\b(?:JSON\.(?:parse|stringify)|readFile|writeFile|localStorage|sessionStorage|workspaceState|globalState|serialized|persisted?|statePath)\b/i.test(
327-
text,
328-
)
329-
) {
328+
const hasExplicitSerializedState =
329+
/\b(?:localStorage|sessionStorage|workspaceState|globalState|statePath)\b/i.test(text);
330+
const hasJsonFilePersistence = lines.some((_, index) => {
331+
const operation = lines.slice(Math.max(0, index - 2), index + 3).join("\n");
332+
return (
333+
/\b(?:readFile|writeFile)\w*\b/i.test(operation) &&
334+
/\bJSON\.(?:parse|stringify)\b/i.test(operation) &&
335+
/\b(?:state|checkpoint|snapshot|cache|store|storage|record|session|history|queue|registry|cursor|profile|credential|memory|database|db)(?:[ _-]?(?:path|file|dir(?:ectory)?)){0,2}\b/i.test(
336+
operation,
337+
)
338+
);
339+
});
340+
if (hasExplicitSerializedState || hasJsonFilePersistence) {
330341
add("serialized state");
331342
}
332-
if (
333-
/\b(?:cache(?:Key|Version|Schema|Namespace)?|cache[_-]?(?:key|version|schema|namespace)|ttl)\b/i.test(
334-
text,
335-
)
336-
) {
343+
if (/\bcache[ _-]?(?:key|version|schema|namespace|ttl)\b/i.test(text)) {
337344
add("persistent cache schema");
338345
}
339346
if (
340-
/\b(?:embedding|vector|collection|dimension|metadata|row[_-]?id|document[_-]?id|chunk[_-]?id|similarity[_-]?index)\b/i.test(
347+
/\b(?:embedding[ _-]?dimension|vector[ _-]?dimension|collection[ _-]?name|row[ _-]?id|document[ _-]?id|chunk[ _-]?id|similarity[ _-]?index)\b/i.test(
341348
text,
342349
)
343350
) {
@@ -360,6 +367,14 @@ function isLikelyOpenClawDataModelPath(path: string): boolean {
360367
return Boolean(dataModelPathHint(path)) || /\.(?:sql|sqlite|db|prisma)$/.test(path);
361368
}
362369

370+
function isOpenClawDataModelTestPath(path: string): boolean {
371+
return (
372+
/(^|\/)(?:__tests__|test|tests|fixtures|__snapshots__)(?:\/|$)/i.test(path) ||
373+
/\.(?:test|spec)\.[cm]?[jt]sx?$/i.test(path) ||
374+
/\.snap$/i.test(path)
375+
);
376+
}
377+
363378
function dataModelPathHint(path: string): string {
364379
if (
365380
/(^|\/)(?:durable-?objects?|workers?|storage)(?:\/|[-_.])|durable-?object|state-storage/i.test(
@@ -386,7 +401,7 @@ function dataModelPathHint(path: string): string {
386401
return "vector/embedding metadata";
387402
}
388403
if (
389-
/(^|\/)(?:migrations?|backfill|doctor|repair|upgrade)(?:\/|[-_.])|(?:migration|backfill|doctor|repair|upgrade)\.(?:ts|js)$/i.test(
404+
/(^|\/)(?:migrations?|backfill|doctor|repair|upgrade)(?:\/|[-_.])|(^|\/)(?:migration|backfill|doctor|repair|upgrade)\.(?:ts|js)$/i.test(
390405
path,
391406
)
392407
) {

‎test/pr-surface-policy.test.ts‎

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,196 @@ test("data model detector ignores query-only and non-semantic docs changes", ()
294294
assert.deepEqual(detection, { change: false, surfaces: [] });
295295
});
296296

297+
test("data model detector ignores workflow, test, and fixture vocabulary", () => {
298+
const detection = dataModelChangeFromPullFilesForTest({
299+
pullFiles: [
300+
{
301+
filename: ".github/workflows/release.yml",
302+
patch:
303+
'@@\n+ metadata=".artifacts/pkg/candidate.json"\n+ if [[ ! -f "$metadata" ]]; then',
304+
},
305+
{
306+
filename: ".github/workflows/checks.yml",
307+
patch: "@@\n+ vector-tests:\n+ runs-on: ubuntu-latest",
308+
},
309+
{
310+
filename: "test/scripts/package-acceptance.test.ts",
311+
patch: '@@\n+ assert.deepEqual(result.metadata, { name: "openclaw" });',
312+
},
313+
{
314+
filename: "test/fixtures/layout.json",
315+
patch: '@@\n+ "dimension": 24,',
316+
},
317+
{
318+
filename: "test/fixtures/vector-schema.ts",
319+
patch: "@@\n+ embeddingDimension: 24,",
320+
},
321+
{
322+
filename: "src/talk/session-runtime.test.ts",
323+
patch: "@@\n+ const parsed = JSON.parse(raw);",
324+
},
325+
],
326+
});
327+
328+
assert.deepEqual(detection, { change: false, surfaces: [] });
329+
});
330+
331+
test("data model detector ignores runtime repair, telemetry, and cache vocabulary", () => {
332+
const detection = dataModelChangeFromPullFilesForTest({
333+
pullFiles: [
334+
{
335+
filename: "src/agents/embedded-agent-runner/run/code-mode-tool-call-repair.ts",
336+
patch: "@@\n+ return repairSmallModelToolCall(payload);",
337+
},
338+
{
339+
filename: "src/agents/tool-search-telemetry.ts",
340+
patch: "@@\n+ metadata: toolMetadata,\n+ cacheRead: usage.cacheRead,",
341+
},
342+
{
343+
filename: "src/agents/code-mode-tool-input-repair.ts",
344+
patch: "@@\n+ return JSON.parse(candidate);",
345+
},
346+
{
347+
filename: "src/gateway/websocket.ts",
348+
patch: '@@\n+ if (req.headers.upgrade !== "websocket") return;',
349+
},
350+
{
351+
filename: "src/util/memo.ts",
352+
patch: "@@\n+const cache = new Map<string, number>();\n+cache.set(key, value);",
353+
},
354+
{
355+
filename: "docs/reference/full-release-validation.md",
356+
patch: "@@\n+| Cross-OS | Tests: upgrade from the prior release |",
357+
},
358+
],
359+
});
360+
361+
assert.deepEqual(detection, { change: false, surfaces: [] });
362+
});
363+
364+
test("data model detector keeps explicit repair and persistence surfaces", () => {
365+
const detection = dataModelChangeFromPullFilesForTest({
366+
pullFiles: [
367+
{
368+
filename: "src/doctor/repair.ts",
369+
patch: "@@\n+ await repair(database);",
370+
},
371+
{
372+
filename: "src/cache/schema.ts",
373+
patch: "@@\n+ entryFingerprint: string;",
374+
},
375+
{
376+
filename: "src/runtime/checkpoint.ts",
377+
patch:
378+
"@@\n+ const raw = await readFile(checkpointPath, 'utf8');\n+ return JSON.parse(raw);",
379+
},
380+
{
381+
filename: "scripts/config-fixture.ts",
382+
patch:
383+
"@@\n+ await writeFile(configPath, JSON.stringify(config));\n+ return readFile(resultPath, 'utf8');",
384+
},
385+
],
386+
});
387+
388+
assert.deepEqual(detection, {
389+
change: true,
390+
surfaces: [
391+
"migration/backfill/repair: src/doctor/repair.ts",
392+
"persistent cache schema: src/cache/schema.ts",
393+
"serialized state: src/runtime/checkpoint.ts",
394+
],
395+
});
396+
});
397+
398+
test("data model detector keeps production snapshot schemas", () => {
399+
const detection = dataModelChangeFromPullFilesForTest({
400+
pullFiles: [
401+
{
402+
filename: "src/storage/snapshots/schema.sql",
403+
patch: "@@\n+ALTER TABLE snapshots ADD COLUMN format_version INTEGER;",
404+
},
405+
],
406+
});
407+
408+
assert.deepEqual(detection, {
409+
change: true,
410+
surfaces: ["database schema: src/storage/snapshots/schema.sql"],
411+
});
412+
});
413+
414+
test("data model detector recognizes semantic prose forms", () => {
415+
const detection = dataModelChangeFromPullFilesForTest({
416+
pullFiles: [
417+
{
418+
filename: "docs/storage.md",
419+
patch:
420+
"@@\n+The cache version changes when persisted entries become incompatible.\n+The embedding dimension remains part of stored vector metadata.",
421+
},
422+
],
423+
});
424+
425+
assert.deepEqual(detection, {
426+
change: true,
427+
surfaces: [
428+
"persistent cache schema: docs/storage.md",
429+
"vector/embedding metadata: docs/storage.md",
430+
],
431+
});
432+
});
433+
434+
test("data model detector recognizes compound persisted path identifiers", () => {
435+
const detection = dataModelChangeFromPullFilesForTest({
436+
pullFiles: [
437+
{
438+
filename: "src/runtime/load-checkpoint.ts",
439+
patch:
440+
"@@\n+ const raw = await readFile(checkpointFilePath, 'utf8');\n+ return JSON.parse(raw);",
441+
},
442+
{
443+
filename: "src/runtime/load-state.ts",
444+
patch:
445+
"@@\n+ const raw = await readFile(state_file_path, 'utf8');\n+ return JSON.parse(raw);",
446+
},
447+
{
448+
filename: "src/runtime/load-cache.ts",
449+
patch:
450+
"@@\n+ const raw = await readFile(cacheDirectoryPath, 'utf8');\n+ return JSON.parse(raw);",
451+
},
452+
],
453+
});
454+
455+
assert.deepEqual(detection, {
456+
change: true,
457+
surfaces: [
458+
"serialized state: src/runtime/load-cache.ts",
459+
"serialized state: src/runtime/load-checkpoint.ts",
460+
"serialized state: src/runtime/load-state.ts",
461+
],
462+
});
463+
});
464+
465+
test("data model detector keeps persistence outside the normal source tree", () => {
466+
const detection = dataModelChangeFromPullFilesForTest({
467+
pullFiles: [
468+
{
469+
filename: "migrations/0001-init.sql",
470+
patch: "@@\n+CREATE TABLE sessions (id TEXT PRIMARY KEY);",
471+
},
472+
{
473+
filename: "state/persisted-state.json",
474+
},
475+
],
476+
});
477+
478+
assert.deepEqual(detection, {
479+
change: true,
480+
surfaces: [
481+
"database schema: migrations/0001-init.sql",
482+
"unknown-data-model-change: state/persisted-state.json",
483+
],
484+
});
485+
});
486+
297487
test("data model detector flags path-hinted persisted field declarations", () => {
298488
const detection = dataModelChangeFromPullFilesForTest({
299489
pullFiles: [

0 commit comments

Comments
 (0)