Skip to content

feat(hygiene 2/5): Graphiti context-memory sink (supersedes PR #2)#7

Merged
cryptoxdog merged 4 commits into
mainfrom
claude/hygiene-2-graphiti-memory
Jul 20, 2026
Merged

feat(hygiene 2/5): Graphiti context-memory sink (supersedes PR #2)#7
cryptoxdog merged 4 commits into
mainfrom
claude/hygiene-2-graphiti-memory

Conversation

@cryptoxdog

Copy link
Copy Markdown
Collaborator

Part 2 of 5 — scoped split of the Cursor-Governance Hygiene Commit Pack.

What

Adds intelligence/context-memory/graphiti_sink.py + show_context_graphiti.py (Graphiti episode emitter + graph context viewer), plus the review-comment fixes (sys.executable, returncode check, defensive key access, UTF-8, stderr surfacing).

Collision resolution — supersedes PR #2

This is the content of open PR #2 with the review fixes folded in. PR #2 should be closed as superseded by this PR (do not merge both — same files). A superseded comment has been posted on PR #2.

Split context

1 of 5 independent, disjoint PRs — any merge order. Applies cleanly on main (git am verified); graphiti_sink.py compiles.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Rr6wpk9eehnJdRmh5BwWGG


Generated by Claude Code

cryptoxdog added 2 commits July 5, 2026 04:15
Patches context-memory to feed Graphiti episodes via graphiti_sink.py and adds
show_context_graphiti.py for querying the graph directly. JSON session storage
kept as local cache; Graphiti becomes the durable substrate.

- add intelligence/context-memory/graphiti_sink.py (emit_session to graph)
- add intelligence/context-memory/show_context_graphiti.py (query graph context)
…ck, defensive key access, UTF-8 encoding, stderr surfacing

Fixes:
- Use sys.executable instead of hard-coded 'python' (interpreter consistency)
- Check proc.returncode before parsing stdout (silent failure prevention)
- Defensive .get() on fact items instead of f['fact'] (KeyError prevention)
- Explicit encoding='utf-8' on JSON cache write (cross-platform determinism)
- Surface stderr in return dict when MCP call fails (debuggability)
- Proper fallback messaging when graph is empty or unavailable
SonarCloud pythonsecurity:S8705 flagged unvalidated CLI input (task_type,
ultimately from sys.argv[1]) flowing into a subprocess.run argument list.
No shell=True is used so this isn't a classic shell-injection, but add
defense-in-depth validation (type/length/control-char checks) before the
value reaches the OS command, per the gate's requirement.
@cursor

cursor Bot commented Jul 20, 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.

@cryptoxdog

Copy link
Copy Markdown
Collaborator Author

Remediation pass:

  • Fixed SonarCloud pythonsecurity:S8705 in show_context_graphiti.pytask_type (ultimately from sys.argv[1]) now goes through _validate_task_type() (type/length/control-char checks) before reaching the subprocess.run([...]) argument list (5f5c23b). No inline review comments were open on this PR.

SonarCloud pythonsecurity:S8705 still flagged line 43 (subprocess.run)
after the prior fix -- the denylist-based _validate_task_type() helper
sanitizes correctly at runtime, but SAST taint tracking generally only
recognizes sanitization it can see directly at/near the sink, not
arbitrary custom functions across a call boundary.

Replaced with an inline allow-list regex (fullmatch) checked directly in
restore() immediately before the subprocess.run() call -- the pattern
taint-tracking tools reliably recognize as clearing tainted input. Same
security properties (rejects control/null bytes, empty input, oversized
input, and now also non-allow-listed punctuation), same 500-char cap.

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

Copy link
Copy Markdown
Collaborator Author

Follow-up fix (cd3bebd): SonarCloud's Quality Gate still failed after the prior fix (_validate_task_type() helper) — its taint tracker doesn't recognize sanitization happening in a separate function across a call boundary, only patterns visible directly at/near the sink. Replaced with an inline allow-list fullmatch regex checked directly in restore() immediately before subprocess.run() — same security properties (rejects control/null bytes, empty/oversized input) plus a tighter allow-listed character set, in the exact shape SAST taint engines reliably recognize as taint-clearing.

@sonarqubecloud

Copy link
Copy Markdown

@cryptoxdog
cryptoxdog merged commit 91bb4f6 into main Jul 20, 2026
2 checks passed
@cryptoxdog
cryptoxdog deleted the claude/hygiene-2-graphiti-memory branch July 20, 2026 02:28
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