Skip to content

fix(chat): do not 404 sends to a live session before its first reply is saved - #165

Merged
kahme247 merged 1 commit into
ompweb-dev:mainfrom
andrebrait:fix/boundary-before-session-file
Oct 1, 2026
Merged

kahme247 merged 1 commit into
ompweb-dev:mainfrom
andrebrait:fix/boundary-before-session-file

Conversation

@andrebrait

Copy link
Copy Markdown
Collaborator

Problem

Sometimes a session looks normal (editor, model picker, and so on), but every message send fails with HTTP 404.

omp creates the session .jsonl only after the first assistant message is committed. Before dispatching each prompt, handleSend calls snapshotRunEntries, which fetches GET /api/sessions/<id>/context?boundary=1. That applies to existing sessions and to pre-spawned new sessions (existingSid). The route had a live-wrapper fallback for sync=1 but not for boundary=1. For a live session with no file yet, boundary mode returned 404, snapshotRunEntries threw, and the prompt was never sent. Every retry failed the same way.

Production access logs show the pattern: right after POST /api/agent/new, context?sync=1 returns 200 while context?boundary=1 for the same id returns 404, repeated on each send.

Fix

When the path does not resolve and a live wrapper exists whose session file does not exist yet, boundary mode returns { entryIds: [] } (no-store). That is the true persisted boundary, and it matches what the new-session path already uses ([]). Without a live wrapper, or when the file exists but does not resolve or is malformed, boundary still returns 404.

Tests

  • lib/session-routes.test.mjs: the pre-persistence test now expects an empty boundary for a live, unpersisted session. It fails without the fix (404 vs 200). It also asserts 404 for an existing unresolvable file, for a malformed file (session_file_malformed), and when there is no wrapper. Dropping the isAlive/existsSync guard makes the test fail.
  • npm test: 901 pass, 0 fail, 4 skipped. tsc --noEmit and ESLint on the changed files are clean.

@andrebrait

Copy link
Copy Markdown
Collaborator Author

Review companion: andrebrait/ompweb#53

@Broglah1

Copy link
Copy Markdown
Contributor

This fixes #160, which reports the same bug with steps to reproduce (new session, type a slash command, Send, HTTP 404). Could you add Fixes #160 to the description so it closes when this merges?

I've closed #161, which fixed the same thing, in favour of this PR. I tested both locally; the comparison is in the review on #161.

…is saved

omp creates the session file only once the first assistant message is committed. handleSend reads context?boundary=1 before dispatching every prompt; for a live session without a file that returned 404, so the prompt was never sent and every retry failed the same way. Boundary mode now returns an empty entry list for a live wrapper whose file does not exist yet, mirroring the sync fallback.
@andrebrait
andrebrait force-pushed the fix/boundary-before-session-file branch from 842d362 to c4fdb1d Compare October 1, 2026 00:13
@kahme247
kahme247 merged commit d8c8654 into ompweb-dev:main Oct 1, 2026
3 checks passed
kahme247 added a commit that referenced this pull request Oct 2, 2026
Merged #183 turns a 404 from the boundary read into an empty baseline so a
prompt is still dispatched. Its own regression test stubs a state the server
cannot produce -- the harness's /api/agent stub succeeds for any unknown id,
which the real route never does -- so it does not actually pin the fix.

These three do:
- the fileless live session that merged #165 already answers 200, proven on
  the unfixed source, so the original repro no longer exists;
- a 404 boundary on a live session (unreadable file, or a wrapper that died
  between get_state and the read) still dispatches, which is the case #183
  genuinely closes;
- a vanished session with no wrapper still fails loudly, so the new fallback
  did not swallow a real error.
kahme247 added a commit that referenced this pull request Oct 2, 2026
Merged #183 turns a 404 from the boundary read into an empty baseline so a
prompt is still dispatched. Its own regression test stubs a state the server
cannot produce -- the harness's /api/agent stub succeeds for any unknown id,
which the real route never does -- so it does not actually pin the fix.

These three do:
- the fileless live session that merged #165 already answers 200, proven on
  the unfixed source, so the original repro no longer exists;
- a 404 boundary on a live session (unreadable file, or a wrapper that died
  between get_state and the read) still dispatches, which is the case #183
  genuinely closes;
- a vanished session with no wrapper still fails loudly, so the new fallback
  did not swallow a real error.
@andrebrait
andrebrait deleted the fix/boundary-before-session-file branch October 2, 2026 15:30
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.

3 participants