Last week I wrote about asking coding agents for the ideal version first, and about the skill that makes the agent check every fact its answer rests on before it scores the options. That check had a gap, since it looked at what each option claims and not at the code the option would change, so an option could pass every check and still break something the agent never read. This post goes through one decision where that happened, and the step the skill gained because of it.
Two notices that both re-resolved protection
The decision came up while merging two branches of a reading app I’m building. The app lets you put books in protected collections, which hide them behind a PIN, and since it’s SwiftUI with TCA and every window on iPad or Mac builds its own store, every window keeps its own copy of which library rows are protected, which has to be resolved again whenever a save changes what is protected. The feature branch added a store notice for exactly that, one that fires only on saves that change the protected set. While the branch was open, develop gained a second notice, which fires on any save that touches a collection or its items so that other windows can resync their collection lists, and its window subscriber re-resolved protection as well. So after the merge, a save that changed a protected collection re-resolved protection twice in every open library window, and the question the session started from was what the merge should do about that.
In the first turn the agent offered two options, dropping the re-resolve from develop’s collection subscriber (which it recommended), or also merging the two save observers in the Core Data stack, which it called “the ideal in full”. That label came from a hook that hands the agent a decision checklist whenever it’s about to put a decision in front of me, and one of its items asks whether the ideal is among the options, so the agent attached the label to an option to answer it, without working out what that option would buy.
In the second turn I ran the skill on those options (its pass added a third, keeping both re-resolves), and its premise check did its job, finding that merging the observers would still leave two notices and two subscribers, so it removed nothing, and that the overlap was wider than the question assumed, since both subscribers also reloaded the sidebar’s collection list and the open collection pages. The verdict was “none match”, and the real ideal it described was one notice per save that says which kinds of thing changed (collections, the protected set, or both), with one subscriber per window running each reaction once.
Then I asked how big that ideal was and whether it was worth building. Sizing it meant reading every consumer of both notices, about 12 production files and 13 test files plus both design records, and that reading turned up the two subscribers’ loops, which look roughly like this:
case .observeCollectionStore:
return .run { send in
for await _ in collectionChanges() {
await send(.collectionStoreChanged)
// Emptying Recently Deleted saves once per book: notices that arrive
// during the wait fold into one trailing reread.
try await clock.sleep(for: .milliseconds(250))
}
}
case .observeProtectedSet:
return .run { send in
for await _ in protectedSetChanges() {
await send(.protectedSetChanged)
}
}
Both streams keep only their newest value, so while the collection subscriber sleeps, any number of saves fold into one reread, which is what we want for resyncing lists when a bulk delete saves once per book. The protected-set subscriber has no wait, because a book that was just protected should leave every window’s screen as soon as the save commits. One combined notice would either make protection wait up to 250 ms behind the collection pacing, or carry two paces inside one subscriber, which rebuilds the two paths in a more tangled place, and two of the protected-set notice’s other consumers (the reader window and the audiobook playback hold) only care about protection and would have to filter the combined notice back down. What it would have saved was a second read of the sidebar list and the open pages on saves that touch a protected collection, which should be rare since they come mostly from collection edits, and since both reads run after the commit, whichever lands last is still current, so neither can show a wrong result. The verdict went back to dropping the duplicate re-resolve, and that’s how the merge went in.
What the premise check didn’t cover
Asked why it took three turns, the agent pointed mainly at two things, and both turned out to be in the skill’s text (the smaller rules further down came from the same answer).
The first is that the premise check ran over the options already on the table. The option the agent invented in the second turn came after that step and went straight into the verdict. That is the one place where, as the earlier post says, the skill lets the agent grow the scope, so when we ask for the ideal and the agent comes back with one of its own, we get the option that was checked least and is most likely to be big.
The second is where the premises came from. The skill had the agent list the facts each option’s score rests on, which in practice meant the facts under the advantage the option claimed, here that one notice would save duplicate reads, and that was true. What decided the question sat in the two subscribers the option would fold into one, how fast each has to react and why they were written apart, and no step asked the agent to read the things an option changes for what they do now. The agent had even printed the 250 ms loop earlier in the session, and it still didn’t come up, because nothing in the procedure made it a premise.
It’s a bit funny that the reading which found it was forced by an effort question, since the skill tells the agent not to plan or estimate effort. To size a change we have to list everything it touches and open each piece, and that list is most of what the scoring was missing, so the new step asks for that reading without the estimate.
Reading what each option changes
The premise step now has a second half. For every option that can reach the verdict, the agent lists each component the option edits, removes, merges or newly relies on, and reads each one for its contract, meaning what triggers it, every consumer (found with a search, since a brief’s list of consumers is not a search), its timing such as a delay, batching or ordering, how it fails, and why it is separate or shaped the way it is, from the comment, design record or commit that says so. An option either keeps each of those clauses or drops it as a cost that the scoring has to name, and merging two things that differ on one clause either keeps both behaviours or gives one of them up. In the output we get one more kind of line under the premises:
Premises checked:
- <fact> - <what was read: path + symbol, or doc section>
- Changes <component>: <trigger; consumers; timing; failure; why separate> - <what was read>
- Open (cannot be checked here): <fact> - <why>
A few smaller rules came with it. An option the pass adds or reshapes after the premise check goes back through it, and so does anything offered as a separate proposal, and a label an option already carries, like “ideal” or “recommended”, is something the pass works out again, including the labels the agent itself gave in an earlier message. An advantage is scored by its size, how often its trigger fires times what each occurrence costs, so removing work that never gave a wrong result is worth the work saved at that frequency and no more (this also took in the older rule that guarding against a failure nothing can produce scores zero). Before the verdict the agent names the fact most likely to flip it and checks it, and if that fact can’t be checked in the session, the verdict either goes to an option that wins without it or says what it would flip to. The checklist hook got the reading step and the label rule, so it now asks the agent to read what each option changes, to derive the ideal from the problem, and to treat calling an option the ideal or the recommendation as a claim that needs checking like any other.
Replaying the decision
To see whether the new text changes anything, I replayed the decision with four read-only subagents that read the two commits from before the merge, with the old and the new skill text pinned to files. Two of them got a fresh brief with the situation and the two first-turn options, one with each text, and the other two got a brief that recreated the second turn, with the premise notes already written down, the wider overlap included.
With the fresh brief, both texts picked dropping the duplicate re-resolve, so that brief didn’t reproduce the original mistake, and the difference was in what they wrote down. The old text never mentioned the 250 ms wait, even though the lines it read included it. The new text’s “Changes” lines recorded the trailing wait and four ways the two save observers differ (which saves they judge, how they judge one, where they publish and who consumes them), sized what dropping the duplicate re-resolve saves as small since saves happen at the pace of a person tapping, and ran a flip check.
The recreated second turn was closer to what happened in the real session. Both texts again picked dropping the re-resolve, and the old one even listed the 250 ms throttle among the differences, then put the one-notice-per-save idea forward as a separate proposal that “saves reads only”, without checking it against the throttle it had just listed. The new one rejected that idea, since one wait policy can’t serve both subscribers and the reader window and the playback hold only want the protected bit, and it sized the saving as a list read that never gave a wrong result. The real session had already said the merged design would need a notice that carries kinds and merges them, and both runs with the new text also gave a reason it never raised, which is that a notice carrying a payload through the current newest-only stream would let a collections-only notice replace a pending protected one and leave a protected row showing.
That’s one run per arm, so it shows what the new text makes the agent write down more than it measures a change in verdicts, but the thing that went missing in the real session is now a line the agent has to fill in.
Summary
Checking every premise, as in the earlier post, covers the facts an option claims about itself, and when we’re weighing an option that merges or removes something, the fact that decides it usually sits in the code being changed, in when that code fires, who reads it, how fast it has to react and why it was kept separate, none of which the option’s own claims mention. The ideal skill now makes the agent list what each option changes and read each part’s contract before it scores anything, and that check applies just as much to an option the agent invents during the pass, or one it already labelled the ideal, as to the ones it started with.