molecule-core/workspace-template/builtin_tools
rabbitblood 48eca7264c fix(memory-tools): #215-class — auth_headers on commit_memory + search_memory HTTP fallback
Context: platform now gates `GET /workspaces/:id/memories` and
`POST /workspaces/:id/memories` behind workspace auth (post-#166 /
#167 AdminAuth wave). The `builtin_tools.memory` tool had three HTTP
call sites:

  1. commit_memory POST fallback (line 121)        ← NO auth_headers
  2. search_memory GET fallback (line 269)         ← NO auth_headers
  3. activity-log helper POST (line 371)           ← HAS auth_headers

Path 3 was already fixed. Paths 1 + 2 silently 401 every call, but the
tool's error-handling path returns `{"success": False}` without surfacing
the auth failure to the agent. Result: the agent sees an empty memory
backlog on every call and assumes there's nothing to do.

## Discovered today

Technical Researcher is the first workspace opted in to the idle-loop
pilot from #216 (reflection-on-completion pattern). The pilot fires
every 10 min, the agent calls `search_memory "research-backlog:..."` as
the first step, gets back an empty result, writes "tr-idle clean" to
memory, and stops. Clean-idle outcome every tick, 9 consecutive ticks.

Looking at TR's activity_logs response bodies:

    "Memory auth has failed on every tick this session — skipping the call"
    "tr-idle — step 2 done. Memory unavailable (auth token missing..."
    "tr-idle 04:15 — clean (memory auth still down, 3rd consecutive tick)"

The AGENT knew the memory calls were failing. The platform 401 error
was surfacing in the tool response, but our instrumentation wasn't
counting it as a defect — we saw "tr-idle clean" writes and assumed
the pilot was working as designed. It was actually silently broken.

## Fix

Import `platform_auth.auth_headers` lazily (same pattern as the
activity-log path already uses), attach `headers=_auth()` to both
httpx call sites. Matches the #225 fix for the register call.

## Not in this PR

- awareness_client.py also makes HTTP calls to a separate AWARENESS_URL
  service (not the platform), which may or may not need the same fix
  depending on that service's auth posture. Out of scope for this PR.

- TR's specific token problem: TR's `/configs/.auth_token` file is
  empty because it was re-provisioned via `apply_template: true`
  (recovery path from the failed-volume incident) and Phase 30.1
  only mints a token on FIRST register per workspace. This fix
  doesn't help TR until TR gets a fresh token — tracked separately.

## Test plan

- [x] Python syntax check on memory.py passes
- [ ] CI: all memory-related tests should still pass (the new code
      paths only add header passing, no shape change)
- [ ] Real-world verification: after TR gets a fresh token, idle-loop
      pilot should produce a dispatch within 10 min (seeded backlog
      already in place from this session)

## Related
- #215 / #225 — register call auth_headers fix (same pattern)
- #216 — TR idle-loop pilot (couldn't measure until this lands)
- #166 / #167 — platform AdminAuth wave that surfaced this gap
2026-04-15 17:26:26 -07:00
..
__init__.py initial commit — Molecule AI platform 2026-04-13 11:55:37 -07:00
a2a_tools.py initial commit — Molecule AI platform 2026-04-13 11:55:37 -07:00
approval.py initial commit — Molecule AI platform 2026-04-13 11:55:37 -07:00
audit.py initial commit — Molecule AI platform 2026-04-13 11:55:37 -07:00
awareness_client.py initial commit — Molecule AI platform 2026-04-13 11:55:37 -07:00
compliance.py fix(security): H3 github_pat_ redaction + M4 atomic token write (audit cycle 10) 2026-04-14 09:34:27 +00:00
delegation.py initial commit — Molecule AI platform 2026-04-13 11:55:37 -07:00
governance.py initial commit — Molecule AI platform 2026-04-13 11:55:37 -07:00
hitl.py initial commit — Molecule AI platform 2026-04-13 11:55:37 -07:00
medo.py initial commit — Molecule AI platform 2026-04-13 11:55:37 -07:00
memory.py fix(memory-tools): #215-class — auth_headers on commit_memory + search_memory HTTP fallback 2026-04-15 17:26:26 -07:00
sandbox.py initial commit — Molecule AI platform 2026-04-13 11:55:37 -07:00
security_scan.py initial commit — Molecule AI platform 2026-04-13 11:55:37 -07:00
telemetry.py initial commit — Molecule AI platform 2026-04-13 11:55:37 -07:00
temporal_workflow.py initial commit — Molecule AI platform 2026-04-13 11:55:37 -07:00