Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5551306
fix(alerts): five ways a page was lost or left open
Makisuo Nov 24, 2026
16ff264
wip(on-call): gaps, departed members and chain tiers
Makisuo Nov 24, 2026
dd837a1
Merge branch 'alerts/lost-pages' into alerts/oncall-gaps
Makisuo Nov 24, 2026
dcb5e52
fix(alerts): close the gaps a review found in the lost-page fixes
Makisuo Nov 24, 2026
2fc74cd
fix(on-call): a step that reaches nobody no longer goes unnoticed
Makisuo Nov 24, 2026
c7882c1
feat(web): warn about coverage gaps and departed people on on-call sc…
Makisuo Nov 24, 2026
fa3074e
Merge branch 'alerts/lost-pages' into alerts/oncall-gaps
Makisuo Nov 24, 2026
53f50c4
Merge remote-tracking branch 'origin/main' into alerts/lost-pages
Makisuo Nov 24, 2026
6878c1d
fix(on-call): review fixes for gap handling
Makisuo Nov 24, 2026
6e20154
Merge branch 'alerts/oncall-gaps-ui' into alerts/oncall-gaps
Makisuo Nov 24, 2026
d0cf95b
style(on-call): format the member notifier
Makisuo Nov 24, 2026
0ea2bf2
Merge remote-tracking branch 'origin/main' into alerts/lost-pages
Makisuo Nov 24, 2026
31ab3d2
fix(alerts): all-clears on rule delete cover every paged destination …
Makisuo Nov 24, 2026
9b5fe37
Merge branch 'alerts/lost-pages' into alerts/oncall-gaps
Makisuo Nov 24, 2026
294bf0c
fix(on-call): review fixes for chains that reach nobody
Makisuo Nov 24, 2026
a198643
Merge remote-tracking branch 'origin/main' into alerts/lost-pages
Makisuo Nov 24, 2026
7bdf929
test(browser): wire goldens follow the SDK version
Makisuo Nov 24, 2026
443b627
ci: size the ai test lanes at 1.5s per file
Makisuo Nov 24, 2026
04fbd34
Merge branch 'alerts/lost-pages' into alerts/oncall-gaps
Makisuo Nov 24, 2026
79284af
Merge remote-tracking branch 'origin/fix/browser-wire-golden-version'…
Makisuo Nov 24, 2026
65189b8
Merge branch 'alerts/lost-pages' into alerts/oncall-gaps
Makisuo Nov 24, 2026
7562fd3
fix(alerts): second round of review fixes for lost pages
Makisuo Nov 24, 2026
afe24b5
Merge branch 'alerts/lost-pages' into alerts/oncall-gaps
Makisuo Nov 24, 2026
682a4de
fix(on-call): say that a departed person's shifts go uncovered when n…
Makisuo Nov 24, 2026
b01a24b
Merge branch 'alerts/lost-pages' into alerts/oncall-gaps
Makisuo Nov 24, 2026
5c1845d
Merge remote-tracking branch 'origin/main' into alerts/lost-pages
Makisuo Nov 24, 2026
3e3f024
fix(mcp): the coverage warning names the gap window the server report…
Makisuo Nov 24, 2026
6864371
fix(alerts): a skipped post earns no all-clear on rule deletion, and …
Makisuo Nov 24, 2026
dc2e03d
Merge branch 'alerts/lost-pages' into alerts/oncall-gaps
Makisuo Nov 24, 2026
90b70b8
fix(alerts): relink an all-clear that outlives its rule while in flig…
Makisuo Nov 24, 2026
f200c3d
Merge branch 'alerts/lost-pages' into alerts/oncall-gaps
Makisuo Nov 24, 2026
9bca24f
Merge main after #3012 was squash-merged
Makisuo Nov 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions apps/ai/src/mcp/lib/oncall-schedules.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** Pieces the on-call schedule MCP tools share: rows, rotation text, schedule lookup and error mapping. */
import { Array as Arr, DateTime, Effect, Option, Schema, String as Str } from "effect"
import { MAX_ONCALL_REPORTED_GAPS, ONCALL_GAP_LOOKAHEAD_MS } from "@maple/domain/http"
import type {
AlertForbiddenError,
AlertMemberDirectoryNotConfiguredError,
Expand Down Expand Up @@ -114,6 +115,8 @@ export const toScheduleRow = (schedule: OnCallScheduleDocument, names: MemberNam
startsAt: schedule.onCallNow.startsAt,
endsAt: schedule.onCallNow.endsAt,
},
coverageGaps: Arr.map(schedule.coverageGaps, (gap) => ({ startsAt: gap.startsAt, endsAt: gap.endsAt })),
departed: Arr.map(schedule.departedUserIds, (userId) => person(names, userId)),
chainIds: [...schedule.chainIds],
createdAt: schedule.createdAt,
updatedAt: schedule.updatedAt,
Expand All @@ -137,6 +140,33 @@ export const formatOnCallNow = (schedule: ScheduleRow): string =>
? "nobody on call right now"
: `${personLabel(schedule.onCallNow.user)} on call until ${schedule.onCallNow.endsAt}`

/**
* What is wrong with the schedule's coverage, or null: e.g. `3 gaps in the next 14 days, next
* 2026-11-14T16:00:00.000Z to 2026-11-16T08:00:00.000Z; left the org: Ben Brook (user_ben)`.
*/
/** How far ahead the server reports gaps, in days: the text names the window it was given. */
const GAP_LOOKAHEAD_DAYS = Math.round(ONCALL_GAP_LOOKAHEAD_MS / 86_400_000)

/** "1 gap", "3 gaps", or "20 or more gaps" when the list was cut at its cap. */
const gapCount = (count: number): string =>
count >= MAX_ONCALL_REPORTED_GAPS
? `${MAX_ONCALL_REPORTED_GAPS} or more gaps`
: `${count} ${count === 1 ? "gap" : "gaps"}`

export const formatCoverageWarning = (schedule: ScheduleRow): string | null => {
const [next] = schedule.coverageGaps
const gaps =
next === undefined
? null
: `${gapCount(schedule.coverageGaps.length)} with nobody on call in the next ${GAP_LOOKAHEAD_DAYS} days, next ${next.startsAt} to ${next.endsAt}`
const departed =
schedule.departed.length === 0
? null
: `left the org (their shifts pass to the next person still in it, or go uncovered): ${Arr.join(Arr.map(schedule.departed, personLabel), ", ")}`
const parts = Arr.filter([gaps, departed], (part) => part !== null)
return parts.length === 0 ? null : Arr.join(parts, "; ")
}

/** One line per layer, e.g. `Primary: weekly, Monday 09:00 · Ana Alves, Ben Brook`. */
export const formatLayers = (schedule: ScheduleRow): string =>
Arr.join(
Expand All @@ -160,6 +190,7 @@ export const scheduleBlocks = (schedule: ScheduleRow) => [
["Description", schedule.description ?? undefined],
["Time zone", schedule.timeZone],
["On call now", formatOnCallNow(schedule)],
["Coverage", formatCoverageWarning(schedule) ?? undefined],
]),
doc.text(formatLayers(schedule)),
]
Expand Down
4 changes: 2 additions & 2 deletions apps/ai/src/mcp/tool-descriptors.generated.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ const layer = (seen: Seen) =>
},
],
onCallNow: null,
coverageGaps: [],
departedUserIds: [],
chainIds: [CHAIN_ID],
createdAt: NOW,
updatedAt: NOW,
Expand Down
28 changes: 26 additions & 2 deletions apps/ai/src/mcp/tools/__tests__/oncall-schedule-tools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* rendered by display name, schedules found by name, and service failures as parameter errors.
*/
import { describe, expect, it } from "vitest"
import { Context, Effect, Layer, Schema } from "effect"
import { Array as Arr, Context, Effect, Layer, Schema } from "effect"
import {
AlertValidationError,
OnCallAtResponse,
Expand Down Expand Up @@ -54,6 +54,8 @@ const scheduleDoc = (overrides: Partial<typeof OnCallScheduleDocument.Encoded> =
startsAt: "2026-11-09T08:00:00.000Z",
endsAt: "2026-11-16T08:00:00.000Z",
},
coverageGaps: [],
departedUserIds: [],
chainIds: [],
createdAt: NOW,
updatedAt: NOW,
Expand All @@ -67,6 +69,8 @@ const notFound = (id: string) =>
})

interface Seen {
/** Replaces fields of the one schedule the listing returns. */
schedule?: Partial<typeof OnCallScheduleDocument.Encoded>
created?: OnCallScheduleCreateRequest
updated?: OnCallScheduleUpdateRequest
overrideCreated?: OnCallOverrideCreateRequest
Expand Down Expand Up @@ -120,7 +124,8 @@ const layer = (seen: Seen) =>
["user_ben", "Ben Brook"],
]),
),
list: () => Effect.succeed(new OnCallSchedulesListResponse({ schedules: [scheduleDoc()] })),
list: () =>
Effect.succeed(new OnCallSchedulesListResponse({ schedules: [scheduleDoc(seen.schedule)] })),
get: (_org, id) =>
id === SCHEDULE_ID ? Effect.succeed(scheduleDoc()) : Effect.fail(notFound(id)),
create: (_org, _user, _roles, request) => {
Expand Down Expand Up @@ -227,6 +232,25 @@ const invalidParameter = (result: Awaited<ReturnType<typeof run>>) =>
const text = (result: McpToolResult) => result.content[0]?.text ?? ""

describe("on-call schedule tools", () => {
it("list_oncall_schedules says a gap list cut at its cap may be longer", async () => {
const gap = (day: number) => ({
startsAt: `2026-11-${String(day).padStart(2, "0")}T16:00:00.000Z`,
endsAt: `2026-11-${String(day).padStart(2, "0")}T18:00:00.000Z`,
})
const capped = await ok(
"list_oncall_schedules",
{},
{ schedule: { coverageGaps: Arr.map(Arr.range(1, 20), gap) } },
)
expect(text(capped)).toContain("20 or more gaps with nobody on call")
const few = await ok(
"list_oncall_schedules",
{},
{ schedule: { coverageGaps: Arr.map(Arr.range(1, 3), gap) } },
)
expect(text(few)).toContain("3 gaps with nobody on call")
})

it("list_oncall_schedules names people by display name and falls back to the user id", async () => {
const result = await ok("list_oncall_schedules", {})
const output = Schema.decodeUnknownSync(ListOnCallSchedulesOutput)(result.structuredContent)
Expand Down
22 changes: 20 additions & 2 deletions apps/ai/src/mcp/tools/list-oncall-schedules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import { Array as Arr, Effect, Schema } from "effect"
import { OnCallSchedulesService } from "@maple/backend/services/alerts/OnCallSchedulesService"
import { CurrentMcpTenant } from "../tenant"
import { toMcpHttpError } from "../lib/map-http-error"
import { formatLayers, formatOnCallNow, memberNames, toScheduleRow } from "../lib/oncall-schedules"
import {
formatCoverageWarning,
formatLayers,
formatOnCallNow,
memberNames,
toScheduleRow,
} from "../lib/oncall-schedules"
import { doc } from "../lib/tool-doc"

export function registerListOnCallSchedulesTool(server: McpToolRegistrar) {
Expand Down Expand Up @@ -45,7 +51,19 @@ export function registerListOnCallSchedulesTool(server: McpToolRegistrar) {
: undefined),
blocks: Arr.flatMap(output.schedules, (schedule) => [
doc.heading(`${schedule.name} (${schedule.id})`),
doc.text(`${schedule.timeZone}: ${formatOnCallNow(schedule)}\n${formatLayers(schedule)}`),
doc.text(
Arr.join(
Arr.filter(
[
`${schedule.timeZone}: ${formatOnCallNow(schedule)}`,
formatLayers(schedule),
formatCoverageWarning(schedule),
],
(line) => line !== null,
),
"\n",
),
),
]),
next: Arr.take(
Arr.map(output.schedules, (schedule) =>
Expand Down
1 change: 1 addition & 0 deletions apps/api/src/routes/v2/alert-incidents.http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ const toV2Event = (doc: AlertIncidentEventDocument): V2AlertIncidentEvent => ({
error_message: doc.page.errorMessage,
},
}),
...(doc.detail === undefined ? undefined : { detail: doc.detail }),
created_at: doc.createdAt,
})

Expand Down
5 changes: 5 additions & 0 deletions apps/api/src/routes/v2/oncall-schedules.http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ export const toV2OnCallSchedule = (doc: OnCallScheduleDocument): V2OnCallSchedul
starts_at: timestamp(doc.onCallNow.startsAt),
ends_at: timestamp(doc.onCallNow.endsAt),
},
coverage_gaps: Arr.map(doc.coverageGaps, (gap) => ({
starts_at: timestamp(gap.startsAt),
ends_at: timestamp(gap.endsAt),
})),
departed_user_ids: doc.departedUserIds,
chain_ids: doc.chainIds,
created_at: timestamp(doc.createdAt),
updated_at: timestamp(doc.updatedAt),
Expand Down
15 changes: 11 additions & 4 deletions apps/web/src/lab/oncall-lab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ import {
checkoutSchedule,
checkoutShifts,
DST_NOW,
formerMemberId,
memberId,
mixedTargetChain,
overrideUuid,
ONCALL_NOW,
onCallGapEvent,
oncallMembers,
pagedEvents,
populatedSchedules,
Expand All @@ -46,8 +48,9 @@ import type { Resources } from "../platform/resources"
import { toEpochMs } from "@maple/ui/lib/time-format"

// `/lab/oncall`: on-call schedules in the hub (the On-call tab and the inbox's "On call now"
// strip), the schedule form, the calendar with overrides and a DST week, the chain dialog with
// people and schedules, and an incident timeline with pages. `?state=` picks one.
// strip), the schedule form, the calendar with overrides, a DST week and a participant who left
// the org, the chain dialog with people and schedules, and an incident timeline with pages and a
// step that found nobody on call. `?state=` picks one.

export const LabState = Schema.Literals([
"schedules-empty",
Expand All @@ -63,6 +66,7 @@ export const LabState = Schema.Literals([
"editor-error",
"calendar",
"calendar-dst",
"calendar-departed",
"override-dialog",
"override-delete",
"chain-dialog",
Expand Down Expand Up @@ -306,7 +310,7 @@ const scheduleFor = (state: LabState): Step<ScheduleModel.Model, ScheduleMessage
{ _tag: "AlertsSchedule", scheduleId: schedulePublicId(1), search: {} },
CONTEXT,
)
const schedule = checkoutSchedule(nowMs)
const schedule = checkoutSchedule(nowMs, state === "calendar-departed" ? [formerMemberId] : [])
const loaded = fold(
start,
[
Expand Down Expand Up @@ -386,7 +390,10 @@ const incidentFor = (): Step<IncidentModel.Model, IncidentMessage.Message> => {
[
IncidentMessage.Message.CompletedFetchActivity({
key: synced.model.activity.key ?? "",
result: Result.succeed(pagedEvents(INCIDENT_ID, toEpochMs(row.first_triggered_at))),
result: Result.succeed([
...pagedEvents(INCIDENT_ID, toEpochMs(row.first_triggered_at)),
onCallGapEvent(INCIDENT_ID, toEpochMs(row.first_triggered_at), "Weekend coverage"),
]),
}),
IncidentMessage.Message.CompletedFetchEscalation({
key: synced.model.escalation.key ?? "",
Expand Down
61 changes: 59 additions & 2 deletions apps/web/src/page/alerts/hub/hub-oncall.scene.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,31 @@ import type { AlertsTab } from "../../../route/search"
import { OrgId } from "@maple/domain"
import { EscalationChainId, OnCallScheduleId } from "@maple/domain/http"
import type { V2OnCallSchedule } from "@maple/domain/http/v2"
import { Result, Schema, Array as Arr, String as Str } from "effect"
import { Option, Result, Schema, Array as Arr, String as Str } from "effect"
import * as Menu from "@maple/views/ui/menu"
import * as Dialog from "@maple/views/ui/dialog"
import { MountDialog } from "@maple/views/ui/dialog"
import { expect as expectView, given, Mount, role, scene, text, within, withViewInputs } from "foldkit/scene"
import {
all,
expect as expectView,
filter,
first,
given,
Mount,
role,
scene,
text,
within,
withViewInputs,
} from "foldkit/scene"
import { describe, expect, test } from "vitest"
import type { PageContext } from "../../contract"
import { chainDestinations, chainUuid } from "../shared/escalation-test-fixtures"
import { SCHEDULE_IN_USE_CODE } from "../shared/oncall-schedules"
import {
checkoutSchedule,
formerMemberId,
memberId,
mixedTargetChain,
ONCALL_NOW,
oncallMembers,
Expand Down Expand Up @@ -97,6 +112,48 @@ describe("alerts hub, on-call schedules", () => {
)
})

test("a schedule with gaps ahead or a participant who left says so on its row, a healthy one says nothing", () => {
const row = (name: string) => first(filter(all.role("listitem"), { hasText: name }))
scene(
{ update: pageUpdate, view },
given(onTab("on-call", ENGINEER, SCHEDULES)),
expectView(within(row("Weekend coverage"), text("3 gaps in the next 14 days"))).toExist(),
expectView(within(row("Weekend coverage"), text(/left the org/u))).not.toExist(),
expectView(within(row("Platform secondary"), text("A former member left the org"))).toExist(),
expectView(within(row("Platform secondary"), text(/gaps? in the next/u))).not.toExist(),
expectView(within(row("Checkout primary"), text(/gaps? in the next/u))).not.toExist(),
expectView(within(row("Checkout primary"), text(/left the org/u))).not.toExist(),
)
})

test("the row names a participant who left while the member list still does, and counts several", () => {
const departing = (ids: ReadonlyArray<string>) =>
onTab("on-call", ENGINEER, [checkoutSchedule(ONCALL_NOW, ids)])
scene(
{ update: pageUpdate, view },
given(departing([memberId(0)])),
expectView(text("Ben Brook left the org")).toExist(),
)
scene(
{ update: pageUpdate, view },
given(departing([memberId(0), formerMemberId])),
expectView(text("2 people left the org")).toExist(),
expectView(text("Ben Brook left the org")).not.toExist(),
)
})

test("a single gap ahead reads in the singular", () => {
const weekends = Option.getOrThrow(
Arr.findFirst(SCHEDULES, (schedule) => schedule.name === "Weekend coverage"),
)
const one = { ...weekends, coverage_gaps: Arr.take(weekends.coverage_gaps, 1) }
scene(
{ update: pageUpdate, view },
given(onTab("on-call", ENGINEER, [one])),
expectView(text("1 gap in the next 14 days")).toExist(),
)
})

test("a member sees the schedules with create, edit and delete locked", () => {
scene(
{ update: pageUpdate, view },
Expand Down
18 changes: 18 additions & 0 deletions apps/web/src/page/alerts/hub/view-oncall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { typography } from "@maple/views/ui/typography"
import { sectionHeading } from "../../kit/section-heading"
import { formatShiftEdge, formatUntil, newScheduleHref, scheduleHref } from "../shared/oncall-schedules"
import { memberName, memberOf } from "../shared/org-members"
import { coverageGapsText, departedText } from "../shared/schedule-health"
import { rowWarning, rowWarnings } from "../../kit/row-warning"
import { Message } from "./message"
import { type Model } from "./model"
import { DELETE_SCHEDULE_DIALOG_ID, scheduleMenuId } from "./update"
Expand Down Expand Up @@ -58,6 +60,21 @@ const onCallPerson = (h: H, model: Model, schedule: V2OnCallSchedule, withZone:
const layerCount = (schedule: V2OnCallSchedule) =>
`${schedule.layers.length} ${pluralize(schedule.layers.length, "layer")}`

/** Under the row's name: the gaps ahead and the participants who left; nothing for a healthy schedule. */
const scheduleWarnings = (h: H, model: Model, schedule: V2OnCallSchedule): ReadonlyArray<Html> => {
const warnings = [
...Option.match(coverageGapsText(schedule), {
onNone: () => [],
onSome: (text) => [rowWarning(h, { icon: "AlertWarningIcon", text })],
}),
...Option.match(departedText(model.members, schedule), {
onNone: () => [],
onSome: (text) => [rowWarning(h, { icon: "UserIcon", text })],
}),
]
return warnings.length === 0 ? [] : [rowWarnings(h, warnings)]
}

const scheduleRow = (h: H, model: Model, schedule: V2OnCallSchedule, nowMs: number): Html => {
const menuId = scheduleMenuId(schedule.id)
const entries: ReadonlyArray<MenuEntry> = [
Expand Down Expand Up @@ -99,6 +116,7 @@ const scheduleRow = (h: H, model: Model, schedule: V2OnCallSchedule, nowMs: numb
typography(h, { size: "xs", tone: "muted", truncate: true }, [
`${schedule.time_zone} · ${layerCount(schedule)}`,
]),
...scheduleWarnings(h, model, schedule),
]),
]),
hstack(h, { gap: "4", className: "w-full pl-7 sm:w-auto sm:pl-0" }, [
Expand Down
Loading
Loading