Skip to content

Opt-in outbound history append endpoint (hardened version of #10) - #11

Merged
mneuronico merged 2 commits into
mainfrom
history-append-fixes
Sep 28, 2026
Merged

mneuronico merged 2 commits into
mainfrom
history-append-fixes

Conversation

@mneuronico

Copy link
Copy Markdown
Owner

Builds on #10 by @jmcafferata (its commit is included unchanged) and hardens it before merging.

What it adds

POST /history/outgoing lets a service that sends WhatsApp/Telegram messages outside the bot (bulk templates, reminders, auto-replies) record them in the user's MAWS history, so the agent has that context when the user answers. Requests are authenticated with a timestamped HMAC-SHA256 (MAWS_HISTORY_WRITE_SECRET) and deduplicated by event_id.

Changes on top of #10

  • Opt-in, zero impact when off. The runtime only routes the endpoint and only handles append_history jobs when MAWS_HISTORY_APPEND_ENABLED=true; bootstrap only deploys the route when history_append.enabled is set in params.json. Previously the route was added to every generated template.
  • Appends are never dropped. With busy_policy=drop, a busy user lock used to silently discard the append after the caller got a 202. Appends now wait for the lock (MAWS_HISTORY_APPEND_LOCK_WAIT_SECONDS, default 60) and otherwise raise so Lambda async retries / SQS retry. Webhook jobs keep the existing drop behavior.
  • The agent sees the message as its own turn. Messages are attributed to the answering agent (history_append.role / MAWS_HISTORY_APPEND_ROLE, the bot's component_name, or the only agent) with msg_type="agent", instead of role="assistant", which MAS showed as a user turn and which agents with positive_filter skipped.
  • FIFO enqueue failures return 502; README documents setup, chat_id/event_id guidance and the shared-history caveat.

Verification

  • mas/ is untouched; pre-existing tests are unchanged and pass (146 passed, 1 skipped; CI green on 3.9-3.12).
  • Differential run of 14 event scenarios (webhooks, GET verify, workers, busy locks, legacy invocations, SQS, requests to /history/outgoing with only the secret set) through main's and this branch's runtime with the feature off: identical responses and side effects. A control run with the feature on differs only in the 5 endpoint scenarios.
  • Generated SAM template is byte-identical to main in 16 param combinations when disabled; enabled adds only the two env vars and the route.
  • New tests cover disabled isolation, stale timestamps, FIFO, lock waits/retries, author resolution and a real AgentSystemManager conversation check.
  • Not yet exercised on a real AWS deployment.

🤖 Generated with Claude Code

jmcafferata and others added 2 commits September 28, 2026 11:46
- Gate /history/outgoing behind MAWS_HISTORY_APPEND_ENABLED (default off) in
  the runtime and behind history_append.enabled in bootstrap, so bots that do
  not opt in keep byte-identical request/worker paths and SAM templates.
- Never drop an append because the user lock is busy: wait for the lock,
  then raise so Lambda async retries or SQS try again (the caller already
  got a 202). Webhook jobs keep the existing drop behavior.
- Attribute appended messages to the answering agent (MAWS_HISTORY_APPEND_ROLE,
  bot component_name, or the only agent) with msg_type "agent", so MAS shows
  them as the agent's own turn and name/type filters include them.
- Return 502 instead of raising when the FIFO enqueue fails.
- Document the opt-in, chat_id/event_id guidance and shared-history caveat.
- Add tests for disabled isolation, stale timestamps, FIFO, lock waits and
  retries, author resolution, and a real-manager conversation check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mneuronico
mneuronico merged commit 9bff879 into main Sep 28, 2026
8 checks passed
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