# PREFRONTAL: The Recipe Execution Substrate — How a Composable, Self-Authoring, Looping Workflow Engine Becomes an Agent's Executive Function: v4.8 → v4.9

From v4.8 (19 Jun) to v4.9 (25 Nov): 12,346 words to 13,822 words, 1,484 words in new or rewritten paragraphs and 8 taken out, 27 paragraphs changed.

## Change note of v4.9

**Three new sections: a semantic matching trial, per-prompt status, gate state**

Adds about 1,500 words drawn from the folder's notes of September and October 2026.

- Section 3.6: a meaning-based matching lane that runs only as a trial with a stopping rule. It switches itself off when it rescues no matches, because each lookup makes the person wait.
- Section 8.5: how the interface knows, for each prompt sent, whether it is still being worked on, lost or cancelled, and the durable record of matches and runs.
- Section 9.7: a gate's memory must belong to the session it protects, and any gate that can refuse forever needs a breaker.
- Section 2.3 explains why two plan calls are not safe to repeat. The evaluation sections say which logged numbers to read.

## Changed paragraphs

Marks: [-removed-] {+added+}.

### Abstract

A recipe is a structured workflow: ordered steps, tool hints, success gates, and failure handlers, written as a portable document rather than as code. The substrate does six things with recipes that together make them an execution engine rather than a static library. (1) It **matches** the user's intent to recipes with a fuzzy, stemmed, edit-distance-tolerant scorer that reports a confidence tier — and that admits negative as well as positive evidence, so a recipe can declare the prompts for which it must *not* be chosen — and seeds a plan automatically at the start of every turn. (2) It **composes** recipes from recipes — a recipe may merge another recipe's steps into its own at plan-build time, or call a sub-recipe at runtime, both cycle- and depth-guarded, exactly as functions call functions. (3) When nothing matches, it **authors** a new recipe on the fly, validates it, persists it, and makes it matchable on the very next turn — closing the loop on its own coverage gaps. (4) It supports bounded **loops** over steps (run *N* times / until-dry / until a marker appears), the element that lifts recipes from straight-line checklists to a structured execution substrate and closes the long-standing structural gap against hand-coded agent workflows. (5) It **routes effort dynamically**, classifying each turn as trivial / standard / deep / ultra and using that classification to *drive* the turn — model tier, thinking budget, orchestration mode, and token generosity all scale to the work. (6) It makes all of this **observable** through a dedicated RECIPES panel that renders the provenance trail (searched → matched → merged → composed → authored), per-subagent vitals, and the compact-versus-expanded decision trail, {+derives each prompt's done-signal from whatever still holds it, and keeps a durable row of every match and every run,+} while keeping orchestration mechanics out of the substantive chat.

### 2.3 Plans as the runtime trace of recipes

{+Workers change the plan through calls to the store, and two of those calls are not safe to repeat. Setting a plan replaces the old one and resets every step to `pending`; closing a plan removes it, so a second close fails because there is no plan left. A worker whose call timed out cannot tell which case it is in: either the request never left, or it arrived and only the answer was lost. A blind resend is wrong in the second case: it wipes the progress the first call recorded, or it reports an error for a close that already worked. The client must therefore keep the two cases apart. A request that provably never left is sent again. A request that left and lost its answer is resolved by reading the plan first, and is sent again only if the plan does not show its effect. The better design removes the read: each mutation carries an idempotency key, the store remembers the keys it has applied, and a repeat with a known key returns the first result instead of acting twice. With keys in the store, every plan call becomes safe to retry, and the client's two-case logic shrinks to "retry until answered".+}

### 3.3 Negative evidence — anti-triggers

A purely *additive* matcher has a real expressive gap: it can score a recipe upward on tag, title, and summary overlap, but it has no way for a recipe to declare *the prompts for which it must not be chosen*. The consequence is concrete: a recipe that fuzzily shares tokens with an out-of-scope prompt can win on lexical score alone, and the only correction available is the low-confidence advisory (§3.3 confidence tiers, below) — a soft signal, after the fact. The discipline that closes this gap is borrowed from the agent-skills plugin (Osmani, 2026), where every skill carries an explicit "When NOT to use" anti-trigger section that [-is-] {+matters+} as [-load-bearing-] {+much+} as its triggers.

### 3.6 A semantic fallback lane, run as a trial

{+### 3.6 A semantic fallback lane, run as a trial+}

### 3.6 A semantic fallback lane, run as a trial

{+The lexical scorer misses prompts that share meaning with a recipe but no words. The obvious remedy is a semantic lane: when the lexical result is weak, embed the prompt and compare it with an embedding of each recipe. The recipe vectors cost almost nothing at turn time, because they are computed once, cached, and refilled in the background when a recipe changes. The prompt vector is the real cost. It is one short embedding call per weak-lexical turn, and it sits on the hot path of §2.2, before the worker's first token. On a small host with a slow local embedding model, the owner waits for that call, up to its timeout, on every turn the lexical lane finds weak. A lane can cost minutes of waiting a day and still never turn a miss into a correct match. So the lane is not a permanent feature. It runs as a trial with a stopping rule.+}

### 3.6 A semantic fallback lane, run as a trial

{+The rule comes from two quantities. Let $t_q$ be the mean time the owner waits for the semantic query, and $t_m$ the time a missed match costs: the work of running the turn without a program, or of steering the agent back onto one. Let $r$ be the rescue rate, the share of weak-lexical turns where the semantic lane finds the right recipe and the lexical lane did not. The lane pays for itself when $r \, t_m > t_q$, so the break-even rescue rate is+}

### 3.6 A semantic fallback lane, run as a trial

{+$$r^* = \frac{t_q}{t_m}.$$+}

### 3.6 A semantic fallback lane, run as a trial

{+The trial must be long enough to tell $r$ from zero at that level. The rule of three gives the length: after $n$ trials with no rescue, the 95 % upper bound on $r$ is about $3/n$. The trial therefore runs for+}

### 3.6 A semantic fallback lane, run as a trial

{+$$n \ge \frac{3}{r^*} = \frac{3\, t_m}{t_q}$$+}

### 3.6 A semantic fallback lane, run as a trial

{+weak-lexical turns. If it ends with zero rescues, the lane switches itself off, because its true rescue rate is then below break-even with 95 % confidence. If it rescues anything, it stays on and is measured like every other matcher path (§10.2). As an illustration with assumed values: a query that averages 5 s against a miss that costs two minutes gives $r^* \approx 4\,\%$ and a trial of about 72 weak turns. The derivation, not the numbers, is the design. A slower host or a cheaper miss shortens the trial and raises the bar the lane must clear.+}

### 5.2 Validation — the gate against a corrupt library

Three checks [-are load-bearing.-] {+matter most.+} The **slug** is also the directory name, so it must be traversal-safe — a self-authoring system that accepted `../../etc` as a slug would be a security hole, not a feature. The **phantom-heading** check forbids a numbered markdown heading inside a step body, because the runner splits steps on exactly that pattern; an un-checked heading would silently desynchronise the step count from the parallelism map. The **parallelism coverage** check guarantees the fan-out groups reference every step once and only once. The same validator gates *both* authoring paths and every imported recipe (§11.3), so there is a single chokepoint through which no malformed or unsafe recipe can reach the library.

### 8.2 The split-of-concerns invariant

One rule governs the panel and is the [-most load-bearing-] invariant [-of-] the whole [-system:-] {+system depends on most:+}

### 8.5 Done-signals per prompt, and the durable record

{+### 8.5 Done-signals per prompt, and the durable record+}

### 8.5 Done-signals per prompt, and the durable record

{+The panel shows what the executive is doing. The person also needs to know, for each prompt they sent, whether it is still being worked on. A stored "busy" flag cannot answer that reliably: a crash, a restart or a lost terminal event leaves the flag set, and the prompt looks alive long after nothing holds it. The substrate therefore **derives** a prompt's state from what currently holds it, and stores no state of its own.+}

### 8.5 Done-signals per prompt, and the durable record

{+Each part of the pipeline that holds a prompt names it. An accepted send that is not yet placed holds it as PREPARING. A turn that answers it holds it as RUNNING, STEERED (new input folded into a running turn) or BEHIND (queued after the turn in front). A session list reports, for each prompt key, the state of whichever holder names it. Four rules keep the states honest:+}

### 8.5 Done-signals per prompt, and the durable record

{+- A terminal event ends only the prompt it names. One turn finishing does not clear the other prompts in the same session. - A prompt that no holder names is LOST, and the surface offers Resend and Dismiss. The person sees the drop and decides what to do with it. - A prompt the person stopped is CANCELLED, never LOST. A deliberate stop is not a failure, and it must not invite a resend. - A typed reset or new-session command ends the turns of the session it leaves, so no prompt from the old session stays shown as running.+}

### 8.5 Done-signals per prompt, and the durable record

{+When a session is stuck, the stuck line names the reply phase it is stuck in (preparing, waiting on the model, running a tool), not only that it is stuck. The interface also reports each prompt and outbox transition it shows as an event row, so a disagreement between what the server derived and what the person saw can be traced afterwards.+}

### 8.5 Done-signals per prompt, and the durable record

{+The same event store keeps two durable rows that the evaluation in §10 is built on. The **match row** is written once for every prompt that reaches the matcher. It records the outcome (`matched`, `merged` or `no_match`), the best score and the catalog size at that moment, and no prompt text, so it can be kept indefinitely without holding anything private. The **run row** is written from every return path of a recipe run (`done`, `error`, `dry_run` or a thrown exception) with the number of steps and of failed steps. A run row written only on success would make completion look better than it is, so the row is written on every return path, the exceptional ones included.+}

### 9.7 A gate's state belongs to the scope it protects

{+### 9.7 A gate's state belongs to the scope it protects+}

### 9.7 A gate's state belongs to the scope it protects

{+Some gates hold state between tool calls. An exploration gate, for example, refuses a write until the model has read something in the current turn, so it keeps a count of reads. The design question is where that count lives, and the answer is fixed by what the gate protects. This gate protects one chat's turn, so the count is keyed by that chat's session and lives where every instance of the gate can see it.+}

### 9.7 A gate's state belongs to the scope it protects

{+The failure that follows from getting this wrong is concrete. If the count is kept per plugin instance instead, any other session that starts a turn resets it. A busy host runs an orchestrator and its subagents, each starting a turn every minute or two. On such a host a chat's read is erased within a minute, and a model that read once and then retried its command is refused again and again, for as long as the other sessions keep starting turns. Nothing in the refusal tells the model why its read did not count, so it cannot fix its own behaviour.+}

### 9.7 A gate's state belongs to the scope it protects

{+Two design rules follow, and they apply to every stateful gate in the substrate:+}

### 9.7 A gate's state belongs to the scope it protects

{+1. **Key the state by what the gate protects** (a session, a plan, a step), and keep it in a store every instance of the gate reads. State kept per process silently couples sessions that share the process. 2. **Put a breaker beside any gate that can refuse without end.** After a few identical refused attempts, the breaker stops the loop and reports the gate, the attempt and the reason. A model that cannot satisfy a gate then costs a few calls, not an hour.+}

### 9.7 A gate's state belongs to the scope it protects

{+The breaker follows the same bounded-by-construction discipline as loops (§6.3): no refusal cycle runs without a ceiling.+}

### 10.2 Matching quality

{+Outside the labelled set, the match rows of §8.5 give the live view. The match rate is read against catalog size: a library that grows while the share of `no_match` prompts stays flat is growing in the wrong places. The best-score distribution of the misses shows whether they fail just under the threshold (a scoring or threshold problem) or far below it (a coverage gap, and an authoring opportunity).+}

### 10.3 Authoring quality and library health

For on-the-fly authoring: the rate at which an authored recipe is re-matched and successfully reused on subsequent turns (the loop-closure rate), the validation rejection rate (how often a draft is malformed), and a periodic audit of library health — duplicate slugs, dead recipes that never match, and recipes whose steps never satisfy their gates. {+The run rows of §8.5 supply recipe completion directly: the share of runs that end `done`, and, for the rest, the failed-step count per recipe, which points at the step whose gate is mis-specified.+} Authoring-from-library (compose) is evaluated against authoring-from-intent on the same gaps: how often the deterministic, skill-wired plan succeeds where the synthesised one would, and vice versa.

### 11.4 The versioned marketplace — implemented (client side)

The design's contract under failure is the [-load-bearing part:-] {+part that matters:+} when the marketplace fetch fails, resolution degrades to the last cached copy — within or even past the TTL — and **never throws**, so an outage degrades a match to local cache rather than hard-failing a turn. Discovery folds a small **clamped** popularity bonus into the matcher score through the *same* post-base adjustment seam as the fitness feedback (§11.2), so there is exactly one place that perturbs base scores. The bonus is additive and hard-clamped to a tiny band — on the order of a fifth of a point against a scale where a single exact tag hit is worth several — with rating (0–5) supplying most of it and download count adding only a gentle log-scaled nudge. A merely-popular recipe can therefore never override a genuine text mismatch, an anti-trigger veto, or out-rank a recipe with stronger empirical fitness. Authored recipes are still never auto-published — publishing stays an explicit human action (§5.3) — and only the frontmatter owner may publish a new version of a slug. The marketplace *backend* itself is a separate deliverable outside the substrate; this is the client-side half.
