Closing the loop

Oncall-agent, part 5. Part 4 ended on a warning to myself: a good answer in the wrong place, in the wrong tone, at the wrong moment, is not an answer. This one is about the last mile, where the system stops being a pipeline and has to behave like a guest.

The first real answer it ever gave, it gave only to me.

A live incident fired in the alerts channel. Somewhere off to the side a flow picked it up, handed it to the agent, and the agent did everything the last three posts describe: stripped the noise, found the neighbours, narrowed them, ranked the fixes. It came back 200. A few seconds later a message appeared in my own private chat, the one Teams keeps for notes to yourself, and nobody else on the planet saw it.

In the very first post I described this moment differently. I said the answer would show up threaded under the alert, a few seconds behind it, like a colleague leaning over. That was the picture in my head when I started. This post is about the distance between that picture and the thing I actually built, and about why I've stopped being in a hurry to close it.


The room

Here is what the alerts channel actually looks like, on an ordinary night.

A PagerDuty card for something that has just triggered. The same card again, a minute later, edited to say someone acknowledged it. A change-request card from the release process. A human writing "heads up, disk filling on one of the prod clusters, watching it" with a dashboard link. A reply to that. A thumbs-up. Another card.

It's a room, not a queue. People talk in it. And the first lesson of this last mile arrived before I'd written any code: the hard part of answering back isn't the answer. It's knowing which of the things said in the room were said to you.

I didn't have the privileges to plug the agent straight into PagerDuty, which would have handed me clean, structured incidents and nothing else. So I did the thing a human does instead: I listened to the room. A Power Automate flow fires on every message posted to the channel and forwards the whole thing to the agent's webhook.

Every message. The human heads-ups, the change requests, the thumbs-ups, the edits. Which means that before the agent can be useful, it has to be very good at one thing: keeping its mouth shut.

Who's talking

Most of what comes in gets ignored, and that turned out to be the most important behaviour in the whole system.

The rule for who counts as speaking to it is almost rude in its simplicity. A message from the PagerDuty bot, carrying a card, about an incident that's still live: maybe for us. Anything from a person: not for us, however urgent it sounds. Anything resolved: over, leave it alone. Everything that falls through gets a polite reason and goes nowhere near the language model:

webhook: skipped (not a PagerDuty message)

webhook: skipped (not a PagerDuty message)

webhook: skipped (status RESOLVED (only TRIGGERED/ACKNOWLEDGED are triaged))

webhook: skipped (not a PagerDuty message)

webhook: triaged "[FAILED]: <env> ipsec pod not ready ..." -> match=flavor candidates=10


(log format real, titles illustrative)

Four skips for one answer is a fairly normal ratio, and I've come to like reading it. Every skipped line is a message the agent heard, understood wasn't its business, and let pass. Nothing spent, nothing said.

There was an earlier version that tried to be cleverer about it. It forwarded the channel's text, the rendered message a human sees, and tried to recognise incidents in that. It was a mess of HTML and half-formatted markdown, and every new kind of card broke it a different way. The version that works ignores everything that isn't structured JSON. It turns out the card PagerDuty posts is a JSON document, stuffed as a string inside the JSON of the Teams message, which is its own small joke. Inside it, the incident is written down twice: once as a pretty headline for humans, and once as plain fields in the card's button data.

I take the plain fields. One reason surprised me. The pretty headline tidies the title for display, and the tidy version matched the memory worse than PagerDuty's ugly canonical form, [FAILED]: ... and all, because the ugly form is what got ingested. Part 1 all over again: the machine doesn't want the nice version of a thing. It wants the version that's the same every time.

The same message, three times

PagerDuty doesn't post a new card when an incident changes state. It edits the old one, in place. Triggered, then acknowledged, then resolved, all on the same card. But the flow sees each edit as a fresh message, so one incident shows up at the door three times wearing slightly different clothes.

My first version answered only the triggered one. Clean rule, obvious reason: the moment it fires is the moment someone needs help.

Then I watched real incidents go by and kept seeing the triggered state never arrive at all. The first thing the agent saw was already acknowledged. The fastest humans on the team were picking up the page before the flow had finished delivering it, and in doing so they were quietly stealing my input. So the gate widened to triggered or acknowledged.

That fix has a cost, and I haven't paid it yet. The same incident can now be answered twice, once per state the flow happens to deliver. There's no deduplication by incident yet. In a private chat that's a mild annoyance. In the room it would be the bot repeating itself, and repetition is how a voice in a channel goes from helpful to muted.

There's also a quieter question in there that I haven't resolved. An acknowledged incident means a human is already on it. Does that person want the answer more, because they're the one working it? Or less, because they already know what they're looking at and a bot butting in is the last thing they need? A good colleague reads that from the person's face. The agent only gets a status field.


Hearing through a wall

One constraint shaped more of this than I expected. The flow that forwards messages wasn't something whose run history I could open. I could see what my webhook received. I couldn't see what the flow had tried to send, or why it hadn't.

So the agent's side of the conversation had to become a very good witness. With a debug switch on, it logs every request in full: headers, body, the whole forwarded message, card and all, uncut. It's verbose and I kept it that way on purpose, because every real fix in this layer started with reading one of those logs and seeing that the room had said something different from what I'd assumed. The edited cards. The acknowledged-first incidents. The JSON hiding inside JSON.

When you can't see the other end of an integration, make your end remember everything. It's the same instinct as the whole project, applied to the project itself. 


Answering back

Getting the answer out had its own small humiliation.

The agent sends its recommendation back to the flow as its HTTP response. The flow checks one thing, whether the message was skipped, and if it wasn't, it posts the answer. For a while that check failed on every single run. The response came back perfect every time, and the post never happened, not once.

The cause was one missing character. In these flow expressions, a value without a leading @ is not a value. It's a literal string. So the condition wasn't asking "did the agent skip this?" It was comparing the text body('HTTP')?['skipped'], as typed, against false, and finding them unequal forever. The whole pipeline worked from end to end and stayed completely silent, which might be the purest bug I've ever met.

Then I got it posting, plainly, to myself. The plain "post to yourself" action only takes text, so the first version I made with tidy HTML formatting printed every tag on the screen. Strip the tags, use real line breaks, and what arrives looks like this:


🔎 On-call triage · flavor match

3 similar past incidents. First try: clear the stale config, then restart.


First try: clear the stale config, then restart

Where to look: ipsec pods, the config volume, last deploy PR


(reconstructed from a real run; the exact wording varies)

Yes, it says "first try" twice. The summary says it and then the template says it again. I've left it in, as a reminder that this is the first draft of a voice, not a finished one.

It's not pretty. It is, though, completely legible on a phone held sideways in the dark, which is the only reading condition I care about.

The richer version, a proper card with sections, is drafted and not finished. Cards can't loop, so the ranked list of fixes has to be flattened into text before the card ever sees it. Half the fields can come back empty when the match is weak, and the flow language falls over on an empty list unless every single read is wrapped in a guard. And the most useful button I wanted, a link straight back to the incident, isn't possible yet, because the answer the agent returns doesn't carry the incident's id. It knows everything about what happened before and has forgotten which incident it's talking about now. I noticed the irony and wrote it on the list.


What fits on a phone at three in the morning

Most of the design work at this layer was deciding what to leave out. I keep doing that in this series.

The agent knows a lot by the time it answers. Ten candidates with their scores. The signature. Which payload fields overlapped. How the confidence was worked out. All of it is real, I worked hard on all of it, and almost none of it belongs in the message.

What survives is what someone who has just been woken up can act on: what it probably is, what to try first, what not to bother with, where to look. The skip line from part 3 stays, always. The scores don't. If someone wants to know why the agent believes something, the reasoning can sit one tap away, not on the first screen.

There was one small surprise in here, which echoes part 3. The top-ranked candidate, the one closest by meaning, often has no root cause written down at all. The incident with the explanation is the third or fourth one along. So "show the best match's root cause" is the wrong rule. It has to be "show the first root cause anyone actually recorded among the good matches." Nearest and most useful turned out to be different things again, in a new place.

And then there's tone, which isn't a field. No @-mentions, ever. Nobody should get pinged by a bot. A reply under the alert, never a new post in the channel. No victory lap when it's confident, no apology essay when it isn't. Say the thing, say how sure, stop.


The night it was confidently wrong

This is the part where the private chat paid for itself.

A monitor alert came in, one of the synthetic "a dashboard check failed" kind, the sort of thing the memory had almost nothing on. The nearest neighbours sat at a similarity of about 0.4, which in our bunched-up corpus means "not related, only written in the same tired dialect." The agent answered anyway. It suggested, with an even tone, a fix for a port conflict in a sidecar container. It looked like a real recommendation and had nothing to do with the alert.

Only I saw it. If it had landed in the room, that would have been the agent's first impression on the team: a confident, specific, irrelevant answer to the person holding the pager. You don't get many first impressions in a room full of tired people, and you don't get to rerun them.

The shrug in part 3, "nothing close in memory, this may be new," was born that night. When a match is weak, the agent now holds back its suggestions and says it isn't sure. I'd written about calibration as manners. This is where I learned it. I'd rather the bot be caught knowing nothing than caught pretending.


The other loop

For most of this project I thought "closing the loop" meant the reply: alert in, answer out, threaded underneath. It's a loop in the plumbing sense. Done.

The loop that actually matters is longer and runs through people.

On a schedule, a refresh pulls new incidents from PagerDuty, picking up from a bookmark where the last run stopped, runs them through everything from part 1 onward, and writes them into the memory. It's incremental and idempotent, the boring guarantees from part 2. Tonight's incident becomes tomorrow's neighbour.

But what goes into the memory is whatever someone wrote down when they closed the incident. The whole beautiful skip line, plain restart, tried 3×, came straight back, exists only because a tired person at the end of a shift typed "restart didn't help" instead of just "fixed." The agent can carry a dead end across the handoff. It can't invent one that nobody wrote.

So the loop runs both ways. The agent answers the alert. The people have to answer the agent, a sentence at a time, in resolution notes, mostly at the worst possible moment to ask anyone for a sentence. Every note that records what didn't work makes the next night slightly cheaper for someone on the other side of the planet. Every "resolved, no notes" is a little forgetting, pre-paid.

I can't automate that part, and I've stopped wanting to. It's the one part of the system that depends on people deciding it's worth it.


Where it is now

It works end to end. Real incidents go in, real recommendations come out, and they come out to me.

Moving it into the room isn't a technical step. The deduplication is an afternoon's work, and so are the card and the link. The real step is asking a team to let a new voice into the one channel they read when they're most tired and least patient, and trusting that it has learned to be quiet. That isn't my decision alone, and it shouldn't be. In the very first post I said I'd made a sort of peace with that. I think I meant it then. I know I mean it now.


What it taught me

Part 1 was subtraction: decide what to ignore. Part 2 was recognition: let the machine feel the shape of a problem without teaching it the words. Part 3 was judgement: nearest is not relevant, and the opinion lives in ordinary code.

This one is restraint. Almost every message in the room gets silence, and that silence is the feature, not the overhead. Most of what makes a colleague good in a channel isn't what they know. It's that they don't talk over people, they don't repeat themselves, they say "I don't know" without embarrassment, and when they do speak it's short and you can act on it. I spent four posts building something that knows things. The last mile was teaching it when that knowledge isn't wanted.

And under all of it, the thing that started the series. A pager is a baton, and it's always still warm from someone else's hands. I wanted some of that warmth to survive the crossing: not only the answer, but the hour that went into it, the dead ends, the "we tried that, it comes straight back." The machine can carry that across the gap between IST and PST without getting tired and without a time zone. But it only remembers what we hand it, and it only helps if it knows when to speak.

That's as close as I've got to a lesson. Memory is something a team does together, and the most a tool can do is make it cheaper. I think that's enough to be going on with.

Comments