Skip to content

feat(events): Append one JSON line per launch to an event log - #723

Merged
blooop merged 13 commits into
mainfrom
ags/events-log
Nov 21, 2026
Merged

blooop merged 13 commits into
mainfrom
ags/events-log

Conversation

@blooop

@blooop blooop commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

dl and dla now write one JSON line for each launch to a log file. A usage review can then measure how long a start takes, and nobody has to set DEVLAUNCH_TIMING first.

In short

Before this change, dl measured a start only when the user set DEVLAUNCH_TIMING before the command. Nothing kept a record of past starts. So nobody could say how long starts took last week, or how many were cold.

Now every dl and dla command appends to an event log. The event log is the file ${XDG_STATE_HOME:-~/.local/state}/devlaunch/events.jsonl, one JSON object on each line. It is on by default. DEVLAUNCH_EVENTS=0 turns it off.

A write to the event log never stops a command. If the write fails, dl drops the line and continues. Each line goes out in one append, so two commands at the same time do not mix their lines.

The field names and the ev values match what the usage-review queries read: sources.sql and the dl_*, dla_* and aid_* metrics.

Evidence

The built dl and dla ran against the test world (the fake devpod that the integration tests use). They wrote this file:

{"ts":"2026-11-21T09:13:05.122Z","ev":"launch","ws":"devlaunch-main-3j1t","repo":null,"branch":null,"cold":false,"seconds":0.017482,"stages":{"devpod-up":0.016424},"verb":"attach"}
{"ts":"2026-11-21T09:13:05.140Z","ev":"session_end","ws":"devlaunch-main-3j1t","repo":null,"branch":null,"seconds":0.017801,"exit":0}
{"ts":"2026-11-21T09:13:05.178Z","ev":"stop","ws":"devlaunch-main-3j1t","repo":null,"branch":null,"seconds":0.033327,"exit":0}
{"ts":"2026-11-21T09:13:05.292Z","ev":"launch","ws":"devlaunch-main-3j1t","repo":null,"branch":null,"cold":false,"seconds":0.109264,"stages":{"devpod-up":0.072553,"tools":0.035113},"verb":"up"}
{"ts":"2026-11-21T09:13:05.340Z","ev":"launch","ws":"devlaunch-main-3j1t","repo":"blooop/devlaunch","branch":"main","cold":false,"seconds":0.023009,"stages":{"devpod-up":0.016812},"verb":"--"}
{"ts":"2026-11-21T09:13:05.340Z","ev":"aid_start","ws":"devlaunch-main-3j1t","repo":"blooop/devlaunch","branch":"main","cold":false,"seconds":0.043923,"stages":{"pick":0.00007,"pr_lookup":0.00005,"prompt":1e-6,"dl":0.023009},"agent":"claude","resume":false}
{"ts":"2026-11-21T09:13:05.357Z","ev":"session_end","ws":"devlaunch-main-3j1t","repo":"blooop/devlaunch","branch":"main","seconds":0.016222,"exit":0}
{"ts":"2026-11-21T09:13:05.357Z","ev":"aid_end","ws":"devlaunch-main-3j1t","repo":"blooop/devlaunch","branch":"main","seconds":0.060187,"exit":0,"agent":"claude"}

DuckDB reads the file:

  • read_json_auto reads ts as TIMESTAMP WITH TIME ZONE, cold as BOOLEAN, seconds as DOUBLE.
  • The usage-review sources.sql, with SET VARIABLE dl_events on this file, loads all 8 lines into dl_events with every column filled.
  • The metrics then give a value: dl_start_seconds_p50 = 0.023009, dla_start_seconds_p50 = 0.043923, aid_start_seconds_p90 = 0.043923, dl_cold_starts_per_day = 0.0.

The lines

ev dl writes it when Fields after ts, ev, ws, repo, branch
launch The workspace is ready and the session is about to start, or an up has finished cold, seconds, stages, verb
session_end The session that a launch started has ended seconds (of the session), exit
stop, kill, remove, prune The verb has finished seconds, exit
aid_start dla gave its start to dl and the workspace is ready cold, seconds, stages, agent, resume
aid_end dla has ended seconds, exit, agent
  • ts is UTC ISO 8601 to the millisecond.
  • ws is the workspace id when the launch knows it. Otherwise it is the target as the user typed it.
  • cold is true when the devpod up of the launch created the workspace.
  • stages on a launch holds the same named stages as the timing document, in seconds.
  • stages on an aid_start holds the steps of dla (pick, pr_lookup, prompt, boot_wait) and dl, the launch inside it.
  • The aid names are the old name of dla. The usage-review queries already filter on them.

What changes

  • rust/devlaunch-core/src/timing.rs: timing::begin now takes a hook, Option<fn(&Ready)>. The new timing::ready calls the hook one time for each command, with a new Ready struct: workspace id, seconds, cold, stages. Core still prints and writes nothing (devlaunch-core module architecture and data model #251).
  • rust/devlaunch-core/src/flows/launch.rs: the launch records whether its devpod up creates the workspace, and calls timing::ready before the attach.
  • rust/dl/src/events.rs (new): the hook, the file path, and the lines. run_with starts it and ends it. render_workspace tells it the verb, so a named workspace and a picked workspace give the same lines. The prune arm tells it prune. An up, a code or a dotfiles that ends with code 0 calls timing::ready itself, because these verbs start no session.
  • The launch line and the aid_start line of one start take one timestamp, so the ts of the aid_start is never later than the ts of its launch. The usage-review join (l.ts >= a.ts) needs this.
  • An aid_end after a dla start that failed before ready names the target the user typed. Before, its ws was null.
  • rust/dla/src/main.rs: dla charges its own steps as stages, then gives the start to dl, then writes aid_end.
  • test/conftest.py: the Python suite now sets XDG_STATE_HOME to a scratch directory. Without this, one suite run wrote two lines into the real ~/.local/state/devlaunch/events.jsonl.
  • README.md, docs/performance.md (new section "The event log"), CHANGELOG.md.

Limits

docs/performance.md ("The event log") states each of these:

  • A picked batch (several rows marked for one verb) writes one line, not one line for each workspace.
  • When the terminal or the pane closes, dl gets SIGHUP and its signal handler exits with _exit(129). The handler writes nothing, so the launch has no session_end, and a dla start has no aid_end.
  • The interactive dla boot (dla --boot-up <spec> up) is a separate process. It creates the workspace and writes its own launch with verb up and cold true. The attach in the foreground then writes a launch with cold false, and aid_start copies cold false. So one interactive start gives two launch lines, and a cold start shows on the up line, not on aid_start.
  • stop, kill and remove write the target as the user typed it in ws. repo and branch are null when the target is a workspace id.
  • A herdr pane shell that attaches to a workspace writes a launch line too.
  • --refresh-stale (the unattended recreate) writes no line.

Merge danger

The public-API rows for timing::Ready, timing::begin and timing::ready in rust/devlaunch-core/public-api.rest.txt are hand-written. This host has no nightly toolchain and no cargo-public-api. The public-api job in CI must confirm the rows. timing::begin changes its signature, so this is a change to the public API of devlaunch-core.

Tests

  • cargo fmt --check: clean.
  • cargo clippy --locked --all-targets -- -D warnings: clean.
  • cargo test --workspace --locked: 3342 passed, 0 failed, 1 ignored.
  • pixi run test (pytest): 888 passed, 7 skipped.
  • prek run --from-ref origin/main --to-ref HEAD: passed.

New tests:

  • rust/dl/tests/launch.rs:
    • A warm attach writes launch then session_end.
    • A cold launch writes cold: true with stages. A stopped workspace that its up starts writes cold: false.
    • An up writes one launch and no session_end. A code or a dotfiles does the same. An up that devpod refuses writes no launch.
    • The log follows XDG_STATE_HOME. A relative XDG_STATE_HOME is ignored. DEVLAUNCH_EVENTS=0 writes no file. A log that cannot be written does not change the exit code or stderr.
  • rust/dl/tests/lifecycle.rs: stop, kill, rm, rme and dl --prune -y each write one line with their ev. A refused rm writes exit: 3.
  • rust/dl/tests/picker.rs: a picked stop and a picked up write the same lines as a named one.
  • rust/dla/tests/rewrite.rs: a dla start writes launch, aid_start, session_end, aid_end, with the dla stages and ws on aid_end. A resume writes resume: true. A start that fails before ready writes an aid_end that names its target.
  • Unit tests in events.rs (the off switch, the timestamp, the line fields, one ts for launch and aid_start) and in timing.rs (the Ready snapshot, one call only, the hook).

🤖 Generated with Claude Code

Summary by Sourcery

Record command usage in a resilient JSONL event log so launch performance and lifecycle activity can be reviewed after the fact.

New Features:

  • Add an enabled-by-default JSONL event log for dl and dla launches, sessions, and lifecycle operations, including timing, cold-start status, stages, and exit details.

Bug Fixes:

  • Ensure event-log failures are non-fatal and do not alter command output or exit status.

Enhancements:

  • Expose launch readiness data from the core timing subsystem so binaries can record usage events without enabling timing reports.
  • Support disabling event logging with DEVLAUNCH_EVENTS=0 and locating logs through XDG_STATE_HOME.

Documentation:

  • Document the event log format, configuration, usage, and known recording limitations.
  • Update the README and changelog with event-log configuration and behavior.

Tests:

  • Add coverage for launch, lifecycle, picker, and dla event records, configuration, failure handling, and timing metadata.

Chores:

  • Isolate the Python test suite's event-log state in a temporary XDG state directory.

dl and dla now write ${XDG_STATE_HOME:-~/.local/state}/devlaunch/events.jsonl,
always on, off with DEVLAUNCH_EVENTS=0. dl writes launch, session_end, stop,
kill, remove and prune; dla adds aid_start (its own stages plus dl's launch)
and aid_end. A write error is dropped and never fails the command.

Core hands the launch over through a hook on timing::begin and a new
timing::ready, so core still renders nothing. The public-API rows for
timing::Ready, begin and ready are hand-written; CI's public-api job checks
them. The Python suite now scopes XDG_STATE_HOME so a test run does not
write into the developer's own log.
@sourcery-ai

sourcery-ai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Extend the timing interface with a launch-ready snapshot and one-shot hook, while retaining the optional stderr timing report; include the hand-maintained public-API record for these changes.

  • rust/devlaunch-core/public-api.rest.txt L3563-3577
  • rust/devlaunch-core/src/timing.rs L480-532, L871-894, L2084-2171 (+24 small edits)

Uses of the API

Record readiness and cold-start information in the launch flow, and trigger readiness for sessionless verbs and lifecycle commands at dispatch.

  • rust/devlaunch-core/src/flows/launch.rs L2206-2211, L4198-4200
  • rust/dl/src/cli.rs L352-368
  • rust/dl/src/commands.rs L137-146, L859-901 (+5 small edits)

Install the event hook for each command and bracket command execution with event-log lifecycle handling.

  • rust/dl/src/lib.rs L28, L591-597
  • rust/dla/src/main.rs L254-263 (+4 small edits)
  • rust/dla/src/rewrite.rs L760-764

Implementation

Implement event construction, timing and workspace association, dla start tracking, and best-effort JSONL appends.

  • rust/dl/src/events.rs L1-509

Configuration

Isolate the Python test suite's event log by setting a scratch XDG_STATE_HOME.

  • test/conftest.py L79-83, L88

Documentation

Explain the event-log format, semantics, limitations and configuration, and announce the feature to users.

  • CHANGELOG.md L10-18
  • README.md L569, L576-578
  • docs/performance.md L145-147, L180-235

Tests

Cover event records across launches, lifecycle verbs, picker paths and dla, including disabled logging and failure cases.

  • rust/dl/tests/launch.rs L2781-2969
  • rust/dl/tests/lifecycle.rs L261-269, L846-884, L1642-1655
  • rust/dl/tests/picker.rs L506-555, L632-651, L1019-1027 (+1 small edits)
  • rust/dla/tests/rewrite.rs L363-439

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.26874% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.82%. Comparing base (6cdd320) to head (10b7870).

Files with missing lines Patch % Lines
rust/dl/src/events.rs 99.05% 3 Missing ⚠️
rust/dla/src/main.rs 88.88% 1 Missing ⚠️
Additional details and impacted files
Flag Coverage Δ
python 42.98% <ø> (ø)
rust 95.01% <99.26%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
shipped code (rust) 95.01% <99.26%> (+0.02%) ⬆️
harness and tooling (python) 42.98% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Each line read the clock on its own, so the two writes could straddle a
millisecond and give launch a ts before aid_start. The usage review pairs them
with an ASOF JOIN on l.ts >= a.ts, which then dropped or mispaired the start.
One ready now reads the clock once and both lines carry it.
Dla's target was filled only when the launch was ready, so a start that
failed first (an unknown workspace) wrote aid_end with ws null. aid_end now
takes the target from the verb dl dispatched, which is known before ready.
The copy of the target on dla's record goes, since the verb already holds it.
code and dotfiles start no session, so they reached neither attach_workspace
nor the up-only ready call: no launch line was written. A Verb now says
whether it is ready without a session; the dispatch fires the ready for all
three, and the event state writes no session_end after them.
The verb was recorded only on the named-target route; the picker went
straight to render_workspace. The record and the sessionless ready now live
in render_workspace, so both routes go through them. A picked batch still
writes one line, and docs/performance.md says which.
With the event log on by default, the timing registry records a launch's
stages even when DEVLAUNCH_TIMING is unset; only DEVLAUNCH_EVENTS=0 as well
leaves it off. DEVLAUNCH_TIMING now controls only the stderr report.
…ot lose

A SIGHUP _exits dl before session_end or aid_end is written. An interactive
dla start that creates the workspace logs the cold start on the boot's up
line, and aid_start copies cold:false from the attach. stop, kill and remove
log the target as typed, with repo null for a workspace id.
@blooop
blooop marked this pull request as ready for review November 21, 2026 19:15
@blooop blooop added the no-external-review Merge without an external review: a recorded decision, not a default label Nov 21, 2026
@blooop

blooop commented Nov 21, 2026

Copy link
Copy Markdown
Owner Author

A five-axis self-review (defects, types, spec, tests, one mutant) ran on this branch and landed its findings as commits 01700da2..10b78707. Sourcery posted no review, so this PR takes the no-external-review label to merge.

🤖 Generated with Claude Code

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 14 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="rust/dl/src/events.rs" line_range="381-386" />
<code_context>
+    };
+    line.push('\n');
+    if let Some(parent) = path.parent() {
+        let _ = std::fs::create_dir_all(parent);
+    }
+    let Ok(mut file) = std::fs::OpenOptions::new()
+        .create(true)
+        .append(true)
+        .open(&path)
+    else {
+        return;
</code_context>
<issue_to_address>
**Private workspace activity is readable**

When `dl` writes the default log under a traversable home with a typical Unix umask such as 022, another local user can read workspace IDs, private repository and branch names, and launch history from the event log because the directory and file use permissive default creation modes.

Create the log directory and file with owner-only permissions (for example, 0700 and 0600).
</issue_to_address>

### Comment 2
<location path="rust/dl/src/events.rs" line_range="391" />
<code_context>
+    /// Whether [`ready`] has already been heard this command: a launch is ready
+    /// once, however many arms call it.
+    readied: bool,
 }

 impl Registry {
</code_context>
<issue_to_address>
**Concurrent appends corrupt event lines**

When a write to the log file completes partially while another process appends, `append` uses `write_all` without a record-level lock, so another process can append between writes and interleave JSON fragments, leaving malformed event lines.

Make each complete event-line append indivisible across processes.

Also at `rust/dl/src/events.rs:390`.
</issue_to_address>

### Comment 3
<location path="rust/dl/src/events.rs" line_range="390" />
<code_context>
+    else {
+        return;
+    };
+    let _ = file.write_all(line.as_bytes());
+}
+
</code_context>
<issue_to_address>
**Failed writes corrupt event lines**

When the filesystem accepts only part of a line before returning an error, `append` ignores the `write_all` error and leaves the written prefix in the log, so the next event follows that fragment and readers encounter malformed JSONL.

Roll back a partial line after a failed write, or otherwise ensure failed appends leave no fragment.

Also at `rust/dl/src/events.rs:391`.
</issue_to_address>

### Comment 4
<location path="rust/dl/src/events.rs" line_range="381-390" />
<code_context>
+    };
+    line.push('\n');
+    if let Some(parent) = path.parent() {
+        let _ = std::fs::create_dir_all(parent);
+    }
+    let Ok(mut file) = std::fs::OpenOptions::new()
+        .create(true)
+        .append(true)
+        .open(&path)
+    else {
+        return;
+    };
+    let _ = file.write_all(line.as_bytes());
+}
+
</code_context>
<issue_to_address>
**State storage stalls launches**

When `XDG_STATE_HOME` is on a filesystem whose operation stalls, `on_ready` calls `append` synchronously before the launch continues, and `create_dir_all`, `open` and `write_all` have no timeout. A stalled network or FUSE state mount therefore blocks the launch instead of letting it proceed without telemetry.

Move event writes off the launch path or otherwise bound their latency so an unavailable state filesystem cannot hold up a launch.
</issue_to_address>

### Comment 5
<location path="rust/dl/src/events.rs" line_range="381-390" />
<code_context>
+    };
+    line.push('\n');
+    if let Some(parent) = path.parent() {
+        let _ = std::fs::create_dir_all(parent);
+    }
+    let Ok(mut file) = std::fs::OpenOptions::new()
+        .create(true)
+        .append(true)
+        .open(&path)
+    else {
+        return;
+    };
+    let _ = file.write_all(line.as_bytes());
+}
+
</code_context>
<issue_to_address>
**Dropped events go unnoticed**

When the state directory cannot be created or the log cannot be opened or written, the directory-creation, open and write errors are discarded without a diagnostic, metric or alert, so launches and lifecycle actions silently disappear from the log and usage reviews undercount them.

Keep telemetry failures non-fatal but provide a rate-limited diagnostic or another observable signal that event recording is unavailable.
</issue_to_address>

### Comment 6
<location path="rust/dl/src/commands.rs" line_range="864" />
<code_context>
+    // logged alike. A picked batch is several calls; the event state keeps the
+    // last verb, and the first ready.
+    let sessionless = verb.ready_without_a_session();
+    crate::events::workspace(Some(target), word, sessionless);
+    let ending = render_verb(
+        runner,
</code_context>
<issue_to_address>
**Workspace removals disappear from log**

When a user removes a workspace with `--rm` or `rmt`, `--rm` keeps the `attach` or `--` verb, so `events::end` writes only `session_end`; `rmt` bypasses `render_workspace` and does not register a workspace verb. Neither path writes a `remove` event, so usage reviews miss these removals.

Record a removal lifecycle event for both `--rm` and `rmt` paths.

Also at `rust/dl/src/events.rs:141-143`.
</issue_to_address>

### Comment 7
<location path="rust/dl/src/commands.rs" line_range="864" />
<code_context>
+    // logged alike. A picked batch is several calls; the event state keeps the
+    // last verb, and the first ready.
+    let sessionless = verb.ready_without_a_session();
+    crate::events::workspace(Some(target), word, sessionless);
+    let ending = render_verb(
+        runner,
</code_context>
<issue_to_address>
**Refused targets disappear from aid_end**

When `dla` hands `dl` a pull-request target that resolution refuses before workspace dispatch, `events::workspace` has not recorded the target when `dla_end` runs, so it writes `aid_end` with `ws: null` instead of the target the user supplied.

Record the target before pull-request resolution can refuse the command.

Also at `rust/dl/src/events.rs:305`.
</issue_to_address>

### Comment 8
<location path="rust/dl/src/commands.rs" line_range="864" />
<code_context>
+    // logged alike. A picked batch is several calls; the event state keeps the
+    // last verb, and the first ready.
+    let sessionless = verb.ready_without_a_session();
+    crate::events::workspace(Some(target), word, sessionless);
+    let ending = render_verb(
+        runner,
</code_context>
<issue_to_address>
**Lifecycle logs rewritten targets**

When A lifecycle verb is given a pull-request spec that resolves to a branch, `dispatch` has already rewritten a pull-request target before `render_workspace` passes it to the event logger. A `stop`, `kill` or `remove` given a pull-request spec therefore logs the resolved branch rather than the target as typed, contrary to the documented event fields and obscuring what the user requested.

Preserve the original command-line target for event logging while continuing to use the resolved target for the operation.
</issue_to_address>

### Comment 9
<location path="rust/dla/src/main.rs" line_range="257" />
<code_context>
     }
     name_agent_for_session_manager(parsed.agent());
-    match launch.resume {
+    start.hand_over(parsed.agent(), parsed.resumes());
+    let code = match launch.resume {
         Some(resume) => dl::run_resumable(&launch.dl_args, resume),
</code_context>
<issue_to_address>
**Early failures omit end lines**

When A `dla` attempt is canceled or refused before it hands the start to `dl`, `DlaStart` is handed to the event state only at `hand_over`, and earlier `dla` exits return without calling `dla_end`. A start canceled during prompt collection or refused during pre-launch lookup therefore produces no `aid_end`, despite the documented end event for a `dla` start.

Finalize and log the `DlaStart` on every post-start exit, including failures before handover.
</issue_to_address>

### Comment 10
<location path="rust/dl/src/events.rs" line_range="347-352" />
<code_context>
+        _ => (None, None),
+    };
+    let mut event = Map::new();
+    event.insert("ts".into(), iso8601(at).into());
+    event.insert("ev".into(), ev.into());
+    event.insert("ws".into(), workspace_id.or(target).into());
+    event.insert("repo".into(), repo.into());
+    event.insert("branch".into(), branch.into());
+    event
+}
+
</code_context>
<issue_to_address>
**Concurrent starts are misattributed**

When two starts for the same workspace become ready within one millisecond, the event records use millisecond timestamps and have no unique start identifier, so both starts can have the same `ts` and `ws`; the usage-review ASOF join can pair an `aid_start` with the other launch and skew metrics.

Give each start a unique identifier shared by its related event records.

Also at `rust/dl/src/events.rs:404`.
</issue_to_address>

### Comment 11
<location path="rust/devlaunch-core/src/flows/launch.rs" line_range="4200" />
<code_context>
 ) -> Result<Session, SessionRefused> {
+    // Ready before the attach stage opens: what follows is the session, which
+    // lasts as long as somebody works in it and is no part of the start.
+    timing::ready(Some(workspace_id));
     timing::stage_result(timing::Stage::Attach, || {
         // First, and unconditionally on the way to every session: the terminal is
</code_context>
<issue_to_address>
**Failed attaches produce session ends**

When the workspace becomes ready but the subsequent attach fails before establishing a session, `timing::ready` sets `readied` before attach, and `events::end` writes `session_end` for every readied non-sessionless command, so the log counts a session that never started.

Write `session_end` only after a session has been established.

Also at `rust/dl/src/events.rs:155-165`.
</issue_to_address>

### Comment 12
<location path="rust/dl/src/commands.rs" line_range="864" />
<code_context>
+    // logged alike. A picked batch is several calls; the event state keeps the
+    // last verb, and the first ready.
+    let sessionless = verb.ready_without_a_session();
+    crate::events::workspace(Some(target), word, sessionless);
+    let ending = render_verb(
+        runner,
</code_context>
<issue_to_address>
**Picked launches lose repository attribution**

When a user launches a workspace by picking it rather than typing its owner/repo target, a picker selection passes only its workspace ID to the event logger, so `base()` cannot derive `repo` or `branch` from the selected row and writes both as null; usage reviews cannot attribute those launches to a repository or branch.

Pass the selected workspace’s known repository and branch metadata to the event logger and use it when building the event fields.

Also at `rust/dl/src/events.rs:338-345`.
</issue_to_address>

### Comment 13
<location path="rust/dl/tests/launch.rs" line_range="2819-2821" />
<code_context>
+    assert_eq!(launch["branch"], "main");
+    assert_eq!(launch["cold"], false);
+    assert!(
+        launch["seconds"].as_f64().is_some_and(|s| s >= 0.0),
+        "{launch}"
+    );
+    assert!(launch["stages"].is_object(), "{launch}");
+    let ts = launch["ts"].as_str().expect("a timestamp");
</code_context>
<issue_to_address>
**Zero durations pass launch test**

When the ready hook supplies zero seconds for a real launch, the launch event reports `seconds: 0` for a real, nonzero launch, but `a_warm_attach_logs_a_warm_launch_and_then_the_end_of_its_session` accepts any nonnegative number at this assertion, so the bad duration passes.

Assert a meaningful lower bound for this nonzero launch, or compare the emitted duration with an independently measured elapsed interval.
</issue_to_address>

### Comment 14
<location path="rust/dl/tests/launch.rs" line_range="2825-2827" />
<code_context>
+    assert!(launch["stages"].is_object(), "{launch}");
+    let ts = launch["ts"].as_str().expect("a timestamp");
+    assert!(
+        ts.ends_with('Z') && ts.len() == "2026-11-21T09:30:05.250Z".len(),
+        "{ts}"
+    );
+    assert_eq!(lines[1]["ws"], MAIN);
+    assert_eq!(lines[1]["exit"], 0);
</code_context>
<issue_to_address>
**Malformed timestamps pass launch test**

When the emitted launch timestamp has the expected length and ends in `Z` but encodes an invalid date or time, the launch event contains an invalid date or time with the expected string length and a trailing `Z`, but `a_warm_attach_logs_a_warm_launch_and_then_the_end_of_its_session` checks only those two properties, so the malformed timestamp passes.

Parse the emitted timestamp as UTC ISO 8601, or assert its components against a controlled-clock value.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread rust/dl/src/events.rs
Comment on lines +381 to +386
let _ = std::fs::create_dir_all(parent);
}
let Ok(mut file) = std::fs::OpenOptions::new()
.create(true)
.append(true)
.open(&path)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Private workspace activity is readable

When dl writes the default log under a traversable home with a typical Unix umask such as 022, another local user can read workspace IDs, private repository and branch names, and launch history from the event log because the directory and file use permissive default creation modes.

Create the log directory and file with owner-only permissions (for example, 0700 and 0600).

Prompt for AI agents
In `rust/dl/src/events.rs` at lines 381-386:

**Private workspace activity is readable**

When `dl` writes the default log under a traversable home with a typical Unix umask such as 022, another local user can read workspace IDs, private repository and branch names, and launch history from the event log because the directory and file use permissive default creation modes.

Create the log directory and file with owner-only permissions (for example, 0700 and 0600).

Comment thread rust/dl/src/events.rs
return;
};
let _ = file.write_all(line.as_bytes());
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Concurrent appends corrupt event lines

When a write to the log file completes partially while another process appends, append uses write_all without a record-level lock, so another process can append between writes and interleave JSON fragments, leaving malformed event lines.

Make each complete event-line append indivisible across processes.

Also at rust/dl/src/events.rs:390.

Prompt for AI agents
In `rust/dl/src/events.rs` at line 391:

**Concurrent appends corrupt event lines**

When a write to the log file completes partially while another process appends, `append` uses `write_all` without a record-level lock, so another process can append between writes and interleave JSON fragments, leaving malformed event lines.

Make each complete event-line append indivisible across processes.

Also at `rust/dl/src/events.rs:390`.

Comment thread rust/dl/src/events.rs
else {
return;
};
let _ = file.write_all(line.as_bytes());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Failed writes corrupt event lines

When the filesystem accepts only part of a line before returning an error, append ignores the write_all error and leaves the written prefix in the log, so the next event follows that fragment and readers encounter malformed JSONL.

Roll back a partial line after a failed write, or otherwise ensure failed appends leave no fragment.

Also at rust/dl/src/events.rs:391.

Prompt for AI agents
In `rust/dl/src/events.rs` at line 390:

**Failed writes corrupt event lines**

When the filesystem accepts only part of a line before returning an error, `append` ignores the `write_all` error and leaves the written prefix in the log, so the next event follows that fragment and readers encounter malformed JSONL.

Roll back a partial line after a failed write, or otherwise ensure failed appends leave no fragment.

Also at `rust/dl/src/events.rs:391`.

Comment thread rust/dl/src/events.rs
Comment on lines +381 to +390
let _ = std::fs::create_dir_all(parent);
}
let Ok(mut file) = std::fs::OpenOptions::new()
.create(true)
.append(true)
.open(&path)
else {
return;
};
let _ = file.write_all(line.as_bytes());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · State storage stalls launches

When XDG_STATE_HOME is on a filesystem whose operation stalls, on_ready calls append synchronously before the launch continues, and create_dir_all, open and write_all have no timeout. A stalled network or FUSE state mount therefore blocks the launch instead of letting it proceed without telemetry.

Move event writes off the launch path or otherwise bound their latency so an unavailable state filesystem cannot hold up a launch.

Prompt for AI agents
In `rust/dl/src/events.rs` at lines 381-390:

**State storage stalls launches**

When `XDG_STATE_HOME` is on a filesystem whose operation stalls, `on_ready` calls `append` synchronously before the launch continues, and `create_dir_all`, `open` and `write_all` have no timeout. A stalled network or FUSE state mount therefore blocks the launch instead of letting it proceed without telemetry.

Move event writes off the launch path or otherwise bound their latency so an unavailable state filesystem cannot hold up a launch.

Comment thread rust/dl/src/events.rs
Comment on lines +381 to +390
let _ = std::fs::create_dir_all(parent);
}
let Ok(mut file) = std::fs::OpenOptions::new()
.create(true)
.append(true)
.open(&path)
else {
return;
};
let _ = file.write_all(line.as_bytes());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Dropped events go unnoticed

When the state directory cannot be created or the log cannot be opened or written, the directory-creation, open and write errors are discarded without a diagnostic, metric or alert, so launches and lifecycle actions silently disappear from the log and usage reviews undercount them.

Keep telemetry failures non-fatal but provide a rate-limited diagnostic or another observable signal that event recording is unavailable.

Prompt for AI agents
In `rust/dl/src/events.rs` at lines 381-390:

**Dropped events go unnoticed**

When the state directory cannot be created or the log cannot be opened or written, the directory-creation, open and write errors are discarded without a diagnostic, metric or alert, so launches and lifecycle actions silently disappear from the log and usage reviews undercount them.

Keep telemetry failures non-fatal but provide a rate-limited diagnostic or another observable signal that event recording is unavailable.

Comment thread rust/dl/src/events.rs
Comment on lines +347 to +352
event.insert("ts".into(), iso8601(at).into());
event.insert("ev".into(), ev.into());
event.insert("ws".into(), workspace_id.or(target).into());
event.insert("repo".into(), repo.into());
event.insert("branch".into(), branch.into());
event

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Concurrent starts are misattributed

When two starts for the same workspace become ready within one millisecond, the event records use millisecond timestamps and have no unique start identifier, so both starts can have the same ts and ws; the usage-review ASOF join can pair an aid_start with the other launch and skew metrics.

Give each start a unique identifier shared by its related event records.

Also at rust/dl/src/events.rs:404.

Prompt for AI agents
In `rust/dl/src/events.rs` at lines 347-352:

**Concurrent starts are misattributed**

When two starts for the same workspace become ready within one millisecond, the event records use millisecond timestamps and have no unique start identifier, so both starts can have the same `ts` and `ws`; the usage-review ASOF join can pair an `aid_start` with the other launch and skew metrics.

Give each start a unique identifier shared by its related event records.

Also at `rust/dl/src/events.rs:404`.

) -> Result<Session, SessionRefused> {
// Ready before the attach stage opens: what follows is the session, which
// lasts as long as somebody works in it and is no part of the start.
timing::ready(Some(workspace_id));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Failed attaches produce session ends

When the workspace becomes ready but the subsequent attach fails before establishing a session, timing::ready sets readied before attach, and events::end writes session_end for every readied non-sessionless command, so the log counts a session that never started.

Write session_end only after a session has been established.

Also at rust/dl/src/events.rs:155-165.

Prompt for AI agents
In `rust/devlaunch-core/src/flows/launch.rs` at line 4200:

**Failed attaches produce session ends**

When the workspace becomes ready but the subsequent attach fails before establishing a session, `timing::ready` sets `readied` before attach, and `events::end` writes `session_end` for every readied non-sessionless command, so the log counts a session that never started.

Write `session_end` only after a session has been established.

Also at `rust/dl/src/events.rs:155-165`.

Comment thread rust/dl/src/commands.rs
// logged alike. A picked batch is several calls; the event state keeps the
// last verb, and the first ready.
let sessionless = verb.ready_without_a_session();
crate::events::workspace(Some(target), word, sessionless);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Picked launches lose repository attribution

When a user launches a workspace by picking it rather than typing its owner/repo target, a picker selection passes only its workspace ID to the event logger, so base() cannot derive repo or branch from the selected row and writes both as null; usage reviews cannot attribute those launches to a repository or branch.

Pass the selected workspace’s known repository and branch metadata to the event logger and use it when building the event fields.

Also at rust/dl/src/events.rs:338-345.

Prompt for AI agents
In `rust/dl/src/commands.rs` at line 864:

**Picked launches lose repository attribution**

When a user launches a workspace by picking it rather than typing its owner/repo target, a picker selection passes only its workspace ID to the event logger, so `base()` cannot derive `repo` or `branch` from the selected row and writes both as null; usage reviews cannot attribute those launches to a repository or branch.

Pass the selected workspace’s known repository and branch metadata to the event logger and use it when building the event fields.

Also at `rust/dl/src/events.rs:338-345`.

Comment thread rust/dl/tests/launch.rs
Comment on lines +2819 to +2821
launch["seconds"].as_f64().is_some_and(|s| s >= 0.0),
"{launch}"
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Zero durations pass launch test

When the ready hook supplies zero seconds for a real launch, the launch event reports seconds: 0 for a real, nonzero launch, but a_warm_attach_logs_a_warm_launch_and_then_the_end_of_its_session accepts any nonnegative number at this assertion, so the bad duration passes.

Assert a meaningful lower bound for this nonzero launch, or compare the emitted duration with an independently measured elapsed interval.

Prompt for AI agents
In `rust/dl/tests/launch.rs` at lines 2819-2821:

**Zero durations pass launch test**

When the ready hook supplies zero seconds for a real launch, the launch event reports `seconds: 0` for a real, nonzero launch, but `a_warm_attach_logs_a_warm_launch_and_then_the_end_of_its_session` accepts any nonnegative number at this assertion, so the bad duration passes.

Assert a meaningful lower bound for this nonzero launch, or compare the emitted duration with an independently measured elapsed interval.

Comment thread rust/dl/tests/launch.rs
Comment on lines +2825 to +2827
ts.ends_with('Z') && ts.len() == "2026-11-21T09:30:05.250Z".len(),
"{ts}"
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Malformed timestamps pass launch test

When the emitted launch timestamp has the expected length and ends in Z but encodes an invalid date or time, the launch event contains an invalid date or time with the expected string length and a trailing Z, but a_warm_attach_logs_a_warm_launch_and_then_the_end_of_its_session checks only those two properties, so the malformed timestamp passes.

Parse the emitted timestamp as UTC ISO 8601, or assert its components against a controlled-clock value.

Prompt for AI agents
In `rust/dl/tests/launch.rs` at lines 2825-2827:

**Malformed timestamps pass launch test**

When the emitted launch timestamp has the expected length and ends in `Z` but encodes an invalid date or time, the launch event contains an invalid date or time with the expected string length and a trailing `Z`, but `a_warm_attach_logs_a_warm_launch_and_then_the_end_of_its_session` checks only those two properties, so the malformed timestamp passes.

Parse the emitted timestamp as UTC ISO 8601, or assert its components against a controlled-clock value.

@blooop
blooop merged commit 222bd29 into main Nov 21, 2026
21 of 23 checks passed
@blooop
blooop deleted the ags/events-log branch November 21, 2026 19:25
@blooop blooop mentioned this pull request Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-external-review Merge without an external review: a recorded decision, not a default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant