Skip to content

fix(sessions): distinguish transient lookup failures from policy denials - #117305

Merged
RomneyDa merged 22 commits into
openclaw:mainfrom
SunnyShu0925:fix/sessions-visibility-lookup-failed-114653
Aug 13, 2026
Merged

RomneyDa merged 22 commits into
openclaw:mainfrom
SunnyShu0925:fix/sessions-visibility-lookup-failed-114653

Conversation

@SunnyShu0925

@SunnyShu0925 SunnyShu0925 commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer cleanup — 2026-08-13

Rebased onto main at 2dffeae1269; current head is be9eb717f5c. Contributor authorship and commit order are preserved. This cleanup does not merge the PR.

What Problem This Solves

Direct session tools previously collapsed operational ownership-lookup failures into policy denials. They could also discard exact ownership already established by sessions.resolve and authorize against a capped sessions.list window instead.

The canonical access path now carries typed transient / credentials / unknown failures plus explicit session-owner and requester-ownership facts through history, send, search, status, and mutation checks. Confirmed misses remain ordinary not-found outcomes.

Maintainer review also repaired three connected authorization gaps:

  • semantic-current and no-argument session_status cannot bypass the shared incognito guard;
  • scoped host grants resolve against the owner-qualified authorization key, so the same bare key under another agent cannot reuse a grant;
  • incognito remains non-overridable for scoped grants, and sessions_search revalidates the granted session incarnation before reading it.

Architecture and compatibility

  • Gateway resolution records exact key and owner facts.
  • Shared Plugin SDK visibility owns incognito and row policy.
  • resolveSessionToolAccess is the single direct-target authorization owner; tool consumers carry its prepared facts forward.
  • Scoped grants remain narrow host capabilities and are linearized against reset/archive/replacement for history, send, search, and status.
  • An older Gateway without exact sessions.resolve support retains the existing sessions.list fallback only for ownership-dependent candidates.
  • No config, default, protocol, SQLite schema, storage migration, or new public plugin subpath is added.

ClawSweeper feedback

  • Deterministic A2A/policy denials are preserved when ownership lookup cannot change the result.
  • Semantic-current and implicit status targets are checked against the live incognito key before Gateway or store access.
  • The requested lightweight Slack HTTP --use-env contract is now covered by extensions/slack/src/channel-actions-setup-status.contract.test.ts without restoring heavyweight bundled-runtime loading in the command test.
  • The owner-qualified scoped-grant, scoped-incognito, and search-incarnation findings discovered during final maintainer review are covered by focused regressions.

LOC review metric

  • Production: +856/-307 (+549 net).
  • Tests: +1134/-270 (+864 net).
  • Total: +1990/-577 (+1413 net).

This is large for a bug fix. The remaining production growth is concentrated in the typed lookup-result contract, explicit multi-agent owner propagation, one canonical direct-access helper, and the status/search integrations that consume those prepared facts. Duplicate resolver-level ownership policy was removed. Reducing it further would either drop the operational-failure distinction or recreate authorization policy in individual tools.

Evidence

  • Focused exact-head Vitest: 6 files / 167 tests passed across access, visibility, history, search, send, and status surfaces.
  • Exact-head core production and test typechecks passed.
  • Exact-head changed-file type-aware lint and formatting passed.
  • Branch autoreview: no accepted/actionable findings; correctness 0.92.
  • Independent owner-boundary re-review: no remaining P0/P1.
  • Delegated pnpm check:changed: every PR-owned gate passed, including conflict/config ratchets, formatting, dead code, SDK API/surface/boundary checks, all four core/extension typecheck lanes, and changed-core lint. The final full-extension lint was blocked by an unrelated current-main max-lines failure in extensions/discord/src/send.creates-thread.test.ts; this branch does not modify that file. Run 31671439673, Testbox tbx_01kzwtffjwzhswvcrmxrtt706w.

Regression coverage

  • Exact child beyond a 100-row list window and legacy exact-resolver fallback.
  • Transient, credential, unknown, malformed-response, and confirmed-miss outcomes.
  • Ordinary cross-agent deterministic denial versus ownership-dependent ACP/native child lookup guidance.
  • Same bare key under different explicit owners.
  • Scoped grants versus incognito and target incarnation replacement.
  • Explicit, semantic-current, and implicit incognito status denial before Gateway/store access.
  • History, send, search, status, list/access mutation, sandbox, and session-companion paths.

Related: #114653, #114180.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Aug 1, 2026
@SunnyShu0925
SunnyShu0925 force-pushed the fix/sessions-visibility-lookup-failed-114653 branch from 5c0771a to 550ddc1 Compare August 1, 2026 08:47
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. labels Aug 1, 2026
@clawsweeper

clawsweeper Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 13, 2026, 2:08 AM ET / 06:08 UTC.

ClawSweeper review

What this changes

This PR replaces repeated direct session visibility checks with one access decision that carries resolved ownership facts and distinguishes transient, credential, unknown, and genuine policy-denial outcomes.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open. The centralized per-target access path appears to correctly preserve deterministic denials while returning actionable lookup-failure outcomes; no discrete patch defect was established. Its broad session-authorization scope warrants owner review before merge.

Priority: P1
Reviewed head: be9eb717f5ca7e4f147f9cbe07fe13654092fd2d
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has credible real-boundary evidence and broad focused coverage, with remaining review centered on the intentionally large authorization refactor.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (logs): The supplied context records a redacted real Gateway-backed after-fix trace for sessions_history and sandboxed sessions_send; focused tests cover the later scoped-grant and incarnation cases.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (logs): The supplied context records a redacted real Gateway-backed after-fix trace for sessions_history and sandboxed sessions_send; focused tests cover the later scoped-grant and incarnation cases.
Evidence reviewed 7 items Canonical access owner: The new helper first preserves scoped grants and deterministic row-policy results, then performs an exact ownership lookup only when ownership could change a same-agent tree decision.
Gateway contract: The Gateway schema supports exact key resolution with spawned-owner filtering and an additive allow-missing probe; the resolver applies spawned visibility before returning the canonical key.
Sibling consumers: History and search consume the prepared access result; search carries a scoped grant's expected session incarnation into the guarded backend read.
Findings None None.
Security None None.

How this fits together

Session tools resolve a requested session through the Gateway, apply shared visibility and agent-to-agent policy, then read, search, send to, or mutate that session. The change makes the access decision carry exact ownership facts to those downstream operations.

flowchart LR
  A[Session tool request] --> B[Gateway session resolution]
  B --> C[Resolved owner facts]
  C --> D[Shared session access decision]
  D --> E[History send search status]
  D --> F[Policy denial]
  D --> G[Actionable lookup failure]
Loading

Decision needed

Question Recommendation
Should this broad centralized session-authorization refactor be accepted as the canonical owner for direct session-tool access? Accept the centralized access owner: Merge after exact-head CI completes, keeping exact ownership resolution and policy evaluation in the shared helper.

Why: The code changes authorization and incognito handling across multiple session operations, so maintainers must accept the boundary and its proportionate production growth.

Before merge

  • Resolve merge risk (P1) - The patch adds a net 549 production lines across session authorization paths; a mistake could wrongly disclose, deny, or stale-associate session access despite the focused coverage.
  • Complete next step (P2) - The remaining action is a maintainer security-boundary judgment, not a safe mechanical repair.
Agent review details

Security

None.

PR surface

Source +549, Tests +864. Total +1413 across 22 files.

View PR surface stats
Area Files Added Removed Net
Source 10 856 307 +549
Tests 12 1134 270 +864
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 22 1990 577 +1413

Review metrics

Metric Value Why it matters
Production versus test LOC production +856/-307 (net +549); tests +1134/-270 (net +864) This is substantial growth for a bug fix, although it consolidates access logic and adds multi-surface regressions.

Stored data model

Persistent data-model change detected: serialized state: src/agents/tools/session-status-tool.ts, serialized state: src/agents/tools/sessions-access.test.ts, serialized state: src/agents/tools/sessions-access.ts, serialized state: src/agents/tools/sessions-history-tool.test.ts, serialized state: src/agents/tools/sessions-history-tool.ts, serialized state: src/agents/tools/sessions-resolution.strict.test.ts, and 25 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #114653
Summary: This PR is the candidate repair for the lookup-failure report; the linked recency-window report remains a distinct partial overlap.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Accept the centralized access owner (recommended)
    Accept the measured production growth because splitting the exact ownership and visibility decision back into callers would recreate divergent session policy.
  2. Pause for a smaller design
    Request a narrower refactor only if it retains one authoritative authorization decision and equivalent owner/incognito regressions.

Technical review

Best possible solution:

Retain one prepared-facts access owner rather than recreating Gateway lookup and policy logic in each tool; no net-neutral alternative was found without reintroducing duplicated authorization policy.

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

Yes for the source path: the prior direct guard converted failed ownership lookup into an ordinary tree denial, and the supplied context includes a redacted real-Gateway after-fix trace for history and sandboxed send.

Is this the best way to solve the issue?

Yes. Resolving exact ownership once and passing prepared facts into direct tool access is more maintainable than each tool depending on a capped listing or independently classifying Gateway failures.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against d94c755eb7a7.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): The supplied context records a redacted real Gateway-backed after-fix trace for sessions_history and sandboxed sessions_send; focused tests cover the later scoped-grant and incarnation cases.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: Session-tool authorization failures can block active agent workflows and misstate the cause.
  • merge-risk: 🚨 session-state: History, search, status, send, and mutation access now consume shared ownership facts and scoped session incarnation checks.
  • merge-risk: 🚨 security-boundary: The patch changes the authorization decision, scoped-grant identity, and incognito exclusion for direct session operations.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): The supplied context records a redacted real Gateway-backed after-fix trace for sessions_history and sandboxed sessions_send; focused tests cover the later scoped-grant and incarnation cases.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied context records a redacted real Gateway-backed after-fix trace for sessions_history and sandboxed sessions_send; focused tests cover the later scoped-grant and incarnation cases.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Commit 0b85f9c introduced the current sessions.resolve feature and schema that provide this PR’s exact ownership proof. (role: introduced the Gateway resolver feature; confidence: high; commits: 0b85f9c174c9; files: packages/gateway-protocol/src/schema/sessions-resolve.ts, src/gateway/sessions-resolve.ts)
  • Josh Avant: Blame attributes the current exact-key visibility behavior in the resolver to this recent mainline work. (role: recent resolver-path contributor; confidence: medium; commits: 705f043e04a1; files: src/gateway/sessions-resolve.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (45 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-11T04:00:31.389Z sha 30e5bc1c2c62623dabfe7da9307faf9dfea95de5 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-11T13:58:35.868Z sha b6b57399f82014a482305aae73e00b9bc99b3077 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-11T14:16:40.600Z sha d3d9e7c9c463a149655670bb55efb9a6f63ea3a7 :: found issues before merge. :: [P1] Preserve the legacy spawned-session resolver fallback | [P1] Redact the requester session key in warnings
  • reviewed 2026-08-11T15:57:14.330Z sha 1069edf7aa0f900a8f470d75c1ec65dd4f9a967f :: needs changes before merge. :: [P1] Preserve the legacy spawned-session resolver fallback | [P1] Redact the requester session key before logging
  • reviewed 2026-08-11T17:00:56.749Z sha aa5b4a84ea10ac5c6bb0d9667c197d91779266c4 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-11T19:12:23.166Z sha a3ee72d7155912c375ff111d356bb3c6608078de :: needs real behavior proof before merge. :: [P2] Preserve deterministic cross-agent denials on lookup failure
  • reviewed 2026-08-12T18:06:47.506Z sha c96b0a411016502374b6e5c60dc8a0839e452e5b :: needs real behavior proof before merge. :: [P1] Check resolved incognito targets before semantic-current substitution
  • reviewed 2026-08-12T19:18:02.378Z sha 2c872b9c5102daf5e4a521b594cf408016c3f3b7 :: needs changes before merge. :: [P2] Preserve Slack HTTP setup-contract coverage

@SunnyShu0925
SunnyShu0925 force-pushed the fix/sessions-visibility-lookup-failed-114653 branch from 550ddc1 to 78a2024 Compare August 1, 2026 08:55
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Aug 1, 2026
@SunnyShu0925
SunnyShu0925 force-pushed the fix/sessions-visibility-lookup-failed-114653 branch from 78a2024 to 11cfbc4 Compare August 1, 2026 09:24
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 1, 2026
@SunnyShu0925
SunnyShu0925 force-pushed the fix/sessions-visibility-lookup-failed-114653 branch from 0c80488 to 095392d Compare August 1, 2026 11:21
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. label Aug 1, 2026
@SunnyShu0925
SunnyShu0925 force-pushed the fix/sessions-visibility-lookup-failed-114653 branch from 095392d to 926e49b Compare August 1, 2026 13:49
@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Addressed the two P1 redaction findings (warn paths now route through formatErrorMessage) and added redacted, real Gateway-backed sessions_history evidence: a loopback Gateway started from this source tree, production callGateway transport, real session store, and a server-side fault injection inside sessions.list (temporary env-gated patch, removed after capture). Full transcript and harness: pr-114653-evidence/real-gateway-evidence.txt.

@clawsweeper

clawsweeper Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Aug 1, 2026
@SunnyShu0925
SunnyShu0925 force-pushed the fix/sessions-visibility-lookup-failed-114653 branch from 926e49b to 0633da1 Compare August 1, 2026 14:40
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 1, 2026
SunnyShu0925 and others added 21 commits August 13, 2026 13:32
Make spawned-session ownership lookup failures observable and
distinguishable from genuine tree-visibility policy denials, with
retryability classification so permanent credential/configuration
failures are not mis-framed as transient. Addresses issue openclaw#114653.

Diagnostic layer only — does not add retry (maintainer product decision)
and does not address the recency-window denial path (openclaw#114180).

Core changes:
- session-visibility-internal: add a core-private three-state lookup result
  (ok / failed with retryable flag) plus classifyLookupRetryable (transport
  closes/timeouts and retryable request errors => retryable; credential/auth/
  unknown => non-retryable) and a shared lookupFailedDenialSuffix.
- session-visibility guard: pick the denial text by retryability so transient
  failures say "retry" and permanent failures say "check gateway configuration
  and credentials"; both still fail closed. Preserves the shipped public
  SessionAccessResult, Set<string> checker input, and test-hook contracts.
- sessions-resolution sandbox resolver: propagate the same retryability-
  classified denial; pass allowMissing: true on the speculative
  sessions.resolve probe and suppress the warn for the expected "No session
  found" miss so ordinary non-owned targets do not log as operational lookup
  failures (reuses callGatewayResolveSession for older-gateway compatibility).
- Tests: transient + permanent error coverage for both guard and sandbox
  resolver paths; classification contract locks; non-owned-miss quietness
  regression; redaction through formatErrorMessage.
…tion

oxlint typescript(no-unnecessary-type-conversion) flagged the redundant
Boolean() wrapper around String.includes() which already returns boolean.
Use ?? false to preserve the undefined->false semantics from the optional
chain.
A failed spawned-session ownership lookup override was relabeling the row
checker's deterministic cross-agent policy denial as a retryable lookup
failure. Retrying the spawned ownership lookup cannot make a known
agent:other:* target eligible, so the cross-visibility refusal must be
preserved as-is.

Constrain the lookup-failure override to same-agent targets by mirroring
the row checker's agent resolution: when the target resolves to a
different agent than the requester, keep the original cross-agent denial
rather than overriding it. Add regression coverage for the cross-agent
case under a failed tree-visibility lookup.

ClawSweeper review P2: preserve cross-agent policy denials on lookup
failure.
Replace the `!!id` coercions in `isCrossAgentTarget` with an explicit
empty-check so the return value reads as a plain inequality. The
`no-implicit-coercion` lint rule flags `!!` on already-resolved strings;
both ids are guaranteed non-empty by the resolve-or-return-false guards
above, so the explicit form is equivalent.
@RomneyDa

Copy link
Copy Markdown
Member

@clawsweeper re-review

Rebased onto current main and updated to exact head f18c67b2030. Addressed the final scoped-access owner boundary: grants now use the owner-qualified authorization target, incognito cannot be overridden by a scoped grant, and sessions_search revalidates the granted session incarnation before reading. Added focused regressions for all three. The prior Slack HTTP setup-contract item is covered by extensions/slack/src/channel-actions-setup-status.contract.test.ts on current main. Please review the current head.

@clawsweeper

clawsweeper Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling commands Command implementations gateway Gateway runtime merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. triage: blank-template Candidate: PR template appears mostly untouched. triage: dirty-candidate Candidate: broad unrelated surfaces; may need splitting or cleanup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants