feat(graph): two-mode session deletion — the first destructive ledger operation
DELETE /api/chats/[id]?mode=preserve-graph|delete-nodes (mode required): - preserve-graph: only extraction bookkeeping dies (coverage rows, legacy checkpoints) — graph ledgers byte-untouched - delete-nodes: the chat's ledger traces die. Node survival = surviving provenance point / mapping line (notes imports carry empty provenance) / surviving event. The creator's aliases + provenance are stripped from a surviving node's create line (owner ruling 2026-09-23: name/statement/createdAt are the shared identity); orphan nodes, their edges, events, mappings, positions, embedding vectors and cluster members die; cluster labels stay (immutable) Gates: 404 unknown, 409 turn_in_flight / jobs_running (with jobIds), 503 extraction_winding_down after a 10s abort-and-poll; the purge is one sync block (ledgers → jobs → chat record last). rewriteLedgers is atomic (tmp + rename). graphRevision (max mtime over graph data files) rides the activity feed + the response as the change stamp. Anti-resurrection: the chat pipeline re-checks chat liveness at each merge — a run that slips past the wind-down aborts with nothing merged or checkpointed; its partial spend dies with the chat.
This commit is contained in:
@@ -79,10 +79,28 @@ function findJobByToolCallId(chatId: string, toolCallId: string): JobRecord | nu
|
||||
return listJobs(chatId).find((j) => j.toolCallId === toolCallId) ?? null;
|
||||
}
|
||||
|
||||
/** Delete every job record file for a chat (session-deletion wave 6) —
|
||||
* running or finished, they are the chat's records and die with it.
|
||||
* Returns how many files were removed. The deletion route refuses while
|
||||
* jobs are still running, so every record here is terminal. */
|
||||
function deleteJobsForChat(chatId: string): number {
|
||||
let removed = 0;
|
||||
for (const job of listJobs(chatId)) {
|
||||
try {
|
||||
fs.unlinkSync(jobFile(job.id));
|
||||
removed++;
|
||||
} catch {
|
||||
/* already gone — the count is best-effort truth */
|
||||
}
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
|
||||
export const jobStore: JobStore = {
|
||||
createJob,
|
||||
getJob,
|
||||
updateJob,
|
||||
listJobs,
|
||||
findJobByToolCallId,
|
||||
deleteJobsForChat,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user