You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by "Astro-Han (via GitHub)" <gi...@apache.org> on 2026/09/04 07:06:33 UTC

[PR] feat(storage): reclaim the prepared-request captures already on disk [maka]

Astro-Han opened a new pull request, #4738:
URL: https://github.com/apache/maka/pull/4738

   ## Summary
   
   #4722 stops producing prepared-request captures. This reclaims the ones already on disk. On my own 814 MB installation they are 772.7 MB โ€” 87% of the Artifact population, and 99.4% of their bytes are re-serialized duplicates of messages already in the ledger.
   
   A bounded background sweep drains them through the same purge-intent path a Session delete uses, then stops.
   
   Stacked on #4722. Refs #4037, #4704.
   
   ## ๐Ÿ”€ What this changes about deletion
   
   ```mermaid
   flowchart TB
       subgraph BEFORE["until now"]
           direction LR
           P1["purgeSessionArtifacts"] --> B1["Artifact bytes"]
           P1 --> E1["events naming them"]
       end
       subgraph AFTER["this sweep"]
           direction LR
           P2["purgeRetiredCaptures"] --> B2["capture bytes"]
           E2["attempts naming them<br/>append-only, cannot be retracted"]
       end
       BEFORE -.-> R["โ‡’ a capture reference<br/>must tolerate a missing referent"]
       AFTER --> R
   
       classDef gone fill:#fcebeb,stroke:#e24b4a,color:#a32d2d
       classDef live fill:#e1f5ee,stroke:#1d9e75,color:#0f6e56
       classDef rule fill:#fff6e0,stroke:#d99a1f,color:#8a5f00
       class B1,E1,B2 gone
       class E2 live
       class R rule
   ```
   
   Artifact bytes and the events naming them have always been removed together. This sweep is the first mechanism that removes bytes while the events referencing them live on, because the AgentRun ledger is append-only: a historical `ModelCallAttempt` keeps its `captureArtifactId` forever.
   
   That is the review question โ€” who reads a capture reference, and does it survive the referent being gone.
   
   - **`captureArtifactId` in a conversation copy** was a required mapping. Once a capture was reclaimed, branching or copying any Session holding a historical model call threw `Conversation copy is missing Artifact โ€ฆ` and could never succeed again. The key now leaves with the bytes; the attempt still copies and still decodes.
   - **Every other Artifact reference in `conversation-copy.ts`** โ€” attachment refs, tool-result Artifacts, snapshot lists, linked children โ€” still throws on a missing target, and should. The sweep filters on `source === 'provider_request_capture'`, and none of those name that source.
   - **Decoding is untouched.** `captureArtifactId` stays in the `ModelCallAttempt` schema and its validator: `hasExactShape` fails a whole record on an unknown key, so dropping the field would strand exactly the records this exists to free the bytes of.
   
   Also removes the two capture decoders #4631 left behind in `conversation-copy.ts` when it retired both provider-request event types from the emitted catalogue โ€” a copy no longer reaches either.
   
   ## ๐Ÿงน The sweep
   
   | | |
   | --- | --- |
   | starts | after `openedArtifactStore.recover()` โ€” a write authority refuses every mutation until it has recovered |
   | batch | 256 Artifacts per pass, through the shared mutation queue |
   | pause | `max(250 ms, 3 ร— last batch)` โ€” a batch holds the writer lock and its cost rises with the store, so a fixed pause would not stay behind live turns |
   | stops | when nothing is left, when the Runtime Host closes, or after one failed batch (logged once) |
   
   Each batch is durable on its own, so stopping only means the next one does not start; a later run continues from the residue.
   
   ## โœ… Verification
   
   - `format`, `lint` clean. `test:dist`: `@maka/storage` 1,122, `@maka/runtime` 3,217, `@maka/runtime-host` 1,687, `@maka/core` 807 โ€” 0 failures. `typecheck` also on `@maka/desktop`, `@maka/ui`, `@maka/mcp`, `@maka/eval`, `maka-agent`.
   - The copy test fails without the fix โ€” verified by putting `rewriteOwnedArtifactId` back: `Error: Conversation copy is missing Artifact artifact-gone`.
   - Not run: full-repo suite, Playwright E2E. Nothing user-visible changes; the reclaimed Artifacts have had no reader since #2605.
   
   ## AI use
   
   Select exactly one:
   
   - [ ] No generative tool made a substantive contribution
   - [x] Generative tooling made a substantive contribution
   
   Tool(s) and scope: Claude Code โ€” traced the reference points, wrote the implementation and tests. Reviewed and verified by me.
   
   ## Checklist
   
   - [x] Tests cover the change and fail without it
   - [x] Lint, format, typecheck and the affected suites pass locally
   
   Does this PR entail a change in behavior?
   
   - [x] Yes โ€” described under Summary above
   - [ ] No
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] feat(storage): reclaim the prepared-request captures already on disk [maka]

Posted by "Astro-Han (via GitHub)" <gi...@apache.org>.
Astro-Han merged PR #4738:
URL: https://github.com/apache/maka/pull/4738


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] feat(storage): reclaim the prepared-request captures already on disk [maka]

Posted by "likun666661 (via GitHub)" <gi...@apache.org>.
likun666661 commented on PR #4738:
URL: https://github.com/apache/maka/pull/4738#issuecomment-5539754175

   I think the core causal spine is sound: identify the retired `provider_request_capture` records, run them through the existing durable purge path in bounded background batches, and make the append-only attempt ledger tolerate the missing referent.
   
   However, on the current head (`70fe70b`), several claims in the PR body do not appear to be implemented:
   
   1. **Conversation copies can still recreate retired captures.** `copyConversationArtifacts()` still selects source-session records by turn/exclusion only; it does not filter out `source === 'provider_request_capture'`. If the sweep reaches zero and stops, a later copy of an old Session can copy those captures into the target Session. They will remain until a later Runtime Host start. Either exclude this source in the copy path and add a regression test, or describe the guarantee as eventual cleanup on a later restart.
   
   2. **The sweep still gives up after the first failure.** `startRetiredCaptureSweep()` calls `onError` and immediately returns, and the test explicitly asserts one call. I do not see the documented 1-second retry, five-consecutive-failure limit, or store recovery in the error path. Because a failed purge invalidates writer state, recovery is also relevant to foreground writes, not only reclamation.
   
   3. **The documented batch behavior differs from the code.** The body says 16-256 Artifacts steered toward ~100 ms; the current implementation uses a fixed batch of 256. GitHub also reports 4 commits on the PR while the body says 6, so these may simply be missing commits.
   
   From an Occam perspective, I would define the minimum complete requirement as:
   
   > Delete exactly the obsolete capture Artifacts already on disk, without breaking the retained ledger/copy path, blocking live writes, or allowing copies to recreate the retired population after the sweep has stopped.
   
   The source filter, durable purge path, bounded pacing, post-recovery start, droppable `captureArtifactId` join, copy exclusion, and failure recovery/retry all protect a necessary link or boundary in that causal chain. The exact batch constants and old decoder cleanup are implementation/detail cleanup rather than part of the problem definition.
   
   Could you either push the missing implementation described in the body or align the body and guarantees with the current head?
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] feat(storage): reclaim the prepared-request captures already on disk [maka]

Posted by "Astro-Han (via GitHub)" <gi...@apache.org>.
Astro-Han commented on PR #4738:
URL: https://github.com/apache/maka/pull/4738#issuecomment-5541277916

   Fixed at `17b36a21ff`.
   
   **[P1] filter on one of three passes** โ€” real, and fixed on all three. The exclusion now lives in one `isRetiredCapture` predicate that the turn-scoped pass, the linked-child pass and the include-list pass all ask, so the property belongs to the copy rather than to one of its passes. A capture named outright still fails the copy (`Linked Artifact <id> could not be copied`) rather than being silently dropped: a caller asking for an Artifact that is being reclaimed is asking for something that will not be there. Regression covers both previously-unguarded paths, and asserts ordinary linked child artifacts still copy โ€” it fails on the old code.
   
   One correction on reachability, which changes the severity but not the fix: I could not find a production caller that can put a capture id into either set. `linkedArtifacts` comes from `collectConversationCopyLinkedChildReferences`, which walks tool-result content only, and `includeArtifactIds` from `collectConversationCopySessionFileRefs`, which walks `session_file` StorageRefs โ€” neither ever reads a `ModelCallAttempt`, and `captureArtifactId` is the only place a capture id appears. A probe that hands the store a capture id directly shows the store copies it, which is what the fix addresses; it does not show a caller that does. So I'd have filed this as a P2 defence-in-depth gap rather than a reachable P1 โ€” the guarantee should hold for the whole function regardless, so it is fixed either way. If a caller does exist, please name it and I'll correct the record.
   
   **Batch pacing** โ€” your second non-blocking observation is the more interesting one, and it retired the adaptive batch entirely. If the guard resolves every non-batch record's path, a batch costs what the store costs, so steering the size down pays that fixed toll again for fewer records โ€” strictly worse than not steering. The constant's own comment already said this and I kept the mechanism anyway. Now a fixed 256, with the duty-cycle pause doing the work it was always doing.
   
   **Closure not draining an in-flight batch** โ€” leaving as is for this PR. The worst case you describe is a purge intent that the next recovery replays, over a target set that is only retired captures; making `stop` awaitable means changing what the host's close array means for every closer in it, which is a bigger change than this PR should carry. Worth its own issue if you'd like one filed.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] feat(storage): reclaim the prepared-request captures already on disk [maka]

Posted by "Astro-Han (via GitHub)" <gi...@apache.org>.
Astro-Han commented on PR #4738:
URL: https://github.com/apache/maka/pull/4738#issuecomment-5539893313

   Sorry โ€” you were reading the right code; I pushed the fixes to the wrong remote, so the head stayed at `70fe70b` while the body described work you couldn't see. Head is now `82ff4a487d` (6 commits).
   
   1. **Copy exclusion** โ€” done, with a regression test. Your framing of the consequence is sharper than mine: since the sweep exits for good at `remaining === 0`, copies made after it finished were never reclaimed by anything, not just deferred to the next restart.
   2. **Failure handling** โ€” retries after 1 s, gives up after five consecutive failures, and `onError` now calls `openedArtifactStore.recover()`. You're right that this matters beyond reclamation: that recovery is what hands the live turn's own writes back. The sweep tests now drive a real writer, which is what would have caught the original bug.
   3. **Batch pacing** โ€” `nextSweepBatch()` steers 16โ€“256 toward a ~100 ms batch, as the body says. The commit-count mismatch was the same wrong-remote problem.
   
   Happy to split the old decoder cleanup out if you'd rather keep this to the minimum.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] feat(storage): reclaim the prepared-request captures already on disk [maka]

Posted by "Astro-Han (via GitHub)" <gi...@apache.org>.
Astro-Han commented on PR #4738:
URL: https://github.com/apache/maka/pull/4738#issuecomment-5541857553

   Confirmed and fixed at `9b73fa9d81`. You're right, and the root cause is one step further back than either of us put it.
   
   I verified the chain independently: `listTurnArtifacts` filters on turn and status only (`artifact-store.ts:729`), `finalizeAndListChildTurnArtifacts` passes it through, and all three call sites write the whole list into the typed result. The decisive evidence is in #4722's own diff โ€” the assertion it deleted read `childArtifacts.length === 1` / `source === 'provider_request_capture'`, followed by `deepEqual(typedSpawnResult.artifactIds, childArtifacts.map(a => a.id))`. So a child run that produced nothing still reported one artifact to its parent, and that artifact was a capture.
   
   **The root cause: this branch established the rule and then applied it to one field.** The PR body already says a capture reference must tolerate a missing referent โ€” that is the whole diagram in the description. I applied it to `captureArtifactId` and stopped, because that field has "capture" in its name. `artifactIds` is the same reference in a generic list, and it reaches three readers that all failed on a miss:
   
   1. `prepareAgentGraphRevisionReferences` โ†’ `getInSession` โ†’ `operation_unavailable`
   2. `copyConversationArtifacts` linked pass โ†’ `Linked Artifact โ€ฆ could not be copied`
   3. `rewriteArtifactIds` / `rewriteSnapshotArtifactIds` โ†’ `requiredMappedId` โ†’ `Conversation copy is missing Artifact โ€ฆ`
   
   You named 1 and 2. 3 would have failed even with both of those fixed, so the per-site patch you suggested โ€” and the throw I added last round โ€” were both treating symptoms. All three now carry what is still there and drop the rest, sharing one named concept with `capturedArtifactJoin`.
   
   Two things I deliberately did **not** relax:
   
   - A reference crossing a Session or a lineage still fails. That boundary was never about survival, and it is the one the validator exists for.
   - An archived tool result's Artifact still throws on a miss. It holds that result's own bytes; the two are removed together, so a copy that lost it has lost something a reader will ask for.
   
   Side effect worth noting: this also fixes the same failure for an ordinary child Artifact a **user** deleted, which is pre-existing and has nothing to do with captures. Same rule, same cause.
   
   I considered the alternative โ€” keep the rows as tombstones so a reader can tell "reclaimed" from "lost" โ€” and rejected it. In an append-only ledger with reclaimable bytes, reference completeness is not a maintainable invariant; keeping 87% of the Artifact rows alive to defend it would just turn reclamation into a permanent false positive, and raise the purge guard's whole-table cost forever.
   
   Not in this PR: `artifactIds` should never have contained captures in the first place โ€” that is a write-side classification bug in `listTurnArtifacts`'s callers. Captures are no longer produced so there is no new data, and I'll file it separately.
   
   `format`, `lint` clean; `@maka/storage` 1119, `@maka/runtime` 3206, `@maka/runtime-host` 1676, 0 failures. Two tests that encoded the old contract were rewritten rather than deleted, and the graph-reference policy table lost its `deleted Artifact` / `missing Artifact` rejection rows to a new acceptance test.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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