Skip to content

Studio: the event log gets its own lock file, events.lock (#805) #811

Done

Description

@danielrispler

Parent

#805

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.lock is 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 uses std::os::unix::fs::MetadataExt for 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-lock is in system-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; with events.lock held, 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 gives false and writes nothing; a data folder with no events.lock gets 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.jsonl or EVENT_LOG) and opens a file to write (OpenOptions, File::create, fs::write). Today it would flag hook/src/answer.rs, which opens a temp file for its decision and names events.jsonl for append (hook/src/answer.rs:96, :212 at 8e7faab21): 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.jsonl directly hold events.lock instead: a_held_lock_gives_a_drops_line_and_no_log_line_once_its_patience_runs_out (hook/tests/deadline.rs), the Cursor case in hook/tests/harness_trees.rs, and a_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.lock and checks that append_to waits, then writes its lines whole. No existing server test writes a Studio… line.
  • docs/studio/behaviour/storage.md lists events.lock among the data folder's files and states the rule: every writer of events.jsonl holds events.lock while it writes, a prune swaps the log only while holding it, and readers take no lock.
  • npm run check passes.

Reading

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

  1. added
    ready-for-agent
    on Nov 28, 2026
  2. danielrispler commented on Nov 28, 2026

    @danielrispler
    OwnerAuthor

    Implemented on #805's integration branch, PR #815 (merged as e4f9727, review fixes in 2e85eff).

    Route outcome: strong·high claude/opus → pass | 21m

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ready-for-agent

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions