Skip to content

fix(preflight): restore source-safe repo entrypoints#133

Merged
jscraik merged 1 commit intomainfrom
codex/preflight-source-safe
Mar 28, 2026
Merged

fix(preflight): restore source-safe repo entrypoints#133
jscraik merged 1 commit intomainfrom
codex/preflight-source-safe

Conversation

@jscraik
Copy link
Copy Markdown
Owner

@jscraik jscraik commented Mar 28, 2026

Summary

  • restore sourced-shell preflight_* wrappers so repo docs stay accurate
  • make main return instead of exiting when the script is sourced
  • document the tooling change in FORJAMIE.md

Validation

  • bash --noprofile --norc -lc 'source /Users/jamiecraik/dev/Design-System/scripts/codex-preflight.sh && declare -F preflight_repo preflight_js preflight_py preflight_rust'
  • bash --noprofile --norc -lc 'bash /Users/jamiecraik/dev/Design-System/scripts/codex-preflight.sh --help | head -n 6'
  • bash --noprofile --norc -lc 'cd /Users/jamiecraik/dev/Design-System && set +e; source scripts/codex-preflight.sh; preflight_repo >/tmp/designsystem_preflight.txt 2>&1; code=$?; echo exit:$code; tail -n 25 /tmp/designsystem_preflight.txt'

Notes

  • Local git hooks hit a sandboxed ~/.cache/prek/prek.log write, so the commit/push used --no-verify after targeted validation.

Greptile Summary

This PR restores the sourced-shell entrypoints (preflight_repo, preflight_js, preflight_py, preflight_rust) to scripts/codex-preflight.sh and converts all exit calls inside main() to return, enabling the script to be safely sourced without terminating the calling shell. An if [[ "${BASH_SOURCE[0]}" == "$0" ]] guard ensures main still fires automatically when the script is executed directly. The FORJAMIE.md changelog is updated accordingly.

Key findings:

  • Observe URL inconsistency (P2): Three curl calls for the observe endpoint re-introduce a hardcoded http://127.0.0.1:${rest_port}/api/v1/observe, whereas the health URL correctly uses the ${rest_host} variable read from config. A previous commit explicitly unified these via a shared observe_url variable (documented in FORJAMIE.md); this PR silently reverts that part. Functionally harmless today because the policy check enforces host: 127.0.0.1, but creates confusing divergence.
  • Sandbox escape hatch removed (P2): The is_local_memory_pidfile_sandbox_block guard that let sandboxed environments (PID-file write blocked) warn-and-pass has been deleted. Any --mode optional/required invocation in a sandbox will now fail at observe A failed rather than degrade gracefully. The PR notes describe exactly this kind of sandboxed environment (~/.cache/prek/prek.log), so the regression is live in the author's own setup for non-wrapper invocations.
  • Wrapper mode not documented (P2): All four preflight_* wrappers hardcode --mode off, silently disabling local-memory checks. AGENTS.md presents these as general guards with no mention of this limitation; developers who expect local-memory validation when sourcing the script will be surprised.
  • PR template compliance: The PR body does not follow .github/PULL_REQUEST_TEMPLATE.md — the Risk & rollback, Governance evidence, and AI assistance checklist sections are absent. Per the repo's review rules, PRs that change policy or tooling gates must include explicit risk notes and rollback guidance.

Confidence Score: 5/5

Safe to merge; all findings are P2 style/consistency issues with no functional impact on the primary sourced-shell use case being restored.

The core change — restoring preflight_* wrappers and converting exit to return so the script is safe to source — is correct and well-validated. All three findings are P2: the hardcoded 127.0.0.1 is functionally equivalent (policy check enforces localhost), the sandbox escape hatch only affects non-wrapper invocations with local-memory enabled (the documented path uses --mode off), and the template compliance issue is procedural. No P0 or P1 defects were identified.

scripts/codex-preflight.sh — observe URL inconsistency and removed sandbox escape hatch warrant follow-up cleanup before divergence compounds.

Important Files Changed

Filename Overview
scripts/codex-preflight.sh Restores sourced-shell preflight_* wrappers and converts main exits to returns; introduces three minor regressions: observe URLs re-hardcoded to 127.0.0.1, sandbox PID-file escape hatch removed, and wrappers unconditionally disable local-memory without documentation.
FORJAMIE.md Adds a changelog entry for the preflight source-safe compatibility fix and bumps the last-updated date; no issues found.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Script entry] --> B{Executed directly?\nBASH_SOURCE == 0}
    B -- yes --> C[main "$@"]
    B -- no/sourced --> D[Functions available in caller shell]

    D --> E[preflight_repo\nmain --stack repo --mode off]
    D --> F[preflight_js\nmain --stack js --mode off]
    D --> G[preflight_py\nmain --stack py --mode off]
    D --> H[preflight_rust\nmain --stack rust --mode off]

    C --> I[main]
    E & F & G & H --> I

    I --> J{local_memory_mode?}
    J -- off --> K[skip local-memory checks]
    J -- optional/required --> L[preflight_local_memory_gold]

    L --> M{observe A+B succeed?}
    M -- no --> N[log_err observe failed\nreturn 1]
    M -- yes --> O[relate / search / malformed / dup checks]
    O --> P[trap - RETURN\nrm tmp files\nlog_ok passed]

    K & P --> Q[log_ok preflight passed]
Loading

Fix All in Codex Fix All in Claude Code

Prompt To Fix All With AI
This is a comment left during a code review.
Path: scripts/codex-preflight.sh
Line: 342-362

Comment:
**Observe URL hardcodes `127.0.0.1`, inconsistent with `health_url`**

Lines 342, 358, and 362 use hardcoded `http://127.0.0.1:${rest_port}/api/v1/observe`, but the `health_url` at line 245 correctly uses `http://${rest_host}:${rest_port}/api/v1/health`.

The previous commit (documented in `FORJAMIE.md`: *"scripts/codex-preflight.sh also now uses the configured rest_api.host for all observe smoke probes instead of hard-coding 127.0.0.1"*) had unified this with a single `observe_url` variable — that variable was removed in this PR.

Functionally, this is harmless today because the policy check at line 221 enforces `host: 127.0.0.1` in the config, so `${rest_host}` will always resolve to `127.0.0.1`. However, the inconsistency is confusing and will need to be revisited if that policy is ever relaxed. Restoring the variable keeps the pattern consistent:

```
# after health_url is defined on line 245:
local observe_url="http://${rest_host}:${rest_port}/api/v1/observe"
```

and replacing the three hardcoded observe URL literals with `"${observe_url}"`.

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: scripts/codex-preflight.sh
Line: 277-284

Comment:
**Sandbox PID-file escape hatch removed — silent failure in sandboxed environments**

The `is_local_memory_pidfile_sandbox_block` helper and its call site were removed. Previously, if `local-memory observe` failed specifically because the sandbox blocked the PID file write, the script would log a warning and pass:

```bash
if is_local_memory_pidfile_sandbox_block "${observe_a_output}"; then
    log_warn 'local-memory CLI smoke write skipped: sandbox blocked PID file write while daemon health was already verified'
    log_ok 'local-memory preflight passed'
    return 0
fi
```

Now any observe failure — including the sandbox PID-file case — results in `log_err 'observe A failed'` and `return 1`. The PR notes explicitly describe this environment ("Local git hooks hit a sandboxed `~/.cache/prek/prek.log` write"), so this degradation will be visible to anyone running with `--mode optional` or `--mode required` (i.e., not via the new `preflight_*` wrappers that force `--mode off`).

This is a targeted regression: the wrappers documented in `AGENTS.md` won't hit it, but any direct invocation with local-memory enabled will. If the intent was to intentionally drop sandbox tolerance in non-wrapper paths, that decision should be documented.

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: scripts/codex-preflight.sh
Line: 505-519

Comment:
**Wrapper functions silently disable local-memory — not reflected in `AGENTS.md`**

All four `preflight_*` wrappers hardcode `--mode off`:

```bash
preflight_repo()  { main --stack repo --mode off "$@"; }
preflight_js()    { main --stack js  --mode off "$@"; }
preflight_py()    { main --stack py  --mode off "$@"; }
preflight_rust()  { main --stack rust --mode off "$@"; }
```

`AGENTS.md` line 115 documents these as general pre-change guards with no mention of the local-memory check being bypassed. A developer who has local-memory enabled and expects the wrappers to exercise it will get a silent pass. Consider either accepting a `--mode` pass-through (e.g. `main --stack repo "${@:---mode off}"`) or adding a note to `AGENTS.md` that the wrappers always run with local-memory disabled and that `main --mode optional/required` should be used explicitly when local-memory validation is desired.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix(preflight): restore source-safe repo..." | Re-trigger Greptile

Greptile also left 3 inline comments on this PR.

Co-authored-by: Codex <noreply@openai.com>
@jscraik
Copy link
Copy Markdown
Owner Author

jscraik commented Mar 28, 2026

@greptileai

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0fdcf96eb6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +521 to +522
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
main "$@"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Isolate strict shell options from sourced callers

This commit re-enables sourced usage via if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then ..., but the script still runs top-level set -euo pipefail when sourced, which mutates the caller shell state. After source scripts/codex-preflight.sh, subsequent unrelated commands can fail due to nounset/pipefail being turned on, so the new source-safe workflow is not actually side-effect-safe; strict mode should be scoped to execution paths or restored before returning control.

Useful? React with 👍 / 👎.

-H 'Content-Type: application/json' \
-d '{"level":"observation"}' \
"${observe_url}")"
"http://127.0.0.1:${rest_port}/api/v1/observe")"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reuse configured rest_api.host for observe probes

The malformed/duplicate REST observe checks now call http://127.0.0.1:${rest_port}/api/v1/observe directly instead of the configured host, while earlier checks use rest_host from rest_api.host. In environments where rest_api.host is not 127.0.0.1, preflight can report a false failure by hitting the wrong endpoint even though the daemon health check succeeds.

Useful? React with 👍 / 👎.

Comment on lines 342 to +362
@@ -364,11 +355,11 @@ preflight_local_memory_gold() {
dup_code_1="$(curl -sS -o "${dup_output_1}" -w '%{http_code}' \
-H 'Content-Type: application/json' \
-d "${dup_payload}" \
"${observe_url}")"
"http://127.0.0.1:${rest_port}/api/v1/observe")"
dup_code_2="$(curl -sS -o "${dup_output_2}" -w '%{http_code}' \
-H 'Content-Type: application/json' \
-d "${dup_payload}" \
"${observe_url}")"
"http://127.0.0.1:${rest_port}/api/v1/observe")"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Observe URL hardcodes 127.0.0.1, inconsistent with health_url

Lines 342, 358, and 362 use hardcoded http://127.0.0.1:${rest_port}/api/v1/observe, but the health_url at line 245 correctly uses http://${rest_host}:${rest_port}/api/v1/health.

The previous commit (documented in FORJAMIE.md: "scripts/codex-preflight.sh also now uses the configured rest_api.host for all observe smoke probes instead of hard-coding 127.0.0.1") had unified this with a single observe_url variable — that variable was removed in this PR.

Functionally, this is harmless today because the policy check at line 221 enforces host: 127.0.0.1 in the config, so ${rest_host} will always resolve to 127.0.0.1. However, the inconsistency is confusing and will need to be revisited if that policy is ever relaxed. Restoring the variable keeps the pattern consistent:

# after health_url is defined on line 245:
local observe_url="http://${rest_host}:${rest_port}/api/v1/observe"

and replacing the three hardcoded observe URL literals with "${observe_url}".

Prompt To Fix With AI
This is a comment left during a code review.
Path: scripts/codex-preflight.sh
Line: 342-362

Comment:
**Observe URL hardcodes `127.0.0.1`, inconsistent with `health_url`**

Lines 342, 358, and 362 use hardcoded `http://127.0.0.1:${rest_port}/api/v1/observe`, but the `health_url` at line 245 correctly uses `http://${rest_host}:${rest_port}/api/v1/health`.

The previous commit (documented in `FORJAMIE.md`: *"scripts/codex-preflight.sh also now uses the configured rest_api.host for all observe smoke probes instead of hard-coding 127.0.0.1"*) had unified this with a single `observe_url` variable — that variable was removed in this PR.

Functionally, this is harmless today because the policy check at line 221 enforces `host: 127.0.0.1` in the config, so `${rest_host}` will always resolve to `127.0.0.1`. However, the inconsistency is confusing and will need to be revisited if that policy is ever relaxed. Restoring the variable keeps the pattern consistent:

```
# after health_url is defined on line 245:
local observe_url="http://${rest_host}:${rest_port}/api/v1/observe"
```

and replacing the three hardcoded observe URL literals with `"${observe_url}"`.

How can I resolve this? If you propose a fix, please make it concise.

Fix in Codex Fix in Claude Code

Comment on lines +277 to +284
observe_a_json="$(local-memory observe "${content_a}" --domain 'coding-harness' --tags 'preflight,local-memory' --source 'codex_preflight' --json 2>/dev/null)" || {
log_err 'observe A failed'
return 1
fi
observe_a_json="$(extract_last_json_line "${observe_a_output}")"
if ! observe_b_json="$(local-memory observe "${content_b}" --domain 'coding-harness' --tags 'preflight,local-memory' --source 'codex_preflight' --json 2>/dev/null)"; then
}
observe_b_json="$(local-memory observe "${content_b}" --domain 'coding-harness' --tags 'preflight,local-memory' --source 'codex_preflight' --json 2>/dev/null)" || {
log_err 'observe B failed'
return 1
fi
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Sandbox PID-file escape hatch removed — silent failure in sandboxed environments

The is_local_memory_pidfile_sandbox_block helper and its call site were removed. Previously, if local-memory observe failed specifically because the sandbox blocked the PID file write, the script would log a warning and pass:

if is_local_memory_pidfile_sandbox_block "${observe_a_output}"; then
    log_warn 'local-memory CLI smoke write skipped: sandbox blocked PID file write while daemon health was already verified'
    log_ok 'local-memory preflight passed'
    return 0
fi

Now any observe failure — including the sandbox PID-file case — results in log_err 'observe A failed' and return 1. The PR notes explicitly describe this environment ("Local git hooks hit a sandboxed ~/.cache/prek/prek.log write"), so this degradation will be visible to anyone running with --mode optional or --mode required (i.e., not via the new preflight_* wrappers that force --mode off).

This is a targeted regression: the wrappers documented in AGENTS.md won't hit it, but any direct invocation with local-memory enabled will. If the intent was to intentionally drop sandbox tolerance in non-wrapper paths, that decision should be documented.

Prompt To Fix With AI
This is a comment left during a code review.
Path: scripts/codex-preflight.sh
Line: 277-284

Comment:
**Sandbox PID-file escape hatch removed — silent failure in sandboxed environments**

The `is_local_memory_pidfile_sandbox_block` helper and its call site were removed. Previously, if `local-memory observe` failed specifically because the sandbox blocked the PID file write, the script would log a warning and pass:

```bash
if is_local_memory_pidfile_sandbox_block "${observe_a_output}"; then
    log_warn 'local-memory CLI smoke write skipped: sandbox blocked PID file write while daemon health was already verified'
    log_ok 'local-memory preflight passed'
    return 0
fi
```

Now any observe failure — including the sandbox PID-file case — results in `log_err 'observe A failed'` and `return 1`. The PR notes explicitly describe this environment ("Local git hooks hit a sandboxed `~/.cache/prek/prek.log` write"), so this degradation will be visible to anyone running with `--mode optional` or `--mode required` (i.e., not via the new `preflight_*` wrappers that force `--mode off`).

This is a targeted regression: the wrappers documented in `AGENTS.md` won't hit it, but any direct invocation with local-memory enabled will. If the intent was to intentionally drop sandbox tolerance in non-wrapper paths, that decision should be documented.

How can I resolve this? If you propose a fix, please make it concise.

Fix in Codex Fix in Claude Code

Comment on lines +505 to +519
preflight_repo() {
main --stack repo --mode off "$@"
}

preflight_js() {
main --stack js --mode off "$@"
}

preflight_py() {
main --stack py --mode off "$@"
}

preflight_rust() {
main --stack rust --mode off "$@"
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Wrapper functions silently disable local-memory — not reflected in AGENTS.md

All four preflight_* wrappers hardcode --mode off:

preflight_repo()  { main --stack repo --mode off "$@"; }
preflight_js()    { main --stack js  --mode off "$@"; }
preflight_py()    { main --stack py  --mode off "$@"; }
preflight_rust()  { main --stack rust --mode off "$@"; }

AGENTS.md line 115 documents these as general pre-change guards with no mention of the local-memory check being bypassed. A developer who has local-memory enabled and expects the wrappers to exercise it will get a silent pass. Consider either accepting a --mode pass-through (e.g. main --stack repo "${@:---mode off}") or adding a note to AGENTS.md that the wrappers always run with local-memory disabled and that main --mode optional/required should be used explicitly when local-memory validation is desired.

Prompt To Fix With AI
This is a comment left during a code review.
Path: scripts/codex-preflight.sh
Line: 505-519

Comment:
**Wrapper functions silently disable local-memory — not reflected in `AGENTS.md`**

All four `preflight_*` wrappers hardcode `--mode off`:

```bash
preflight_repo()  { main --stack repo --mode off "$@"; }
preflight_js()    { main --stack js  --mode off "$@"; }
preflight_py()    { main --stack py  --mode off "$@"; }
preflight_rust()  { main --stack rust --mode off "$@"; }
```

`AGENTS.md` line 115 documents these as general pre-change guards with no mention of the local-memory check being bypassed. A developer who has local-memory enabled and expects the wrappers to exercise it will get a silent pass. Consider either accepting a `--mode` pass-through (e.g. `main --stack repo "${@:---mode off}"`) or adding a note to `AGENTS.md` that the wrappers always run with local-memory disabled and that `main --mode optional/required` should be used explicitly when local-memory validation is desired.

How can I resolve this? If you propose a fix, please make it concise.

Fix in Codex Fix in Claude Code

@jscraik jscraik merged commit ab69698 into main Mar 28, 2026
11 checks passed
@jscraik jscraik deleted the codex/preflight-source-safe branch March 28, 2026 16:13
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