Skip to content

feat(implement): stage piece-wise partials off the bootable file, publish atomically - #67

Merged
rodrigoteamx merged 1 commit into
mainfrom
feat/implement-staging
Sep 2, 2026
Merged

feat(implement): stage piece-wise partials off the bootable file, publish atomically#67
rodrigoteamx merged 1 commit into
mainfrom
feat/implement-staging

Conversation

@rodrigoteamx

Copy link
Copy Markdown
Contributor

What

The root fix for the killer of run 12 (D-11): implement's piece-wise authoring (0.22) wrote each partial DIRECTLY to the live scaffolded plugin file — the app REGISTERS and loads it at boot, so a half-written class (measured live: an unclosed brace on Tareas.php) killed the WHOLE app, agent included, with the repair trapped inside the process that would not boot.

  • mode=start/append now write to a sibling <scaffold>.php.milpa-part (suffix after .php, invisible to any *.php autoloader) — the live scaffold stays byte-identical and valid throughout authoring.
  • mode=finish reads the assembled staging, runs the SAME landing gate (extracted to one land() path), and only on GREEN publishes atomically via temp+rename (POSIX-atomic, mode-preserving), then deletes staging. On RED the live file stays the untouched scaffold and staging is kept so the caller can fix and finish again. Even mid-finish a boot loads either the valid scaffold or the complete candidate — never a broken partial.
  • Single-shot lands atomically too (invisible durability detail; result and bytes byte-identical).

Evidence

Falsifiers red-first, and the D-11 invariant proven by mutation (write-live-directly → the three named tests go red); tests 414 → 420, 0 regressions; the 0.22 equivalence adapted to the STRONGER staging invariant (concat asserted on staging AND live-scaffold byte-identical); coverage 92.35% ≥ 90; all gates green including cs-fixer. Adversarially verified: scaffold never partial through start+4 broken appends; atomic publish via temp+rename (grep-proven zero direct live writes); red discards; split mid-4-byte-UTF8 reassembles byte-identical; 60-check independent harness green.

…lish atomically

Measured live (greenhouse fixture series, run 12): mode=start/append wrote each
partial DIRECTLY to the live plugin source the app registers and loads at boot.
An append left a class with an unclosed brace; that half-written file was loaded
at boot, so the whole app — the agent that had to repair it included — died
inside a process that would no longer boot. A partial must never be a bootable
file.

The staging discipline:

- STAGING_SUFFIX (`.milpa-part`): the partial lives at `<scaffold>.php.milpa-part`,
  a sibling whose path does NOT end in `.php`, so every autoloader/glob keyed on
  the `*.php` extension is blind to it and can never load it as a source.
- mode=start writes the first section to STAGING (truncating stale staging), NOT
  the live file; mode=append appends verbatim to STAGING. The live scaffold stays
  byte-identical to what `make` left through the whole authoring — a mid-authoring
  boot loads valid PHP.
- mode=append/finish now require the STAGING file to exist (the scaffold existing
  is no longer sufficient); its absence teaches mode=start first.
- mode=finish reads the assembly from STAGING and judges it through the SAME
  landing gate a single-shot passes. On GREEN it publishes atomically and deletes
  staging; on RED the live file stays the untouched scaffold and staging is KEPT,
  so the caller can append a fix and finish again. The bootable file never carries
  a red assembly.

The landing gate is one code path for both doors and now lands through
publishAtomically (temp file + rename): rename(2) is atomic on POSIX, so a crash
never leaves the live file half-written — single-shot included. The temp lives in
the target's own directory (a cross-device rename would fail) and inherits the
scaffold's file mode, so the durability is invisible past the bytes. The 0.22
equivalence still holds: start+append+finish over a split of C lands the live
file byte-identical to single-shot with C, same verify verdict.

Falsifiers (tests/Operations/ImplementHandlerTest.php): D-11 core (live scaffold
byte-identical through start+append; the deliberately-unclosed partial only at
staging), finish publishes atomically on green and deletes staging, finish
discards on red keeping staging, append/finish refused without staging even when
the scaffold exists, single-shot leaves no staging sibling, publish preserves the
file mode. testAppendIsVerbatimByteConcatenation strengthened to assert the bytes
on staging AND the live scaffold untouched (on 0.22 the same append wrote straight
into the live file).
@rodrigoteamx
rodrigoteamx merged commit 311ffdb into main Sep 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant