Repository navigation
docs(emitters): make plan.Policy data and define its envelopes - #1331
Open
OmarAlJarrah wants to merge 5 commits into
Open
OmarAlJarrah wants to merge 5 commits into
OmarAlJarrah wants to merge 5 commits into
Conversation
plan.Policy held a function, PrimaryResponse, and Plan.Version hashed the policy. A function has no stable bytes: json/v2 refuses it, its printed form is an address that changes every run, and skipping it gives two policies that pick different responses one version. The policy is now data from a closed vocabulary: PrimaryResponse is an ordered list of rules and DefaultFails says whether an unpicked Default is the catch-all failure. Version hashes the document's digest without sources, a new plan.Revision bumped with every change to Build's output, and the policy's deterministic JSON. EnvelopeDetect named a type nothing defined. plan.Policy.Envelopes now lists envelopes a configuration names, none by default. Each matches a body by the bases it reaches or by the members it declares, and says where the value sits and which flag value means the call failed. A matched success returns that member, keeps the envelope reachable through WithResponse, and turns a 2xx whose flag says it failed into a failure with no fault or kind, decoded as the operation's matching error body. Failures and pages are read whole. T-30 pins the plan's identity and T-31 the envelope reads.
…into docs/emitters-envelopes-policy-data # Conflicts: # docs/emitters/docs-and-mock.md # docs/emitters/testing/mandatory-tests.md
OmarAlJarrah
changed the base branch from
main
to
docs/emitters-inclusive-unions
November 2, 2026 03:17
This was referenced Nov 2, 2026
…into docs/emitters-envelopes-policy-data
…into docs/emitters-envelopes-policy-data
…into docs/emitters-envelopes-policy-data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two gaps in
plan.Policy, resolved as one contract, because the shape of the envelope policy depends on what the policy may hold.The policy is data (#1014).
plan.Policyheld a function,PrimaryResponse, andPlan.Versionhashed the policy. A function has no stable bytes.encoding/json/v2refuses the field, its printed form is an address that changes every run, and leaving it out gives two policies that pick different responses the same version, so the plan cache would serve one the other's plan. Now:PrimaryResponseis an ordered list of rules (lowest_2xx,unconditional,default), and the first one an operation meets picks. TheDefault's other use, the catch-all failure, is its own switch,DefaultFails. The defaults reproduce today's behaviour exactly, and "neither or both" stays expressible.Versionhashes the document's digest (canonical JSON withsourcesleft out, whichBuildnever reads), a newplan.Revision, and the policy's deterministic JSON.plan.Revisionis a departure from the issue, which hashed only the document and the policy. Without it, a fix toBuildwould leave every cached plan current. The plan's goldens hold it the wayIRVersionholds the IR's shape: a golden that changes at an unmovedRevisionfails.Revision.Envelopes (#695).
EnvelopeDetect EnvelopePolicynamed a type nothing defined.plan.Policy.Envelopesnow lists the envelopes a configuration names, and the default names none:Basesits model reaches throughBase/Mixins, or by theMembersit declares. The issue proposed composition alone, but on the golden spec that misses about one envelope in six and needs 113 IDs (numbers below).Membersmust name every member, so a body that merely has aresultis never unwrapped. A per-operation opt-out isExcept []ir.OpIDin the policy rather than a hint as the issue suggested: the plan reads no hint (the plan-or-refine test's second rule).ResponsePlan.Envelope,docs/emitters/plan/responses.md#envelopes). A matched success returns the member atValue. A pager's page is read whole, its items wherePagination.Itemssays. The rest of the envelope stays reachable: an enveloped operation has aWithResponsemethod, whoseResponsecarriesEnvelope.Failsis a failure with no fault and no kind, retried only as its status would be. Its body decodes as the first error entry the same envelope matches, and is never decoded as the success type: 2,200 golden success bodies declaresuccess: enum [true], which a failing body cannot decode into.The page-information output the issue asked for is not added. The pager already reads its paths from the IR's
Pagination, and the envelope stays reachable for everything else.Measured on the golden spec (spec @319dc756, morphic @b206dc99), primary body = lowest 2xx, JSON content:
success,errors,messagesandresult.successthroughBase/Mixins(113 distinct components). 427 declare it inline.Out of scope: hashing
naming.Policyand the runtime policy, which the design never hashes. What the manifest records about them is #713's.Closes #1014
Closes #695
Test plan
Base/Mixinschains and flattened members. An earlier reading of "a component declaring all four members" gave 667 and was wrong: the shared components declaresuccess,errorsandmessages, and the body addsresult. The text states the corrected measure.Policy,Envelopeand example literal, extracted verbatim against stubirtypes, passgo vet.EnvelopeDetect,EnvelopePolicyor the function-valuedPrimaryResponseswept:policy.mdwas the only one.prior-art.md's "unwrap decisions are recorded asPropPaths" still holds.TestDocuments_LinksResolve,TestEmitterDocs_TargetStepsAreCanonicaland the other doc tests over the new anchors and step row.Stacked on #1329, because both edit
docs-and-mock.md,refine/steps.mdand the end ofdocs/emitters/testing/mandatory-tests.md. Merge #1329 first. Once it lands, GitHub retargets this PR tomain, and "Update branch" (a merge ofmain, which conflicts nowhere) brings the diff back to this change alone.