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
Check · Review · Land · Live done — Landed and live in production.
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.
shipped production is serving it deploy aba151a
2 earlier comments · 1 event
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.tsis new and holds the rule. Emails are never held, and the daylight-saving cases are tested. - Profile: it gains a
timeZonefield, an IANA name checked withIntl.DateTimeFormat. The default isAGENT_TIMEZONE, thenTZ, thenAmerica/New_York. An invalid name is a 422, and leaving it out keeps the current one. - Approval:
approveReplyrecords an outside-hours text as a newheldmessage status withgoes_atandapproved_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:
cancelHeldreturns the text to a draft and un-answers a first reply. - Sending:
turn()(soPOST /tickand 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
scheduledForwhen held, andPOST /leads/:id/unholdtakes it back. Both are in/openapi.jsonandcontract/openapi.json. - MCP:
send_replycarriesscheduledFor, and there is a newcancel_held_texttool. - Terminal: the lead screen shows when it goes,
htakes it back, and the profile edit asks for the time zone.
- README: "Quiet hours" paragraph added.
- Migration: it rebuilds
messageandprofilewith 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.tomlandsrc/test-setup.tsset 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
timeZonein the profile. openapi.jsonwas 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
heldand cancelling asunhold. 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.
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.
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.updatedoor insrc/contract.test.tsnow also exercisescancelHeld, which backsPOST /leads/:id/unhold. It also exercises the MCP toolcancel_held_text, looked up in the realtoolslist.- 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
setStatedoes underpermit("lead","update"). The test already covers anon, user and admin on rows that are theirs and on rows that aren't.
- Each check runs on a lead with a text actually held for the next 8:00. The test builds that state with
- README: the Quiet hours paragraph now says the 8:00 delivery is done by the clock and isn't audited. Activity shows
heldand the cancel, but never the send. - Tests:
src/contract.test.tsandsrc/quiet.test.tspass (22 tests). I didn't run the full suite. - Not run: the repo has no
tsconfig.json, so I didn't runbun x tsc --noEmit;bun x tsconly printed its help text. There is noscripts/gate.tsto run either. - Contract: no
contract.jsoncell changed. - Disagreements: none.
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.
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.
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:designis clean. I could not type-check: the repository has notsconfig.json, sobun x tsc --noEmitonly 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
src/quiet.tsis new and holds the rule. Emails are never held, and the daylight-saving cases are tested.timeZonefield, an IANA name checked withIntl.DateTimeFormat. The default isAGENT_TIMEZONE, thenTZ, thenAmerica/New_York. An invalid name is a 422, and leaving it out keeps the current one.approveReplyrecords an outside-hours text as a newheldmessage status withgoes_atandapproved_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.cancelHeldreturns the text to a draft and un-answers a first reply.turn()(soPOST /tickand the in-process clock) sends held texts once their time comes.scheduledForwhen held, andPOST /leads/:id/unholdtakes it back. Both are in/openapi.jsonandcontract/openapi.json.send_replycarriesscheduledFor, and there is a newcancel_held_texttool.htakes it back, and the profile edit asks for the time zone.messageandprofilewith 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.tomlandsrc/test-setup.tsset 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.timeZonein the profile.openapi.jsonwas regenerated.heldand cancelling asunhold. 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