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

A text approved late at night waits until 8 a.m. and the desk says when it will go #44

Merged opened this

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

Merged

Texts approved outside 8:00 a.m.–9:00 p.m. in the agent's time zone are now held until the next 8:00. All 219 tests pass, including the new ones, and bun run lint:design is clean.

Notes

shipped production is serving it deploy aba151a

opened this

Texts approved outside 8:00 a.m.–9:00 p.m. in the agent's time zone are now held until the next 8:00. All 219 tests pass, including the new ones, and bun run lint:design is clean. I could not type-check: the repository has no tsconfig.json, so bun x tsc --noEmit only prints its help. I also did not boot the app by hand, because the port is unknown. The server tests start the real server instead.

What changed

  • Rule: src/quiet.ts is new and holds the rule. Emails are never held, and the daylight-saving cases are tested.
  • Profile: it gains a timeZone field, an IANA name checked with Intl.DateTimeFormat. The default is AGENT_TIMEZONE, then TZ, then America/New_York. An invalid name is a 422, and leaving it out keeps the current one.
  • Approval: approveReply records an outside-hours text as a new held message status with goes_at and approved_at. For a first reply the lead counts as answered at approval and the follow-ups start only when the text goes, so the response record counts approval time. A line under the record says so.
  • Cancel: cancelHeld returns the text to a draft and un-answers a first reply.
  • Sending: turn() (so POST /tick and the in-process clock) sends held texts once their time comes.
  • Opt-out and edits: a lead who has opted out, or lost their phone, gets the text back as an email draft instead. A held text for a lead who is later marked lost is set aside, and one that falls due after 9 p.m. waits for the next 8:00.
  • Doors:
    • Page: the lead page and the desk show "Goes at 8:00 a.m. tomorrow" with a Cancel button, and warn before you approve a text in quiet hours.
    • API: the reply answer carries scheduledFor when held, and POST /leads/:id/unhold takes it back. Both are in /openapi.json and contract/openapi.json.
    • MCP: send_reply carries scheduledFor, and there is a new cancel_held_text tool.
    • Terminal: the lead screen shows when it goes, h takes it back, and the profile edit asks for the time zone.
  • README: "Quiet hours" paragraph added.
  • Migration: it rebuilds message and profile with their rows, so data is kept. It is safe to rerun, as two existing migration tests require.

Worth a look

  • QUIET_HOURS=off: this env switch turns quiet hours off and is documented in the README. bunfig.toml and src/test-setup.ts set it for the suite. Without it, the many existing tests that approve texts at fixed or real times would pass or fail depending on the hour. The quiet-hours tests turn it back on.
  • Existing tests I edited: these four changed only because the feature adds a field or step.
    • The terminal profile-edit tests have one more field to step through.
    • The MCP tool-list test has the new tool.
    • The profile tests expect timeZone in the profile.
    • openapi.json was regenerated.
  • Tick interval: the in-process tick runs every 5 minutes instead of hourly, so a held text goes within minutes of 8:00.
  • Audit: approving a held text is audited as held and cancelling as unhold. The delivery at 8:00 is done by the clock, not a person, so it is not audited. The Activity "sent only" filter therefore does not list it.

No contract cell changed.

Closes #42

2 earlier comments · 1 event
commented

Texts approved outside 8:00 a.m.–9:00 p.m. in the agent's time zone are now held until the next 8:00. All 219 tests pass, including the new ones, and bun run lint:design is clean. I could not type-check: the repository has no tsconfig.json, so bun x tsc --noEmit only prints its help. I also did not boot the app by hand, because the port is unknown. The server tests start the real server instead.

What changed

  • Rule: src/quiet.ts is new and holds the rule. Emails are never held, and the daylight-saving cases are tested.
  • Profile: it gains a timeZone field, an IANA name checked with Intl.DateTimeFormat. The default is AGENT_TIMEZONE, then TZ, then America/New_York. An invalid name is a 422, and leaving it out keeps the current one.
  • Approval: approveReply records an outside-hours text as a new held message status with goes_at and approved_at. For a first reply the lead counts as answered at approval and the follow-ups start only when the text goes, so the response record counts approval time. A line under the record says so.
  • Cancel: cancelHeld returns the text to a draft and un-answers a first reply.
  • Sending: turn() (so POST /tick and the in-process clock) sends held texts once their time comes.
  • Opt-out and edits: a lead who has opted out, or lost their phone, gets the text back as an email draft instead. A held text for a lead who is later marked lost is set aside, and one that falls due after 9 p.m. waits for the next 8:00.
  • Doors:
    • Page: the lead page and the desk show "Goes at 8:00 a.m. tomorrow" with a Cancel button, and warn before you approve a text in quiet hours.
    • API: the reply answer carries scheduledFor when held, and POST /leads/:id/unhold takes it back. Both are in /openapi.json and contract/openapi.json.
    • MCP: send_reply carries scheduledFor, and there is a new cancel_held_text tool.
    • Terminal: the lead screen shows when it goes, h takes it back, and the profile edit asks for the time zone.
  • README: "Quiet hours" paragraph added.
  • Migration: it rebuilds message and profile with their rows, so data is kept. It is safe to rerun, as two existing migration tests require.

Worth a look

  • QUIET_HOURS=off: this env switch turns quiet hours off and is documented in the README. bunfig.toml and src/test-setup.ts set it for the suite. Without it, the many existing tests that approve texts at fixed or real times would pass or fail depending on the hour. The quiet-hours tests turn it back on.
  • Existing tests I edited: these four changed only because the feature adds a field or step.
    • The terminal profile-edit tests have one more field to step through.
    • The MCP tool-list test has the new tool.
    • The profile tests expect timeZone in the profile.
    • openapi.json was regenerated.
  • Tick interval: the in-process tick runs every 5 minutes instead of hourly, so a held text goes within minutes of 8:00.
  • Audit: approving a held text is audited as held and cancelling as unhold. The delivery at 8:00 is done by the clock, not a person, so it is not audited. The Activity "sent only" filter therefore does not list it.

No contract cell changed.

Changes requested — before the latest push

Quiet hours work as the issue asks, and I found no security problem. The rule is pure, the zone is validated, the migration is versioned, and the unhold route goes through the same permission and same-origin path as the other lead changes. One change is needed.

Fix: src/contract.test.ts has no row for the new doors. POST /leads/:id/unhold, cancelHeld and the MCP tool cancel_held_text are not in the permission matrix. Next to the showing block (around line 125), add a check that cancelHeld is allowed exactly where permit("lead","update") allows it. Cover anon, user and admin, on a lead that has a held text. Also check cancel_held_text through the MCP with the same expectations.

No contract.json cell is loosened.

Not blocking, but worth a line in the README: the 8:00 delivery is done by the clock and is not audited, so Activity shows held but never the send.

commented

This push addresses sentinel's requested change. The held-text doors are now in the permission matrix, and the README notes that the 8:00 send isn't audited.

  • Permission matrix: the lead.update door in src/contract.test.ts now also exercises cancelHeld, which backs POST /leads/:id/unhold. It also exercises the MCP tool cancel_held_text, looked up in the real tools list.
    • Each check runs on a lead with a text actually held for the next 8:00. The test builds that state with hold() directly, so it doesn't depend on the clock or the lead's consent.
    • Both doors must answer exactly as setState does under permit("lead","update"). The test already covers anon, user and admin on rows that are theirs and on rows that aren't.
  • README: the Quiet hours paragraph now says the 8:00 delivery is done by the clock and isn't audited. Activity shows held and the cancel, but never the send.
  • Tests: src/contract.test.ts and src/quiet.test.ts pass (22 tests). I didn't run the full suite.
  • Not run: the repo has no tsconfig.json, so I didn't run bun x tsc --noEmit; bun x tsc only printed its help text. There is no scripts/gate.ts to run either.
  • Contract: no contract.json cell changed.
  • Disagreements: none.
commented

The preview's one failing test, a change is on the event stream, and a late client hears what it missed in src/server.test.ts, is fixed. The full suite now passes locally (219 pass, 0 fail). The failure only showed up when the whole suite ran in one process, and it reproduced for me that way.

Cause: the test opened /events with no cursor. The server replays its last 100 events to a client like that, so the test's first "heard" event was whichever old one came first, not the lead it had just created. The quiet-hours tests in this pull emit enough extra events that the heard event had already been pushed out of the 100 by the time the late client asked for it.

Fix: the test now opens the first stream with ?since=999999999, so it replays nothing and hears only what it creates. Only the test changed, and the server's replay behaviour is untouched. I changed the test because it was wrong: it assumed the server's event history would still hold the event it was looking for.

To try: bun test runs the whole suite.

Approved

Earlier asks are met. (1) The held-text doors are in the permission matrix: src/contract.test.ts now runs cancelHeld and the MCP tool cancel_held_text against a lead with a text actually held, and both must answer exactly as setState does under permit(lead, update). (2) The README says the 8:00 delivery is done by the clock and is not audited. The only change since my last review is the server.test.ts fix (the event-stream test now opens with ?since=999999999). That is a fair fix to a test that was wrong, and the server is untouched. No contract.json cell is loosened. Writes go through permit. The migration keeps rows and is safe to rerun. The preview answers 200. I could not check the sign-in-only pages or the openapi output on the preview. Non-blocking: the repository has no tsconfig.json, so type-checking is not covered. Non-blocking: the openapi route description for the timeZone field is long and could be shortened.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs