Skip to content

fix: a message the session can't save is reported - #48

Closed
mekjr1 wants to merge 1 commit into
mainfrom
fix/session-write-errors
Closed

mekjr1 wants to merge 1 commit into
mainfrom
fix/session-write-errors

Conversation

@mekjr1

@mekjr1 mekjr1 commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Fixes #36.

Sessions.AddMessage and AddFullMessage returned nothing. JSONLBackend handed the store's error to the standard library's log.Printf, which goes to stderr and not to gateway.log. The turn then went on as if the message were saved. A full disk or a permission problem could keep a message out of <workspace>/sessions/<key>.jsonl. It was then missing from the next turn's context, and from the chat when reopened, with no sign of why.

Now:

  • session.SessionStore's AddMessage and AddFullMessage return the store's error (JSONLBackend). The sub-turns' in-memory store returns nil. The interface's doc no longer calls Add* fire-and-forget.
  • Every append of a turn's messages goes through turnState.noteSessionWrite. That covers the user message, tool calls and their results, denied and skipped calls, steering messages, and the reply.
    • Each failure is logged through Compa's logger.
    • The turn's first failure also emits agent.error with stage session_save, as a failed Save does.
    • It also sends a notice to the chat, except on internal channels: "Couldn't save this conversation: . Later turns won't see what wasn't saved, and the chat won't show it when reopened."
    • The turn goes on, and its reply still reaches the chat. A full disk fails every append, hence one report per turn.
  • JSONLBackend's other failures (summary, history, truncation, metadata) are logged through Compa's logger instead of log.Printf.

A failed Save still fails the turn, as before.

For Go embedders, this changes an exported interface: a type that implements session.SessionStore must return an error from AddMessage and AddFullMessage. CHANGELOG lines under Changed and Fixed. No doc describes the session store.

Tests:

  • TestRunTurn_SessionAppendErrorIsReportedOnce runs a turn whose user message and reply both fail to append. It checks that the reply still comes, with one session_save error and one notice naming the error. It fails when the failure isn't reported, and when it's reported for each message.
  • TestJSONLBackend_AddReturnsTheStoreError fails when the backend drops the error.

@mekjr1

mekjr1 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #63, which includes this change or replaces it.

@mekjr1 mekjr1 closed this Oct 9, 2026
@mekjr1
mekjr1 deleted the fix/session-write-errors branch October 9, 2026 03:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A failed session write loses the message, and only stderr says so

1 participant