Skip to content

feature(op): Compilation and initialization — bytecode lifecycle (Phase 3) - #199

Merged
David-Noble-at-work merged 1 commit into
developfrom
feature/mem-resource-phase-3
Mar 7, 2026
Merged

David-Noble-at-work merged 1 commit into
developfrom
feature/mem-resource-phase-3

Conversation

@David-Noble-at-work

Copy link
Copy Markdown
Contributor

Summary

  • Compile(): Compiles synthetic source via SourceProgramOptions, serializes bytecode via Program.Write, stores in Compiled field, records CompilerVersion. Idempotent. Errors on empty/invalid source.
  • Init(thread): Loads compiled bytecode via CompiledProgram when CompilerVersion matches (fast path). Falls back to source recompilation on version mismatch or missing bytecode. Extracts named function from globals, stores as live callable.
  • Three-tier storage model complete: source text (human-readable, recompilable) → compiled bytecode (fast load, version-pinned) → live callable (zero-cost invocation)

Test plan

  • Compile produces non-empty bytecode with correct CompilerVersion
  • Compile is idempotent (same bytecode on repeated calls)
  • Compile rejects empty source and invalid source
  • Init loads from compiled bytecode (fast path)
  • Init falls back to source recompilation on version mismatch
  • Init works with source only (no prior Compile)
  • Init extracts the correct named function from globals
  • Init rejects missing function name and non-callable globals
  • Bytecode round-trip: copy bytecode to new Callable → Init → correct result
  • End-to-end: Extract (with closure) → Compile → Init → call → correct result
  • make build passes
  • make test passes (full suite)
  • make vet clean

…se 3)

Add Compile() and Init(thread) methods to mem.Callable, completing the
three-tier storage model: source text → compiled bytecode → live callable.

Compile() compiles the synthetic source via SourceProgramOptions, serializes
bytecode via Program.Write, stores in Compiled field, records CompilerVersion.
Idempotent — recompiling the same source produces identical bytecode.

Init(thread) loads compiled bytecode via CompiledProgram when the compiler
version matches (fast path). On version mismatch or missing bytecode, falls
back to source recompilation. Extracts the named function from globals and
stores it as the live callable for Fn().

12 new tests:
- Compile: non-empty bytecode, idempotent, no-source error, invalid-source error
- Init: compiled bytecode path, version mismatch fallback, source-only (no
  bytecode), extracts named function, rejects missing name, rejects non-callable
- BytecodeRoundTrip: copy bytecode to new Callable, Init, verify result
- ExtractCompileInitRoundTrip: end-to-end Extract → Compile → Init → call
@David-Noble-at-work
David-Noble-at-work merged commit 13ae2e8 into develop Mar 7, 2026
2 checks passed
@David-Noble-at-work
David-Noble-at-work deleted the feature/mem-resource-phase-3 branch March 7, 2026 23:33
David-Noble-at-work pushed a commit that referenced this pull request Sep 23, 2026
The last commit of the pull request closes the plan, per #199. Every other box
is ticked: vet, lint and test clean, gofmt clean, and the live path exercised
with the built binary -- a superseded completion retired and reported, and a
file edited after install left and reported.

Two findings recorded in the plan because they will recur. misspell enforces US
spelling in Go source even though this repository's prose is British, which
cost the first lint run. And `gofmt -l` with no file operands reads standard
input, so the pre-flight added to the PR script is guarded on there being
changed Go files -- unguarded it would hang on a branch that touches no Go.

The CI box states the arrangement rather than the outcome, which arrives after
this commit; the merge gate enforces it.
David-Noble-at-work added a commit that referenced this pull request Sep 23, 2026
…r owns (#934)

* chore(plan): self install replaces the record

Lane 17 of noblefactor-ops#217, ahead of #228 -- a serious bug, corrected
while the analysis is fresh.

Ruled 2026-09-23: the manifest is a record of what the tool owns, self install
implicitly uninstalls a prior install, and that holds for every app. All four
products build through cli.NewRootCmd, so it is one function.

Ruled the same day, B over A: install, then retire what the prior record owned
and this one does not -- rather than retire first and install into the gap.
Both reach the same state. B does not remove a running executable, which
Windows refuses, and does not leave the tool absent if the install then fails.
Nothing here is transactional.

Ruled the same day on vocabulary: writ's verb is reused to describe the
function, and its model is not. "We get a manifest, not a trace." A trace has
receipts that fold, lifetimes to prune, and a replayable graph behind its
reconciliation; a manifest is paths and hashes written at the end of one
operation. The plan records the distinction so a later reader does not reach
for readback.Fold here.

One open question carries a proposal rather than an answer: a file whose hash
has changed cannot be deleted and cannot be trusted, and that does not change.
But the forgetting can -- the new record could retain it as a modified entry
instead of dropping it, which is this issue reproduced one file at a time. Not
in the phases; a requirement of its own if wanted.

* fix(cli): self install replaces the record, retiring what it no longer owns

runSelfInstall never read the prior manifest. It wrote files, then overwrote
the record with a list built from scratch -- so a file at a path this install
no longer writes was left on disk and disowned in the same operation, and
self uninstall, which reads only the record, could never reach it again.

star's extensions moved under devlore/ in #918 and stranded 24 files exactly
that way. They were removed by hand on 2026-09-23.

Ruled that day: the manifest is a record of what the tool owns, self install
implicitly uninstalls a prior install, and it holds for every app. lore, star,
writ and devlore-test all build through cli.NewRootCmd, so this one function
satisfies it for all four.

Ruled B over A: install, then retire what the prior record owned and this one
does not -- rather than retire first and install into the gap. Both reach the
same state. B does not remove the running executable, which Windows refuses,
and does not leave the tool absent when the install that was to replace it
fails partway. Nothing here is transactional.

The removal loop is now removeRecordedFiles, shared with self uninstall, hash
guard included: a file whose content no longer matches what was recorded may
be the operator's edit, so it is left and reported. That does not change --
there is no safe way to delete it and no way to trust it.

runSelfUninstall loses its nolint:gocognit; extracting the loop took it back
under the threshold, verified by golangci-lint.

Five tests, and the two that prove the fix were made to fail with the
retirement disabled. The other three still pass without it, correctly: they
guard against over-deletion, not under-deletion.

* doc(cli): self install takes deploy's verb, and not its model

10-command-line-interface.md section 3 is where #913 defines the four
lifecycle operations by what each does to the record. self install has a
record too -- share/<tool>/manifest.json -- and now replaces it rather than
overwriting it, so the note belongs beside them, with the reason the verb is
the same.

It also says what is deliberately not shared. A trace carries receipts that
fold, lifetimes to prune, and a reconciliation that can restore a system
because the graph behind it is replayable. A manifest is paths and hashes
written at the end of one operation. It answers "is this the file I wrote" and
cannot answer "what would it take to get back here". Ruled 2026-09-23: reuse
the vocabulary to describe the function, not the infrastructure behind it.

self install's own Long listed five steps and the retirement made it six. That
correction belonged in the commit that made it stale -- rule 12, missed, and
caught here rather than left.

docs/cli needs no commit: gitignored in this repository, generated by make
build and published by docs-publish.yaml. The behaviour reaches it through the
Long above.

* chore(plan): #933 reads complete

The last commit of the pull request closes the plan, per #199. Every other box
is ticked: vet, lint and test clean, gofmt clean, and the live path exercised
with the built binary -- a superseded completion retired and reported, and a
file edited after install left and reported.

Two findings recorded in the plan because they will recur. misspell enforces US
spelling in Go source even though this repository's prose is British, which
cost the first lint run. And `gofmt -l` with no file operands reads standard
input, so the pre-flight added to the PR script is guarded on there being
changed Go files -- unguarded it would hang on a branch that touches no Go.

The CI box states the arrangement rather than the outcome, which arrives after
this commit; the merge gate enforces it.
David-Noble-at-work added a commit that referenced this pull request Oct 24, 2026
… run made, byte for byte (#1163)

## Summary

Lane 48 of #949.

- **The version comes from the commit (#980).** A branch run of the Release workflow took its version's timestamp from the clock, so a rerun published a second pre-release of the same commit; a tag run's rerun failed, the release existing. `.github/scripts/release-version.sh` now stamps a develop, main or `release/*` build with its commit's committer time in UTC, so a rerun computes the version the first run did. A `v*` tag's version is the tag.
- **The release step creates, completes or leaves alone** (ruled 2026-10-23). `.github/scripts/release-publish.sh` creates a release that is not there; leaves one that has every asset as it is; and replaces every asset of one that lacks an asset, so the archives and the checksums file come from one build.
- **A rebuild of a commit is the same bytes** (ruled 2026-10-23, "B"). `BUILD_DATE` is the commit's time, not the clock; the binaries are built with `-trimpath`; every archive is packed in name order with each file at the commit's time, owned by 0:0, the `.tar.gz` through `gzip -n` and the `.zip` with `zip -X`. That takes GNU tar, which `make dist` now checks for. The Release workflow pins Go 1.27.3, what `1.27` resolved to for the last release, since a new patch would change the bytes; its version step runs under `shell: bash`, so a failed script fails the step.
- **The test.** `scripts/Test-Release.sh`, run by `make test-release`, a step of `make quality-gate` and so of CI's quality-gate job: the version for each kind of ref against a commit of known time, twice; the release step against a stand-in `gh` that records its calls, in all three states; and two `make dist` builds, a `.tar.gz` and a Windows `.zip`, compared byte for byte. All 12 checks failed at `fcc43546` and pass.
- **The plan stays `active`.** Its last box is the merge commit's Release run, rerun after the merge, leaving one pre-release for that commit; no commit in this pull request can record it (#199).
- **Plan:** `docs/plans/fix/980-rerunning-a-release-run-doesn-t.md`.

Resolves #980

## Test plan

- [x] `make test-release` fails at `fcc43546`, all 12 checks, and passes with the fix
- [x] This script's pre-flight: `make check-all`
- [ ] CI on this pull request, every leg
- [ ] After the merge: the merge commit's Release run rerun, and one pre-release for that commit

Written with AI assistance.

Signed-off-by: David Noble <[email protected]>
Assisted-by: Claude Code
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