Skip to content

fix: five behaviour fixes (allowlists, MEMORY.md guard, link summaries, WhatsApp shutdown, .env docs) - #24

Merged
emanuilo merged 5 commits into
mainfrom
fix/behavior
Nov 24, 2026
Merged

emanuilo merged 5 commits into
mainfrom
fix/behavior

Conversation

@emanuilo

Copy link
Copy Markdown
Owner

Summary

Five behaviour fixes kept out of the code-shape refactor, one commit each.

 access (bot/inbound.is_allowed, slack._check_channel)
-  Slack: empty SLACK_ALLOWED_USERS → everyone; Telegram: empty → nobody, banner "allowed users: all"
+  empty user allowlist → nobody, on every platform; startup warning names the env var
+  Slack: empty SLACK_ALLOWED_CHANNELS → any channel the allowed users write in (DMs work)

 Consolidator._replace_memory
+  refuse a reply that doesn't start with "# Personal Memory" and contain "## Index"
+  → warning with 80-char preview, raise (same 1-hour retry as a failed call)

 links.summarize
-  return "Could not summarize: {e}"   → agent saw it as the page summary
+  log warning, return None            → no summary block (same as an unfetchable page)

 whatsapp shutdown
-  partial sync close(), backend never aclose()d
+  run_until_stopped(): full async shutdown, shared with Slack

 docs/configuration.md
-  "a .env in the current folder is read"
+  real order: shell > .env found upward from the package > ~/.memclaw/.env

Evidence

Each fix started with a failing test.

  • Allowlist — Before: test_slack_empty_allowlist_lets_everyone_in (parity). After: test_slack_empty_allowlist_blocks_everyone, test_slack_empty_channel_list_means_any_channel (allowed user in from a DM, stranger ignored), banner/warning tests for Telegram and four Slack list combinations.
  • MEMORY.md — Before: "API Error: Connection refused" written over MEMORY.md. After: error text, Cursor's placeholder, empty, cut-off and text-before-title replies all refused; MEMORY.md, .history/ and meta.json untouched; a valid reply is still written.
  • Link summary: new parity case test_link_that_cannot_be_summarized_adds_nothing on Telegram, Slack and WhatsApp.
  • WhatsApp: a real Ctrl+C signal to the running bot and a normal disconnect both run shutdown exactly once (failed before the fix).
  • pytest: 620 passed, 20 skipped (was 603); every commit checked individually (pytest, ruff, code-shape check); baseline still empty.

Merge Danger

Door: two-way

Blast Radius: Slack users, consolidation

  • Slack: anyone running with an empty SLACK_ALLOWED_USERS (which used to mean everyone) is now locked out until they list users. README calls it out; the bot warns at start.
  • Consolidation: the prompt now always requires ## Index ("even when there is nothing to index yet"), which the new guard relies on. A bad reply makes memclaw consolidate exit with an error, like a failed call.
  • Library: the unused close() methods on the inbound pipeline and Telegram bot were removed.

🤖 Generated with Claude Code

On Slack an empty SLACK_ALLOWED_USERS let everyone in, while on Telegram
an empty ALLOWED_USER_IDS let nobody in, and Telegram's start banner
still said "allowed users: all".

Who may use the bot is now deny-by-default everywhere: is_allowed() only
lets in who is on the list, and the Slack wizard asks for
SLACK_ALLOWED_USERS as required. SLACK_ALLOWED_CHANNELS stays optional:
empty means any channel the allowed users write in (DMs included), a
list still restricts to those channels. At start each platform prints
its allowlists and warns, naming the env var, when the user list is
empty. WhatsApp keeps its self-chat rule.
A backend can return error text instead of raising ("API Error:
Connection refused", Cursor's "I couldn't generate a response."), or a
reply can be empty or cut off. Consolidation wrote any of these over
MEMORY.md, replacing the user's whole profile.

Consolidator._replace_memory, the only MEMORY.md writer, now checks the
reply has what the prompt requires (starts with "# Personal Memory", has
"## Index"; the prompt now asks for the index heading even when empty).
Anything else logs a warning with a short preview and raises, like a
failed backend call: MEMORY.md, .history/ and meta.json are untouched and
the background run waits an hour instead of paying for a new call after
every reply. An empty reply, which used to return False, takes this path.
LinkProcessor.summarize returned "Could not summarize: <error>" when the
OpenAI call failed, and the pipeline handed that to the agent as
"[Link summary] <url>: Could not summarize: ... Save it if the content is
worth remembering."

It now logs the failure and returns None, the same as for a page that
couldn't be fetched, so that link gets no summary block. The parity tests
pin this on Telegram, Slack and WhatsApp.
Telegram and Slack run the async shutdown (consolidation, the backend's
aclose, reminders) when they stop; WhatsApp only called the sync close(),
so the AI backend was never shut down.

Slack and WhatsApp now both stop through run_until_stopped() in
memclaw.bot: run the bot until it returns or Ctrl+C, then always await its
aclose(). WhatsAppBot gets aclose() in place of close(); the sync
Inbound.close() / TelegramBot.close() had no callers left and are gone.
docs/configuration.md said a .env in the current directory is picked up.
It isn't: load_dotenv() in memclaw/config.py uses python-dotenv's
find_dotenv(), which searches upward from the installed memclaw package's
folder (the current folder only in a REPL or debugger). Describe the real
order instead: shell environment, then that .env, then ~/.memclaw/.env.
@emanuilo
emanuilo merged commit d1d8d26 into main Nov 24, 2026
5 checks passed
@emanuilo
emanuilo deleted the fix/behavior branch November 24, 2026 09:53
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