You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/engram-cloud/troubleshooting.md
+4-3Lines changed: 4 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -103,7 +103,7 @@ You may also see the failure only during the final server push, even after `doct
103
103
write chunk: cloud: push chunk ...: status 400: invalid push payload: sessions[N].directory is required
104
104
```
105
105
106
-
It means a historical `session` mutation in `sync_mutations` is missing `directory`, a local `sessions` row for the project still has an empty/null `directory`, or a historical `observation` mutation is missing one of the required upsert fields: `sync_id`, `session_id`, `type`, `title`, `content`, or `scope`. Newer Engram versions write these fields correctly, but old journal rows or local session rows may still need repair before first cloud upload.
106
+
It means a historical `session` mutation in `sync_mutations` is missing `directory`, a local `sessions` row included in the project export still has an empty/null `directory`, or a historical `observation` mutation is missing one of the required upsert fields: `sync_id`, `session_id`, `type`, `title`, `content`, or `scope`. Newer Engram versions write these fields correctly, but old journal rows or local session rows may still need repair before first cloud upload.
107
107
108
108
### Safe path: helper script
109
109
@@ -144,7 +144,7 @@ If doctor reveals another legacy blocker after each repair, use loop mode after
Loop mode repairs exactly one supported blocker (`entity=session|observation op=upsert`), reruns `engram cloud upgrade doctor --project <project>`, then repeats until doctor no longer reports a supported blocker. If doctor reports ready but local `sessions` rows for the project still have empty/null `directory`, loop mode applies that fallback repair and reruns doctor once more. It still stops on unsupported blockers, project mismatches, or observation payloads that cannot be fully inferred. In non-interactive loop mode, rerun with `--interactive` when the script asks for human-provided observation fields.
147
+
Loop mode repairs exactly one supported blocker (`entity=session|observation op=upsert`), reruns `engram cloud upgrade doctor --project <project>`, then repeats until doctor no longer reports a supported blocker. If doctor reports ready but local `sessions` rows included in the project export still have empty/null `directory`, loop mode applies that fallback repair and reruns doctor once more. It still stops on unsupported blockers, project mismatches, or observation payloads that cannot be fully inferred. In non-interactive loop mode, rerun with `--interactive` when the script asks for human-provided observation fields.
148
148
149
149
If one-shot mode finds no doctor blocker but reports local sessions with empty/null directory, preview and apply the fallback explicitly:
150
150
@@ -176,7 +176,7 @@ For session repairs, the script patches one legacy row in `sync_mutations` by ad
176
176
"directory": "/absolute/path/to/project"
177
177
```
178
178
179
-
It also updates `sessions.directory` only when the matching session row exists and its directory is empty. In the fallback path for `sessions[N].directory is required`, it updates only local `sessions` rows for the requested project where `directory IS NULL OR directory = ''`; it does not modify `sync_mutations`.
179
+
It also updates `sessions.directory` only when the matching session row exists and its directory is empty. In the fallback path for `sessions[N].directory is required`, it updates only local `sessions` rows included in the requested project export scope where `directory IS NULL OR directory = ''`; it does not modify `sync_mutations`.
180
180
181
181
For observation repairs, the script reads the authoritative local row from `observations` using `payload.sync_id` or `entity_key`, then fills only missing or empty fields in the mutation payload:
182
182
@@ -252,6 +252,7 @@ If you want to inspect before using the helper:
252
252
sqlite3 ~/.engram/engram.db "select seq, entity, op, entity_key, payload from sync_mutations where seq = 873;"
253
253
sqlite3 ~/.engram/engram.db "select id, project, directory from sessions where id = 'manual-save-current';"
254
254
sqlite3 ~/.engram/engram.db "select id, project, started_at, directory from sessions where project = '<project>' and (directory is null or directory = '');"
255
+
sqlite3 ~/.engram/engram.db "select s.id, s.project, s.started_at, s.directory from sessions s where (s.directory is null or s.directory = '') and (s.project = '<project>' or s.id in (select session_id from observations where ifnull(project, '') = '<project>' union select session_id from user_prompts where ifnull(project, '') = '<project>'));"
Copy file name to clipboardExpand all lines: tools/repair-missing-session-directory.sh
+41-10Lines changed: 41 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -284,28 +284,50 @@ empty_session_count() {
284
284
printf'0\n'
285
285
return 0
286
286
fi
287
+
scope_predicate=$(empty_session_scope_predicate)
288
+
sqlite_scalar "SELECT COUNT(*) FROM sessions WHERE ifnull(directory, '') = '' AND $scope_predicate;"
289
+
}
290
+
291
+
empty_session_scope_predicate() {
287
292
PROJECT_SQL=$(sql_escape "$PROJECT")
288
-
sqlite_scalar "SELECT COUNT(*) FROM sessions WHERE project = '$PROJECT_SQL' AND ifnull(directory, '') = '';"
293
+
predicate="(project = '$PROJECT_SQL'"
294
+
295
+
if have_table observations;then
296
+
predicate="$predicate OR id IN (
297
+
SELECT session_id FROM observations
298
+
WHERE ifnull(project, '') = '$PROJECT_SQL'
299
+
OR (ifnull(project, '') = '' AND session_id IN (SELECT id FROM sessions WHERE project = '$PROJECT_SQL'))
300
+
)"
301
+
fi
302
+
303
+
if have_table user_prompts;then
304
+
predicate="$predicate OR id IN (
305
+
SELECT session_id FROM user_prompts
306
+
WHERE ifnull(project, '') = '$PROJECT_SQL'
307
+
OR (ifnull(project, '') = '' AND session_id IN (SELECT id FROM sessions WHERE project = '$PROJECT_SQL'))
308
+
)"
309
+
fi
310
+
311
+
printf'%s\n'"$predicate)"
289
312
}
290
313
291
314
preview_empty_sessions() {
292
-
PROJECT_SQL=$(sql_escape "$PROJECT")
315
+
scope_predicate=$(empty_session_scope_predicate)
293
316
info "Affected local sessions:"
294
317
if have_column sessions started_at;then
295
-
sqlite_box "SELECT id, project, started_at, ifnull(directory, '') AS directory FROM sessions WHERE project = '$PROJECT_SQL' AND ifnull(directory, '') = '' ORDER BY ifnull(started_at, ''), id;"||true
318
+
sqlite_box "SELECT id, project, started_at, ifnull(directory, '') AS directory FROM sessions WHERE ifnull(directory, '') = '' AND $scope_predicate ORDER BY ifnull(started_at, ''), id;"||true
296
319
else
297
-
sqlite_box "SELECT id, project, ifnull(directory, '') AS directory FROM sessions WHERE project = '$PROJECT_SQL' AND ifnull(directory, '') = '' ORDER BY id;"||true
320
+
sqlite_box "SELECT id, project, ifnull(directory, '') AS directory FROM sessions WHERE ifnull(directory, '') = '' AND $scope_predicate ORDER BY id;"||true
298
321
fi
299
322
}
300
323
301
324
repair_empty_sessions() {
302
325
have_table sessions || die "sessions table not found in DB: $DB"
303
-
PROJECT_SQL=$(sql_escape "$PROJECT")
304
326
missing_count=$(empty_session_count)
305
327
306
328
if [ "$missing_count"="0" ];then
307
-
info "No local sessions with empty/null directory found for project '$PROJECT'."
308
-
return1
329
+
info "No local sessions in project export scope with empty/null directory found for project '$PROJECT'."
info "No supported sync_mutations blocker found, but $missing_count local session row(s) for project '$PROJECT' have empty/null directory."
377
+
info "No supported sync_mutations blocker found, but $missing_count local session row(s) in project export scope for '$PROJECT' have empty/null directory."
355
378
if [ "$FIX_EMPTY_SESSIONS"-eq 1 ] || [ "$ALL"-eq 1 ];then
0 commit comments