Skip to content

fix(gateway): scope session data lookups by agent [AI] - #81386

Merged
pgondhi987 merged 39 commits into
openclaw:mainfrom
pgondhi987:fix/fix-642
May 16, 2026
Merged

pgondhi987 merged 39 commits into
openclaw:mainfrom
pgondhi987:fix/fix-642

Conversation

@pgondhi987

Copy link
Copy Markdown
Contributor

Summary

  • Problem: Several Gateway and memory query paths loaded combined session stores without carrying an agent scope.
  • Why it matters: Request-scoped APIs could do broader session, artifact, memory, and usage discovery than intended.
  • What changed: Threaded agentId through run lookup, artifact, abort, usage, memory search, and wiki search/read paths; defaulted affected gateway-style reads to the effective/default agent when no agent is supplied.
  • What did NOT change (scope boundary): No auth model, token format, network behavior, or provider/runtime execution behavior changed.
  • AI-assisted: Yes.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

  • Related: maintainer-provided private report
  • This PR fixes a bug or regression

Real behavior proof (required for external PRs)

  • Behavior or issue addressed: Agent-scoped Gateway and memory APIs should not perform broad configured-agent session store discovery when a narrower scope is available.
  • Real environment tested: Not run in this automation pass.
  • Exact steps or command run after this patch: Not run in this automation pass.
  • Evidence after fix (screenshot, recording, terminal capture, console output, redacted runtime log, linked artifact, or copied live output): Not available.
  • Observed result after fix: Covered by added/updated focused regression tests in the changed files.
  • What was not tested: Live Gateway with multiple configured agents.
  • Before evidence (optional but encouraged): N/A

Root Cause (if applicable)

  • Root cause: Multiple code paths called combined session store loading without passing an agent scope, so default discovery could include more agent stores than the request path needed.
  • Missing detection / guardrail: Tests did not assert that run lookup, usage listing, memory transcript visibility, and wiki gateway calls passed an agent-scoped store load.
  • Contributing context (if known): The shared loader intentionally supports broad discovery when no agent scope is provided, but these paths needed request-scoped behavior.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: src/gateway/server-session-key.test.ts, src/gateway/server-methods/artifacts.test.ts, src/gateway/server-methods/usage.sessions-usage.test.ts, extensions/memory-core/src/session-search-visibility.test.ts, extensions/memory-wiki/src/query.test.ts, extensions/memory-wiki/src/gateway.test.ts
  • Scenario the test should lock in: Affected calls carry agent scope into session store lookup and do not retain out-of-scope session transcript hits.
  • Why this is the smallest reliable guardrail: These tests exercise the exact seams where store scope is selected without requiring a full Gateway runtime.
  • Existing test that already covers this (if any): Existing tests covered general behavior but not agent-scoped store loading.
  • If no new test is added, why not: N/A

User-visible / Behavior Changes

Gateway usage, artifact, wiki, and memory transcript queries without an explicit agentId now operate within the effective/default agent scope instead of broad configured-agent discovery.

Diagram (if applicable)

Before:
[RPC/tool request] -> [combined session store load without agent scope] -> [broad store discovery]

After:
[RPC/tool request] -> [resolve/pass agent scope] -> [agent-scoped store discovery] -> [scoped result]

Security Impact (required)

  • New permissions/capabilities? (Yes/No) No
  • Secrets/tokens handling changed? (Yes/No) No
  • New/changed network calls? (Yes/No) No
  • Command/tool execution surface changed? (Yes/No) No
  • Data access scope changed? (Yes/No) Yes
  • If any Yes, explain risk + mitigation: Data access is narrowed by threading agent scope through affected session, artifact, usage, memory, and wiki lookup paths. This is intended hardening and does not add new access.

Repro + Verification

Environment

  • OS: Not run in this automation pass
  • Runtime/container: Not run in this automation pass
  • Model/provider: N/A
  • Integration/channel (if any): Gateway, memory-core, memory-wiki
  • Relevant config (redacted): Multiple configured agents with templated session stores

Steps

  1. Configure at least two agents with separate session stores.
  2. Query affected Gateway or memory paths with a run/session/memory lookup from one agent context.
  3. Confirm only the effective/requested agent scope is searched.

Expected

  • Affected APIs load session stores with an agent scope and return only scoped results.

Actual

  • Not run in this automation pass.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios: Code inspection of all changed call paths and added/updated regression coverage.
  • Edge cases checked: Run lookup cache scoping, artifact run queries, usage default/requested agent behavior, memory transcript stem filtering, wiki gateway default agent propagation.
  • What you did not verify: Local test execution, CI, and live multi-agent Gateway behavior.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for maintainers.

Compatibility / Migration

  • Backward compatible? (Yes/No) Yes
  • Config/env changes? (Yes/No) No
  • Migration needed? (Yes/No) No
  • If yes, exact upgrade steps: N/A

Risks and Mitigations

  • Risk: Consumers that relied on broad default usage or memory/session discovery may see narrower results unless they pass an explicit agent scope.
    • Mitigation: The affected schemas and SDK artifact query type now accept agentId, and default behavior follows the effective/default agent scope.

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime extensions: memory-core Extension: memory-core extensions: memory-wiki size: M maintainer Maintainer-authored PR labels May 13, 2026
@clawsweeper

clawsweeper Bot commented May 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

Summary
Threads optional agentId through Gateway session lookup, artifact, abort, usage, memory-core, and memory-wiki paths, updates protocol/SDK/Swift types, and adds focused regression tests.

Reproducibility: yes. from source inspection: current main has run lookup, usage, memory-core, and memory-wiki paths calling combined session-store loading without carrying an agent scope. I did not establish a live multi-agent Gateway reproduction in this read-only review.

Real behavior proof
Needs real behavior proof before merge: Missing: the PR body states no real environment, command, or after-fix evidence was run; the contributor should add redacted terminal/log output, screenshot, recording, or linked artifact and update the PR body for re-review, or ask a maintainer for @clawsweeper re-review.

Next step before merge
Protected data-scope PR with missing contributor real-behavior proof; maintainers need to review and approve after proof is supplied.

Security
Cleared: The diff narrows session and memory data lookup scope and does not add dependencies, CI changes, secret handling, token-format changes, or new network execution.

Review details

Best possible solution:

Land a maintainer-approved version that scopes no-agent Gateway and memory reads to the effective/default agent, keeps protocol and SDK contracts aligned, and includes focused regression tests plus redacted multi-agent proof.

Do we have a high-confidence way to reproduce the issue?

Yes from source inspection: current main has run lookup, usage, memory-core, and memory-wiki paths calling combined session-store loading without carrying an agent scope. I did not establish a live multi-agent Gateway reproduction in this read-only review.

Is this the best way to solve the issue?

Yes for the code direction: carrying the effective or requested agent scope into the existing loader and call sites is the narrow maintainable fix. It is not merge-ready until the external PR supplies real behavior proof and a maintainer approves the protected data-scope change.

What I checked:

  • Protected PR state: Provided PR context shows this PR is open at head 1709263 with labels including maintainer, gateway, extensions: memory-core, extensions: memory-wiki, and P1; protected labels prevent cleanup auto-close. (1709263a51d1)
  • Missing real behavior proof: The PR body says no real environment or exact command was run after the patch, evidence after fix is not available, and live Gateway with multiple configured agents was not tested. (1709263a51d1)
  • Current main run lookup is unscoped: Current main resolves run ids by loading the combined Gateway session store without an agent scope before matching sessionId. (src/gateway/server-session-key.ts:53, e71d10fd4d74)
  • Current main usage lookup is unscoped: Current main sessions.usage loads the combined session store without passing an agentId, then builds usage entries from that store. (src/gateway/server-methods/usage.ts:834, e71d10fd4d74)
  • Current main memory visibility is unscoped: Current main memory-core session visibility loads the combined session store without a scoped agent and only applies the guard when a requester session key exists. (extensions/memory-core/src/session-search-visibility.ts:34, e71d10fd4d74)
  • PR scopes central lookups: The PR diff adds agentId to protocol/query types and passes an effective/requested agent id into run lookup, artifact, abort, usage, memory-core, and memory-wiki paths. (src/gateway/server-session-key.ts:67, 1709263a51d1)

Likely related people:

  • steipete: Current blame and log history show recent work carrying the Gateway session lookup, usage, memory-wiki, and session-store surfaces touched by this PR. (role: recent area contributor; confidence: high; commits: e71d10fd4d74, c92265a51b72; files: src/gateway/server-session-key.ts, src/gateway/server-methods/usage.ts, extensions/memory-wiki/src/query.ts)
  • BunsDev: Recent usage-session history includes a focused session lineage rollup fix in the same sessions.usage area. (role: usage area contributor; confidence: medium; commits: d12c92c216ab; files: src/gateway/server-methods/usage.ts)
  • nefainl: The memory-core session visibility behavior being extended here traces to a prior merged memory search visibility fix credited to this contributor. (role: memory visibility contributor; confidence: medium; commits: 2c716f5677de; files: extensions/memory-core/src/session-search-visibility.ts, extensions/memory-core/src/tools.ts)

Remaining risk / open question:

  • The PR body has no after-fix real behavior proof from a live or otherwise real multi-agent Gateway setup.
  • The default behavior for no-agent Gateway and memory queries narrows from broad configured-agent discovery to effective/default-agent scope, so compatibility impact should be explicitly accepted by maintainers.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 5774517fcee6.

@pgondhi987

Copy link
Copy Markdown
Contributor Author

Reviewed by automation; no code change was required for this comment.

Quoted comment from @clawsweeper:

ClawSweeper status: review started.

I am starting a fresh review of this pull request: fix(gateway): scope session data lookups by agent [AI] This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
* fix: scope gateway session lookups by agent

* addressing review-skill

* addressing review-skill

* addressing review-skill

* addressing review-skill

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* addressing review-skill

* addressing review-skill

* addressing review-skill

* addressing review-skill

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* addressing ci

* addressing ci

* fix: complete root-cause handling

* addressing review-skill

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* Fix Swift protocol optional initializer defaults

* Stabilize node command lookup in approval test

* Fix browser proxy approval test node lookup

* Trim unrelated changes from issue 642 fix

* Remove unrelated formatting churn from issue 642 fix

* Fix Swift protocol generator lint

* docs: add changelog entry for PR merge
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
galiniliev pushed a commit to galiniliev/openclaw that referenced this pull request May 25, 2026
* fix: scope gateway session lookups by agent

* addressing review-skill

* addressing review-skill

* addressing review-skill

* addressing review-skill

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* addressing review-skill

* addressing review-skill

* addressing review-skill

* addressing review-skill

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* addressing ci

* addressing ci

* fix: complete root-cause handling

* addressing review-skill

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* Fix Swift protocol optional initializer defaults

* Stabilize node command lookup in approval test

* Fix browser proxy approval test node lookup

* Trim unrelated changes from issue 642 fix

* Remove unrelated formatting churn from issue 642 fix

* Fix Swift protocol generator lint

* docs: add changelog entry for PR merge
galiniliev pushed a commit to galiniliev/openclaw that referenced this pull request May 25, 2026
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
* fix: scope gateway session lookups by agent

* addressing review-skill

* addressing review-skill

* addressing review-skill

* addressing review-skill

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* addressing review-skill

* addressing review-skill

* addressing review-skill

* addressing review-skill

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* addressing ci

* addressing ci

* fix: complete root-cause handling

* addressing review-skill

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* Fix Swift protocol optional initializer defaults

* Stabilize node command lookup in approval test

* Fix browser proxy approval test node lookup

* Trim unrelated changes from issue 642 fix

* Remove unrelated formatting churn from issue 642 fix

* Fix Swift protocol generator lint

* docs: add changelog entry for PR merge
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
* fix: scope gateway session lookups by agent

* addressing review-skill

* addressing review-skill

* addressing review-skill

* addressing review-skill

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* addressing review-skill

* addressing review-skill

* addressing review-skill

* addressing review-skill

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* addressing ci

* addressing ci

* fix: complete root-cause handling

* addressing review-skill

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* addressing codex review

* Fix Swift protocol optional initializer defaults

* Stabilize node command lookup in approval test

* Fix browser proxy approval test node lookup

* Trim unrelated changes from issue 642 fix

* Remove unrelated formatting churn from issue 642 fix

* Fix Swift protocol generator lint

* docs: add changelog entry for PR merge
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui extensions: memory-core Extension: memory-core extensions: memory-wiki gateway Gateway runtime maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. scripts Repository scripts size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant