189 lines
5.5 KiB
Markdown
189 lines
5.5 KiB
Markdown
|
|
# 🔍 VFS Root Debugging Instructions
|
||
|
|
|
||
|
|
## Problem Summary
|
||
|
|
|
||
|
|
Despite 7 attempted fixes (v4.5.1 through v4.7.1), vfs.readdir('/') still returns empty even though:
|
||
|
|
- ✅ 600 document entities exist
|
||
|
|
- ✅ 608 Contains relationships exist
|
||
|
|
- ✅ 9 collection entities (directories) exist
|
||
|
|
|
||
|
|
## Root Cause Hypothesis
|
||
|
|
|
||
|
|
The VFS instance is likely using a **different root entity ID** than the actual root directory where files were imported. This would explain why:
|
||
|
|
- Import succeeds (creates files under the REAL root)
|
||
|
|
- getRelations() succeeds (relationships exist in database)
|
||
|
|
- But readdir('/') returns empty (VFS querying the WRONG root)
|
||
|
|
|
||
|
|
## Debug Script
|
||
|
|
|
||
|
|
I've created `debug-vfs-root.js` which will:
|
||
|
|
1. Show the root entity ID that VFS is using
|
||
|
|
2. List ALL collection entities (directories) in the database
|
||
|
|
3. For each directory, count outgoing Contains relationships
|
||
|
|
4. Identify which directory is the VFS root and whether it has children
|
||
|
|
|
||
|
|
## How to Run
|
||
|
|
|
||
|
|
```bash
|
||
|
|
# Make sure you're using v4.7.1
|
||
|
|
$ cd /path/to/brainy/project
|
||
|
|
|
||
|
|
# Copy the debug script to your Brainy installation
|
||
|
|
$ cp /media/dpsifr/storage/home/Projects/brainy/debug-vfs-root.js .
|
||
|
|
|
||
|
|
# Run it with your FileSystemStorage database
|
||
|
|
$ node debug-vfs-root.js
|
||
|
|
```
|
||
|
|
|
||
|
|
## Expected Output
|
||
|
|
|
||
|
|
The script will show:
|
||
|
|
```
|
||
|
|
🔍 VFS Root Debugging Script
|
||
|
|
============================================================
|
||
|
|
✅ Brainy initialized
|
||
|
|
|
||
|
|
✅ VFS instance created
|
||
|
|
|
||
|
|
📍 VFS Root Entity ID: abc123-xyz...
|
||
|
|
|
||
|
|
✅ Root entity EXISTS in database:
|
||
|
|
Type: collection
|
||
|
|
Path: /
|
||
|
|
VFS Type: directory
|
||
|
|
Created: 2025-10-27T16:45:00.000Z
|
||
|
|
|
||
|
|
🔍 Finding ALL collection entities (directories)...
|
||
|
|
Found 9 collection entities:
|
||
|
|
|
||
|
|
👑 ID: abc123-xyz...
|
||
|
|
Path: /
|
||
|
|
VFS Type: directory
|
||
|
|
Created: 2025-10-27T16:45:00.000Z
|
||
|
|
✅ THIS IS THE VFS ROOT
|
||
|
|
|
||
|
|
ID: def456-uvw...
|
||
|
|
Path: /Characters
|
||
|
|
VFS Type: directory
|
||
|
|
Created: 2025-10-27T16:46:00.000Z
|
||
|
|
|
||
|
|
[... 7 more directories ...]
|
||
|
|
|
||
|
|
🔍 Checking Contains relationships FROM each collection...
|
||
|
|
|
||
|
|
Collection abc123-xyz...:
|
||
|
|
Path: /
|
||
|
|
Outgoing Contains: 8
|
||
|
|
✅ THIS IS THE VFS ROOT - should return 8 items for readdir('/')
|
||
|
|
|
||
|
|
Collection def456-uvw...:
|
||
|
|
Path: /Characters
|
||
|
|
Outgoing Contains: 127
|
||
|
|
|
||
|
|
[... more directories ...]
|
||
|
|
|
||
|
|
🔍 Counting ALL Contains relationships in database...
|
||
|
|
Total Contains relationships: 608
|
||
|
|
|
||
|
|
📋 Sample Contains relationships (first 10):
|
||
|
|
1. abc123-xyz... -> def456-uvw...
|
||
|
|
From: / (directory)
|
||
|
|
To: /Characters (directory)
|
||
|
|
|
||
|
|
2. def456-uvw... -> ghi789-rst...
|
||
|
|
From: /Characters (directory)
|
||
|
|
To: /Characters/entity-001.json (file)
|
||
|
|
|
||
|
|
[... more samples ...]
|
||
|
|
|
||
|
|
============================================================
|
||
|
|
🏁 Debug Complete
|
||
|
|
```
|
||
|
|
|
||
|
|
## What to Look For
|
||
|
|
|
||
|
|
### ✅ Good Case (VFS Working)
|
||
|
|
```
|
||
|
|
📍 VFS Root Entity ID: abc123-xyz...
|
||
|
|
✅ Root entity EXISTS in database
|
||
|
|
Collection abc123-xyz...:
|
||
|
|
Path: /
|
||
|
|
Outgoing Contains: 8 👈 NON-ZERO!
|
||
|
|
✅ THIS IS THE VFS ROOT
|
||
|
|
```
|
||
|
|
|
||
|
|
### ❌ Bad Case #1: VFS Using Wrong Root
|
||
|
|
```
|
||
|
|
📍 VFS Root Entity ID: xxx000-yyy...
|
||
|
|
✅ Root entity EXISTS in database
|
||
|
|
Collection xxx000-yyy...:
|
||
|
|
Path: /
|
||
|
|
Outgoing Contains: 0 👈 ZERO! This is the bug!
|
||
|
|
✅ THIS IS THE VFS ROOT
|
||
|
|
|
||
|
|
Collection abc123-zzz...:
|
||
|
|
Path: /
|
||
|
|
Outgoing Contains: 8 👈 Files are under THIS root instead!
|
||
|
|
```
|
||
|
|
|
||
|
|
### ❌ Bad Case #2: VFS Root Doesn't Exist
|
||
|
|
```
|
||
|
|
📍 VFS Root Entity ID: xxx000-yyy...
|
||
|
|
❌ Root entity DOES NOT EXIST in database!
|
||
|
|
This is the bug! VFS is using a root ID that doesn't exist.
|
||
|
|
```
|
||
|
|
|
||
|
|
### ❌ Bad Case #3: Root Has No Children
|
||
|
|
```
|
||
|
|
📍 VFS Root Entity ID: abc123-xyz...
|
||
|
|
✅ Root entity EXISTS in database
|
||
|
|
Collection abc123-xyz...:
|
||
|
|
Path: /
|
||
|
|
Outgoing Contains: 0 👈 ZERO! Files aren't under root!
|
||
|
|
✅ THIS IS THE VFS ROOT
|
||
|
|
|
||
|
|
[All other collections have Contains relationships, but NOT from root]
|
||
|
|
```
|
||
|
|
|
||
|
|
## What This Tells Us
|
||
|
|
|
||
|
|
Based on the output, we can determine:
|
||
|
|
|
||
|
|
1. **If "Outgoing Contains: 0" for VFS root**: The VFS is querying the correct root, but that root has no children. This means files were created under a DIFFERENT root or weren't properly linked.
|
||
|
|
|
||
|
|
2. **If multiple "/" paths exist**: There are duplicate root entities. VFS is using one root, but files are under a different root.
|
||
|
|
|
||
|
|
3. **If "Root entity DOES NOT EXIST"**: VFS is using a stale/wrong entity ID that was deleted or never existed.
|
||
|
|
|
||
|
|
4. **If "Outgoing Contains: 8"**: VFS root HAS children! This means my v4.7.1 fix has another bug - the optimization isn't being triggered or has a logic error.
|
||
|
|
|
||
|
|
## Next Steps
|
||
|
|
|
||
|
|
Please run this script and send me the full output. Based on what we see, I'll know exactly how to fix the real bug!
|
||
|
|
|
||
|
|
## Architecture Notes
|
||
|
|
|
||
|
|
The VFS query flow is:
|
||
|
|
```
|
||
|
|
vfs.readdir('/')
|
||
|
|
-> PathResolver.resolve('/')
|
||
|
|
-> returns this.rootEntityId
|
||
|
|
-> PathResolver.getChildren(rootEntityId)
|
||
|
|
-> brain.getRelations({ from: rootEntityId, type: VerbType.Contains })
|
||
|
|
-> brainy.ts builds filter
|
||
|
|
-> storage.getVerbs({ filter: { sourceId: rootEntityId, verbType } })
|
||
|
|
-> MY v4.7.1 FIX: Check if sourceId + verbType filters exist
|
||
|
|
-> If YES: Call getVerbsBySource_internal(rootEntityId)
|
||
|
|
-> Get verbs from graph adjacency index
|
||
|
|
-> Filter by verbType
|
||
|
|
-> Return Contains relationships
|
||
|
|
```
|
||
|
|
|
||
|
|
If the debug shows "Outgoing Contains: 0" for the VFS root, then either:
|
||
|
|
- A. getVerbsBySource_internal() is broken
|
||
|
|
- B. The graph adjacency index isn't being populated
|
||
|
|
- C. My v4.7.1 optimization has a bug and isn't being called
|
||
|
|
- D. The rootEntityId is wrong
|
||
|
|
|
||
|
|
This script will tell us which one!
|