Public: anyone can read this; the crew can change it.

Pressed Send by mistake? For one minute after, one tap takes it back to a draft #91

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

For 60 seconds after a message is approved, the lead's page shows Undo send beside it, and one tap puts the message and the lead back as they were. The new tests pass, as do the star, db and openapi tests.

Notes

shipped production is serving it deploy aba151a

opened this

For 60 seconds after a message is approved, the lead's page shows Undo send beside it, and one tap puts the message and the lead back as they were. The new tests pass, as do the star, db and openapi tests. In the last full run of the src/ tests, src/live.test.ts ("a write from another process on the same file reaches the bus") failed, and it fails the same way without my changes. I could not run a TypeScript check, because the repo has no tsconfig.json. scripts/gate.ts does not exist here. bun scripts/lint-design.ts printed nothing, which I took as clean.

What changed

  • Snapshot: each approval keeps a snapshot of the lead's state, replied_at and back_on, plus all its messages as they stood just before. It is stored in a new undo_send table, kept to one row per lead. The logic is in src/undo.ts, called from reply() in src/actions.ts.
  • Undo: the message returns to a draft with the words as sent. The lead's state and clock go back, so a first reply undone leaves the lead new with its clock running and out of the response record. Follow-ups the send created are deleted, so sending again does not duplicate them.
  • Route: POST /leads/:id/undo goes through the same-origin check and permit as an update of the lead. Anon gets 401.
  • Window: the 60 seconds are measured on the server's clock. After that, or when there is nothing to undo, the route answers 409 with a plain sentence.
  • Page: the button shows in the history entry of the message just sent, and in the held-text pane. The "desk confirmation after approving" is this same lead page: the approval redirects there with "Sent."
  • Held texts: undo applies to them within the minute of approval, restoring the pre-approval state.
  • Audit: the send was already recorded. The undo is a new unsent row, shown on Activity as "took back the message to … (undo send)", with who and when.
  • README: a new "Undo send" paragraph sits next to Quiet hours.
  • Contract: contract/openapi.json is regenerated, since the route added an entry.
  • Tests: src/undo.test.ts covers undo restoring draft, state and clock, the refusal after the minute, anon refused, both audit rows, resend without duplicate follow-ups, held texts, the page button, and the route over HTTP including a cross-site POST.

Choices

  • Changed since the send: if the lead's updated_at changed after the send, undo answers 409 rather than overwriting the newer change. This also covers a held text that has already gone out at 8:00.
  • Star test: src/star.test.ts asserted that its migration was the last one. I loosened that to > 0 because the new table migration comes after it. The test was wrong to pin the order; its behaviour check is unchanged.

Not done

  • Undo is not in the MCP tools or the terminal, only the page and the JSON route.
  • The "Messages sent only" filter on Activity still shows only sends, not undos.
  • No contract.json cell was loosened.

To try it: approve a reply on a lead and press Undo send on the lead page within a minute.

🤖 Generated with Claude Code

Closes #74

3 earlier comments · 2 events
commented

For 60 seconds after a message is approved, the lead's page shows Undo send beside it, and one tap puts the message and the lead back as they were. The new tests pass, as do the star, db and openapi tests. In the last full run of the src/ tests, src/live.test.ts ("a write from another process on the same file reaches the bus") failed, and it fails the same way without my changes. I could not run a TypeScript check, because the repo has no tsconfig.json. scripts/gate.ts does not exist here. bun scripts/lint-design.ts printed nothing, which I took as clean.

What changed

  • Snapshot: each approval keeps a snapshot of the lead's state, replied_at and back_on, plus all its messages as they stood just before. It is stored in a new undo_send table, kept to one row per lead. The logic is in src/undo.ts, called from reply() in src/actions.ts.
  • Undo: the message returns to a draft with the words as sent. The lead's state and clock go back, so a first reply undone leaves the lead new with its clock running and out of the response record. Follow-ups the send created are deleted, so sending again does not duplicate them.
  • Route: POST /leads/:id/undo goes through the same-origin check and permit as an update of the lead. Anon gets 401.
  • Window: the 60 seconds are measured on the server's clock. After that, or when there is nothing to undo, the route answers 409 with a plain sentence.
  • Page: the button shows in the history entry of the message just sent, and in the held-text pane. The "desk confirmation after approving" is this same lead page: the approval redirects there with "Sent."
  • Held texts: undo applies to them within the minute of approval, restoring the pre-approval state.
  • Audit: the send was already recorded. The undo is a new unsent row, shown on Activity as "took back the message to … (undo send)", with who and when.
  • README: a new "Undo send" paragraph sits next to Quiet hours.
  • Contract: contract/openapi.json is regenerated, since the route added an entry.
  • Tests: src/undo.test.ts covers undo restoring draft, state and clock, the refusal after the minute, anon refused, both audit rows, resend without duplicate follow-ups, held texts, the page button, and the route over HTTP including a cross-site POST.

Choices

  • Changed since the send: if the lead's updated_at changed after the send, undo answers 409 rather than overwriting the newer change. This also covers a held text that has already gone out at 8:00.
  • Star test: src/star.test.ts asserted that its migration was the last one. I loosened that to > 0 because the new table migration comes after it. The test was wrong to pin the order; its behaviour check is unchanged.

Not done

  • Undo is not in the MCP tools or the terminal, only the page and the JSON route.
  • The "Messages sent only" filter on Activity still shows only sends, not undos.
  • No contract.json cell was loosened.

To try it: approve a reply on a lead and press Undo send on the lead page within a minute.

🤖 Generated with Claude Code

Changes requested — before the latest push

The undo itself is well built. It snapshots the lead, restores it whole, uses server time, is a same-origin POST that goes through permit, and is audited. It loosens no cell. One thing blocks it.

Fix first: the terminal is missing (both doors). The review list says anything a person can do on the page they can do in src/tty.ts too. The README says outright that "MCP and the terminal do not have it". Add an undo command to src/tty.ts that calls undoSend with the terminal's who, so it goes through permit and the audit like the page. It must emit lead.changed so web viewers update live. Add a test for it, and change the README sentence to say the terminal has it. Say in the README whether MCP has it. The list has no exception for leaving a door out on purpose.

Smaller points to fix in the same round:

  • reply() in src/actions.ts runs capture, the send and keep as separate statements. Wrap them in one transaction so a failure between them cannot leave a send with no way back, or a stale snapshot.
  • src/star.test.ts now pins the migration at > 0. Pin it to the migration's real position, or check that the star migration comes before the undo table, so the test can still fail.
  • Mason did not run tsc. Run bun x tsc --noEmit and say what happened.

I did not open the preview for this review; this comes from reading the diff.

commented

I've fixed all four review points and pushed; tsc still can't run here, as explained under the last point. The new and touched tests pass: src/undo.test.ts, src/star.test.ts, src/terminal.test.ts, src/contract.test.ts, src/quiet.test.ts and src/openapi.test.ts. I did not re-run the whole src/ suite after this round.

  • Terminal: pressing z on a lead now calls undoSend with the terminal's who, so it goes through permit and the audit like the page, and it emits lead.changed. The hint "z undo send (for a minute)" shows only while the minute lasts. After the minute the key does nothing. A new test covers the key, the audit row and the expired case.
  • Terminal file: the review said src/tty.ts, but the terminal's commands are in src/terminal.ts; tty.ts is only a 36-line launcher. I made the change in src/terminal.ts.
  • MCP: I added an undo_send tool as well, so no door is left out. A test covers it, and the README now says the page, the JSON door, MCP (undo_send) and the terminal all have undo.
  • Transaction: capture, the send (or hold) and keep now run in one db.transaction in reply(), so a failure rolls all three back together.
  • Star test: it still asserts the starred migration's position is greater than 0. It now also asserts that the undo_send migration comes after it, so it can still fail. I did not pin an exact index, since every later migration would break it.
  • tsc: bun x tsc --noEmit does not type-check this repo. There is no tsconfig.json and no typescript dependency, so it resolves to an unrelated package and prints its help text. I did not add a config or a dependency just to get a check. The Bun test run still loads every changed file.

🤖 Generated with Claude Code

commented

The preview's one failing test was my miss, and it's fixed and pushed. src/server.test.ts lists every MCP tool by name, and I had added undo_send last round without adding it to that list. I added it. src/server.test.ts now passes (37 passed, 0 failed). I did not re-run the full suite.

This is the same pull as before: the Undo send button on the lead page, the POST /leads/:id/undo route, z in the terminal and the undo_send MCP tool. Nothing else changed this round.

🤖 Generated with Claude Code

Approved

Earlier asks are met: undo is on the terminal (z, gated by permit and audited), MCP (undo_send) is added, capture, send and keep run in one transaction, and the MCP tool list test is fixed. The preview answers 200. I could not diff against f06971d894ee because the commit is not in the clone, so I read the full change. No contract.json cell is loosened. The route is a same-origin POST through permit, with anon refused. The undo is audited as unsent. Tests cover restore, expiry, anon, audit, resend without duplicates, held texts, terminal and MCP. Non-blocking: the Activity filter for messages sent still omits undos.

commented

Left #74 open: 1 unticked item remain (For 60 seconds after a message is marked sent, the lead's page (and the desk's confirmation after approving) shows "Undo send" beside it. Pressing it returns the message to a draft with its words as sent, and the lead's clock and state go back to what they were before the send (a first reply undone leaves the lead new and its clock running again).).

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs