Skip to content

refactor(identity): shared deriveScopeKey β€” P4/G3 graphiti-memory (REBUILT) - #36

Merged
supmo668 merged 1 commit into
mainfrom
graphiti-p4-deriveScopeKey-land
Jun 23, 2026
Merged

supmo668 merged 1 commit into
mainfrom
graphiti-p4-deriveScopeKey-land

Conversation

@supmo668

@supmo668 supmo668 commented Jun 23, 2026 •

Copy link
Copy Markdown

P4 / G3 β€” shared deriveScopeKey (REBUILT on a durable ref)

Extract the canonical memory-partition rule (external_id ?? id) into a single source of truth β€” new extensions/shared/scope-key.ts (deriveScopeKey). Both writers now import it instead of computing it independently:

  • auth-memory-gate/src/scope.ts β€” the [MEMORY_SCOPE].scope_key it injects
  • memory-graphiti/identity.ts β€” resolveIdentityScopeKey, the identity-strategy groupId

Behavior-preserving consolidation: the partition key and the identity scope key can no longer drift. Adds scope-key.test.ts (3 tests) pinning the precedence.

Reframe (the original premise was infeasible)

The literal G3 plan β€” memory-graphiti reads auth-memory-gate's emitted [MEMORY_SCOPE] block β€” is infeasible: the before_agent_start hook chain runs hooks in parallel and only merges each hook's prependContext, so the block is never visible to memory-graphiti. A shared resolver is the correct way to share the contract.

Out of scope

The user_id-vs-external_id precedence (SJ #9–#11) is explicitly out of scope β€” this preserves today's behavior. When precedence is settled later it becomes a single-function change in scope-key.ts.

Rebuild note

P4 was QG-passed locally but LOST β€” the prior QGR ran against an uncommitted working tree, never committed/pushed, wiped by a submodule reset to clean P3 (main@f6b086723). This PR rebuilds it on a durable ref: committed + pushed before the receipt was minted.

Gates

  • oxfmt clean Β· tsgo 0 Β· extensions suite 204p/13skip Β· sealed 38/38
  • QGR receipt d65a0dd (diff-base origin/main = f6b086723), receipt-verify βœ“

Base: main (f6b086723). Independent of P5/P6 (no file overlap). Land order: P4 β†’ P5 β†’ P6.

πŸ€– Generated with Claude Code

Summary by CodeRabbit

  • Tests

    • Added test coverage for identity scope key derivation logic.
  • Refactor

    • Consolidated identity scope key derivation into a shared utility, ensuring consistent behavior across the system.

…veScopeKey (P4/G3 graphiti-memory)

Extract the canonical memory-partition rule (external_id ?? id) into a single
source of truth: extensions/shared/scope-key.ts (deriveScopeKey). Both writers
now import it instead of computing it independently:
  - auth-memory-gate scope.ts (the [MEMORY_SCOPE].scope_key it injects)
  - memory-graphiti identity.ts (resolveIdentityScopeKey, the identity groupId)

Behavior-preserving consolidation β€” the partition key and the identity scope
key can no longer drift. Adds scope-key.test.ts (3 tests) pinning the precedence.

REFRAME: the literal G3 plan (memory-graphiti parses auth-memory-gate's emitted
[MEMORY_SCOPE] block) is INFEASIBLE β€” the before_agent_start hook chain runs
hooks in PARALLEL and only merges each hook's prependContext, so the block is
never visible to memory-graphiti. A shared resolver is the correct way to share
the contract. The user_id-vs-external_id PRECEDENCE (SJ #9–#11) is OUT OF SCOPE
here β€” this preserves today's behavior; when precedence is settled it becomes a
single-function change in scope-key.ts.

Gates: oxfmt clean, tsgo 0, extensions 204p/13skip, sealed 38/38.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@github-actions

Copy link
Copy Markdown

⚠️ Formal models conformance drift detected

The formal models extracted constants (generated/*) do not match this openclaw PR.

This check is informational (not blocking merges yet).
See the formal-models-conformance-drift artifact for the diff.

If this change is intentional, follow up by updating the formal models repo or regenerating the extracted artifacts there.

@coderabbitai

coderabbitai Bot commented Jun 23, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. πŸŽ‰

ℹ️ Recent review info
βš™οΈ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c1123f0a-9226-483f-93f9-9156315470fb

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between f6b0867 and 648ceda.

πŸ“’ Files selected for processing (4)
  • extensions/auth-memory-gate/src/scope.ts
  • extensions/memory-graphiti/identity.ts
  • extensions/shared/scope-key.test.ts
  • extensions/shared/scope-key.ts

πŸ“ Walkthrough

Walkthrough

A new shared module extensions/shared/scope-key.ts introduces ScopeKeyIdentity and deriveScopeKey, which selects external_id when present and falls back to id. Two extensions (auth-memory-gate and memory-graphiti) replace their independent inline external_id ?? id expressions with calls to this helper. A Vitest suite covers the three key scenarios.

Changes

Shared scope-key extraction and adoption

Layer / File(s) Summary
Shared ScopeKeyIdentity type and deriveScopeKey helper
extensions/shared/scope-key.ts, extensions/shared/scope-key.test.ts
New shared module exports ScopeKeyIdentity and deriveScopeKey, which returns external_id when non-null, otherwise id. Vitest suite asserts external_id precedence, null fallback, and extra-field passthrough.
Callsite migration in auth-memory-gate and memory-graphiti
extensions/auth-memory-gate/src/scope.ts, extensions/memory-graphiti/identity.ts
Replaces inline external_id ?? id fallback in resolveScope and resolveIdentityScopeKey with deriveScopeKey(identity), adding the corresponding imports in both files.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

πŸ‡ A key was computed in two separate spots,
Drifting apart, connecting the dots β€”
Now one shared helper does all the work,
No inline fallback with logic to lurk.
The bunny hops on, with one source of truth! 🌿

πŸš₯ Pre-merge checks | βœ… 5
βœ… Passed checks (5 passed)
Check name Status Explanation
Title check βœ… Passed The title accurately summarizes the main change: extracting the scope key derivation rule into a shared function across the auth-memory-gate and memory-graphiti extensions.
Description check βœ… Passed The description provides comprehensive context including problem statement, architectural rationale, scope boundaries, and verification gates, though it omits some template sections like explicit change type selection and security impact checklist.
Docstring Coverage βœ… Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check βœ… Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check βœ… Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
πŸ“ Generate docstrings
  • Create stacked PR
  • Commit on current branch
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch graphiti-p4-deriveScopeKey-land

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands.

@supmo668
supmo668 merged commit cece3c2 into main Jun 23, 2026
7 of 12 checks passed
@supmo668
supmo668 deleted the graphiti-p4-deriveScopeKey-land branch June 23, 2026 12:41
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