Skip to content

fix(build): use build-time constants for binary detection and pretty stream logger#982

Merged
Wirasm merged 3 commits intodevfrom
fix/979-build-time-binary-constants
Apr 8, 2026
Merged

fix(build): use build-time constants for binary detection and pretty stream logger#982
Wirasm merged 3 commits intodevfrom
fix/979-build-time-binary-constants

Conversation

@Wirasm
Copy link
Copy Markdown
Collaborator

@Wirasm Wirasm commented Apr 8, 2026

Summary

Replaces runtime binary-build detection with a build-time BUNDLED_IS_BINARY constant in @archon/paths/bundled-build.ts, rewritten by scripts/build-binaries.sh (with an EXIT trap to restore dev defaults). Also rewrites @archon/paths/logger.ts to use pino-pretty as a destination stream instead of a worker-thread transport — eliminating the /$bunfs/ require.resolve crash entirely. Same code path runs in dev and compiled binaries; no environment detection in the logger at all.

Closes #960, #961, #979. Supersedes #962 and #963.

Why

Runtime detection in #962/#963 needed two ANDed heuristics per package (import.meta.dir prefix + exec basename) because Bun has two compile modes (ESM vs CJS bytecode) and only one signal works per mode. Heuristics are brittle (Windows backslash, case sensitivity, renamed interpreters), duplicated across @archon/paths and @archon/workflows, and will silently break on future Bun compile modes. Archon already uses build-time constants for BUNDLED_VERSION — extending that pattern is the principled fix.

For the logger: pino-pretty as a worker-thread transport calls require.resolve('pino-pretty') inside Bun's /\$bunfs/ virtual filesystem and crashes. As a destination stream, the formatter runs synchronously on the main thread — no worker, no resolve, no detection.

Changes

  • CREATE packages/paths/src/bundled-build.tsBUNDLED_IS_BINARY, BUNDLED_VERSION, BUNDLED_GIT_COMMIT (dev defaults)
  • CREATE packages/paths/src/bundled-build.test.ts — assert dev defaults
  • REWRITE packages/paths/src/logger.tspretty() as destination stream
  • UPDATE packages/paths/package.json — promote pino-pretty from optionalDependencies to dependencies
  • UPDATE packages/paths/src/index.ts — re-export new constants
  • REFACTOR packages/workflows/src/defaults/bundled-defaults.ts — delete isBunVirtualFs(); isBinaryBuild() is now a one-line wrapper around the constant (kept for spyOn back-compat in loader.test.ts)
  • TRIM packages/workflows/src/defaults/bundled-defaults.test.ts — drop deleted-function tests
  • UPDATE packages/cli/src/commands/version.ts — import from @archon/paths
  • DELETE packages/cli/src/commands/bundled-version.ts — superseded
  • UPDATE scripts/build-binaries.sh — rewrite new file path, set BUNDLED_IS_BINARY=true, restore via EXIT trap

Test plan

  • `bun run validate` (type-check + lint + format + tests, all packages) passes
  • `bun run cli version` reports `Build: source (bun)` in dev
  • Reviewer: `bash scripts/build-binaries.sh && ./dist/binaries/archon-darwin-arm64 version` reports real version + `Build: binary`
  • Reviewer: compiled binary `workflow list` runs without the pino-pretty crash
  • Reviewer: after build script, `git status packages/paths/src/bundled-build.ts` is clean (trap restored)

Credit

Thanks to @leex279 for catching the original bugs in #960/#961 and the initial fixes in #962/#963 — this PR replaces them with a more principled architecture but the diagnosis is theirs.

…stream logger

Replaces runtime detection of compiled binaries (env sniffing via
import.meta.dir / process.execPath) with a build-time BUNDLED_IS_BINARY
constant in @archon/paths/bundled-build.ts, rewritten by
scripts/build-binaries.sh and restored on EXIT via a trap.

Also rewrites @archon/paths/logger.ts to use pino-pretty as a destination
stream instead of a worker-thread transport. The formatter now runs on
the main thread, eliminating the require.resolve('pino-pretty') lookup
that crashes inside Bun's /\$bunfs/ virtual filesystem in compiled
binaries. The same code path runs in dev and binaries — no environment
detection in the logger at all.

isBinaryBuild() in @archon/workflows is kept as a one-line wrapper
around BUNDLED_IS_BINARY so existing spyOn-based test mocking in
loader.test.ts continues to work without modification.

Closes #960
Closes #961
Closes #979
Supersedes #962
Supersedes #963

Co-Authored-By: leex279 <leex279@users.noreply.github.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 8, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 96210fcc-3735-4415-9458-aa3dcc5d055a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/979-build-time-binary-constants

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Wirasm
Copy link
Copy Markdown
Collaborator Author

Wirasm commented Apr 8, 2026

End-to-end binary verification done locally on darwin-arm64:

  • ✅ `./dist/binaries/archon-darwin-arm64 version` → `Archon CLI v0.2.13`, `Build: binary`, `Git commit: ae4a87b`
  • ✅ `./dist/binaries/archon-darwin-arm64 workflow list` → lists bundled workflows, no pino-pretty crash
  • ✅ `git status packages/paths/src/bundled-build.ts` → clean (EXIT trap restored dev defaults)

All four targets compiled successfully (darwin-arm64 60M, darwin-x64 65M, linux-arm64 96M, linux-x64 97M).

@Wirasm
Copy link
Copy Markdown
Collaborator Author

Wirasm commented Apr 8, 2026

PR Review Summary (multi-agent)

Important Issues

Agent Issue Location
silent-failure-hunter pretty() call not wrapped — if init throws, module import crashes with no actionable message. Wrap in try/catch and fall back to plain JSON logging. packages/paths/src/logger.ts (buildLogger usePretty block)
silent-failure-hunter EXIT trap uses 2>/dev/null || true, silently hiding restore failures. If git checkout fails, dev tree is left with BUNDLED_IS_BINARY=true. Drop || true so failures are visible. scripts/build-binaries.sh:14
code-reviewer isBinaryBuild() wrapper is a YAGNI compat shim kept only for a spyOn seam in loader.test.ts. Prefer mocking BUNDLED_IS_BINARY directly and deleting the wrapper. packages/workflows/src/defaults/bundled-defaults.ts:117
code-reviewer pino-pretty promoted from optionalDependencies → dependencies. Correct given unconditional import, but worth a note — slim production installs now get an extra dep. packages/paths/package.json:15

Suggestions

Agent Suggestion Location
pr-test-analyzer No direct tests for logger rewrite (TTY stream selection + level propagation) — this is the exact code path the PR fixes. Add a minimal logger test. packages/paths/src/logger.ts:58-71
pr-test-analyzer EXIT trap untested — consider a bash/bats smoke test that simulates build failure and asserts the file is restored. scripts/build-binaries.sh:13

Strengths

  • bundled-build.test.ts directly guards the highest-risk regression (dev never ships BUNDLED_IS_BINARY=true).
  • Removing isBunVirtualFs tests alongside the function — no orphaned coverage.
  • Build-time constant approach is the principled fix vs. dual runtime heuristics; consistent with existing BUNDLED_VERSION pattern.

Documentation

  • No stale docs found. CLAUDE.md, docs-web/, and contributing docs are clean.

Verdict

NEEDS MINOR FIXES — core approach is sound and well-motivated. Address the two silent-failure patterns (logger try/catch, drop || true in trap) before merge; the YAGNI shim and logger test are nice-to-haves.

- logger: wrap pino-pretty init in try/catch and fall back to JSON so a
  broken TTY or missing peer can't crash module load.
- build-binaries.sh: drop '2>/dev/null || true' from the EXIT trap so a
  failed bundled-build.ts restore is visible instead of silently leaving
  the dev tree with BUNDLED_IS_BINARY=true.
- bundled-defaults: unmark isBinaryBuild() @deprecated and document why
  the wrapper is the intentional test seam (mock.module pollution in Bun).
@Wirasm Wirasm merged commit e778994 into dev Apr 8, 2026
4 checks passed
@Wirasm Wirasm deleted the fix/979-build-time-binary-constants branch April 8, 2026 09:02
puvuglobal pushed a commit to puvuglobal/Archon that referenced this pull request Apr 8, 2026
…eam00#982)

Projects with docs outside `docs/` (e.g., `packages/docs-web/src/content/docs/`)
get broken bundled commands because the path is hardcoded. Add `docs.path` to
`.archon/config.yaml` and thread it through the workflow engine as `$DOCS_DIR`
(default: `docs/`), following the same pipeline as `$BASE_BRANCH`.

Changes:
- Add `docs.path` to RepoConfig and `docsPath` to MergedConfig/WorkflowConfig
- Thread `docsDir` through executor-shared, executor, and dag-executor
- Update bundled commands to use `$DOCS_DIR` instead of hardcoded `docs/`
- Add optional docs path prompt to `archon setup`
- Add variable reference and configuration documentation
- Resolve pre-existing merge conflicts in server/api.ts

Fixes coleam00#982
Tyone88 pushed a commit to Tyone88/Archon that referenced this pull request Apr 16, 2026
…eam00#982)

Projects with docs outside `docs/` (e.g., `packages/docs-web/src/content/docs/`)
get broken bundled commands because the path is hardcoded. Add `docs.path` to
`.archon/config.yaml` and thread it through the workflow engine as `$DOCS_DIR`
(default: `docs/`), following the same pipeline as `$BASE_BRANCH`.

Changes:
- Add `docs.path` to RepoConfig and `docsPath` to MergedConfig/WorkflowConfig
- Thread `docsDir` through executor-shared, executor, and dag-executor
- Update bundled commands to use `$DOCS_DIR` instead of hardcoded `docs/`
- Add optional docs path prompt to `archon setup`
- Add variable reference and configuration documentation
- Resolve pre-existing merge conflicts in server/api.ts

Fixes coleam00#982
Tyone88 pushed a commit to Tyone88/Archon that referenced this pull request Apr 16, 2026
…stream logger (coleam00#982)

* fix(build): use build-time constants for binary detection and pretty stream logger

Replaces runtime detection of compiled binaries (env sniffing via
import.meta.dir / process.execPath) with a build-time BUNDLED_IS_BINARY
constant in @archon/paths/bundled-build.ts, rewritten by
scripts/build-binaries.sh and restored on EXIT via a trap.

Also rewrites @archon/paths/logger.ts to use pino-pretty as a destination
stream instead of a worker-thread transport. The formatter now runs on
the main thread, eliminating the require.resolve('pino-pretty') lookup
that crashes inside Bun's /\$bunfs/ virtual filesystem in compiled
binaries. The same code path runs in dev and binaries — no environment
detection in the logger at all.

isBinaryBuild() in @archon/workflows is kept as a one-line wrapper
around BUNDLED_IS_BINARY so existing spyOn-based test mocking in
loader.test.ts continues to work without modification.

Closes coleam00#960
Closes coleam00#961
Closes coleam00#979
Supersedes coleam00#962
Supersedes coleam00#963

Co-Authored-By: leex279 <leex279@users.noreply.github.com>

* style(workflows): hoist BUNDLED_IS_BINARY import to top of file

* fix(build,logger): harden pretty init and trap restore

- logger: wrap pino-pretty init in try/catch and fall back to JSON so a
  broken TTY or missing peer can't crash module load.
- build-binaries.sh: drop '2>/dev/null || true' from the EXIT trap so a
  failed bundled-build.ts restore is visible instead of silently leaving
  the dev tree with BUNDLED_IS_BINARY=true.
- bundled-defaults: unmark isBinaryBuild() @deprecated and document why
  the wrapper is the intentional test seam (mock.module pollution in Bun).

---------

Co-authored-by: leex279 <leex279@users.noreply.github.com>
joaobmonteiro pushed a commit to joaobmonteiro/Archon that referenced this pull request Apr 26, 2026
…eam00#982)

Projects with docs outside `docs/` (e.g., `packages/docs-web/src/content/docs/`)
get broken bundled commands because the path is hardcoded. Add `docs.path` to
`.archon/config.yaml` and thread it through the workflow engine as `$DOCS_DIR`
(default: `docs/`), following the same pipeline as `$BASE_BRANCH`.

Changes:
- Add `docs.path` to RepoConfig and `docsPath` to MergedConfig/WorkflowConfig
- Thread `docsDir` through executor-shared, executor, and dag-executor
- Update bundled commands to use `$DOCS_DIR` instead of hardcoded `docs/`
- Add optional docs path prompt to `archon setup`
- Add variable reference and configuration documentation
- Resolve pre-existing merge conflicts in server/api.ts

Fixes coleam00#982
joaobmonteiro pushed a commit to joaobmonteiro/Archon that referenced this pull request Apr 26, 2026
…stream logger (coleam00#982)

* fix(build): use build-time constants for binary detection and pretty stream logger

Replaces runtime detection of compiled binaries (env sniffing via
import.meta.dir / process.execPath) with a build-time BUNDLED_IS_BINARY
constant in @archon/paths/bundled-build.ts, rewritten by
scripts/build-binaries.sh and restored on EXIT via a trap.

Also rewrites @archon/paths/logger.ts to use pino-pretty as a destination
stream instead of a worker-thread transport. The formatter now runs on
the main thread, eliminating the require.resolve('pino-pretty') lookup
that crashes inside Bun's /\$bunfs/ virtual filesystem in compiled
binaries. The same code path runs in dev and binaries — no environment
detection in the logger at all.

isBinaryBuild() in @archon/workflows is kept as a one-line wrapper
around BUNDLED_IS_BINARY so existing spyOn-based test mocking in
loader.test.ts continues to work without modification.

Closes coleam00#960
Closes coleam00#961
Closes coleam00#979
Supersedes coleam00#962
Supersedes coleam00#963

Co-Authored-By: leex279 <leex279@users.noreply.github.com>

* style(workflows): hoist BUNDLED_IS_BINARY import to top of file

* fix(build,logger): harden pretty init and trap restore

- logger: wrap pino-pretty init in try/catch and fall back to JSON so a
  broken TTY or missing peer can't crash module load.
- build-binaries.sh: drop '2>/dev/null || true' from the EXIT trap so a
  failed bundled-build.ts restore is visible instead of silently leaving
  the dev tree with BUNDLED_IS_BINARY=true.
- bundled-defaults: unmark isBinaryBuild() @deprecated and document why
  the wrapper is the intentional test seam (mock.module pollution in Bun).

---------

Co-authored-by: leex279 <leex279@users.noreply.github.com>
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