feat(service,database): chat writes answer the transaction they committed in

Draft
CH
8d ago
+186-58

Part of making workspace chat live over Neon Realtime. Stacked on #3916. One change: chat writes return their txid, as Neon's mutations guide does it.

What changes

  • txid from the write itself. Each chat write reads pg_current_xact_id()::text in its own RETURNING. The covered writes are:

    • a post
    • an answer
    • a resolve
    • a channel's read-to
    • a topic channel opened or edited

    Chat writes run several statements in one transaction, so the txid comes from the write that changes the row, as the guide says. There's no extra round trip.

  • A write that changes nothing answers no txid, so there's nothing to wait for. That covers:

    • a post repeated under its key
    • a read-to where the cursor already stands (the chat_read upsert only moves forward)
    • an edit that leaves the topic as it was (is distinct from)
    • a read-to of every channel, which the window never sends
  • Wire: each chatWriteAnswerSchema variant gains an optional txid.

  • Store: readTo now answers { txid } or false. A message or channel row answered by a write carries txid; one read back doesn't.

The host's wait on the txid is #3923's child PR.

Tests

  • New chat-store.test.ts case:
    • a post answers a txid, and its repeat doesn't
    • a read-to answers one, and the same read-to again doesn't
    • a topic open and a real edit answer one, and a no-op edit doesn't
  • coding-agents-app.test.ts checks that a read-to through the route carries the txid, and that a repeat carries none.
  • Goldens for chatWriteAnswerSchema and codingAgentChatWriteAnswerViewSchema were regenerated under LUKE_UPDATE_FIXTURES=1. The only change is the optional txid.
  • Checks were run one at a time on the stack's top: tsc for each touched package, biome, oxlint, knip, discarded-effect, the repository checks, and the affected vitest suites.

Made with Luke