fix(engine): warn once about a bad allowlist flag, not per tool call #10

Merged
thklein merged 1 commit from fix/flag-warn-once into main 2026-09-13 09:22:33 +00:00
Owner

Found while reviewing the bump of gptscript#9 into bpai, before anything has set the flag — which is the window worth fixing it in, since enabling it is the entire point of that bump.

strictToolEnv is re-evaluated on every tool invocation. That is deliberate: it keeps the check cheap and lets t.Setenv drive it in tests. But the misconfiguration warning sat inside it, so an operator writing GPTSCRIPT_TOOL_ENV_ALLOWLIST: "yes" in a values file would get a WARN line per tool call, forever — turning a one-line mistake into a log flood, at the exact moment they are reading those logs to work out why their tools changed behaviour.

The decision stays per call. Only the warning moves behind a sync.Once.

The test asserts on the sync.Once itself rather than on captured output: the Once is the mechanism, and a test that swapped the logger would pass against a version that logged every time through some other path.

Verified locally (this fork's CI is red on main and gates nothing): go build ./..., go test ./pkg/engine/... -count=1, golangci-lint run ./pkg/engine/... — the only lint finding is the pre-existing import-ordering one on cmd.go, byte-identical on main.

Found while reviewing the bump of gptscript#9 into bpai, before anything has set the flag — which is the window worth fixing it in, since enabling it is the entire point of that bump. `strictToolEnv` is re-evaluated on **every tool invocation**. That is deliberate: it keeps the check cheap and lets `t.Setenv` drive it in tests. But the misconfiguration warning sat inside it, so an operator writing `GPTSCRIPT_TOOL_ENV_ALLOWLIST: "yes"` in a values file would get a `WARN` line **per tool call, forever** — turning a one-line mistake into a log flood, at the exact moment they are reading those logs to work out why their tools changed behaviour. The decision stays per call. Only the warning moves behind a `sync.Once`. The test asserts on the `sync.Once` itself rather than on captured output: the Once *is* the mechanism, and a test that swapped the logger would pass against a version that logged every time through some other path. Verified locally (this fork's CI is red on `main` and gates nothing): `go build ./...`, `go test ./pkg/engine/... -count=1`, `golangci-lint run ./pkg/engine/...` — the only lint finding is the pre-existing import-ordering one on `cmd.go`, byte-identical on `main`.
fix(engine): warn once about a bad allowlist flag, not per tool call
Some checks failed
Request reviewers for Dependabot PRs / request_reviewers (pull_request_target) Has been skipped
smoke / check-label (pull_request_target) Failing after 2s
smoke / gpt-4o-2024-08-06 (pull_request_target) Has been skipped
smoke / gpt-4o-mini-2024-07-18 (pull_request_target) Has been skipped
smoke / claude-3-7-sonnet-20250219 (pull_request_target) Has been skipped
integration / integration (ubuntu-22.04) (pull_request) Failing after 34s
test / test (ubuntu-22.04) (pull_request) Failing after 36s
Validate docs build / validate-docs (pull_request) Failing after 43s
test / test (windows-latest) (pull_request) Has been cancelled
integration / integration (windows-latest) (pull_request) Has been cancelled
8aeb56e41f
strictToolEnv is re-evaluated on every tool invocation — deliberately,
so it stays cheap and testable — and the misconfiguration warning sat
inside it. An operator writing "yes" in a values file would therefore
get a WARN line for every tool call the instance ever makes, flooding
the exact logs they are reading to find out what went wrong.

The decision stays per call; only the warning moves behind a sync.Once.

Found reviewing the bump of this commit into bpai, before anything set
the flag — which is the window worth fixing it in, since enabling it is
the whole point of that bump.
thklein deleted branch fix/flag-warn-once 2026-09-13 09:22:33 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
basepeak-ai/gptscript!10
No description provided.