本文へ移動
cccskills
無料GitHub で公開

rfdb-batchhandle-deletes-existing-nodes

Fix nodes silently disappearing from RFDB when an enricher or post-resolution pass writes new nodes via BatchHandle. Use when: (1) writing a TypeScript enricher that should ADD nodes/edges to existing files, (2) after calling `client.createBatch()` + `batch.addNode({file: 'X', ...})` + `batch.commit()` the original nodes in file X have vanished, (3) tests that load a graph fixture, run an enricher, then query original nodes get empty results, (4) a verification step shows expected nodes pre-enrichment but 0 post-enrichment. Root cause: `BatchHandle.commit()` invokes RFDB's `commit_batch` which AUTO-POPULATES `changed_files` from each added node's `file` field, then the server DELETES all existing nodes whose `file` matches before inserting new ones — file-level upsert semantics. This is correct for the JS/Haskell analyzers (which fully re-emit a file's contents) but catastrophic for enrichers that only ADD to existing files.

インストール方法を見る

含まれるファイル(1)

  • SKILL.md4.9 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

RFDB BatchHandle deletes existing nodes in changed files

Problem

BatchHandle.commit() is not append-only. It performs file-level upsert: the set of changed_files is automatically populated from the file field of every node added in the batch, and the server deletes ALL existing nodes in those files before inserting the new batch.

This is correct semantics for the per-file analyzer pipeline (Haskell JS analyzer re-emits a whole file's nodes when re-analyzing), but it's a trap for enrichers that ADD nodes to existing files (the typical pattern for post-resolution enrichment such as libraryCallbackEnricher.ts).

Context / Trigger Conditions

  • Writing a TypeScript enricher that runs post-resolution (after main analysis).
  • Enricher creates new domain nodes (e.g., cli:command, mcp:tool, http:route) with file: <some existing source file> so they're discoverable via find_nodes(file: X).
  • Uses client.createBatch() → batch.addNode(...) → batch.addEdge(...) → batch.commit().
  • After commit(): original CALL/FUNCTION/MODULE nodes in those files have disappeared.
  • Tests show pre-enrichment query returns N nodes; post-enrichment returns just the new domain nodes.

Solution

Use direct client.addNodes(...) and client.addEdges(...) calls instead of BatchHandle. These bypass the changed_files auto-population and don't trigger file-level deletion.

// ❌ WRONG — wipes existing nodes in the file
const batch = await client.createBatch();
batch.addNode({ id, type: 'cli:command', name, file: existingFile, ... });
batch.addEdge({ src: callId, dst: id, type: 'EXPOSES' });
batch.addEdge({ src: id, dst: handlerId, type: 'HANDLES' });
await batch.commit();   // ← DELETES original nodes in `existingFile`!

// ✅ RIGHT — append-only writes
await client.addNodes([
  { id, type: 'cli:command', name, file: existingFile, /* ... */ }
]);
await client.addEdges([
  { src: callId, dst: id, type: 'EXPOSES' },
  { src: id, dst: handlerId, type: 'HANDLES' }
]);

Trade-off: BatchHandle is more efficient (single round-trip) and atomic. The direct calls are safer for additive writes but split into multiple round-trips. For enrichers, correctness wins.

Verification

Write a regression test that:

  1. Creates a fixture graph with existing FUNCTION nodes in file X.
  2. Runs the enricher (which adds new domain nodes also tagged file: X).
  3. Asserts the original FUNCTION nodes still exist after enrichment.

Without the fix, this test fails with original count → 0 post-commit.

Example

From packages/util/src/enrichers/libraryCallbackEnricher.ts — the enricher appends cli:command/mcp:tool nodes to source files that already contain CALL nodes for the framework registration. Using BatchHandle.commit() during initial implementation wiped out the original CALL nodes that the enricher itself had just queried (they were referenced by EXPOSES/HANDLES edges, which then dangled).

Notes

  • This is distinct from rfdb-stale-node-cleanup (where cleanup is INCOMPLETE due to L1/index desync); here cleanup is COMPLETE and that's the problem.
  • The Haskell analyzer pipeline is unaffected because each per-file analyzer emits the WHOLE file's nodes — file-level upsert is desirable there.
  • The convention addNodes/addEdges direct API exists for exactly this enricher use case. Search for it in the RFDBClient interface.
  • If you must use BatchHandle for atomicity, an alternative is to give enricher-emitted nodes a SYNTHETIC file path (e.g., __features/<name>) that doesn't collide with any source file. Mirrors how METRIC nodes use __grafema_perf/{phase}.

References

  • Discovery context: _ai/research/cognitive-debt-and-feature-detection.md Phase 4 enrichment pipeline
  • Implementation: packages/util/src/enrichers/libraryCallbackEnricher.ts
  • Server side: commit_batch handler in packages/rfdb-server/src/

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Fix Elixir/Erlang AST processing bugs in Grafema beam-analyzer. Use when: (1) Elixir parser returns MODULE node but 0 functions/calls — body nesting issue, (2) Erlang parser crashes with "cannot convert list to string" on OTP 26+ — location format changed from integer to keyword list, (3) pipe operator |> creates spurious CALL nodes instead of desugared function calls — clause ordering bug, (4) multi-module .ex files return only the first module — missing __block__ handler, (5) installing Erlang/Elixir on macOS with outdated Xcode/Clang.

日本語の概要は準備中です。原文の説明を表示しています。

Disentinel/grafema362026年8月24日 更新

Fires after fixing any non-trivial bug or regression. Asks: could the graph have caught this as a guarantee? Pairs with reflection-in-and-on-action — picks up after "earliest catchable signal" and asks the next question: was that signal expressible in graph? Triggers: (1) after any non-trivial bug fix is verified working, (2) after a regression report (something used to work, broke), (3) during step 6 (knowledge extraction) of the workflow, (4) when reflection-on-action surfaces a "would have been catchable" signal. Outcome is a triage decision (graph-reachable? rule expressible? rule sound?) and either a draft Linear issue + guarantee proposal, or a recorded "graph capability gap" note. Never auto-creates guarantees.

日本語の概要は準備中です。原文の説明を表示しています。

Disentinel/grafema362026年8月24日 更新

Fix Playwright automation failures against code-server (VS Code in browser). Use when: (1) trust dialog blocks all clicks — "monaco-dialog-modal-block intercepts pointer events", (2) button:has-text() finds wrong buttons behind modal dialog, (3) keyboard shortcuts don't work — Meta vs Control inconsistency, (4) VS Code extension activity bar icon not found by aria-label, (5) panels show placeholder text despite extension being "Connected". Covers trust dialog dismissal, keyboard shortcut hybrid mode, extension panel selectors, and database connection verification for Grafema extension.

日本語の概要は準備中です。原文の説明を表示しています。

Disentinel/grafema362026年8月24日 更新

Systematic methodology for achieving 100% backward dataflow reachability in a new language. Create gauntlet fixture, write trace, diagnose gaps, fix analyzer/algorithm, iterate to 100%. Language-agnostic process. Use when: (1) adding a new language to Grafema, (2) auditing dataflow coverage for existing language, (3) user says "/dataflow-gauntlet".

日本語の概要は準備中です。原文の説明を表示しています。

Disentinel/grafema362026年8月24日 更新

Fix docker exec hanging when starting background processes (servers, daemons) inside containers. Use when: (1) docker exec never returns despite using & or nohup, (2) background server started in container causes docker exec to hang indefinitely, (3) env_startup_command in SWE-bench or similar frameworks times out, (4) setsid/disown needed for proper process detachment in Docker. Root cause: docker exec tracks ALL processes in the exec session, not just the top-level PID.

日本語の概要は準備中です。原文の説明を表示しています。

Disentinel/grafema362026年8月24日 更新

Fix Node.js CLI tools crashing inside Docker containers when host-installed node_modules require a newer Node version than the container provides. Use when: (1) "SyntaxError: Invalid regular expression flags" with /v flag in string-width or similar packages, (2) node_modules installed on host with Node 20+ but container has Node 18, (3) `npm install` with file: protocol creates symlinks that break inside Docker, (4) pnpm workspace packages become broken symlinks in containers. Covers version detection, Node binary mounting, and npm install strategies for cross-version compatibility.

日本語の概要は準備中です。原文の説明を表示しています。

Disentinel/grafema362026年8月24日 更新

Disentinel のスキルをすべて見る

このスキルの問題を報告する