-
Notifications
You must be signed in to change notification settings - Fork 1
fix(preflight): restore source-safe repo entrypoints #133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ Options: | |
| Examples: | ||
| ./scripts/codex-preflight.sh | ||
| ./scripts/codex-preflight.sh --stack js | ||
| ./scripts/codex-preflight.sh --stack py --mode required | ||
| ./scripts/codex-preflight.sh --stack py --mode optional | ||
| ./scripts/codex-preflight.sh --repo-fragment local-memory | ||
|
|
||
| Legacy compatibility: | ||
|
|
@@ -69,11 +69,6 @@ extract_local_memory_rest_value() { | |
| ' "${config_path}" | ||
| } | ||
|
|
||
| is_local_memory_pidfile_sandbox_block() { | ||
| local output="${1:-}" | ||
| [[ "${output}" == *"failed to write PID file"* && "${output}" == *"operation not permitted"* ]] | ||
| } | ||
|
|
||
|
|
||
| make_tmp_file() { | ||
| mktemp "${TMPDIR:-/tmp}/local-memory-preflight.XXXXXX.json" | ||
|
|
@@ -248,7 +243,6 @@ preflight_local_memory_gold() { | |
| fi | ||
|
|
||
| local health_url="http://${rest_host}:${rest_port}/api/v1/health" | ||
| local observe_url="http://${rest_host}:${rest_port}/api/v1/observe" | ||
| local health_json | ||
| if [[ "${running}" != 'true' ]]; then | ||
| if health_json="$(curl -fsS "${health_url}" 2>/dev/null)"; then | ||
|
|
@@ -262,6 +256,7 @@ preflight_local_memory_gold() { | |
| log_err 'local-memory daemon is not running' | ||
| return 1 | ||
| fi | ||
|
|
||
| if ! health_json="$(curl -fsS "${health_url}")"; then | ||
| log_err "REST health endpoint unreachable at ${health_url}" | ||
| return 1 | ||
|
|
@@ -279,21 +274,15 @@ preflight_local_memory_gold() { | |
|
|
||
| local observe_a_json | ||
| local observe_b_json | ||
| local observe_a_output | ||
| if ! observe_a_output="$(local-memory observe "${content_a}" --domain 'coding-harness' --tags 'preflight,local-memory' --source 'codex_preflight' --json 2>&1)"; then | ||
| 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 | ||
| 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 | ||
| } | ||
| observe_a_json="$(extract_last_json_line "${observe_a_json}")" | ||
| observe_b_json="$(extract_last_json_line "${observe_b_json}")" | ||
|
|
||
| local id_a | ||
|
|
@@ -350,8 +339,10 @@ preflight_local_memory_gold() { | |
| malformed_code="$(curl -sS -o "${malformed_output}" -w '%{http_code}' \ | ||
| -H 'Content-Type: application/json' \ | ||
| -d '{"level":"observation"}' \ | ||
| "${observe_url}")" | ||
| "http://127.0.0.1:${rest_port}/api/v1/observe")" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The malformed/duplicate REST observe checks now call Useful? React with 👍 / 👎. |
||
| if [[ "${malformed_code}" -lt 400 ]]; then | ||
| trap - RETURN | ||
| rm -f "${malformed_output}" "${dup_output_1}" "${dup_output_2}" | ||
| log_err "malformed payload did not return an error (HTTP ${malformed_code})" | ||
| return 1 | ||
| fi | ||
|
|
@@ -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")" | ||
|
Comment on lines
342
to
+362
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Lines 342, 358, and 362 use hardcoded The previous commit (documented in Functionally, this is harmless today because the policy check at line 221 enforces and replacing the three hardcoded observe URL literals with Prompt To Fix With AIThis 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. |
||
| echo "ℹ️ duplicate behavior snapshot: first=${dup_code_1}, second=${dup_code_2}" | ||
|
|
||
| local daemon_log="${HOME}/.local-memory/daemon.log" | ||
|
|
@@ -384,6 +375,8 @@ preflight_local_memory_gold() { | |
| log_warn "daemon log not found at ${daemon_log}" | ||
| fi | ||
|
|
||
| trap - RETURN | ||
| rm -f "${malformed_output}" "${dup_output_1}" "${dup_output_2}" | ||
| log_ok 'local-memory preflight passed' | ||
| } | ||
|
|
||
|
|
@@ -398,7 +391,7 @@ main() { | |
| if (( $# > 3 )); then | ||
| log_err "legacy positional mode accepts at most 3 arguments" | ||
| usage >&2 | ||
| exit 2 | ||
| return 2 | ||
| fi | ||
| expected_repo="${1:-}" | ||
| bins_csv="${2:-}" | ||
|
|
@@ -431,51 +424,52 @@ main() { | |
| ;; | ||
| -h|--help) | ||
| usage | ||
| exit 0 | ||
| return 0 | ||
| ;; | ||
| *) | ||
| log_err "unknown argument: $1" | ||
| usage >&2 | ||
| exit 2 | ||
| return 2 | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| case "${local_memory_mode}" in | ||
| off|optional|required) ;; | ||
| *) log_err "invalid --mode: ${local_memory_mode}"; exit 2 ;; | ||
| *) log_err "invalid --mode: ${local_memory_mode}"; return 2 ;; | ||
| esac | ||
|
|
||
| log_section 'Codex Preflight' | ||
| echo "pwd: $(pwd)" | ||
|
|
||
| if ! command -v git >/dev/null 2>&1; then | ||
| log_err 'missing binary: git' | ||
| exit 2 | ||
| return 2 | ||
| fi | ||
|
|
||
| local root | ||
| if ! root="$(git rev-parse --show-toplevel 2>/dev/null)"; then | ||
| local git_root | ||
| if ! git_root="$(git rev-parse --show-toplevel 2>/dev/null)"; then | ||
| log_err 'not inside a git repo (git rev-parse failed)' | ||
| exit 2 | ||
| return 2 | ||
| fi | ||
| if [[ -z "${root}" ]]; then | ||
| if [[ -z "${git_root}" ]]; then | ||
| log_err 'git rev-parse returned empty root' | ||
| exit 2 | ||
| return 2 | ||
| fi | ||
| root="$(cd -- "${root}" && pwd -P)" | ||
| echo "repo root: ${root}" | ||
| git_root="$(cd -- "${git_root}" && pwd -P)" | ||
| echo "git root: ${git_root}" | ||
| echo "workspace root: ${WORKSPACE_ROOT}" | ||
|
|
||
| if [[ "${root}" != "${WORKSPACE_ROOT}" ]]; then | ||
| log_err "script workspace mismatch: expected ${WORKSPACE_ROOT}" | ||
| exit 2 | ||
| if [[ "${WORKSPACE_ROOT}" != "${git_root}" && "${WORKSPACE_ROOT}" != "${git_root}"/* ]]; then | ||
| log_err "script workspace mismatch: ${WORKSPACE_ROOT} is not inside git root ${git_root}" | ||
| return 2 | ||
| fi | ||
| if [[ -n "${expected_repo}" && "${root}" != *"${expected_repo}"* ]]; then | ||
| log_err "repo mismatch: expected fragment '${expected_repo}' in '${root}'" | ||
| exit 2 | ||
| if [[ -n "${expected_repo}" && "${WORKSPACE_ROOT}" != *"${expected_repo}"* ]]; then | ||
| log_err "repo mismatch: expected fragment '${expected_repo}' in '${WORKSPACE_ROOT}'" | ||
| return 2 | ||
| fi | ||
|
|
||
| cd "${root}" | ||
| cd "${WORKSPACE_ROOT}" | ||
|
|
||
| if [[ "${stack}" == 'auto' ]]; then | ||
| stack="$(detect_stack)" | ||
|
|
@@ -490,16 +484,16 @@ main() { | |
| fi | ||
|
|
||
| check_bins "${bins_csv}" | ||
| check_paths "${root}" "${paths_csv}" | ||
| check_paths "${WORKSPACE_ROOT}" "${paths_csv}" | ||
|
|
||
| echo "git branch: $(git rev-parse --abbrev-ref HEAD)" | ||
| echo "clean?: $(git status --porcelain | wc -l | tr -d ' ') changes" | ||
| echo "git branch: $(git -C "${WORKSPACE_ROOT}" rev-parse --abbrev-ref HEAD)" | ||
| echo "clean?: $(git -C "${WORKSPACE_ROOT}" status --porcelain -- . | wc -l | tr -d ' ') changes" | ||
|
|
||
| if [[ "${local_memory_mode}" != 'off' ]]; then | ||
| if ! preflight_local_memory_gold; then | ||
| if [[ "${local_memory_mode}" == 'required' ]]; then | ||
| log_err 'local-memory preflight failed (required mode)' | ||
| exit 2 | ||
| return 2 | ||
| fi | ||
| log_warn 'local-memory preflight failed (optional mode)' | ||
| fi | ||
|
|
@@ -508,4 +502,22 @@ main() { | |
| log_ok 'preflight passed' | ||
| } | ||
|
|
||
| main "$@" | ||
| 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 "$@" | ||
| } | ||
|
Comment on lines
+505
to
+519
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
All four 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 "$@"; }
Prompt To Fix With AIThis 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. |
||
|
|
||
| if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then | ||
| main "$@" | ||
|
Comment on lines
+521
to
+522
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This commit re-enables sourced usage via Useful? React with 👍 / 👎. |
||
| fi | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
is_local_memory_pidfile_sandbox_blockhelper and its call site were removed. Previously, iflocal-memory observefailed specifically because the sandbox blocked the PID file write, the script would log a warning and pass:Now any observe failure — including the sandbox PID-file case — results in
log_err 'observe A failed'andreturn 1. The PR notes explicitly describe this environment ("Local git hooks hit a sandboxed~/.cache/prek/prek.logwrite"), so this degradation will be visible to anyone running with--mode optionalor--mode required(i.e., not via the newpreflight_*wrappers that force--mode off).This is a targeted regression: the wrappers documented in
AGENTS.mdwon'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