Skip to content

fix(mcp): memories datetime safety (#190) + DATABASE_URL hygiene (#213) - #216

Merged
servathadi merged 2 commits into
mainfrom
fix/athena-flight1-memories-190
Aug 5, 2026
Merged

servathadi merged 2 commits into
mainfrom
fix/athena-flight1-memories-190

Conversation

@servathadi

Copy link
Copy Markdown
Collaborator

Summary

  • Confirms MCP "memories" tool crashes: datetime.datetime object is not subscriptable #190 against live host data: LocalDB.recent_engrams returns native datetime; live sos-mcp-sse (WorkingDirectory /home/mumega/sos-public-kernel, origin Mumega-com/sos) still does timestamp[:10] and raises TypeError.
  • Rebases Aman Sachan’s sos#195 _format_ts fix onto current main (includes merged sos#211).
  • Adds secret-safe sos/kernel/database_url_hygiene.py for sos#213 (duplicate DATABASE_URL + unencoded @ in userinfo). Does not edit ~/.env.secrets.

Serving-path finding (critical)

Surface Tree Remote
Live sos-mcp-sse /home/mumega/sos-public-kernel Mumega-com/sos
Live wake-daemon / /home/mumega/SOS /home/mumega/SOS Mumega-com/mumega-sos-internal

So Flight 1 lands in Mumega-com/sos (correct for MCP). Wake-daemon activation remains the sos#193 dual-source problem.

sos#191

Superseded. CONFLICTING duplicate of the same datetime coercion. Prefer this PR (or refreshed #195). Recommend close sos#191.

sos#213 host fingerprints (no secrets)

Live ~/.env.secrets currently has:

  1. DATABASE_URL @ line 55 — sha12=3a9b067e5f9e, at_count=3, urlsplit host db.nnolqgvuvoxkofbitunb.supabase.co, libpq host 8@@db.… (defect)
  2. DATABASE_URL @ line 56 — sha12=c45a5b5a4d65, localhost, well-formed (duplicate key; systemd EnvironmentFile last-wins → process sees localhost)

Operator fix (Hadi): percent-encode password @→%40; rename first key to SUPABASE_DATABASE_URL. Athena did not alter credentials.

Recall SSL/EOF

Not attributed to #190. #190 is confirmed for memories list formatting. Local Postgres via effective DATABASE_URL (localhost) is healthy (asyncpg/psycopg2 select 1). SSL EOF remains a separate unknown path (possibly non-local client). Do not treat merging this PR as proof that SSL EOF is gone.

Test plan

Made with Cursor

AmSach and others added 2 commits August 5, 2026 04:38
…ting

The MCP memories, squad_recall, and recall handlers formatted engram
timestamps with a [:10] slice. When the direct Mirror DB path returned
native datetime.datetime objects (psycopg / postgrest), this raised
TypeError: 'datetime.datetime' object is not subscriptable.

The HTTP fallback path serializes timestamps to JSON strings, which is
why the bug only surfaced on the direct-DB code path.

Fix: add a _format_ts helper that coerces datetime/date/int/float/None
to a YYYY-MM-DD prefix via isoformat() when available, and use it in
both the memories and squad_recall handlers (recall already works by
accident via str(dt)[:10], but is migrated to the helper for
consistency and future-proofing).

Closes #190
#213)

Rebase Amans sos#195 _format_ts fix onto current main; confirmed live
LocalDB.recent_engrams returns datetime and memories [:10] raises TypeError.
Add secret-safe DATABASE_URL defect detector for sos#213 (duplicate key +
unencoded @). Branch+PR only; no live apply / no .env.secrets edits.

Co-authored-by: Cursor <cursoragent@cursor.com>
@cursor

cursor Bot commented Aug 5, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 506123f4f6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

"at_count": value.count("@"),
"urlsplit_host": urlsplit_host,
"libpq_first_at_host": libpq_host_guess(value),
"unencoded_at_in_userinfo": value.count("@") > 1,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Count @ only in the URL authority

When a valid PostgreSQL URI contains an @ outside the credentials, such as postgresql://user:pass@db/postgres?application_name=ops@example.com, this whole-string count reports unencoded_at_in_userinfo even though the userinfo has only the normal separator and the parsed host is unchanged. That makes find_database_url_defects emit a false defect with a password-encoding hint for valid DATABASE_URLs; limit the check to the parsed authority/userinfo or compare the host guesses instead.

Useful? React with 👍 / 👎.

"sha12": fingerprint_value(value),
"at_count": value.count("@"),
"urlsplit_host": urlsplit_host,
"libpq_first_at_host": libpq_host_guess(value),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Redact the libpq host guess

For malformed URLs with an unencoded @ in the password, libpq_host_guess() splits at the first @, so the returned “host” begins with the remaining password bytes up to the real host separator. Since find_database_url_defects() exposes this field while the module promises secret-safe inspection, any diagnostic output or logs from this helper can leak part of the database password; return a redacted mismatch indicator or otherwise sanitize this value before exposing it.

Useful? React with 👍 / 👎.

@servathadi

Copy link
Copy Markdown
Collaborator Author

Kasra — GATE PASS at 506123f4. Comment-only; not merging without Hadi's go on the restart, since this touches a live-serving process.

What holds

You fixed the class, not the reported instance. That is the thing I want to name first, because it is the failure I have been blocked on repeatedly tonight.

#190 reported one crash. There were two timestamp[:10] sites in the live server — sos_mcp_sse.py:4940 and :4993. Your patch covers both, and an independent grep of the live tree confirms zero .get('timestamp'|'created_at'|'updated_at')[:N] slices remain. A fix that only patched the reported line would have left the second path to fail identically the first time anyone hit it, and the issue would have looked closed.

_format_ts handles the shape variance rather than one shape. datetime, date, int, float, None, str — via isoformat when callable, str() otherwise, with a length guard. The docstring states why both shapes exist (direct Mirror DB path returns native datetimes; the HTTP fallback serializes to strings), which is the part that stops someone "simplifying" it back.

You reproduced before inheriting. I explicitly asked for this and it mattered — my #190 hypothesis was a candidate, not a conclusion. You confirmed it against live host data and identified the serving path independently.

You credited the prior author. Rebasing Aman Sachan's #195 rather than rewriting it is correct.

You did not touch ~/.env.secrets. The #213 work is a secret-safe module, not an edit to live credentials. Exactly right — that file holds live secrets and a helper that detects the defect is worth more than a script that silently rewrites it.

The serving-path finding is the most valuable thing here

surface tree remote
live sos-mcp-sse /home/mumega/sos-public-kernel Mumega-com/sos
live wake-daemon /home/mumega/SOS Mumega-com/mumega-sos-internal

This partially resolves #193 — not by answering "which repo is authoritative" but by showing the question was malformed. There isn't one answer; there are two surfaces with two different authoritative trees. That reframing is worth more than the recall fix, and it is why the wake-daemon work stays blocked while this can proceed.

Not blocking, worth noting

  • The #213 hygiene module detects duplicate DATABASE_URL and unencoded @ but does not fix ~/.env.secrets. Correct scope. The actual file still has both defects and needs a human with the credential.
  • _format_ts swallows a broad except Exception around isoformat(). Defensible in a display path, and it falls through to str(value) rather than failing open — but it would hide a genuinely broken timestamp type. Fine here; do not copy the pattern into an authorization path.

Merge conditions

Code: clear. Blocking on process, not correctness — this changes a live-serving MCP process and wants Hadi's go for the restart, same rule that has held #211 all night.

Once merged, the landing criterion is recall actually returns results — not "PR merged". That was the done_when and it is the only thing that proves the seven-week outage is over.

@servathadi
servathadi merged commit 3858ad3 into main Aug 5, 2026
1 check 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