Skip to content

Studio: Windows foundations — the event log's own lock file, and LF checkouts (#805) - #815

Merged
danielrispler merged 8 commits into
mainfrom
issue-805-windows-foundations
Nov 28, 2026
Merged

danielrispler merged 8 commits into
mainfrom
issue-805-windows-foundations

Conversation

@danielrispler

@danielrispler danielrispler commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

Closes #805
Closes #811
Closes #812

Spec #805's integration branch. Its third ticket, #813 (the Rust test fake and docs/studio/research/windows.md), is its own PR, #816, since it needed the ubuntu job.

Summary

#811: the event log gets its own lock file. events.lock sits beside events.jsonl, and nothing locks the log itself any more, so a reader never meets a lock (on Windows a lock on the log blocks reads).

 append / locked(log, patience)                 hook, answer hook, server's append_to
-  loop: open events.jsonl for append, lock it, (dev, ino) still the log's? else reopen
+  lock events.lock (create if missing), then open events.jsonl for append
+  Locked { log, lock }: the log closes first, then the lock goes
   write the line in one write

 prune(log)
   read the log, write events.jsonl.next              no lock, as today
-  lock events.jsonl; same (dev, ino) as the file read?
+  lock events.lock (60 s); log not shorter than the bytes read?
   copy the tail, remove the state file, rename .next into place, let go
  • Waits unchanged: 5 s for a hook, 1 s for Codex and Cursor, 60 s for the server and the prune. OpenCode's order (session record, then the log's lock) unchanged.
  • hook/src/answer.rs and hook/src/main.rs take the log's path from the log code (event_log_in), so hook/src/lib.rs is the only file that names it.
  • New law log-writers-hold-the-log-lock (on: hook, backing: check), backed by a source scan: a statement outside hook/src/lib.rs that names the log (events.jsonl, EVENT_LOG, event_log(, event_log_in() and opens a file to write (OpenOptions, File::create, fs::write) fails it. Inline test modules are cut; a #[cfg(test)] mod tests; line is not.
  • docs/studio/behaviour/storage.md states the rule.

#812: LF checkouts. A new .gitattributes (* text=auto eol=lf, binary for png, jpg, gif, ico and webp), listed in system-map.json's ignored.

Evidence

Tests tagged @law: log-writers-hold-the-log-lock (hook/tests/prune.rs unless named), each run red against the old code with an assertion failure, except the threads case (the old code already gave whole lines; it went red against a mutation that wrote each line in two unlocked parts):

a_line_waiting_for_the_lock_lands_in_the_log_that_replaced_it          (rewritten: holds events.lock)
an_append_against_a_held_lock_lands_once_it_is_let_go_or_writes_nothing_when_its_patience_runs_out
    rows: patience 5 s -> the log reads whole while held, then the line lands
          patience 100 ms -> false, nothing written
a_data_folder_with_no_lock_file_gets_one_on_the_first_append_and_keeps_its_lines
appends_from_many_threads_at_once_give_whole_lines
a_prunes_tail_copy_keeps_the_lines_appended_between_its_read_and_its_swap
no_file_but_the_log_code_names_the_log_and_opens_a_file_to_write       the law's scan
a_held_lock_gives_a_drops_line_and_no_log_line_once_its_patience_runs_out   (hook/tests/deadline.rs, now holds events.lock)
the_servers_lines_wait_for_the_logs_lock_then_land_whole               (server/src/tests.rs)

The scan went red against both mutations the correctness pass found it missed, in a dropped WIP commit: OpenOptions::new().append(true).open(studio_hook::event_log(home)) in server/src/learning.rs, and fs::write(studio_hook::event_log(home), "") after #[cfg(test)] mod tests; in server/src/lib.rs. It names ["server/src/learning.rs", "server/src/lib.rs"]. A path bound to a variable in one statement and opened in the next still gets past it.

Moved to holding events.lock: the deadline test above, the Cursor case in hook/tests/harness_trees.rs, and the prune case. The OpenCode case works unchanged through studio_hook::locked.

Tests merged: while_the_lock_is_held_the_log_reads_whole_and_an_append_waits_then_lands and an_append_whose_patience_is_shorter_than_the_hold_writes_nothing became the two rows of an_append_against_a_held_lock_lands_once_it_is_let_go_or_writes_nothing_when_its_patience_runs_out. None removed.

git ls-files --eol | awk '{print $1, $2}' | sort | uniq -c, the same before and after .gitattributes:

   2 i/ w/
   6 i/-text w/-text
 789 i/lf w/lf
   3 i/none w/none

After it, every text file is attr/text=auto eol=lf and the 6 images attr/-text. git add --renormalize . then git status --short showed only .gitattributes and system-map.json.

npm run check passes on the tip 2e85eff2f. In the review-fix implementer's run, ui/tests/check-slot.test.mjs "four checks run two at a time…" failed once (SyntaxError: Unexpected end of JSON input), on code this diff doesn't touch. It passed on its one rerun, and again in the merger's full check.

Correctness pass

A reviewer traced every writer, the prune, the lock order and stored data both ways, ran cargo nextest run -p studio-hook (89/89) and the server's lock and read-loop tests, and tried mutations against the scan.

  • Fixed: the scan missed a writer that takes the log's path from event_log(), and anything after a file's first #[cfg(test)] (line 6 of 368 in system-map/src/extract/mod.rs). The spec review had reported the second one already.
  • Fixed (standards review): two held-lock tests were one behaviour with two outcomes, now one table. "events.lock" and its open chain were spelled out in four files, now only hook/src/lib.rs (studio_hook::lock_file, and the tests hold it through studio_hook::locked). hook/src/main.rs named EVENT_LOG. docs/studio/development.md was missing the server test, and prune.rs's header comment was out of date.
  • Accepted, for Daniel: a hook copy from the previous build, still running through the restart, locks events.jsonl itself, so the new prune doesn't wait for it. If the first prune of the new build swaps the log between that hook's (dev, ino) check and its write, the line goes to the replaced file, with no drops.txt entry. The reviewer reproduced it with a scratch test. The window is microseconds in one restart, and a swap happens only when the log's first line is over 30 days old. Spec Q2 accepted the in-flight old hook, though its reasoning covered two writers, not a prune. The fix would be for the prune to lock events.jsonl too, for one release.
  • Rejected: deadline.rs reading the log with unwrap_or_default (correct: the log is created only under the lock now).

Outside review

gemini-4-neon-medium, one round on e4f972706. cost: 3.5 min, 190564 tokens; Gemini quota left: weekly 47% to 46%, 5h 100% to 97%

  • Rejected: "the length check misses a log another prune replaced and hooks grew past the bytes read". Spec Q3 accepts this: server/src/read_loop.rs:219 (Follower::start_at) is the prune's only caller, and it runs once per start under the data folder's lock (server/src/lock.rs), so two prunes never overlap. The correctness pass had reported it too, with the same conclusion.

Merge Danger

Door: two-way

No stored format changes: an old data folder gets events.lock on its first write, and its log, archive and state read as before. Rolling back leaves an events.lock nobody reads.

Blast Radius: the event log

Every writer of events.jsonl changes how it locks. The one gap is the restart window above.

Route outcome: #811 strong·high claude/opus → pass; #812 medium·medium claude/sonnet → pass; review fixes strong·high claude/opus → pass. Medium UI tickets so far: none in this spec.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CVqACdL6QruKkvHdjdYPVr

danielrispler and others added 7 commits November 28, 2026 17:29
Every writer of events.jsonl (the hook, the answer hook, the server's own
lines) takes events.lock beside it, then opens the log for append; the
prune holds it only for the tail copy, the state file's removal and the
rename. Nothing locks the log itself, the (dev, ino) same-file check goes,
and the prune's replaced-log check is a length check. New law
log-writers-hold-the-log-lock, with tests through the public log API, a
server case for append_to, and a source scan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CVqACdL6QruKkvHdjdYPVr
The law's scan reads statement by statement and cuts only inline test
modules, so a writer naming the log through `event_log(` or placed after
`#[cfg(test)] mod tests;` is caught. The two held-lock append tests are
one table. The lock's path is `studio_hook::lock_file`, and the tests
hold the lock through `studio_hook::locked`. The hook's main takes the
log's path from `event_log_in`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CVqACdL6QruKkvHdjdYPVr
@danielrispler danielrispler changed the title Studio: Windows foundations — a separate event-log lock and LF checkouts (#805) Studio: Windows foundations — the event log's own lock file, and LF checkouts (#805) Nov 28, 2026
@danielrispler
danielrispler marked this pull request as ready for review November 28, 2026 16:08
@danielrispler
danielrispler merged commit 968a1f0 into main Nov 28, 2026
2 checks passed
@danielrispler
danielrispler deleted the issue-805-windows-foundations branch November 28, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant