Skip to content

fix(j5): a refused new message in a shared conversation leaves no author record - #863

Merged
Jacksondr5 merged 3 commits into
j5/mainfrom
fix/refused-message-leaves-no-author
Nov 1, 2026
Merged

Jacksondr5 merged 3 commits into
j5/mainfrom
fix/refused-message-leaves-no-author

Conversation

@Jacksondr5

@Jacksondr5 Jacksondr5 commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner

Problem

In a shared conversation, stampMessage writes a new message's author record (author, note, stored prefix) while J5 admits it, before upstream dispatches it. If upstream refused the message, the record stayed with no message behind it. Because the insert is ON CONFLICT … DO NOTHING, a retry under the same message id kept the old prefix and note, so the platform's lines might not be stripped and the note might be wrong. A launch's first message had the same problem, and clients send a stable draft messageId on launch.

Closes #740

What changed

The fix reserves the record at admission and releases it if upstream refuses.

  • The record is still written at admission, exactly as before. That write is what reserves the id: a second sender under the same id is refused with "This message was already sent." It also keeps true the timeline's assumption that a message's record exists before the message does.
  • If upstream's dispatch fails, SharedConversation.dispatch deletes the record, but only while upstream holds no message under that id (DELETE … AND NOT EXISTS (SELECT 1 FROM orchestration_v2_projection_messages WHERE message_id = …), one statement). So a request that fails after upstream committed the message keeps its record. A refused message's row, with its told_json, goes away, so a retry under the same id records afresh with the current name, prefix and note.
  • Launches had the same issue, so they're fixed here too. SharedConversation.admitLaunch becomes SharedConversation.launch(personId, input, upstreamLaunch), and CommandAdmission.admitLaunch becomes launchThread(input, upstreamLaunch). ws.ts now wraps upstream's launch handler the way it already wraps dispatch, so a failed launch releases its first message's record under the same condition.
  • Unchanged: queued edits keep fix(j5): a refused edit to a queued message keeps its author record #739's deferred, conditional write. Answers, scheduled runs and inbox replies are unchanged too.

An attempt releases only a record it wrote itself: recordAuthor now reports whether its insert wrote the row (RETURNING). So a retry that overlaps a pending send under the same id finds the first attempt's row, and if the retry fails it leaves that row in place.

A failure to release is logged. That message's record then stays as it was, which is the behaviour before this PR.

Tests (on upstream's real orchestrator, in SharedConversation.integration.test.ts):

  • "a new message upstream refuses leaves no author record, and its retry is recorded". Upstream refuses Priya's message to continue a run that never ran (OrchestratorDispatchError). No record and no stored message remain. She is renamed, sends again under the same id, and the record names "Priya Shah" with a prefix equal to the stored text's.
  • "a launch upstream refuses leaves no author record for its first message". Upstream refuses a launch into a project it doesn't have (ThreadLaunchError), and no record remains. The relaunch under the same message id records the current name and the matching prefix.
  • "a message's id is held from admission, and its record kept once upstream stored it":
    • Sam sends under Priya's id while hers is between admission and upstream's dispatch, and is refused with "This message was already sent." Her record and stored text are hers.
    • Her next message is stored by upstream, then the request fails, and the message keeps its record.
    • Her client retries a send that is still on its way to upstream, the retry fails first, and then upstream takes the first attempt: the record is present and correct.
  • Both refusal tests fail without the release. The kept-record case fails without the stored-message condition, and the overlapping-retry case fails if an attempt releases a row it didn't write.
  • The existing launch test now goes through conversation.launch with upstream's real launch, and also checks that the record's prefix matches the stored text.

Upstream impact

  • apps/server/src/ws.ts, FORK.md case 78: the orchestration.launchThread entry in admittedHandlers is now j5Commands.launchThread(input, upstream's handler), which replaces admitLaunch(input).pipe(Effect.flatMap(…)). The launch needs this callback shape to release on failure. It is one line shorter. The case 78 text in FORK.md is updated to match. Its file-table row already lists 78.

Review

GPT-6-Astra and Claude Fable 5.1 reviewed the first version, which deferred a conditional insert until upstream accepted the message. That dropped the id reservation: two senders under one id could both pass admission. It also broke the timeline's assumption that a message's record exists before the message. This version restores the eager write and releases it on refusal instead. Astra's second round found that an overlapping retry's release could delete the first attempt's row. Each attempt now releases only a row it wrote.

Checklist

  • One concern: the description has no "also"
  • Tests cover the changed behavior (backend changes ship with focused tests)
  • UI changes: before/after screenshots above, and a video for motion or interaction. Not applicable: no UI change.
  • Live testing: not run. Nothing visible changes (lastTold already ignored run-less messages), and the regression tests drive upstream's real orchestrator and launch with their real refusals.
  • Upstream-owned files: each one is recorded in FORK.md (case text and file-table row) in this PR
  • Upstream product: unchanged
  • Surfaces: a person's messages reach this through orchestration.dispatchCommand and orchestration.launchThread via CommandAdmission, which web, desktop and mobile all use. Agents and service sessions have no person and were never stamped. No contract change.
  • Docs: no product or user docs describe this. FORK.md case 78 updated.

vp run check:changed passes: format, lint, knip, typecheck of 3 packages, and the tests beside changes. All 28 test files that import the changed modules pass (205 tests).

Built by Claude Opus 5.5 in Claude Code (J5 Code).

🤖 Generated with Claude Code

…hor record

A person's new message, and a launch's first message, recorded its author,
note and stored prefix while J5 admitted it, before upstream dispatched it.
If upstream refused it, the record stayed with no message behind it, and a
retry under the same message id kept the old prefix and note.

stampMessage now checks the message id is the author's at admission, as
before, and returns its record write instead of running it.
SharedConversation.dispatch runs that write after upstream accepts, as it
does for edits since #739, and the write is conditional on the stored text
being exactly this message's. Launches go through a new
SharedConversation.launch, wrapped around upstream's launch in ws.ts as
dispatch is, and its write runs whether upstream's launch succeeds or fails,
because a launch can store the message and then fail.

Closes #740

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
j5-code Ready Ready Preview Nov 1, 2026 2:55am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

  • Run on-demand review

This review includes 8 billable files and costs up to $2.00.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 9 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available. Your 54 included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between f24b6f1 and 7ce162b.

Files selected for processing: 8
  • FORK.md
  • apps/server/src/j5/sharing/CommandAdmission.test.ts
  • apps/server/src/j5/sharing/CommandAdmission.ts
  • apps/server/src/j5/sharing/SharedConversation.integration.test.ts
  • apps/server/src/j5/sharing/SharedConversation.test.ts
  • apps/server/src/j5/sharing/SharedConversation.ts
  • apps/server/src/j5/sharing/messageStamps.ts
  • apps/server/src/ws.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@github-actions github-actions Bot added size:L 100-499 effective changed lines (test files excluded in mixed PRs). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. labels Nov 1, 2026
…efusal

Review of #863 found that writing a new message's author record only after
upstream accepted it dropped the reservation that refuses a second sender
under the same message id, and broke the timeline's assumption that a
message's record exists before the message does.

The record is written at admission again, exactly as on j5/main. If
upstream's dispatch or launch fails, the record is deleted, but only while
upstream stored no message under that id, so a request that fails after
upstream committed the message keeps its record. A retry under the same id
after a refusal then records afresh. Queued edits keep #739's deferred,
conditional write. The launch still needs the callback shape in ws.ts to
release on failure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review of #863 found that two overlapping attempts by the same person under
the same message id share one record: the second finds the first's row, and
if the second then failed, its release deleted that row, so the first
committed with no record.

recordAuthor now reports whether its insert wrote the row, and a message's
release does nothing unless this attempt wrote it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Jacksondr5
Jacksondr5 merged commit e47ddd6 into j5/main Nov 1, 2026
33 checks passed
@Jacksondr5
Jacksondr5 deleted the fix/refused-message-leaves-no-author branch November 1, 2026 03:11

This branch was successfully deployed

1 active deployment
Preview — 7ce162b4 Deployed Nov 1, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 effective changed lines (test files excluded in mixed PRs). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A refused new message in a shared conversation still leaves an author record

1 participant