mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 08:02:28 +00:00
* perf(computer): add mac helper owner-loss benchmark Measure the release helper's resident memory before and after its owner-session deadline. Record exact revisions, per-trial RSS, retained state, and clean-exit latency so lifecycle reclamation is reproducible. * fix(computer): reap mac helper after client loss Bind the detached macOS helper lifetime to authenticated socket ownership. Reap the helper after its final authenticated client disconnects, and add a startup deadline for sessions that never authenticate. * test(computer): harden owner benchmark cleanup * test(computer): make owner benchmark cleanup failure-safe * test(computer): close remaining owner cleanup races
51 lines
1.5 KiB
Swift
51 lines
1.5 KiB
Swift
public struct AgentSessionConnectionID: Hashable, Sendable {
|
|
public let rawValue: UInt64
|
|
|
|
public init(rawValue: UInt64) {
|
|
self.rawValue = rawValue
|
|
}
|
|
}
|
|
|
|
public enum AgentSessionRegistration: Sendable {
|
|
case rejected
|
|
case claimed
|
|
case retained
|
|
}
|
|
|
|
public struct AgentSessionOwnership: Sendable {
|
|
private var authenticatedConnections: Set<AgentSessionConnectionID> = []
|
|
private var wasClaimed = false
|
|
private var sessionClosed = false
|
|
|
|
public init() {}
|
|
|
|
public mutating func registerConnection(
|
|
_ connection: AgentSessionConnectionID,
|
|
authenticated: Bool
|
|
) -> AgentSessionRegistration {
|
|
guard authenticated, !sessionClosed else { return .rejected }
|
|
let inserted = authenticatedConnections.insert(connection).inserted
|
|
guard inserted else { return .rejected }
|
|
guard !wasClaimed else { return .retained }
|
|
wasClaimed = true
|
|
return .claimed
|
|
}
|
|
|
|
public mutating func disconnect(_ connection: AgentSessionConnectionID) -> Bool {
|
|
guard authenticatedConnections.remove(connection) != nil else { return false }
|
|
guard wasClaimed, authenticatedConnections.isEmpty else { return false }
|
|
sessionClosed = true
|
|
return true
|
|
}
|
|
}
|
|
|
|
public func isAuthenticatedAgentSession(
|
|
expectedToken: String?,
|
|
requestToken: String?,
|
|
authorizedPeer: Bool
|
|
) -> Bool {
|
|
guard authorizedPeer else { return false }
|
|
guard let expectedToken else { return true }
|
|
return requestToken == expectedToken
|
|
}
|