Skip to content

fix(hooks): write stop entry in a single append - #736

Open
89799969 wants to merge 1 commit into
zilliztech:mainfrom
89799969:fix/stop-hook-atomic-append
Open

89799969 wants to merge 1 commit into
zilliztech:mainfrom
89799969:fix/stop-hook-atomic-append

Conversation

@89799969

Copy link
Copy Markdown

Problem

The Stop hook writes one session entry with several separate echo/write syscalls into a single >> redirect. Two sessions stopping at the same moment on a shared daily memory file can interleave heading, anchor comment, and summary lines (see #727).

Fix

Build each entry in memory and append it with one printf write:

  • plugins/claude-code/hooks/stop.sh
  • plugins/codex/hooks/stop.sh

One O_APPEND write keeps the entry whole against other appenders, matching what the JS integrations already get from a single �ppendFile. No lock (unavailable on macOS).

Tests

  • ests/test_stop_hook_atomic_append.py
  • sequential codex worker appends stay contiguous
  • 8 concurrent workers keep each session block whole

`
python -m pytest tests/test_stop_hook_atomic_append.py -v

2 passed

`

Notes

A duplicate ## Session heading is still possible when grep and append are not one operation; that only costs a repeated heading, while interleaving mis-resolves the progressive-disclosure anchor.

Fixes #727

Concurrent Stop workers share one daily memory file (worktrees and
synced folders). Multiple echo/write syscalls let heading, anchor
comment, and summary interleave across sessions. Build each entry in
memory and append with one printf write so the block stays whole under
O_APPEND. Cover the codex worker with sequential and concurrent tests.

Fixes zilliztech#727

This branch has not been deployed

No deployments
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.

Stop hook appends a session entry as five separate writes, so concurrent sessions interleave in the daily memory file

1 participant