Skip to content

Config: read safety flags strictly and normalize blocked_operations and the numeric limits - #149

Merged
kLOsk merged 1 commit into
kLOsk:mainfrom
HeyImBG:fix/config-safety-types
Dec 4, 2026
Merged

kLOsk merged 1 commit into
kLOsk:mainfrom
HeyImBG:fix/config-safety-types

Conversation

@HeyImBG

@HeyImBG HeyImBG commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

What was broken
load_config passed the safety: values through untouched:

  • allow_chat_approval: "false" (quoted) stayed the string "false", which is truthy, so it switched chat approval on (safety/approval.py). two_phase_apply and require_dry_run had the same problem. _flag already exists for the GTM and views switches for this reason.
  • blocked_operations: update_campaign (a bare name) was kept as a string, so check_blocked_operation did a substring match ("update" counted as blocked); an empty blocked_operations: became None and raised TypeError.
  • max_daily_budget: "20" raised TypeError: '>' not supported between 'float' and 'str' on the first budget check.

What changed (src/adloop/config.py)

  • _safety_flag: real bool as is; true/yes/on/1 and false/no/off/0 as text; missing or blank gives the default; any other value keeps the stricter setting (chat approval off, two-phase apply on, dry run on).
  • _number: converts text to a number (whole numbers stay ints, so the bid message reads "50%"); an unusable value, NaN or infinity (text "nan", "inf", "1e400" or YAML .nan/.inf) raises ValueError: safety.<key> must be a finite number, got .... NaN is refused because budget > nan is always False and would switch the cap off.
  • _operations: a bare name becomes a one-item list; blank or None becomes [].

Behaviour notes

  • require_dry_run: "false" is now False. It follows the user's explicit setting; before, the text was truthy and was ignored.
  • two_phase_apply defaults to False, so a missing value is unchanged; only an unrecognized value now means on. The approval.py readers (lines 151, 176, 654, 660) get a real bool.

Tests
New tests/test_config_safety_types.py. pytest tests: 2739 passed, 2 skipped (run with PYTHONPATH pointing at this checkout's src). No ruff config or lint command in the repo; none run.

AI disclosure
Found, written and tested with Claude Code; I'm responsible for it.

…umeric limits

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A3CSuaJkYYX2HyAsaXbLGH
@kLOsk
kLOsk merged commit 9b3dcf2 into kLOsk:main Dec 4, 2026
3 checks passed
kLOsk added a commit that referenced this pull request Dec 4, 2026
Follow-up to #149. blocked_operations given as text with commas or
spaces between the names (update_campaign, remove_entity) was kept as
one name and blocked nothing; before #149 it blocked by the substring
accident. Such text is split into names now, nested lists are
flattened, and a value that is not a name or a list of names (true, 5)
is refused with the setting's name instead of a TypeError.

A blank section (safety: with nothing below it) reads as empty instead
of crashing the load, and a section that is not a mapping is refused by
name.

A confirmation dialog can be answered for an hour instead of the SDK's
ten minutes. A later answer came back as a bare "Invalid or expired
requestState", which is what someone who stepped away from the screen
got.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Jr3T22aqqRobKScfCwiyfY
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.

2 participants