Skip to content

Commit e6ed7e3

Browse files
authored
feat(audit): record session action decisions (#129093)
* feat(audit): record session action decisions * fix(protocol): preserve session sharing client compatibility
1 parent 8cf6c12 commit e6ed7e3

46 files changed

Lines changed: 2411 additions & 661 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/android/app/src/main/java/ai/openclaw/app/gateway/GatewayProtocol.kt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,7 @@ enum class GatewayMethod(
778778
ToolsGithubAuthorizeCancel("tools.github.authorize.cancel"),
779779
SessionsGithubPublish("sessions.github.publish"),
780780
DiagnosticsLanes("diagnostics.lanes"),
781+
SessionMembersListEvidence("session.members.listEvidence"),
781782
}
782783

783784
enum class GatewayEvent(
@@ -792,6 +793,7 @@ enum class GatewayEvent(
792793
SessionObserver("session.observer"),
793794
SessionOperation("session.operation"),
794795
SessionSharing("session.sharing"),
796+
SessionSharingEvidence("session.sharing.evidence"),
795797
SessionSuggestion("session.suggestion"),
796798
SessionTyping("session.typing"),
797799
SessionTool("session.tool"),

‎apps/android/app/src/test/java/ai/openclaw/app/gateway/GatewayProtocolGeneratedTest.kt‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,48 @@ class GatewayProtocolGeneratedTest {
5454
assertNull(decoded.observedProjects)
5555
}
5656

57+
@Test
58+
fun legacyFramesDecodePrincipalLessSharingErrorsAndRefreshEvents() {
59+
for (id in listOf("unknown", "absent")) {
60+
val response =
61+
json.decodeFromString(
62+
GatewayResponseFrame.serializer(),
63+
"""{"type":"res","id":"$id","ok":false,"error":{"code":"INVALID_REQUEST","message":"session membership includes actor evidence this client cannot represent","details":{"code":"SESSION_MEMBER_ACTOR_EVIDENCE_UNSUPPORTED","recommendedMethod":"session.members.listEvidence"}}}""",
64+
)
65+
assertEquals("INVALID_REQUEST", response.error?.code)
66+
assertEquals(
67+
"session.members.listEvidence",
68+
response.error
69+
?.details
70+
?.jsonObject
71+
?.get("recommendedMethod")
72+
?.jsonPrimitive
73+
?.content,
74+
)
75+
}
76+
77+
val ignoredEvidence =
78+
json.decodeFromString(
79+
GatewayEventFrame.serializer(),
80+
"""{"type":"event","event":"session.sharing.evidence","payload":{"action":"member-added","sessionKey":"agent:main:main","agentId":"main","actorState":"unknown","identityId":"profile-bob","ts":2}}""",
81+
)
82+
val refresh =
83+
json.decodeFromString(
84+
GatewayEventFrame.serializer(),
85+
"""{"type":"event","event":"sessions.changed","payload":{"reason":"sharing","sessionKey":"agent:main:main","agentId":"main","ts":2}}""",
86+
)
87+
assertEquals("session.sharing.evidence", ignoredEvidence.event)
88+
assertEquals("sessions.changed", refresh.event)
89+
assertEquals(
90+
"sharing",
91+
refresh.payload
92+
?.jsonObject
93+
?.get("reason")
94+
?.jsonPrimitive
95+
?.content,
96+
)
97+
}
98+
5799
@Test
58100
fun generatedGatewayCatalogsAreCompleteAndUnique() {
59101
val methods = GatewayMethod.entries.map { it.rawValue }

‎apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6883,6 +6883,32 @@ public struct SessionMember: Codable, Sendable {
68836883
}
68846884
}
68856885

6886+
public struct SessionMemberEvidence: Codable, Sendable {
6887+
public let identityid: String
6888+
public let addedby: String?
6889+
public let addedbystate: String?
6890+
public let addedat: Int
6891+
6892+
public init(
6893+
identityid: String,
6894+
addedby: String? = nil,
6895+
addedbystate: String? = nil,
6896+
addedat: Int)
6897+
{
6898+
self.identityid = identityid
6899+
self.addedby = addedby
6900+
self.addedbystate = addedbystate
6901+
self.addedat = addedat
6902+
}
6903+
6904+
private enum CodingKeys: String, CodingKey {
6905+
case identityid = "identityId"
6906+
case addedby = "addedBy"
6907+
case addedbystate = "addedByState"
6908+
case addedat = "addedAt"
6909+
}
6910+
}
6911+
68866912
public struct SessionMembersListResult: Codable, Sendable {
68876913
public let sessionkey: String
68886914
public let owner: SessionSharingIdentity?
@@ -6917,6 +6943,40 @@ public struct SessionMembersListResult: Codable, Sendable {
69176943
}
69186944
}
69196945

6946+
public struct SessionMembersListEvidenceResult: Codable, Sendable {
6947+
public let sessionkey: String
6948+
public let owner: SessionSharingIdentity?
6949+
public let members: [SessionMemberEvidence]
6950+
public let identities: [SessionSharingIdentity]
6951+
public let role: SessionSharingRole
6952+
public let allowedvisibilities: [SessionVisibility]
6953+
6954+
public init(
6955+
sessionkey: String,
6956+
owner: SessionSharingIdentity? = nil,
6957+
members: [SessionMemberEvidence],
6958+
identities: [SessionSharingIdentity],
6959+
role: SessionSharingRole,
6960+
allowedvisibilities: [SessionVisibility])
6961+
{
6962+
self.sessionkey = sessionkey
6963+
self.owner = owner
6964+
self.members = members
6965+
self.identities = identities
6966+
self.role = role
6967+
self.allowedvisibilities = allowedvisibilities
6968+
}
6969+
6970+
private enum CodingKeys: String, CodingKey {
6971+
case sessionkey = "sessionKey"
6972+
case owner
6973+
case members
6974+
case identities
6975+
case role
6976+
case allowedvisibilities = "allowedVisibilities"
6977+
}
6978+
}
6979+
69206980
public struct SessionMemberAddParams: Codable, Sendable {
69216981
public let sessionkey: String
69226982
public let agentid: String?
@@ -7021,6 +7081,44 @@ public struct SessionSharingEvent: Codable, Sendable {
70217081
}
70227082
}
70237083

7084+
public struct SessionSharingEvidenceEvent: Codable, Sendable {
7085+
public let action: SessionSharingAction
7086+
public let sessionkey: String
7087+
public let agentid: String
7088+
public let actorstate: String?
7089+
public let visibility: SessionVisibility?
7090+
public let identityid: String?
7091+
public let ts: Int
7092+
7093+
public init(
7094+
action: SessionSharingAction,
7095+
sessionkey: String,
7096+
agentid: String,
7097+
actorstate: String? = nil,
7098+
visibility: SessionVisibility? = nil,
7099+
identityid: String? = nil,
7100+
ts: Int)
7101+
{
7102+
self.action = action
7103+
self.sessionkey = sessionkey
7104+
self.agentid = agentid
7105+
self.actorstate = actorstate
7106+
self.visibility = visibility
7107+
self.identityid = identityid
7108+
self.ts = ts
7109+
}
7110+
7111+
private enum CodingKeys: String, CodingKey {
7112+
case action
7113+
case sessionkey = "sessionKey"
7114+
case agentid = "agentId"
7115+
case actorstate = "actorState"
7116+
case visibility
7117+
case identityid = "identityId"
7118+
case ts
7119+
}
7120+
}
7121+
70247122
public struct SessionSuggestion: Codable, Sendable {
70257123
public let id: String
70267124
public let sessionkey: String

‎apps/shared/OpenClawKit/Tests/OpenClawKitTests/GatewayModelsCompatibilityTests.swift‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,62 @@ struct GatewayModelsCompatibilityTests {
6666
#expect(mutation.sectionorder == nil)
6767
}
6868

69+
@Test
70+
func `session sharing decodes present unknown and absent actor evidence`() throws {
71+
let presentList = try JSONDecoder().decode(
72+
SessionMembersListResult.self,
73+
from: Data(
74+
#"{"sessionKey":"main","members":[{"identityId":"present","addedBy":"profile-ada","addedAt":1}],"identities":[],"role":"owner","allowedVisibilities":["shared"]}"#
75+
.utf8))
76+
let principalLessList = try JSONDecoder().decode(
77+
SessionMembersListEvidenceResult.self,
78+
from: Data(
79+
#"{"sessionKey":"main","members":[{"identityId":"unknown","addedByState":"unknown","addedAt":2},{"identityId":"absent","addedAt":3}],"identities":[],"role":"owner","allowedVisibilities":["shared"]}"#
80+
.utf8))
81+
82+
#expect(presentList.members[0].addedby == "profile-ada")
83+
#expect(principalLessList.members[0].addedby == nil)
84+
#expect(principalLessList.members[0].addedbystate == "unknown")
85+
#expect(principalLessList.members[1].addedby == nil)
86+
#expect(principalLessList.members[1].addedbystate == nil)
87+
for member in [
88+
#"{"identityId":"unknown","addedByState":"unknown","addedAt":2}"#,
89+
#"{"identityId":"absent","addedAt":3}"#,
90+
] {
91+
#expect(throws: DecodingError.self) {
92+
try JSONDecoder().decode(
93+
SessionMembersListResult.self,
94+
from: Data(
95+
#"{"sessionKey":"main","members":[\#(member)],"identities":[],"role":"owner","allowedVisibilities":["shared"]}"#
96+
.utf8))
97+
}
98+
}
99+
100+
let present = try JSONDecoder().decode(
101+
SessionSharingEvent.self,
102+
from: Data(
103+
#"{"action":"visibility","sessionKey":"main","agentId":"main","actor":{"type":"human","id":"profile-ada"},"ts":1}"#
104+
.utf8))
105+
106+
#expect(present.actor.id == "profile-ada")
107+
108+
let principalLess = try JSONDecoder().decode(
109+
[SessionSharingEvidenceEvent].self,
110+
from: Data(
111+
#"[{"action":"member-added","sessionKey":"main","agentId":"main","actorState":"unknown","identityId":"member","ts":2},{"action":"member-removed","sessionKey":"main","agentId":"main","identityId":"member","ts":3}]"#
112+
.utf8))
113+
114+
#expect(principalLess[0].actorstate == "unknown")
115+
#expect(principalLess[1].actorstate == nil)
116+
#expect(throws: DecodingError.self) {
117+
try JSONDecoder().decode(
118+
SessionSharingEvent.self,
119+
from: Data(
120+
#"{"action":"member-added","sessionKey":"main","agentId":"main","actorState":"unknown","identityId":"member","ts":2}"#
121+
.utf8))
122+
}
123+
}
124+
69125
@Test
70126
func `device pair setup results decode older gateway payloads`() throws {
71127
let result = try JSONDecoder().decode(

‎docs/concepts/channel-docking.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ Docking does not:
122122

123123
It only changes the delivery route for the current session.
124124

125+
Dock commands are handled directly as chat commands rather than admitted model
126+
runs. Their success or failure remains visible in the command reply, but they
127+
do not create a run-audit selector or decision receipt.
128+
125129
## Troubleshooting
126130

127131
**The command says the sender is not linked.**

‎docs/concepts/session-tool.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ These tools are still subject to the active tool profile and allow/deny policy.
3030

3131
Group, provider, sandbox, and per-agent policies can still remove those tools after the profile stage. Use `/tools` from the affected session to inspect the effective tool list.
3232

33+
Session access denials are rendered from the same typed visibility decision
34+
used by the enforcement boundary. When execution audit collection is enabled
35+
for an admitted run, a private queued fact retains the evaluated policy inputs
36+
and an installation-local opaque target reference, not the raw target session
37+
key. Public inspection renders that generic fact as an unverified
38+
`decision.record`; it does not claim a trusted reason or target display. A
39+
successful session operation is not labeled `enforced` merely because its
40+
mechanics succeeded.
41+
42+
For the same admitted run, create, fork, send, patch, reset, archive, restore,
43+
and delete results can queue attribution-only generic facts. The private facts
44+
distinguish committed or scheduled work from typed lifecycle conflicts and
45+
definitive no-ops; their public display remains generic and unverified. Direct
46+
Gateway sharing operations are outside this run-audit boundary.
47+
3348
## Listing and reading sessions
3449

3550
`sessions_list` returns focused discovery rows: session key, durable session ID, agent, kind, channel, label/title/preview fields, sidebar category, parent and child relationships, last update, archive/pin state, state version, model, context/total token counts, run status, and whether the last run aborted. Filter by `kinds` (array; accepted values: `main`, `group`, `cron`, `hook`, `node`, `other`), exact `label`, exact `agentId`, `search` text, or recency (`activeMinutes`). Active sessions are returned by default; pass `archived: true` to inspect archived sessions instead. Set `includeDerivedTitles`, `includeLastMessage`, or `messageLimit` (capped at 20) when you need mailbox-style triage: a visibility-scoped derived title, a last-message preview snippet, or bounded recent messages on each row. Use the returned `sessionId` as `expectedSessionId` when the `sessions` tool archives, restores, or deletes another session; this prevents a stale key from targeting a replacement. Delivery routing, other internal IDs, per-run timings/settings, cost estimates, and transcript paths remain omitted; use `session_status`, conversation tools, and `sessions_history` for those owner-specific details. Derived titles and previews are produced only for sessions the caller can already see under the configured session tool visibility policy, so unrelated sessions stay hidden. When visibility is restricted, `sessions_list` returns optional `visibility` metadata showing the effective mode and a warning that results may be scope-limited.

‎docs/gateway/audit.md‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,37 @@ outcome-affecting. Wildcard/open policy and explicit attribution-only adapters
205205
remain `attribution-only`; mixed or missing evidence is `unknown`. Identity and
206206
the corresponding decision share the existing audit-writer FIFO.
207207

208+
An admitted session-tool access denial queues a private `session` decision
209+
through that same FIFO. The access owner supplies the reason, policy inputs,
210+
and missing evidence; the audit writer replaces the target session reference
211+
with an installation-local HMAC before persistence. The raw session key is not
212+
retained. A policy denial that changed the outcome is `enforced`, while an
213+
ownership lookup that cannot supply `session.owner` evidence remains `unknown`.
214+
Public inspection intentionally renders generic facts as an unverified
215+
`decision.record`; it does not expose their private reason or target display.
216+
Calls without the exact admitted execution and its active receipt authority
217+
create no selector or fact.
218+
219+
Run-bound session tools also queue their owner-returned result after the final
220+
await and authority recheck. Create, fork, send, patch, reset, archive, restore,
221+
and delete facts distinguish committed or scheduled work from typed lifecycle
222+
conflicts and definitive no-ops. These mechanics are `attribution-only`; the
223+
public generic display remains unverified rather than presenting their private
224+
reason or target as trusted evidence.
225+
226+
Direct session-sharing methods and `/dock-*` commands do not admit model runs,
227+
so they do not synthesize run selectors. Sharing events preserve a verified
228+
profile actor when one exists; an expected but unresolved profile is reported
229+
as unknown, while omitted principal evidence is unattributed. Neither state is
230+
reconstructed from operator scope, a shared token, session routing, or room
231+
metadata. Member listings use the same distinction: `addedBy` contains only a
232+
real principal id, `addedByState: "unknown"` reports explicit principal-less
233+
evidence, and omission means no actor evidence was supplied. Internal storage
234+
markers are never returned by the Gateway. Beta-only `local-operator` and
235+
`operator.admin` member-attribution values are discarded as absent evidence;
236+
they are not migrated or presented as principals. Docking retains its normal
237+
visible command result and session-route update without run-audit attribution.
238+
208239
For an admitted run with message auditing enabled, run inspection also adapts
209240
the outbound message lifecycle. It deterministically merges the lazy progress
210241
owner with terminal ledger rows and reports `queued`, `platform-started`,

‎docs/gateway/config-agents.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ See [Multi-Agent Sandbox & Tools](/tools/multi-agent-sandbox-tools) for preceden
12911291
- `suggest`: allow `suggest`, where viewers can submit suggestions for the session owner or an `operator.admin` connection to send, queue, edit, or dismiss without granting direct access to send or manage the session.
12921292
- `drafts`: allow `draft`, which hides the session from non-admin, non-owner session lists and event broadcasts.
12931293

1294-
Session visibility and membership are maintained as canonical sharing state. Structured `session.sharing` and `session.suggestion` change events refresh connected clients without adding administrative narration to conversation transcripts. These controls coordinate operators sharing one agent; they are not a security boundary between tenants. Use separate Gateways or agents when work requires isolation.
1294+
Session visibility and membership are maintained as canonical sharing state. Structured `session.sharing` events carry an attributed actor; principal-less changes use the additive `session.sharing.evidence` event. Every sharing change also emits the existing `sessions.changed` row refresh, so clients that do not recognize the evidence event still refresh canonical state. These events and `session.suggestion` do not add administrative narration to conversation transcripts. These controls coordinate operators sharing one agent; they are not a security boundary between tenants. Use separate Gateways or agents when work requires isolation.
12951295

12961296
</Accordion>
12971297

‎packages/gateway-protocol/src/public-schema.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,12 @@ export {
228228
SessionMemberMutationResultSchema,
229229
SessionMemberRemoveParamsSchema,
230230
SessionMemberSchema,
231+
SessionMemberEvidenceSchema,
231232
SessionMembersListParamsSchema,
233+
SessionMembersListEvidenceResultSchema,
232234
SessionMembersListResultSchema,
233235
SessionSharingActionSchema,
236+
SessionSharingEvidenceEventSchema,
234237
SessionSharingEventSchema,
235238
SessionSharingIdentitySchema,
236239
SessionSharingRoleSchema,

‎packages/gateway-protocol/src/schema/protocol-schema-fragment-sessions-collaboration.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ export const SessionCollaborationProtocolSchemas = {
2121
SessionVisibilitySetResult: sessionsSharing.SessionVisibilitySetResultSchema,
2222
SessionMembersListParams: sessionsSharing.SessionMembersListParamsSchema,
2323
SessionMember: sessionsSharing.SessionMemberSchema,
24+
SessionMemberEvidence: sessionsSharing.SessionMemberEvidenceSchema,
2425
SessionMembersListResult: sessionsSharing.SessionMembersListResultSchema,
26+
SessionMembersListEvidenceResult: sessionsSharing.SessionMembersListEvidenceResultSchema,
2527
SessionMemberAddParams: sessionsSharing.SessionMemberAddParamsSchema,
2628
SessionMemberRemoveParams: sessionsSharing.SessionMemberRemoveParamsSchema,
2729
SessionMemberMutationResult: sessionsSharing.SessionMemberMutationResultSchema,
2830
SessionSharingAction: sessionsSharing.SessionSharingActionSchema,
2931
SessionSharingEvent: sessionsSharing.SessionSharingEventSchema,
32+
SessionSharingEvidenceEvent: sessionsSharing.SessionSharingEvidenceEventSchema,
3033
SessionSuggestionState: sessionsSuggestions.SessionSuggestionStateSchema,
3134
SessionSuggestionAction: sessionsSuggestions.SessionSuggestionActionSchema,
3235
SessionSuggestionResolution: sessionsSuggestions.SessionSuggestionResolutionSchema,

0 commit comments

Comments
 (0)