Skip to content

dogfood: Echo records are fsynced on the async task before the reply's final SSE frames / JSON body #11

Open

Description

@n0rpan

Reported by oxa itself in the goal loop (task deng, model anthropic/claude-opus-5-5, host air):

  • Where: engine/crates/server/src/echo.rs:463 (append_line: f.write_all(...)?; f.sync_data()), called from engine/crates/server/src/service.rs:480 (echo_record → p.write()) and :518 (echo_adopt); call sites service.rs:2202–2205 (non-stream) and :2335–2339 (stream)
  • Severity: P2 (latency at the end of every agent turn, and a blocked tokio worker thread)
  • Trigger: echo enabled (the default, EchoConfig::default has enabled: true). Any non-ephemeral chat completion.
  • Mechanism: in the stream path the finish chunk, usage and timings are built into frames. Then st.echo_adopt(...) and st.echo_record(...) run synchronously inside the tokio::spawned async block, and only after that does for f in frames { if !send_final(&tx, api::sse(&f), stall).await … send them. The non-stream path does the same before api::chat_response. Each pending append opens the file and calls sync_data(). The audit-N4 comment ("the file append and its fsync run after the store's mutex is released") moved the fsync out of the mutex but not off the async task or the reply path. The client therefore sees finish_reason/[DONE] only after one or more disk flushes. In an agent loop, the next tool call cannot start until then. Issue oxstack/ox-llm#213 listed "Echo record writes fsync inside async code" and was closed as parked, but the code at HEAD 474e71a4 is unchanged.
  • Fix: send the final frames first and then do the echo writes. Alternatively, run PendingAppend::write in tokio::task::spawn_blocking (or a dedicated writer thread/channel). Keep the in-memory record_deferred where it is, so the next request's splice already sees the record.
  • Not verified: the fsync latency on the target SSD, and whether a lost echo line after a crash matters enough to keep sync_data at all (a missing record costs a cache miss, not data).

🤖 Generated with Claude Code (oxa goal loop)

Activity

  1. added
    bug
    on Nov 16, 2026
  2. n0rpan commented on Nov 19, 2026

    @n0rpan
    ContributorAuthor

    Triage 2026-11-19: this issue is now tracked in #28 (Cluster: Engine performance and hardware, priority P2), planned PR 1: "Hot path". It will be fixed there together with its related issues, not one by one.

  3. transferred this issue fromon Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions