feat(hygiene 2/5): Graphiti context-memory sink (supersedes PR #2)#7
Conversation
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.
|
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. |
|
Remediation pass:
|
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>
|
Follow-up fix (cd3bebd): SonarCloud's Quality Gate still failed after the prior fix ( |
|



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 amverified);graphiti_sink.pycompiles.🤖 Generated with Claude Code
https://claude.ai/code/session_01Rr6wpk9eehnJdRmh5BwWGG
Generated by Claude Code