[PR #4343] [CLOSED] [Engine] dsv41: a kept conversation's files are its owner's alone (0600) #5019

Closed
opened 2026-11-07 16:32:04 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4343
Author: @suifei
Created: 10/27/2026
Status: ❌ Closed

Base: main ← Head: claude/busy-albattani-fjntdn


📝 Commits (1)

  • 1e2d2d8 [Engine] dsv41: a kept conversation's files are its owner's alone (0600)

📊 Changes

4 files changed (+95 additions, -9 deletions)

View changed files

📝 docs/DEEPSEEK41.md (+2 -1)
📝 src/dsv41/ds4_main.cpp (+17 -7)
📝 src/dsv41/ds4_slotmeta.hpp (+38 -0)
📝 tests/dsv41/slot_test.cpp (+38 -1)

📄 Description

Problem and result

The DeepSeek engine keeps a displaced conversation in its slot folder. serve/server.py's deepseek_slot_env() turns this on for every DeepSeek engine (STRATA_DS4_SLOT_KEEP=1). A slot's .meta holds the conversation's token ids, which decode to the prompt. Its .bin holds the model state. Both files were written with the process umask. On the box where this was found, the folder was drwxrwxr-x and the files 664, so any other user on the machine could read every kept conversation.

After this change, on Linux:

  • every slot file is created 0600 as it is made;
  • the files an earlier version left behind are made 0600 when the engine starts;
  • a slot folder the engine creates itself is 0700.

Windows is unchanged: the folder's inherited ACL decides there.

none

Approach

  • ds4_slotmeta.hpp gets two helpers:
    • create_private(path) removes any leftover file of that name, then creates the file with open(O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0600). The mode is set as the file is made, so no other user can open it in between. A file is removed first because a mode only applies at creation, and an interrupted write can leave a .tmp with a looser mode.
    • make_private(path) sets an existing file to 0600.
  • Both slot writers call create_private on their .tmp before the stream opens and truncates it: slotmeta::write for .meta, and slot_write_file in ds4_main.cpp for .bin. The stream keeps the mode.
  • The start-up scan calls make_private on every .meta and .bin it keeps.
  • The folder is set to 0700 only when create_directories just created it. A folder that already exists keeps its mode, because STRATA_DS4_SLOT_DIR can name a folder of the user's own. The file modes protect the content either way.
  • The file format, slot selection and timing are unchanged. A chmod does not change mtime, so the 7-day expiry is unaffected.
  • docs/DEEPSEEK41.md says who can read the slots.

Validation

Revision 1e2d2d8 (base 4b9e05a). Ubuntu 24.04 container, Linux 6.18 x86_64, g++ 13.3.0, CUDA 13.2, four L20s.

Passed:

  1. The CUDA build, in a fresh Ninja build directory with the project's production options (-DSTRATA_ENABLE_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=native -DSTRATA_BUILD_DSV41=ON -DSTRATA_BUILD_TESTS=ON, CUDA 13.2, Release):
    cmake -S <src> -B /tmp/build0600 -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CUDA_COMPILER=/usr/local/cuda-13.2/bin/nvcc \
          -DCMAKE_CUDA_ARCHITECTURES=native -DSTRATA_ENABLE_CUDA=ON -DSTRATA_ENABLE_HIP=OFF -DSTRATA_ENABLE_SYCL=OFF \
          -DSTRATA_BUILD_DSV41=ON -DSTRATA_BUILD_TESTS=ON -DSTRATA_NATIVE_EXPERTS=ON -DSTRATA_MMQ_KQUANTS=ON -DSTRATA_MMQ_TQ_OVERLAY=ON
    cmake --build /tmp/build0600 --target strata-dsv41 ds4_slot_test -j 48     # rc=0
    
    strata-dsv41 35,588,952 bytes and ds4_slot_test 74,264 bytes linked.
  2. The test from that build (not a hand-compiled one): /tmp/build0600/ds4_slot_test printed slot_test: all passed, exit 0. The new checks run with umask(0), so a mode can only come from the code: a written .meta is 0600; a write over a leftover 0666 .tmp still gives a 0600 file and leaves no .tmp; make_private turns a 0664 file into 0600; create_private gives an empty 0600 file and returns false for a missing folder; make_private returns false for a missing file.
  3. The engine on the L20s, end to end (STRATA_DS4_SLOT_DIR=/tmp/slot0600-test, a throw-away folder; a slot whose identity does not match is deleted at start, so never the production folder):
    • a folder that did not exist yet: after the engine started, stat -c '%a' /tmp/slot0600-test -> 700;
    • two conversations of ~1,100 tokens each (nonces at the front), the engine stopped: ds4 slots: wrote 2 conversation(s) to /tmp/slot0600-test; the four files (2 .bin, 2 .meta) were 600;
    • those files chmod 664, the same folder, the engine restarted: ds4 slots: folder /tmp/slot0600-test: 2 conversation(s) kept from earlier runs (kept, not refused or deleted), and stat -c '%a' on the four files -> 600 again - the start-up scan made them private;
    • a next turn of one of those conversations after the restart: not verified. Its log had no took back ... from the folder line, so that turn read its prompt again (about 1,100 tokens, under a second here, so the turn's 2.5 s does not tell the two apart). The start-up scan registers a kept conversation as a file slot - the .bin is read only when a prompt actually continues it, and that path prints took back a N-token conversation from the folder. Taking a conversation back is not what this change asserts; what the run shows is that the files survive, are tightened to 0600 and are not deleted.
  4. g++ -std=c++17 -fsyntax-only -Wall -Wextra -DSTRATA_VERSION='"x"' -Isrc/dsv41 -Iinclude src/dsv41/ds4_main.cpp: no errors and no warnings.

Failed:
none observed

Not run:

  • the HIP build: no ROCm on this machine. Asked the maintainers for one in a comment; this PR stays a draft until it has been done (CONTRIBUTING asks for both builds).
  • a Windows build: the POSIX parts are behind #ifndef _WIN32 and were not compiled there.
  • a second, non-root user trying to read a slot: the checks use stat for the mode bits, not a second user's access.
  • a take-back from a file slot after a restart: GEN with the kept conversation's own tokens plus a few new ones, then
    took back a N-token conversation from the folder and DONE's reused close to N. The end-to-end run's next turn did
    not continue the kept conversation closely enough to take it back, so this is left for a follow-up run.

Limits

  • An existing slot folder keeps its mode. The default ds4-slots folder of an existing install stays 775, so other users can still list file names, sizes and times, but not read the content. chmod 700 on it closes that.
  • Windows is unchanged.
  • This covers the DeepSeek engine's slot folder only.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4343 **Author:** [@suifei](https://github.com/suifei) **Created:** 10/27/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `claude/busy-albattani-fjntdn` --- ### 📝 Commits (1) - [`1e2d2d8`](https://github.com/Niko1221/Strata/commit/1e2d2d82aafc47751d88b7f8b6a1c37457152da2) [Engine] dsv41: a kept conversation's files are its owner's alone (0600) ### 📊 Changes **4 files changed** (+95 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `docs/DEEPSEEK41.md` (+2 -1) 📝 `src/dsv41/ds4_main.cpp` (+17 -7) 📝 `src/dsv41/ds4_slotmeta.hpp` (+38 -0) 📝 `tests/dsv41/slot_test.cpp` (+38 -1) </details> ### 📄 Description ## Problem and result The DeepSeek engine keeps a displaced conversation in its slot folder. `serve/server.py`'s `deepseek_slot_env()` turns this on for every DeepSeek engine (`STRATA_DS4_SLOT_KEEP=1`). A slot's `.meta` holds the conversation's token ids, which decode to the prompt. Its `.bin` holds the model state. Both files were written with the process umask. On the box where this was found, the folder was `drwxrwxr-x` and the files `664`, so any other user on the machine could read every kept conversation. After this change, on Linux: - every slot file is created `0600` as it is made; - the files an earlier version left behind are made `0600` when the engine starts; - a slot folder the engine creates itself is `0700`. Windows is unchanged: the folder's inherited ACL decides there. ## Related discussion none ## Approach - `ds4_slotmeta.hpp` gets two helpers: - `create_private(path)` removes any leftover file of that name, then creates the file with `open(O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0600)`. The mode is set as the file is made, so no other user can open it in between. A file is removed first because a mode only applies at creation, and an interrupted write can leave a `.tmp` with a looser mode. - `make_private(path)` sets an existing file to `0600`. - Both slot writers call `create_private` on their `.tmp` before the stream opens and truncates it: `slotmeta::write` for `.meta`, and `slot_write_file` in `ds4_main.cpp` for `.bin`. The stream keeps the mode. - The start-up scan calls `make_private` on every `.meta` and `.bin` it keeps. - The folder is set to `0700` only when `create_directories` just created it. A folder that already exists keeps its mode, because `STRATA_DS4_SLOT_DIR` can name a folder of the user's own. The file modes protect the content either way. - The file format, slot selection and timing are unchanged. A `chmod` does not change mtime, so the 7-day expiry is unaffected. - `docs/DEEPSEEK41.md` says who can read the slots. ## Validation Revision `1e2d2d8` (base `4b9e05a`). Ubuntu 24.04 container, Linux 6.18 x86_64, g++ 13.3.0, CUDA 13.2, four L20s. **Passed:** 1. The CUDA build, in a fresh Ninja build directory with the project's production options (`-DSTRATA_ENABLE_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=native -DSTRATA_BUILD_DSV41=ON -DSTRATA_BUILD_TESTS=ON`, CUDA 13.2, Release): ``` cmake -S <src> -B /tmp/build0600 -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CUDA_COMPILER=/usr/local/cuda-13.2/bin/nvcc \ -DCMAKE_CUDA_ARCHITECTURES=native -DSTRATA_ENABLE_CUDA=ON -DSTRATA_ENABLE_HIP=OFF -DSTRATA_ENABLE_SYCL=OFF \ -DSTRATA_BUILD_DSV41=ON -DSTRATA_BUILD_TESTS=ON -DSTRATA_NATIVE_EXPERTS=ON -DSTRATA_MMQ_KQUANTS=ON -DSTRATA_MMQ_TQ_OVERLAY=ON cmake --build /tmp/build0600 --target strata-dsv41 ds4_slot_test -j 48 # rc=0 ``` `strata-dsv41` 35,588,952 bytes and `ds4_slot_test` 74,264 bytes linked. 2. The test from that build (not a hand-compiled one): `/tmp/build0600/ds4_slot_test` printed `slot_test: all passed`, exit 0. The new checks run with `umask(0)`, so a mode can only come from the code: a written `.meta` is `0600`; a write over a leftover `0666` `.tmp` still gives a `0600` file and leaves no `.tmp`; `make_private` turns a `0664` file into `0600`; `create_private` gives an empty `0600` file and returns false for a missing folder; `make_private` returns false for a missing file. 3. The engine on the L20s, end to end (`STRATA_DS4_SLOT_DIR=/tmp/slot0600-test`, a throw-away folder; a slot whose identity does not match is *deleted* at start, so never the production folder): - a folder that did not exist yet: after the engine started, `stat -c '%a' /tmp/slot0600-test` -> **700**; - two conversations of ~1,100 tokens each (nonces at the front), the engine stopped: `ds4 slots: wrote 2 conversation(s) to /tmp/slot0600-test`; the four files (2 `.bin`, 2 `.meta`) were **600**; - those files `chmod 664`, the same folder, the engine restarted: `ds4 slots: folder /tmp/slot0600-test: 2 conversation(s) kept from earlier runs` (kept, not refused or deleted), and `stat -c '%a'` on the four files -> **600** again - the start-up scan made them private; - a next turn of one of those conversations after the restart: **not verified**. Its log had no `took back ... from the folder` line, so that turn read its prompt again (about 1,100 tokens, under a second here, so the turn's 2.5 s does not tell the two apart). The start-up scan registers a kept conversation as a *file slot* - the `.bin` is read only when a prompt actually continues it, and that path prints `took back a N-token conversation from the folder`. Taking a conversation back is not what this change asserts; what the run shows is that the files survive, are tightened to `0600` and are not deleted. 4. `g++ -std=c++17 -fsyntax-only -Wall -Wextra -DSTRATA_VERSION='"x"' -Isrc/dsv41 -Iinclude src/dsv41/ds4_main.cpp`: no errors and no warnings. **Failed:** none observed **Not run:** - **the HIP build**: no ROCm on this machine. Asked the maintainers for one in a comment; this PR stays a draft until it has been done (CONTRIBUTING asks for both builds). - a Windows build: the POSIX parts are behind `#ifndef _WIN32` and were not compiled there. - a second, non-root user trying to read a slot: the checks use `stat` for the mode bits, not a second user's access. - a take-back from a file slot after a restart: `GEN` with the kept conversation's own tokens plus a few new ones, then `took back a N-token conversation from the folder` and `DONE`'s `reused` close to N. The end-to-end run's next turn did not continue the kept conversation closely enough to take it back, so this is left for a follow-up run. ## Limits - An existing slot folder keeps its mode. The default `ds4-slots` folder of an existing install stays `775`, so other users can still list file names, sizes and times, but not read the content. `chmod 700` on it closes that. - Windows is unchanged. - This covers the DeepSeek engine's slot folder only. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:32:04 +07:00
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#5019
No description provided.