[GH-ISSUE #5253] [Engine] conversation cache: an opt-in store seam that hands out file descriptors #3125

Open
opened 2026-11-07 14:38:16 +07:00 by bsakaguchi · 4 comments
Owner

Originally created by @G0-0000 on GitHub (Nov 4, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/5253

What

I would like to agree the scope of a narrow seam in the conversation cache before writing any code.

Today ConversationStore (the artifact-level layer under the disk cache) maps a cache name to a local path. A store that cannot hand out its own file has to materialise a temporary copy, which costs one full write and one full read of the snapshot. That is fine for a test backend and expensive for anything else.

Proposal: add three opt-in methods to the store.

  • lease_read(name) returns an open descriptor (passed with SCM_RIGHTS) and a lease that covers the whole read: both passes of the session file and the delta chain.
  • stage_write(name) and stage_append(name, committed) return a descriptor that the existing writer fills.
  • commit_write(name, bytes) performs the rename and the directory flush.

The local store implements them with the calls it already makes. A store that does not implement them falls back to today's path and materialize. Defaults do not change and the default path stays byte-identical.

Why

#4226 and #1937 are two disk-cache designs, and #3485 measures another layout. A user who wants a different medium or a different eviction policy currently has to patch the engine and rebuild it.

A descriptor-based seam lets one external process own placement, eviction and accounting while the engine keeps the byte path: the same O_DIRECT reads and writes, with no copy through another process.

It also gives deletion the lifetime it needs. The reader opens the file twice (a validate pass and an apply pass) and reopens it for every delta record, so unlink is only safe when a lease covers the whole operation, not a single descriptor.

Non-goals

  • No change to the session-file format, the identity fingerprints, or the recompute gate.
  • No new default; the seam is opt-in and the local store behaves exactly as today.
  • No plugin ABI and no dynamic loading; the external process talks over a Unix socket.
  • POSIX-first: SCM_RIGHTS is POSIX-only, so an external store is a POSIX capability from day one. Windows keeps the local store and today's path; DuplicateHandle over a named pipe is a different mechanism and stays out of scope.

Question

Is a three-commit, opt-in PR in scope?

  1. Store methods with the local fallback and no behaviour change.
  2. RawFile adopting an external descriptor, plus the fd read entry points.
  3. The fd write path and the Publisher split into stage and commit.

If yes, should the protocol details live here or in a separate issue?

Environment

Tesla V100-SXM2 32 GB · 128 GB RAM · Ubuntu Linux · engine 0.1.56.30 (app 0.2.10). This is the machine the disk cache in #4226 was measured on.

Originally created by @G0-0000 on GitHub (Nov 4, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/5253 **What** I would like to agree the scope of a narrow seam in the conversation cache before writing any code. Today `ConversationStore` (the artifact-level layer under the disk cache) maps a cache name to a local path. A store that cannot hand out its own file has to materialise a temporary copy, which costs one full write and one full read of the snapshot. That is fine for a test backend and expensive for anything else. Proposal: add three opt-in methods to the store. - `lease_read(name)` returns an open descriptor (passed with SCM_RIGHTS) and a lease that covers the whole read: both passes of the session file and the delta chain. - `stage_write(name)` and `stage_append(name, committed)` return a descriptor that the existing writer fills. - `commit_write(name, bytes)` performs the rename and the directory flush. The local store implements them with the calls it already makes. A store that does not implement them falls back to today's path and `materialize`. Defaults do not change and the default path stays byte-identical. **Why** [#4226](https://github.com/Niko1221/Strata/pull/4226) and #1937 are two disk-cache designs, and #3485 measures another layout. A user who wants a different medium or a different eviction policy currently has to patch the engine and rebuild it. A descriptor-based seam lets one external process own placement, eviction and accounting while the engine keeps the byte path: the same O_DIRECT reads and writes, with no copy through another process. It also gives deletion the lifetime it needs. The reader opens the file twice (a validate pass and an apply pass) and reopens it for every delta record, so `unlink` is only safe when a lease covers the whole operation, not a single descriptor. **Non-goals** - No change to the session-file format, the identity fingerprints, or the recompute gate. - No new default; the seam is opt-in and the local store behaves exactly as today. - No plugin ABI and no dynamic loading; the external process talks over a Unix socket. - POSIX-first: `SCM_RIGHTS` is POSIX-only, so an external store is a POSIX capability from day one. Windows keeps the local store and today's path; `DuplicateHandle` over a named pipe is a different mechanism and stays out of scope. **Question** Is a three-commit, opt-in PR in scope? 1. Store methods with the local fallback and no behaviour change. 2. `RawFile` adopting an external descriptor, plus the fd read entry points. 3. The fd write path and the `Publisher` split into stage and commit. If yes, should the protocol details live here or in a separate issue? **Environment** Tesla V100-SXM2 32 GB · 128 GB RAM · Ubuntu Linux · engine 0.1.56.30 (app 0.2.10). This is the machine the disk cache in [#4226](https://github.com/Niko1221/Strata/pull/4226) was measured on.
Author
Owner

@github-actions[bot] commented on GitHub (Nov 4, 2026):

Thanks for the issue. To keep the tracker readable, every item needs an area prefix in the title and the parts of the issue form filled in. This one is missing:

  • Add your graphics card with its VRAM, your RAM and your operating system.

Edit the issue (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment /reopen.

Details: CONTRIBUTING.md

<!-- gh-comment-id:6643696321 --> @github-actions[bot] commented on GitHub (Nov 4, 2026): Thanks for the issue. To keep the tracker readable, every item needs an area prefix in the title and the parts of the issue form filled in. This one is missing: - [ ] Add your graphics card with its VRAM, your RAM and your operating system. Edit the issue (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment `/reopen`. Details: [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md)
Author
Owner

@udqe commented on GitHub (Nov 5, 2026):

A user-side yes to the scope question, with two of your claims confirmed from the running engine's side and one cross-OS wrinkle worth a line in the scope doc before anyone codes.

The numbers your seam would move are real on a production box. Windows 11, 2x RTX 4090, 128 GB RAM, engine 0.1.56, conversation cache 12 GiB in 4 slots. Today's boot logged, verbatim: conversation cache: parked 176099 tokens in 2022.1 ms; parked=1 bytes=3524505280 evictions=0 - a single conversation park is 3.3 GiB of snapshot and two seconds of write; the second park added another 3.6 GiB (cumulative 7,364,180,760 bytes) - and then the eviction path fired for real: conversation cache: evicted 1 parked conversation to admit this snapshot (3301 MiB plus 2560 MiB floor). So the two things your issue makes extensible - the materialize double-copy and the eviction policy - are exactly the two that cost us real bytes and real seconds at ordinary chat sizes. A seam where an external process owns placement and eviction without a copy through it is a feature this user would switch on.

Your lifetime argument matches the code as shipped. The RawFile/Publisher pair in src/core/conversation_file.cpp exists in exactly the two platform shapes your design implies (the Windows Publisher at :277 with its DeleteFileW temp cleanup, the POSIX one at :465), and the O_DIRECT your byte path relies on is not even a fixed open flag - it is switched onto the open descriptor via fcntl with a fall back to buffered I/O when the filesystem refuses (:443-452). Which is to say: an external store handing you an already-open descriptor is compatible with how the reader actually behaves (it wants an fd, a path is just how it currently gets one), and your lease-over-the-whole-operation requirement is the right shape - the reopen-per-delta pattern means a per-descriptor lease is not a lease.

The wrinkle: SCM_RIGHTS is POSIX-only, and one meaningful slice of conversation-cache production is Windows (this box among them, judging by the tracker's reports). Your opt-in framing makes Windows SAFE - the local store keeps its current path and the default is byte-identical - but the external-store capability would be POSIX from day one, since Windows fd passing is DuplicateHandle over a named pipe, a genuinely different mechanism. That is not an argument against the seam; it is an argument for one sentence in the Non-goals saying the protocol is POSIX-first, so a reviewer is not left wondering whether the Windows Publisher was forgotten when it was deliberately left alone.

On your three questions: yes, the commit split reads in the right order (fallback-first, then the fd read entry points, then the write path - each commit reviewable with the default path untouched), and keep the protocol in this issue until commit 3, then summarize the final wire format in that PR's body so the review trail stays in one place.

Housekeeping from someone who has lived with that bot: your issue is missing the machine-spec field and the auto-note says it closes in five days - edit the description and it goes away on its own; this is exactly the kind of thread the tracker cannot afford to lose to a template.

Scope note: I am a user, not a reviewer - my checks here are code-reading of the shipped tree (main at 2026-11-03) and my own engine's log; I have not built or run your seam because it does not exist yet, which is rather the point of the issue.

(ai-assisted; our quoted lines from production boot 2026-11-04 14:36, protocol disclosed in the #3976/#5031 footers)

<!-- gh-comment-id:6647150399 --> @udqe commented on GitHub (Nov 5, 2026): A user-side yes to the scope question, with two of your claims confirmed from the running engine's side and one cross-OS wrinkle worth a line in the scope doc before anyone codes. **The numbers your seam would move are real on a production box.** Windows 11, 2x RTX 4090, 128 GB RAM, engine 0.1.56, conversation cache 12 GiB in 4 slots. Today's boot logged, verbatim: `conversation cache: parked 176099 tokens in 2022.1 ms; parked=1 bytes=3524505280 evictions=0` - a single conversation park is 3.3 GiB of snapshot and two seconds of write; the second park added another 3.6 GiB (cumulative 7,364,180,760 bytes) - and then the eviction path fired for real: `conversation cache: evicted 1 parked conversation to admit this snapshot (3301 MiB plus 2560 MiB floor)`. So the two things your issue makes extensible - the materialize double-copy and the eviction policy - are exactly the two that cost us real bytes and real seconds at ordinary chat sizes. A seam where an external process owns placement and eviction without a copy through it is a feature this user would switch on. **Your lifetime argument matches the code as shipped.** The `RawFile`/`Publisher` pair in `src/core/conversation_file.cpp` exists in exactly the two platform shapes your design implies (the Windows `Publisher` at :277 with its `DeleteFileW` temp cleanup, the POSIX one at :465), and the O_DIRECT your byte path relies on is not even a fixed open flag - it is switched onto the open descriptor via `fcntl` with a fall back to buffered I/O when the filesystem refuses (:443-452). Which is to say: an external store handing you an already-open descriptor is compatible with how the reader actually behaves (it wants an fd, a path is just how it currently gets one), and your lease-over-the-whole-operation requirement is the right shape - the reopen-per-delta pattern means a per-descriptor lease is not a lease. **The wrinkle: SCM_RIGHTS is POSIX-only, and one meaningful slice of conversation-cache production is Windows** (this box among them, judging by the tracker's reports). Your opt-in framing makes Windows SAFE - the local store keeps its current path and the default is byte-identical - but the external-store capability would be POSIX from day one, since Windows fd passing is `DuplicateHandle` over a named pipe, a genuinely different mechanism. That is not an argument against the seam; it is an argument for one sentence in the Non-goals saying the protocol is POSIX-first, so a reviewer is not left wondering whether the Windows `Publisher` was forgotten when it was deliberately left alone. On your three questions: yes, the commit split reads in the right order (fallback-first, then the fd read entry points, then the write path - each commit reviewable with the default path untouched), and keep the protocol in this issue until commit 3, then summarize the final wire format in that PR's body so the review trail stays in one place. Housekeeping from someone who has lived with that bot: your issue is missing the machine-spec field and the auto-note says it closes in five days - edit the description and it goes away on its own; this is exactly the kind of thread the tracker cannot afford to lose to a template. Scope note: I am a user, not a reviewer - my checks here are code-reading of the shipped tree (main at 2026-11-03) and my own engine's log; I have not built or run your seam because it does not exist yet, which is rather the point of the issue. (ai-assisted; our quoted lines from production boot 2026-11-04 14:36, protocol disclosed in the #3976/#5031 footers)
Author
Owner

@github-actions[bot] commented on GitHub (Nov 5, 2026):

Thanks, this follows the format now.

<!-- gh-comment-id:6651404186 --> @github-actions[bot] commented on GitHub (Nov 5, 2026): Thanks, this follows the format now.
Author
Owner

@G0-0000 commented on GitHub (Nov 5, 2026):

Thanks, both points taken.

  • The POSIX-first sentence is now in Non-goals: SCM_RIGHTS is POSIX-only, so an external store is a POSIX capability from day one; Windows keeps the local store and today's path, and DuplicateHandle over a named pipe stays out of scope.
  • Protocol details stay in this issue until commit 3, then the wire format is summarised in the PR body, as you suggested.

On the numbers: your park and eviction figures are exactly the cost this seam exists to remove. Our own measurements are on a single V100-32G Linux box (#4226), so I make no claim about the Windows slice either way; your log is the only Windows figure in this thread and I quote it as yours.

The Windows Publisher is deliberately left alone, not forgotten: the default path stays byte-identical.

Still waiting on a maintainer for the scope question itself.

<!-- gh-comment-id:6655923870 --> @G0-0000 commented on GitHub (Nov 5, 2026): Thanks, both points taken. - The POSIX-first sentence is now in Non-goals: SCM_RIGHTS is POSIX-only, so an external store is a POSIX capability from day one; Windows keeps the local store and today's path, and DuplicateHandle over a named pipe stays out of scope. - Protocol details stay in this issue until commit 3, then the wire format is summarised in the PR body, as you suggested. On the numbers: your park and eviction figures are exactly the cost this seam exists to remove. Our own measurements are on a single V100-32G Linux box (#4226), so I make no claim about the Windows slice either way; your log is the only Windows figure in this thread and I quote it as yours. The Windows Publisher is deliberately left alone, not forgotten: the default path stays byte-identical. Still waiting on a maintainer for the scope question itself.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#3125
No description provided.