Repository navigation
Description
Parent
What to build
The event log gets its own lock file, events.lock, beside events.jsonl in the data folder. Every writer of the log takes it first, then opens the log for append: the hook, the answer hook and the server's own lines (StudioRename, StudioDelete, StudioPromptName, a SessionEnd with reason process_gone). The prune holds it while it swaps the new log in. Nothing locks events.jsonl itself any more, so a reader never meets a lock. The (dev, ino) same-file check goes, and the prune's replaced-log check becomes a check that the log did not shrink below the bytes it read. Waits, OpenCode's lock order and the drop to drops.txt stay as today. Nothing changes for a user on macOS or Linux, and an old data folder needs no step.
The design is settled in #805, "Implementation Decisions" ("The event log's lock") and "Made without Daniel" (Q1–Q3).
Acceptance criteria
- The hook crate's public log API keeps its shape for callers: append with a patience, get the log open under the lock for a write, prune. The value handed back for a write holds the lock and the open log and lets both go when dropped.
-
events.lockis opened read-write, created if missing, locked exclusively with std's file lock, and never written, read, truncated, replaced or deleted. - No code locks
events.jsonl, and no code usesstd::os::unix::fs::MetadataExtfor the log. - The prune takes
events.lock(60 s patience) only for the tail copy, the state file's removal and the rename; its replaced-log check is a length check. - The law
log-writers-hold-the-log-lockis insystem-map.json,on: "hook",backing: "check", with the spec's text. - Tests tagged
@law: log-writers-hold-the-log-lock, through the public log API, cover each case of Spec: Windows foundations — a separate event-log lock, LF checkouts, a Rust test fake, the Windows npm names #805's Testing Decisions, "The log's lock": a line waiting through a prune lands in the new log; withevents.lockheld, the log opens and reads whole and an append waits then lands; concurrent appends from threads give whole lines; a patience shorter than the hold givesfalseand writes nothing; a data folder with noevents.lockgets one on the first append and keeps its lines; the prune's tail copy keeps lines appended between its read and its swap. - A source-scan test, tagged with the law and modelled on
no_git_or_gh_is_built_outside_the_runner, fails when a shipped Rust file (not a test file) other than the hook crate's log code names the event log (events.jsonlorEVENT_LOG) and opens a file to write (OpenOptions,File::create,fs::write). Today it would flaghook/src/answer.rs, which opens a temp file for its decision and namesevents.jsonlforappend(hook/src/answer.rs:96,:212at8e7faab21): that file takes the log's path from the hook crate's log code instead of naming it, so the scan's allowlist stays the log code alone. - The three tests that lock
events.jsonldirectly holdevents.lockinstead:a_held_lock_gives_a_drops_line_and_no_log_line_once_its_patience_runs_out(hook/tests/deadline.rs), the Cursor case inhook/tests/harness_trees.rs, anda_line_waiting_for_the_lock_lands_in_the_log_that_replaced_it(hook/tests/prune.rs). The OpenCode case keeps working through the API. - A new case beside the server's unit tests holds
events.lockand checks thatappend_towaits, then writes its lines whole. No existing server test writes aStudio…line. -
docs/studio/behaviour/storage.mdlistsevents.lockamong the data folder's files and states the rule: every writer ofevents.jsonlholdsevents.lockwhile it writes, a prune swaps the log only while holding it, and readers take no lock. -
npm run checkpasses.
Reading
- Spec: Windows foundations — a separate event-log lock, LF checkouts, a Rust test fake, the Windows npm names #805, "Implementation Decisions" ("The event log's lock") and "Made without Daniel" Q1–Q3: the design and what was set aside.
- Spec: Windows foundations — a separate event-log lock, LF checkouts, a Rust test fake, the Windows npm names #805, "Testing Decisions": the cases and the three tests that move.
docs/studio/research/windows.md, "CI spike results" (probeslock-blocks-reader,lock-append-only,lock-file-beside-log): why the log itself can't be the lock on Windows. It lands with the fake's ticket; until then it is in the main checkout, untracked.docs/studio/behaviour/map.md: how to add a law and tag a test.
Touches
- Files:
hook/src/lib.rs,hook/src/answer.rs,hook/tests/prune.rs,hook/tests/deadline.rs,hook/tests/harness_trees.rs,server/src/lib.rs,server/src/tests.rs,docs/studio/behaviour/storage.md,system-map.json - Session: auto mode
- Route: strong · effort high — concurrency and persistence: the log's lock and the prune's swap, which every writer and the read loop depend on
Activity
Studio: the event log gets its own lock file, events.lock (#811)
Merge issue-811-studio-the-event-log into integration (#811)
danielrispler commentedon Nov 28, 2026
Implemented on #805's integration branch, PR #815 (merged as e4f9727, review fixes in 2e85eff).
Route outcome: strong·high claude/opus → pass | 21m
Studio: Windows foundations — the event log's own lock file, and LF c…