Skip to content

feat(linux): автодрейн очередей рефлексии через systemd.path#3

Open
xxxvita wants to merge 1 commit intovbcherepanov:mainfrom
xxxvita:feat/linux-systemd-autodrain
Open

feat(linux): автодрейн очередей рефлексии через systemd.path#3
xxxvita wants to merge 1 commit intovbcherepanov:mainfrom
xxxvita:feat/linux-systemd-autodrain

Conversation

@xxxvita
Copy link
Copy Markdown

@xxxvita xxxvita commented Apr 15, 2026

Что добавляется

Linux-аналог macOS LaunchAgent'а для автоматического дрейна очередей рефлексии v6. На macOS launchagents/com.claude.memory.reflection.plist через WatchPaths ловит touch ~/.claude-memory/.reflect-pending и запускает run_reflection.py. На Linux эквивалента не было — после memory_save задачи в triple_extraction_queue, deep_enrichment_queue и representations_queue просто копились, Ollama их не обрабатывала, и граф знаний не рос.

Этот PR добавляет systemd.path + oneshot .service unit, которые дают то же поведение через inotify, и встраивает их в install.sh так, чтобы они автоматически ставились на Linux.

Что именно в PR

  • systemd/claude-memory-reflection.path — watcher с PathChanged=@MEMORY_DIR@/.reflect-pending
  • systemd/claude-memory-reflection.serviceType=oneshot, ExecStart=@INSTALL_DIR@/.venv/bin/python @INSTALL_DIR@/src/tools/run_reflection.py
  • systemd/README.md — ссылочный мини-документ про управление через systemctl --user и journalctl --user -u ...
  • install.sh +34 строки, новый Step 5bsed подставляет @INSTALL_DIR@ и @MEMORY_DIR@, копирует unit'ы в ~/.config/systemd/user/, делает daemon-reload и enable --now у .path unit'а

Почему это не затронет macOS

Step 5b обёрнут в if [ "$(uname)" = "Linux" ]. На macOS блок пропускается целиком, всё работает как раньше через launchagents/*.plist. Новая папка systemd/ — аддитивная, никаких существующих файлов не меняет, кроме install.sh.

Если systemctl по какой-то причине недоступен, unit-файлы всё равно копируются с WARN в stdout, но пользователь может включить их руками.

Что проверено

Протестировано end-to-end на Manjaro Linux (Python 3.12, systemd 254, Ollama 0.20.7, qwen2.5-coder:7b):

[memory-reflection] Drain complete:
  triples={'processed': 3, 'failed': 0, 'skipped': 0},
  enrich={'processed': 3, 'failed': 0, 'skipped': 0},
  repr={'processed': 3, 'failed': 0, 'skipped': 0}
done in 42.5s

Один запуск с холодным стартом qwen: 42.5 сек wall / 5.5 сек CPU / 785 MB RAM peak на три записи. Последующие вызовы в пределах TTL кэша модели Ollama — ~10 сек.

Что не проверено

  • Только Manjaro. На Ubuntu/Fedora/Arch поведение systemd.path с PathChanged идентично, но formally я проверял один дистрибутив.
  • Не тестировал в headless-окружении без user-session (например, root-only CI). Для таких сценариев systemctl --user не работает — скрипт корректно даёт WARN и пропускает активацию.

Generated with Claude Code

…rain

On macOS, `launchagents/com.claude.memory.reflection.plist` uses WatchPaths
to run `run_reflection.py` whenever `memory_save` touches
`~/.claude-memory/.reflect-pending`. Without that trigger, the v6
triple_extraction / deep_enrichment / representations queues just
accumulate — nothing calls Ollama to drain them.

Linux had no equivalent. This adds a systemd.path + oneshot .service
pair that gives the same behavior via inotify, and wires them into
install.sh so they get installed automatically on Linux machines.

Files:
- systemd/claude-memory-reflection.path — PathChanged=…/.reflect-pending
- systemd/claude-memory-reflection.service — Type=oneshot,
  ExecStart=.venv/bin/python src/tools/run_reflection.py
- systemd/README.md — manual management reference

Both unit files use @INSTALL_DIR@ and @MEMORY_DIR@ placeholders;
install.sh substitutes them via sed during install, copies to
~/.config/systemd/user/, reloads, and enables the .path unit.

New step 5b in install.sh runs only when `uname = Linux` and is
skipped silently on macOS (where launchagents/ is the canonical path).
If systemctl is missing the files are still copied with a WARN.

Verified end-to-end on Manjaro: save → touch → systemd fires → qwen
extraction → 3 queue items drained in 42.5s wall / 5.5s CPU / 785 MB
RAM peak (qwen2.5-coder:7b).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant