My gateway config had a one-line convenience: if no billing secret is set, reuse the connect secret. It looked tidy and it always worked. That was the problem. The key for the low-stakes account-linking door quietly also opened the billing door, and no log, test or error would ever have told me. One commit on 2026-10-07 took the fallback out and made the gateway refuse to start when the two keys match.
The Pocket Operator is my AI assistant in Telegram: one shared bot, a separate sandbox per person. Its gateway has two inbound ingest surfaces that other services call. Connect links a person’s account to their sandbox. Billing reports payment events, the part I wired up in Billing that ships switched off. Each door is guarded by its own shared secret in gateway.env: CONNECT_INGEST_SECRET and BILLING_INGEST_SECRET. A caller that knows a secret can talk to that door. That is the whole lock. So the one rule that matters is that the two locks take different keys.
gateway.env in load_settings().
Here is the line, in gateway/pocket_gateway/config.py: billing_ingest_secret = env.get("BILLING_INGEST_SECRET") or env.get("CONNECT_INGEST_SECRET", ""). Read it as: if I forgot to set the billing secret, use the connect secret instead. There was even a test that made sure of it, named billing_secret_defaults_to_connect_secret, asserting that billing came up enabled with nothing but the connect key set. It felt helpful. One fewer thing to configure. But look at what it really says: whoever holds the key to the connect door also holds the key to the billing door. And the moment you would most want a warning, when you forgot a setting, is exactly when the default makes everything work, silently.
- billing_ingest_secret=env.get("BILLING_INGEST_SECRET") or env.get("CONNECT_INGEST_SECRET", ""),+ billing_ingest_secret=billing_secret,or.
The fix has two halves. First, no fallback: if BILLING_INGEST_SECRET is not set, the billing secret is empty and billing_enabled is False. A forgotten setting now turns the door off instead of borrowing someone else’s key. Second, the case a fallback can’t catch: what if I set both, by hand, to the same value? Then the gateway stops at boot with one plain sentence: BILLING_INGEST_SECRET must differ from CONNECT_INGEST_SECRET; refusing to start. Three lines of code, checked before the settings object even exists. A mistake there now costs me one failed start while I am at the keyboard, not a quiet open door I find out about later.
BILLING_INGEST_SECRET must differ from CONNECT_INGEST_SECRET; refusing to start
The fallback was not an accident that slipped past the tests. The tests asserted it. test_billing_secret_defaults_to_connect_secret checked that the billing secret equalled the connect secret and that billing came up enabled. A green suite was guarding the exact behaviour I now think is wrong. The fix rewrote that test to say the opposite (test_billing_secret_does_not_fall_back_to_connect_secret: empty secret, billing off) and added test_billing_secret_equal_to_connect_secret_refuses_start, which expects SystemExit. I have no sign the shared key was ever used against the billing door. That is not comfort, it is the point: nothing in the old setup would have told me if it had been.
The tests that flipped, what each config does before and after, where a mistake gets caught, and the one-line rule I took away. Tap any image to enlarge it and read the exact prompt that drew it.




Convenient defaults are great for things like a port number or a timeout. For a secret they do the opposite of what you want: they turn a missing setting, the one moment you would want a loud warning, into a quiet success. The rule I took from this: a missing secret turns its door off, a reused secret stops the boot. Fail closed at start, while I am watching, not open at 3am, while I am not. If you run an agent with more than one inbound hook, grep your config for or env.get( next to the word SECRET.
The one-line fallback, why it was dangerous, and the gateway refusing to start when the two secrets match.
The pattern from this episode: one secret per inbound door, no fallbacks, and a boot check that refuses to start when two doors share a key, plus the two pytest tests that pin it. Everything in this episode is free and open — clone it, run it, make it yours.
load_settings() pattern: unset secret = feature off
cmd pytest gateway/tests/test_config.py
template the refuse-to-start check: secrets must differ
assets grep recipe: or env.get( next to SECRET
# repo soon. Python 3 + pytest: pytest gateway/tests/test_config.py -k billing_secret
No GitHub? Comment TWOKEYS on the post and the bot DMs you the link.
Next: the pipeline that writes these pages every night now registers each build as staging and runs a 13-check QA gate on it before anything is pushed. The builder grades its own output, and it is allowed to fail.