#5475·opensre

A contended session write is dropped silently

Author: YauhenBichelCreated Aug 23, 2026Updated Sep 23, 2026
Labelsbugreliability

Problem

A contended session write is dropped silently.

jsonl_store.py:98 — _locked catches Timeout, logs "session file lock timed out; skipping write", and re-raises. Every caller (open_session, flush, _append_entry, ...) wraps the call in contextlib.suppress(Exception). The exception is swallowed, the host is told nothing, and the turn never appears in the session file.

The current test suite pins this as intended: test_enabled_lock_skips_a_write_another_holder_is_blocking.

Why it matters

The dropped records include tool_intent and the write-ahead entries. Losing them does not merely lose history — a session replayed after a restart is missing the turn, so the agent's own record of what it did disagrees with what happened.

Silent is the problem, not the timeout. A user whose message vanished has no signal, and neither does an operator.

Steps

  1. Pick a policy and commit to it in the module docstring:

    • wait longer, then raise a typed error the host surfaces to the user, or
    • fail the turn loudly.

    Not "log and drop". Say in the PR which you chose and why.

  2. Introduce a typed exception (e.g. SessionWriteUnavailable) rather than leaking filelock.Timeout — the store's callers should not import filelock.

  3. Remove the blanket contextlib.suppress(Exception) from the write paths, or narrow it so the timeout escapes while genuinely-optional failures do not.

  4. Rewrite test_enabled_lock_skips_a_write_another_holder_is_blocking. It asserts the old policy. State plainly in the PR description that the test is being changed because it encoded the bug, not because it broke.

  5. Make sure the host surfaces it. The gateway must not send an exception's detail to a chat user (CWE-209, see AGENTS.md) — log detail server-side, surface a generic sentence.

Expected result

A contended write either succeeds after waiting or produces an error someone can see. No path where a user's turn disappears with a WARNING in a log nobody reads.

Verification

Hold the lock from a second process, then attempt a write:

bash
OPENSRE_SESSION_FILE_LOCK=1 uv run python -m pytest \
  tests/core/agent_harness/session/test_jsonl_store_lock.py -q

Expected: the rewritten test asserts the typed error (or the successful wait), not a skipped write.

End to end — with a lock held externally, send one message through the gateway and confirm the user sees a real message and the log carries the detail. Describe what you saw in the PR.

Confirm no raw detail leaks to the chat surface:

bash
grep -rn "str(exc)\|repr(exc)\|format_exc" gateway/transports/*/[a-z]*.py | grep -v test

Checklist

  • Policy chosen and stated in the module docstring
  • Typed exception; callers do not import filelock
  • suppress(Exception) no longer swallows the timeout on write paths
  • The old test rewritten, with the reason in the PR description
  • Chat surfaces show a generic message; detail is logged server-side
  • make lint format typecheck test

Out of scope

open_session truncation, and the default value of OPENSRE_SESSION_FILE_LOCK. Both are tracked separately; neither blocks this issue, and this one does not block them.

Claiming this issue

Ask in OpenSRE Discord before you start so a maintainer can assign it. Ask OpenSRE maintainers and write a commit under this issue.

Testing this from a surface

Same rig as #5474 — two tasks writing one session:

  1. Gateway up on Slack Socket Mode, Telegram, or Discord.
  2. Two messages to the same conversation, close together.
  3. uv run opensre --resume <session-id>.

Pass: a write that cannot get the lock surfaces to the user or fails the turn. Fail (today): the turn is missing from the session and nobody — user or operator — is told.