You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by as...@apache.org on 2026/09/04 11:05:18 UTC

(maka) 01/02: fix(storage): stop conversation copies from reintroducing retired captures

This is an automated email from the ASF dual-hosted git repository.

Astro-Han pushed a commit to branch feat/reclaim-retired-provider-request-captures
in repository https://gitbox.apache.org/repos/asf/maka.git

commit a8f3087fb53809117fe569c497853ae936914e89
Author: AstroHan <le...@outlook.com>
AuthorDate: Fri Sep 4 19:05:00 2026 +0800

    fix(storage): stop conversation copies from reintroducing retired captures
    
    A fork copied every Artifact of the source Session, retired provider-request
    captures included. That put condemned bytes back into a new Session -- and
    because the sweep stops for good once it sees an empty residue, anything
    copied after it finished was never reclaimed at all, which is the whole point
    of retiring them. It also let the copy and the sweep race over the same
    record.
    
    The copy now leaves that source out, which is also the only source a reader
    never asks for.
    
    Generated-by: Claude Code
---
 .../storage/src/__tests__/artifact-store.test.ts   | 32 ++++++++++++++++++++++
 packages/storage/src/artifact-store.ts             | 10 +++++--
 2 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/packages/storage/src/__tests__/artifact-store.test.ts b/packages/storage/src/__tests__/artifact-store.test.ts
index aafd71d204..f60dbb5193 100644
--- a/packages/storage/src/__tests__/artifact-store.test.ts
+++ b/packages/storage/src/__tests__/artifact-store.test.ts
@@ -322,6 +322,38 @@ describe('SQLite Artifact store', () => {
     });
   });
 
+  test('a conversation copy leaves retired captures behind rather than reintroducing them', async () => {
+    await withWorkspace(async (root) => {
+      const authority = createArtifactStoreWriteAuthority(root);
+      await authority.recover();
+      const { store } = authority;
+      const kept = await store.create(artifactInput('kept-artifact', 'kept', 10));
+      await store.create({
+        ...artifactInput('capture-artifact', 'request', 11),
+        source: 'provider_request_capture',
+      });
+
+      const copied = await store.copyConversationArtifacts({
+        sourceSessionId: 'session-1',
+        targetSessionId: 'session-copy',
+        turnIds: ['turn-1'],
+      });
+
+      // The sweep runs once and stops when nothing is left. A copy that
+      // carried captures would put them back afterwards, so every fork would
+      // hand the new Session a fresh set of bytes nobody reads and nothing
+      // will come back for.
+      assert.equal(copied.artifactIds.get('capture-artifact'), undefined);
+      assert.ok(copied.artifactIds.get(kept.id));
+      assert.deepEqual(
+        (await store.list('session-copy', { includeDeleted: true })).map((record) => record.source),
+        ['fixture'],
+      );
+      // And the source keeps its own until the sweep takes them.
+      assert.deepEqual(await store.purgeRetiredCaptures(8), { purged: 1, remaining: 0 });
+    });
+  });
+
   test('reclaims retired request captures in bounded batches and leaves everything else', async () => {
     await withWorkspace(async (root) => {
       const authority = createArtifactStoreWriteAuthority(root);
diff --git a/packages/storage/src/artifact-store.ts b/packages/storage/src/artifact-store.ts
index 23e22cc08d..8c1513b2a6 100644
--- a/packages/storage/src/artifact-store.ts
+++ b/packages/storage/src/artifact-store.ts
@@ -428,7 +428,13 @@ class SqliteArtifactStore implements ArtifactAuthorityStore {
           (record) =>
             record.sessionId === input.sourceSessionId &&
             turnIds.has(record.turnId) &&
-            !excludedArtifactIds.has(record.id),
+            !excludedArtifactIds.has(record.id) &&
+            // A retired capture is on its way off disk and nothing reads one.
+            // Copying it would hand the new Session bytes already condemned,
+            // and would put records back after the sweep finished and stopped
+            // looking. Leaving them out also keeps the two from racing: the
+            // sweep can no longer delete a record this copy is holding.
+            record.source !== RETIRED_CAPTURE_ARTIFACT_SOURCE,
         )
         .map((record) => ({ ...record }));
       for (const [sessionId, artifactIds] of requestedLinkedArtifactIds) {
@@ -912,7 +918,7 @@ class SqliteArtifactStore implements ArtifactAuthorityStore {
       const retired = this.records.filter(
         (record) => record.source === RETIRED_CAPTURE_ARTIFACT_SOURCE,
       );
-      const batch = retired.slice(0, Math.max(0, limit));
+      const batch = retired.slice(0, limit);
       await this.purgeRecordsUnlocked(batch);
       outcome = { purged: batch.length, remaining: retired.length - batch.length };
     });


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org