Skip to content

Commit 3d10513

Browse files
tarasclaude
andcommitted
🔀 Take #939's authored-stop repair under the Git observations (#940)
Integrates the approved #939 head 0217795, which PR943 publishes and CI run 39135245943 reports green, into this already-published branch. An additive merge rather than a rebase: cfb997c is published, both original reviewers PASSed it at that exact SHA, and rewriting it would discard that. What arrives is one commit — `<Fail>` marks its own throw as an authored stop, and the settling boundary in `execute.ts` uses that mark instead of inferring intent from an undescribed failure. It names this story's refusals among the things that must keep escaping, which is why the merge is worth evidence rather than a formality: a Git protocol refusal, an admission rejection and a secret-gate fatal all reach that boundary, and none of them is a document deciding to stop. Nothing overlapped. The parent touches `packages/core/src/components/Fail.ts`, `packages/core/src/execute.ts` and `packages/cli/src/repl/model.ts`; this story touches none of them, and its own 35 files are byte-identical to the reviewed head. The three incoming files are byte-identical to the approved parent, so the merged tree adds no third version of either side. Evidence on the merged tree, each passing on its first run: F1 18 passed, F2 9, F3 15 including RGO1–RGO5, F4 13, with 0 failed throughout. The parent's own boundary suites — `fail-component` and `output-error-mode` — also pass here, 15 passed, which is what rules out this story's refusals being swallowed as authored stops. Co-Authored-By: Claude Opus 5 <[email protected]>
2 parents cfb997c + 0217795 commit 3d10513

3 files changed

Lines changed: 78 additions & 11 deletions

File tree

‎packages/cli/src/repl/model.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,6 @@ function buildEntry(segment: EntrySegment, markers: readonly string[]): Result<E
790790
scope: entry.key,
791791
names: Object.freeze(names),
792792
});
793-
checkpoints.push({ marker, kind: "binding", label: names.join(", ") });
794793
}
795794
transcript.push({
796795
kind: "terminal",
@@ -1655,7 +1654,9 @@ function readSettlement(event: Close): ReplTerminal | undefined {
16551654
* one its own root validated, so a record carrying that name is not a value a
16561655
* later entry inherits.
16571656
*/
1658-
function readResultBindings(carried: Json | undefined): ReplBindingMap | undefined | typeof MALFORMED {
1657+
function readResultBindings(
1658+
carried: Json | undefined,
1659+
): ReplBindingMap | undefined | typeof MALFORMED {
16591660
if (carried === undefined) {
16601661
return undefined;
16611662
}

‎packages/core/src/components/Fail.ts‎

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,60 @@ export class FailInvocationError extends Error {
4040
}
4141
}
4242

43+
/**
44+
* The mark itself.
45+
*
46+
* Stable and namespaced, because it is read across loaded copies. Changing this
47+
* string is changing a cross-copy contract.
48+
*/
49+
const AUTHORED_STOP = "executablemd.core.fail.authoredStop";
50+
51+
/**
52+
* State that this failure is the document deciding to stop, and answer with it.
53+
*
54+
* ## Why a mark rather than a class, a name or a message
55+
*
56+
* What reads this is the settling boundary, deciding whether an undescribed
57+
* failure is the document's own outcome or something escaping through it. Only
58+
* one undescribed failure is a decision the document made; a Git protocol
59+
* refusal, a retained-history rejection, an assertion abort and a missing
60+
* launcher all reach the same place and all have to keep escaping.
61+
*
62+
* `<Fail>` raises an ordinary `Error` carrying exactly the author's sentence,
63+
* and that is the public contract — so there is no class to test and no name or
64+
* message to read. `instanceof` would also answer no across a separately
65+
* loaded copy of this module, and `name` is writable, so any error at all could
66+
* wear it. A namespaced own property survives the boundary and is only there
67+
* because this throw site put it there.
68+
*
69+
* Non-enumerable, so an error that is copied, wrapped or serialized does not
70+
* take the mark along by accident: a failure that merely *carries* this one as a
71+
* cause is not the document's decision, and the boundary reads the object it
72+
* was handed rather than searching for a mark underneath it.
73+
*/
74+
function markAuthoredStop<E extends Error>(error: E): E {
75+
if (Object.getOwnPropertyDescriptor(error, AUTHORED_STOP) === undefined) {
76+
Object.defineProperty(error, AUTHORED_STOP, { value: true, enumerable: false });
77+
}
78+
return error;
79+
}
80+
81+
/**
82+
* Whether this exact failure is a valid `<Fail>` deciding to stop the document.
83+
*
84+
* Answers `false` for everything else: an unmarked error, one merely named or
85+
* worded like an authored stop, a mark inherited from a prototype rather than
86+
* put on this object, and a wrapper that holds a marked error as its cause. An
87+
* invocation `<Fail>` refused is not the author's decision either, so the
88+
* refusal below is never marked.
89+
*/
90+
export function authoredStop(error: unknown): boolean {
91+
if (typeof error !== "object" || error === null) {
92+
return false;
93+
}
94+
return Object.getOwnPropertyDescriptor(error, AUTHORED_STOP)?.value === true;
95+
}
96+
4397
const BINDING = "<Fail> raises its message and binds nothing, so `as` is not accepted.";
4498

4599
const PAIRED = '<Fail> is self-closing and has no content: write <Fail message="…" /> instead.';
@@ -48,7 +102,7 @@ function* Fail(props: Record<string, Json>): Operation<string> {
48102
if (yield* hasBinding()) {
49103
throw new FailInvocationError(BINDING);
50104
}
51-
throw new Error(String(props.message));
105+
throw markAuthoredStop(new Error(String(props.message)));
52106
}
53107

54108
/**

‎packages/core/src/execute.ts‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ import { useEvalScope } from "@effectionx/scope-eval";
201201
import { declaredRouting, FOREGROUND, route, withRouting } from "./foreground.ts";
202202
import type { ForegroundRouting } from "./foreground.ts";
203203
import { checkedFailureLedger, refuseCheckedFailure } from "./component-failures.ts";
204+
import { authoredStop } from "./components/Fail.ts";
204205
import { provideTestHarnessInstallers } from "./test-harness.ts";
205206
import type { TestHarnessInstaller } from "./test-harness.ts";
206207
import type { CheckedFailures } from "./component-failures.ts";
@@ -2003,7 +2004,7 @@ function parseDocumentResult(value: unknown): DocumentResult {
20032004
*
20042005
* Nothing before a root exists, which is a different record from one whose root
20052006
* computed no data: a result that never had a root says so by omitting the
2006-
* member rather than by claiming an empty environment.
2007+
* member rather than by reporting an empty environment.
20072008
*/
20082009
function carriedBindings(computed: ComputedBindings): { bindings?: JsonObject } {
20092010
const data = computed.computed();
@@ -2424,14 +2425,25 @@ function* documentWorkflow(
24242425
if (durabilityFailure(error) !== undefined || filesFatalFailure(error) !== undefined) {
24252426
throw error;
24262427
}
2427-
// An authored failure the document decided is its outcome, whether or not
2428-
// it arrived wrapped in a printing boundary's description. A plain `<Fail>`
2429-
// throws an ordinary Error, and before this it left the canonical boundary
2430-
// without a document result at all — so the body's own rendered text and
2431-
// the data it had computed were lost to every later reader, even though the
2432-
// run was over and had decided. `describeFailure` reads the wrapper for its
2433-
// own account when there is no description to read.
2428+
// An authored failure the document decided is its outcome. Usually that
2429+
// decision arrives described, through a printing boundary. The one other
2430+
// eligible failure is the Error a valid `<Fail>` raised: it reaches here
2431+
// unchanged and undescribed, and before it was recognized it left the
2432+
// canonical boundary with no document result at all — so the body's own
2433+
// rendered text and the data it had computed were lost to every later
2434+
// reader, even though the run was over and had decided.
2435+
//
2436+
// Everything else undescribed is not the document's outcome and escapes as
2437+
// it always has: a Git protocol refusal, a retained-history rejection, an
2438+
// assertion abort, a missing launcher. The mark is read off the object this
2439+
// boundary was handed, never searched for underneath it, so a wrapper or a
2440+
// teardown failure that merely carries an authored stop is not adopted as
2441+
// one. `describeFailure` reads the wrapper for its own account when there
2442+
// is no description to read.
24342443
const documentation = documentationFailure(error);
2444+
if (documentation === undefined && !authoredStop(error)) {
2445+
throw error;
2446+
}
24352447
// Everything the document rendered: the buffered selection, or what the
24362448
// streaming loop emitted together with that tail.
24372449
const rendered =

0 commit comments

Comments
 (0)