1
This commit is contained in:
@@ -16,119 +16,176 @@ const DefaultRemoteWorkspaceAdapterMailboxConsumerCapacity = 32
|
||||
const RemoteWorkspaceFrameProbeSinkRuntimeID = "node_agent_rdp_worker_contract_probe"
|
||||
|
||||
type RemoteWorkspaceFrameProbeSink struct {
|
||||
mu sync.Mutex
|
||||
sequence int64
|
||||
queueCapacity int
|
||||
sessionTTL time.Duration
|
||||
sessions map[string]*remoteWorkspaceAdapterProbeSession
|
||||
terminalSessions map[string]remoteWorkspaceAdapterProbeTerminalSession
|
||||
sessionCreatedTotal int64
|
||||
sessionBoundTotal int64
|
||||
sessionBackpressureTotal int64
|
||||
sessionExpiredTotal int64
|
||||
sessionClosedTotal int64
|
||||
sessionResetTotal int64
|
||||
sessionControlTotal int64
|
||||
mailboxEventSequence int64
|
||||
mailboxEnqueuedTotal int64
|
||||
mailboxDrainedTotal int64
|
||||
mailboxDroppedTotal int64
|
||||
mailboxReadTotal int64
|
||||
mailboxWaitTotal int64
|
||||
mailboxWaitTimeoutTotal int64
|
||||
mailboxEmptyReadTotal int64
|
||||
mailboxResumeReadTotal int64
|
||||
mailboxAfterSequenceReadTotal int64
|
||||
mailboxReturnedTotal int64
|
||||
mailboxSkippedTotal int64
|
||||
mailboxConsumerReadTotal int64
|
||||
mailboxConsumerAckTotal int64
|
||||
mailboxConsumerResetTotal int64
|
||||
mailboxConsumerEvictedTotal int64
|
||||
lastMailboxReadAt string
|
||||
lastMailboxAdapterSessionID string
|
||||
lastMailboxWaitMs int
|
||||
lastMailboxWaited bool
|
||||
lastMailboxWaitTimeout bool
|
||||
lastMailboxEmpty bool
|
||||
lastMailboxResumeFrom string
|
||||
lastMailboxResumeSequence int64
|
||||
lastMailboxResumeConsumerID string
|
||||
lastMailboxAfterSequence int64
|
||||
lastMailboxSkippedCount int
|
||||
lastMailboxReturnedCount int
|
||||
lastMailboxConsumerID string
|
||||
lastMailboxConsumerAdapterSessionID string
|
||||
lastMailboxConsumerReadAt string
|
||||
lastMailboxConsumerAckAt string
|
||||
lastMailboxConsumerCheckpoint int64
|
||||
lastMailboxConsumerAck int64
|
||||
acceptedFramesTotal int64
|
||||
droppedFramesTotal int64
|
||||
ackedFramesTotal int64
|
||||
backpressureCount int64
|
||||
lastBackpressureAt string
|
||||
lastBackpressureReason string
|
||||
lastRejectedFrameCount int
|
||||
lastRejectedAdapterSessionID string
|
||||
lastRejectedChannelClass string
|
||||
lastRejectedAdapterContractID string
|
||||
lastRejectedQueueCapacity int
|
||||
lastRejectedQueueDepth int
|
||||
lastControl RemoteWorkspaceAdapterSessionControlResult
|
||||
last RemoteWorkspaceFrameBatchDeliveryReceipt
|
||||
mu sync.Mutex
|
||||
sequence int64
|
||||
queueCapacity int
|
||||
sessionTTL time.Duration
|
||||
sessions map[string]*remoteWorkspaceAdapterProbeSession
|
||||
terminalSessions map[string]remoteWorkspaceAdapterProbeTerminalSession
|
||||
sessionCreatedTotal int64
|
||||
sessionBoundTotal int64
|
||||
sessionBackpressureTotal int64
|
||||
sessionExpiredTotal int64
|
||||
sessionClosedTotal int64
|
||||
sessionResetTotal int64
|
||||
sessionControlTotal int64
|
||||
mailboxEventSequence int64
|
||||
mailboxEnqueuedTotal int64
|
||||
mailboxDrainedTotal int64
|
||||
mailboxDroppedTotal int64
|
||||
mailboxReadTotal int64
|
||||
mailboxWaitTotal int64
|
||||
mailboxWaitTimeoutTotal int64
|
||||
mailboxEmptyReadTotal int64
|
||||
mailboxResumeReadTotal int64
|
||||
mailboxAfterSequenceReadTotal int64
|
||||
mailboxReturnedTotal int64
|
||||
mailboxSkippedTotal int64
|
||||
mailboxPreflightTotal int64
|
||||
mailboxPreflightAckTotal int64
|
||||
mailboxPreflightCheckpointTotal int64
|
||||
mailboxConsumerReadTotal int64
|
||||
mailboxConsumerAckTotal int64
|
||||
mailboxConsumerResetTotal int64
|
||||
mailboxConsumerEvictedTotal int64
|
||||
lastMailboxReadAt string
|
||||
lastMailboxAdapterSessionID string
|
||||
lastMailboxWaitMs int
|
||||
lastMailboxWaited bool
|
||||
lastMailboxWaitTimeout bool
|
||||
lastMailboxEmpty bool
|
||||
lastMailboxResumeFrom string
|
||||
lastMailboxResumeSequence int64
|
||||
lastMailboxResumeConsumerID string
|
||||
lastMailboxAfterSequence int64
|
||||
lastMailboxSkippedCount int
|
||||
lastMailboxReturnedCount int
|
||||
lastMailboxPreflightAt string
|
||||
lastMailboxPreflightAdapterSessionID string
|
||||
lastMailboxPreflightConsumerID string
|
||||
lastMailboxPreflightResumeFrom string
|
||||
lastMailboxPreflightResumeSequence int64
|
||||
lastMailboxPreflightAfterSequence int64
|
||||
lastMailboxPreflightAvailableCount int
|
||||
lastMailboxPreflightReturnedCount int
|
||||
lastMailboxPreflightSkippedCount int
|
||||
lastMailboxPreflightFirstSequence int64
|
||||
lastMailboxPreflightLastSequence int64
|
||||
lastMailboxPreflightFirstRetained int64
|
||||
lastMailboxPreflightLastRetained int64
|
||||
lastMailboxPreflightMailboxDropped int64
|
||||
lastMailboxPreflightDiagnosticState string
|
||||
lastMailboxPreflightStaleCursor bool
|
||||
lastMailboxPreflightMissingDropped int
|
||||
lastMailboxPreflightRecommendedAction string
|
||||
lastMailboxPreflightActionHints []string
|
||||
lastMailboxPreflightActionReason string
|
||||
lastMailboxPreflightActionContext map[string]any
|
||||
lastMailboxPreflightOperatorSummary string
|
||||
lastMailboxPreflightOperatorStatus string
|
||||
lastMailboxPreflightOperatorSeverity string
|
||||
lastMailboxPreflightOperatorFields map[string]any
|
||||
lastMailboxConsumerID string
|
||||
lastMailboxConsumerAdapterSessionID string
|
||||
lastMailboxConsumerReadAt string
|
||||
lastMailboxConsumerAckAt string
|
||||
lastMailboxConsumerCheckpoint int64
|
||||
lastMailboxConsumerAck int64
|
||||
acceptedFramesTotal int64
|
||||
droppedFramesTotal int64
|
||||
ackedFramesTotal int64
|
||||
backpressureCount int64
|
||||
lastBackpressureAt string
|
||||
lastBackpressureReason string
|
||||
lastRejectedFrameCount int
|
||||
lastRejectedAdapterSessionID string
|
||||
lastRejectedChannelClass string
|
||||
lastRejectedAdapterContractID string
|
||||
lastRejectedQueueCapacity int
|
||||
lastRejectedQueueDepth int
|
||||
lastControl RemoteWorkspaceAdapterSessionControlResult
|
||||
last RemoteWorkspaceFrameBatchDeliveryReceipt
|
||||
}
|
||||
|
||||
type remoteWorkspaceAdapterProbeSession struct {
|
||||
ID string
|
||||
State string
|
||||
CreatedAt time.Time
|
||||
BoundAt time.Time
|
||||
LastActivityAt time.Time
|
||||
LastBackpressureAt time.Time
|
||||
ClosedAt time.Time
|
||||
DeliveryCount int64
|
||||
BackpressureCount int64
|
||||
AcceptedFrames int64
|
||||
DroppedFrames int64
|
||||
AckedFrames int64
|
||||
Mailbox []RemoteWorkspaceAdapterMailboxEvent
|
||||
MailboxEnqueued int64
|
||||
MailboxDrained int64
|
||||
MailboxDropped int64
|
||||
MailboxRead int64
|
||||
MailboxWait int64
|
||||
MailboxWaitTimeout int64
|
||||
MailboxEmptyRead int64
|
||||
MailboxResumeRead int64
|
||||
MailboxAfterSequenceRead int64
|
||||
MailboxReturnedTotal int64
|
||||
MailboxSkippedTotal int64
|
||||
MailboxConsumers map[string]*remoteWorkspaceAdapterMailboxConsumerState
|
||||
MailboxConsumerReadTotal int64
|
||||
MailboxConsumerAckTotal int64
|
||||
MailboxConsumerResetTotal int64
|
||||
MailboxConsumerEvictedTotal int64
|
||||
LastMailboxConsumerID string
|
||||
LastMailboxConsumerReadAt time.Time
|
||||
LastMailboxConsumerAckAt time.Time
|
||||
LastMailboxConsumerCheckpoint int64
|
||||
LastMailboxConsumerAck int64
|
||||
LastMailboxReadAt time.Time
|
||||
LastMailboxWaitMs int
|
||||
LastMailboxWaited bool
|
||||
LastMailboxTimeout bool
|
||||
LastMailboxEmpty bool
|
||||
LastMailboxResumeFrom string
|
||||
LastMailboxResumeSequence int64
|
||||
LastMailboxResumeConsumerID string
|
||||
LastMailboxAfterSequence int64
|
||||
LastMailboxSkippedCount int
|
||||
LastMailboxReturnedCount int
|
||||
LastChannelID string
|
||||
LastResourceID string
|
||||
LastRouteID string
|
||||
LastReason string
|
||||
ID string
|
||||
State string
|
||||
CreatedAt time.Time
|
||||
BoundAt time.Time
|
||||
LastActivityAt time.Time
|
||||
LastBackpressureAt time.Time
|
||||
ClosedAt time.Time
|
||||
DeliveryCount int64
|
||||
BackpressureCount int64
|
||||
AcceptedFrames int64
|
||||
DroppedFrames int64
|
||||
AckedFrames int64
|
||||
Mailbox []RemoteWorkspaceAdapterMailboxEvent
|
||||
MailboxEnqueued int64
|
||||
MailboxDrained int64
|
||||
MailboxDropped int64
|
||||
MailboxRead int64
|
||||
MailboxWait int64
|
||||
MailboxWaitTimeout int64
|
||||
MailboxEmptyRead int64
|
||||
MailboxResumeRead int64
|
||||
MailboxAfterSequenceRead int64
|
||||
MailboxReturnedTotal int64
|
||||
MailboxSkippedTotal int64
|
||||
MailboxPreflightTotal int64
|
||||
MailboxPreflightAckTotal int64
|
||||
MailboxPreflightCheckpointTotal int64
|
||||
MailboxPreflightOperatorStatusCounts map[string]int64
|
||||
MailboxPreflightOperatorSeverityCounts map[string]int64
|
||||
MailboxConsumers map[string]*remoteWorkspaceAdapterMailboxConsumerState
|
||||
MailboxConsumerReadTotal int64
|
||||
MailboxConsumerAckTotal int64
|
||||
MailboxConsumerResetTotal int64
|
||||
MailboxConsumerEvictedTotal int64
|
||||
LastMailboxConsumerID string
|
||||
LastMailboxConsumerReadAt time.Time
|
||||
LastMailboxConsumerAckAt time.Time
|
||||
LastMailboxConsumerCheckpoint int64
|
||||
LastMailboxConsumerAck int64
|
||||
LastMailboxReadAt time.Time
|
||||
LastMailboxWaitMs int
|
||||
LastMailboxWaited bool
|
||||
LastMailboxTimeout bool
|
||||
LastMailboxEmpty bool
|
||||
LastMailboxResumeFrom string
|
||||
LastMailboxResumeSequence int64
|
||||
LastMailboxResumeConsumerID string
|
||||
LastMailboxAfterSequence int64
|
||||
LastMailboxSkippedCount int
|
||||
LastMailboxReturnedCount int
|
||||
LastMailboxPreflightAt time.Time
|
||||
LastMailboxPreflightConsumerID string
|
||||
LastMailboxPreflightResumeFrom string
|
||||
LastMailboxPreflightResumeSequence int64
|
||||
LastMailboxPreflightAfterSequence int64
|
||||
LastMailboxPreflightAvailableCount int
|
||||
LastMailboxPreflightReturnedCount int
|
||||
LastMailboxPreflightSkippedCount int
|
||||
LastMailboxPreflightFirstSequence int64
|
||||
LastMailboxPreflightLastSequence int64
|
||||
LastMailboxPreflightFirstRetained int64
|
||||
LastMailboxPreflightLastRetained int64
|
||||
LastMailboxPreflightMailboxDropped int64
|
||||
LastMailboxPreflightDiagnosticState string
|
||||
LastMailboxPreflightStaleCursor bool
|
||||
LastMailboxPreflightMissingDropped int
|
||||
LastMailboxPreflightRecommendedAction string
|
||||
LastMailboxPreflightActionHints []string
|
||||
LastMailboxPreflightActionReason string
|
||||
LastMailboxPreflightActionContext map[string]any
|
||||
LastMailboxPreflightOperatorSummary string
|
||||
LastMailboxPreflightOperatorStatus string
|
||||
LastMailboxPreflightOperatorSeverity string
|
||||
LastMailboxPreflightOperatorFields map[string]any
|
||||
LastChannelID string
|
||||
LastResourceID string
|
||||
LastRouteID string
|
||||
LastReason string
|
||||
}
|
||||
|
||||
type remoteWorkspaceAdapterMailboxConsumerState struct {
|
||||
@@ -251,29 +308,43 @@ type RemoteWorkspaceAdapterMailboxConsumer struct {
|
||||
}
|
||||
|
||||
type RemoteWorkspaceAdapterMailboxPreflightSnapshot struct {
|
||||
SchemaVersion string `json:"schema_version"`
|
||||
AdapterRuntimeID string `json:"adapter_runtime_id"`
|
||||
AdapterSessionID string `json:"adapter_session_id"`
|
||||
ObservedAt string `json:"observed_at"`
|
||||
ReadOnly bool `json:"read_only"`
|
||||
ConsumerID string `json:"consumer_id"`
|
||||
ResumeFrom string `json:"resume_from"`
|
||||
ResumeSequence int64 `json:"resume_sequence"`
|
||||
AfterSequence int64 `json:"after_sequence"`
|
||||
Limit int `json:"limit"`
|
||||
MailboxDepth int `json:"mailbox_depth"`
|
||||
MailboxEnqueued int64 `json:"mailbox_enqueued_total"`
|
||||
MailboxReadTotal int64 `json:"mailbox_read_total"`
|
||||
ConsumerReadTotal int64 `json:"consumer_read_total"`
|
||||
ConsumerAckTotal int64 `json:"consumer_ack_total"`
|
||||
ConsumerCheckpointSequence int64 `json:"consumer_checkpoint_sequence"`
|
||||
ConsumerAckSequence int64 `json:"consumer_ack_sequence"`
|
||||
ConsumerLagCount int `json:"consumer_lag_count"`
|
||||
ExpectedAvailableCount int `json:"expected_available_count"`
|
||||
ExpectedReturnedCount int `json:"expected_returned_count"`
|
||||
ExpectedSkippedCount int `json:"expected_skipped_count"`
|
||||
FirstExpectedSequence int64 `json:"first_expected_sequence,omitempty"`
|
||||
LastExpectedSequence int64 `json:"last_expected_sequence,omitempty"`
|
||||
SchemaVersion string `json:"schema_version"`
|
||||
AdapterRuntimeID string `json:"adapter_runtime_id"`
|
||||
AdapterSessionID string `json:"adapter_session_id"`
|
||||
ObservedAt string `json:"observed_at"`
|
||||
ReadOnly bool `json:"read_only"`
|
||||
ConsumerID string `json:"consumer_id"`
|
||||
ResumeFrom string `json:"resume_from"`
|
||||
ResumeSequence int64 `json:"resume_sequence"`
|
||||
AfterSequence int64 `json:"after_sequence"`
|
||||
Limit int `json:"limit"`
|
||||
MailboxDepth int `json:"mailbox_depth"`
|
||||
MailboxEnqueued int64 `json:"mailbox_enqueued_total"`
|
||||
MailboxDropped int64 `json:"mailbox_dropped_total"`
|
||||
MailboxReadTotal int64 `json:"mailbox_read_total"`
|
||||
ConsumerReadTotal int64 `json:"consumer_read_total"`
|
||||
ConsumerAckTotal int64 `json:"consumer_ack_total"`
|
||||
ConsumerCheckpointSequence int64 `json:"consumer_checkpoint_sequence"`
|
||||
ConsumerAckSequence int64 `json:"consumer_ack_sequence"`
|
||||
ConsumerLagCount int `json:"consumer_lag_count"`
|
||||
ExpectedAvailableCount int `json:"expected_available_count"`
|
||||
ExpectedReturnedCount int `json:"expected_returned_count"`
|
||||
ExpectedSkippedCount int `json:"expected_skipped_count"`
|
||||
FirstExpectedSequence int64 `json:"first_expected_sequence,omitempty"`
|
||||
LastExpectedSequence int64 `json:"last_expected_sequence,omitempty"`
|
||||
FirstRetainedSequence int64 `json:"first_retained_sequence,omitempty"`
|
||||
LastRetainedSequence int64 `json:"last_retained_sequence,omitempty"`
|
||||
DiagnosticState string `json:"diagnostic_state"`
|
||||
StaleCursor bool `json:"stale_cursor"`
|
||||
MissingDroppedCount int `json:"missing_dropped_count"`
|
||||
RecommendedAction string `json:"recommended_action"`
|
||||
ActionHints []string `json:"action_hints"`
|
||||
ActionReason string `json:"action_reason"`
|
||||
ActionContext map[string]any `json:"action_context"`
|
||||
OperatorSummary string `json:"operator_summary"`
|
||||
OperatorStatus string `json:"operator_status"`
|
||||
OperatorSeverity string `json:"operator_severity"`
|
||||
OperatorSummaryFields map[string]any `json:"operator_summary_fields"`
|
||||
}
|
||||
|
||||
type RemoteWorkspaceAdapterSessionSnapshot struct {
|
||||
@@ -646,11 +717,13 @@ func (s *RemoteWorkspaceFrameProbeSink) ensureSessionLocked(delivery RemoteWorks
|
||||
session := s.sessions[sessionID]
|
||||
if session == nil {
|
||||
session = &remoteWorkspaceAdapterProbeSession{
|
||||
ID: sessionID,
|
||||
State: "created",
|
||||
CreatedAt: now,
|
||||
LastActivityAt: now,
|
||||
MailboxConsumers: map[string]*remoteWorkspaceAdapterMailboxConsumerState{},
|
||||
ID: sessionID,
|
||||
State: "created",
|
||||
CreatedAt: now,
|
||||
LastActivityAt: now,
|
||||
MailboxConsumers: map[string]*remoteWorkspaceAdapterMailboxConsumerState{},
|
||||
MailboxPreflightOperatorStatusCounts: map[string]int64{},
|
||||
MailboxPreflightOperatorSeverityCounts: map[string]int64{},
|
||||
}
|
||||
s.sessions[sessionID] = session
|
||||
s.sessionCreatedTotal++
|
||||
@@ -1180,7 +1253,74 @@ func (s *RemoteWorkspaceFrameProbeSink) PreflightAdapterSessionMailboxConsumerRe
|
||||
firstExpected = session.Mailbox[startIndex].Sequence
|
||||
lastExpected = session.Mailbox[startIndex+returned-1].Sequence
|
||||
}
|
||||
return RemoteWorkspaceAdapterMailboxPreflightSnapshot{
|
||||
var firstRetained int64
|
||||
var lastRetained int64
|
||||
if len(session.Mailbox) > 0 {
|
||||
firstRetained = session.Mailbox[0].Sequence
|
||||
lastRetained = session.Mailbox[len(session.Mailbox)-1].Sequence
|
||||
}
|
||||
diagnosticState := "ready"
|
||||
staleCursor := false
|
||||
missingDropped := 0
|
||||
recommendedAction := "resume_from_cursor"
|
||||
actionHints := []string{"resume_from_requested_cursor"}
|
||||
actionReason := "cursor_window_available"
|
||||
if firstRetained > 0 && resumeSequence < firstRetained-1 {
|
||||
diagnosticState = "stale_cursor_gap"
|
||||
staleCursor = true
|
||||
missingDropped = int(firstRetained - resumeSequence - 1)
|
||||
recommendedAction = "reset_consumer_and_resync"
|
||||
actionHints = []string{"reset_consumer_cursor", "request_full_adapter_resync", "resume_from_checkpoint_after_resync"}
|
||||
actionReason = "consumer_cursor_before_first_retained_sequence"
|
||||
} else if returned == 0 {
|
||||
diagnosticState = "caught_up"
|
||||
recommendedAction = "wait_for_new_mailbox_events"
|
||||
actionHints = []string{"keep_consumer_cursor", "long_poll_after_sequence"}
|
||||
actionReason = "cursor_caught_up_to_retained_mailbox"
|
||||
}
|
||||
actionContext := map[string]any{
|
||||
"consumer_id": consumerID,
|
||||
"resume_from": resumeFrom,
|
||||
"resume_sequence": resumeSequence,
|
||||
"first_retained_sequence": firstRetained,
|
||||
"last_retained_sequence": lastRetained,
|
||||
"mailbox_depth": len(session.Mailbox),
|
||||
"mailbox_dropped_total": session.MailboxDropped,
|
||||
"missing_dropped_count": missingDropped,
|
||||
"expected_available_count": available,
|
||||
"expected_returned_count": returned,
|
||||
"expected_skipped_count": startIndex,
|
||||
"consumer_checkpoint_sequence": consumer.CheckpointSequence,
|
||||
"consumer_ack_sequence": consumer.AckSequence,
|
||||
}
|
||||
operatorSummary := "consumer cursor can resume from requested window"
|
||||
operatorStatus := "ready_to_resume"
|
||||
operatorSeverity := "ok"
|
||||
if diagnosticState == "stale_cursor_gap" {
|
||||
operatorSummary = "stale cursor gap: reset consumer and resync before resume"
|
||||
operatorStatus = "resync_required"
|
||||
operatorSeverity = "warn"
|
||||
} else if diagnosticState == "caught_up" {
|
||||
operatorSummary = "consumer cursor is caught up; wait for new mailbox events"
|
||||
operatorStatus = "caught_up"
|
||||
operatorSeverity = "info"
|
||||
}
|
||||
operatorSummaryFields := map[string]any{
|
||||
"diagnostic_state": diagnosticState,
|
||||
"recommended_action": recommendedAction,
|
||||
"action_reason": actionReason,
|
||||
"operator_status": operatorStatus,
|
||||
"operator_severity": operatorSeverity,
|
||||
"resume_from": resumeFrom,
|
||||
"resume_sequence": resumeSequence,
|
||||
"first_retained_sequence": firstRetained,
|
||||
"last_retained_sequence": lastRetained,
|
||||
"missing_dropped_count": missingDropped,
|
||||
"expected_available_count": available,
|
||||
"expected_returned_count": returned,
|
||||
"expected_skipped_count": startIndex,
|
||||
}
|
||||
snapshot := RemoteWorkspaceAdapterMailboxPreflightSnapshot{
|
||||
SchemaVersion: "rap.remote_workspace_adapter_mailbox_preflight.v1",
|
||||
AdapterRuntimeID: RemoteWorkspaceFrameProbeSinkRuntimeID,
|
||||
AdapterSessionID: adapterSessionID,
|
||||
@@ -1193,6 +1333,7 @@ func (s *RemoteWorkspaceFrameProbeSink) PreflightAdapterSessionMailboxConsumerRe
|
||||
Limit: limit,
|
||||
MailboxDepth: len(session.Mailbox),
|
||||
MailboxEnqueued: session.MailboxEnqueued,
|
||||
MailboxDropped: session.MailboxDropped,
|
||||
MailboxReadTotal: session.MailboxRead,
|
||||
ConsumerReadTotal: session.MailboxConsumerReadTotal,
|
||||
ConsumerAckTotal: session.MailboxConsumerAckTotal,
|
||||
@@ -1204,7 +1345,236 @@ func (s *RemoteWorkspaceFrameProbeSink) PreflightAdapterSessionMailboxConsumerRe
|
||||
ExpectedSkippedCount: startIndex,
|
||||
FirstExpectedSequence: firstExpected,
|
||||
LastExpectedSequence: lastExpected,
|
||||
}, nil
|
||||
FirstRetainedSequence: firstRetained,
|
||||
LastRetainedSequence: lastRetained,
|
||||
DiagnosticState: diagnosticState,
|
||||
StaleCursor: staleCursor,
|
||||
MissingDroppedCount: missingDropped,
|
||||
RecommendedAction: recommendedAction,
|
||||
ActionHints: actionHints,
|
||||
ActionReason: actionReason,
|
||||
ActionContext: actionContext,
|
||||
OperatorSummary: operatorSummary,
|
||||
OperatorStatus: operatorStatus,
|
||||
OperatorSeverity: operatorSeverity,
|
||||
OperatorSummaryFields: operatorSummaryFields,
|
||||
}
|
||||
s.recordAdapterSessionMailboxPreflightLocked(session, snapshot, now)
|
||||
return snapshot, nil
|
||||
}
|
||||
|
||||
func (s *RemoteWorkspaceFrameProbeSink) recordAdapterSessionMailboxPreflightLocked(session *remoteWorkspaceAdapterProbeSession, snapshot RemoteWorkspaceAdapterMailboxPreflightSnapshot, now time.Time) {
|
||||
s.mailboxPreflightTotal++
|
||||
if snapshot.ResumeFrom == "ack" {
|
||||
s.mailboxPreflightAckTotal++
|
||||
}
|
||||
if snapshot.ResumeFrom == "checkpoint" {
|
||||
s.mailboxPreflightCheckpointTotal++
|
||||
}
|
||||
s.lastMailboxPreflightAt = now.Format(time.RFC3339Nano)
|
||||
s.lastMailboxPreflightAdapterSessionID = snapshot.AdapterSessionID
|
||||
s.lastMailboxPreflightConsumerID = snapshot.ConsumerID
|
||||
s.lastMailboxPreflightResumeFrom = snapshot.ResumeFrom
|
||||
s.lastMailboxPreflightResumeSequence = snapshot.ResumeSequence
|
||||
s.lastMailboxPreflightAfterSequence = snapshot.AfterSequence
|
||||
s.lastMailboxPreflightAvailableCount = snapshot.ExpectedAvailableCount
|
||||
s.lastMailboxPreflightReturnedCount = snapshot.ExpectedReturnedCount
|
||||
s.lastMailboxPreflightSkippedCount = snapshot.ExpectedSkippedCount
|
||||
s.lastMailboxPreflightFirstSequence = snapshot.FirstExpectedSequence
|
||||
s.lastMailboxPreflightLastSequence = snapshot.LastExpectedSequence
|
||||
s.lastMailboxPreflightFirstRetained = snapshot.FirstRetainedSequence
|
||||
s.lastMailboxPreflightLastRetained = snapshot.LastRetainedSequence
|
||||
s.lastMailboxPreflightMailboxDropped = snapshot.MailboxDropped
|
||||
s.lastMailboxPreflightDiagnosticState = snapshot.DiagnosticState
|
||||
s.lastMailboxPreflightStaleCursor = snapshot.StaleCursor
|
||||
s.lastMailboxPreflightMissingDropped = snapshot.MissingDroppedCount
|
||||
s.lastMailboxPreflightRecommendedAction = snapshot.RecommendedAction
|
||||
s.lastMailboxPreflightActionHints = append([]string(nil), snapshot.ActionHints...)
|
||||
s.lastMailboxPreflightActionReason = snapshot.ActionReason
|
||||
s.lastMailboxPreflightActionContext = cloneStringAnyMap(snapshot.ActionContext)
|
||||
s.lastMailboxPreflightOperatorSummary = snapshot.OperatorSummary
|
||||
s.lastMailboxPreflightOperatorStatus = snapshot.OperatorStatus
|
||||
s.lastMailboxPreflightOperatorSeverity = snapshot.OperatorSeverity
|
||||
s.lastMailboxPreflightOperatorFields = cloneStringAnyMap(snapshot.OperatorSummaryFields)
|
||||
if session == nil {
|
||||
return
|
||||
}
|
||||
session.MailboxPreflightTotal++
|
||||
if snapshot.ResumeFrom == "ack" {
|
||||
session.MailboxPreflightAckTotal++
|
||||
}
|
||||
if snapshot.ResumeFrom == "checkpoint" {
|
||||
session.MailboxPreflightCheckpointTotal++
|
||||
}
|
||||
incrementStringInt64Map(&session.MailboxPreflightOperatorStatusCounts, snapshot.OperatorStatus)
|
||||
incrementStringInt64Map(&session.MailboxPreflightOperatorSeverityCounts, snapshot.OperatorSeverity)
|
||||
session.LastMailboxPreflightAt = now
|
||||
session.LastMailboxPreflightConsumerID = snapshot.ConsumerID
|
||||
session.LastMailboxPreflightResumeFrom = snapshot.ResumeFrom
|
||||
session.LastMailboxPreflightResumeSequence = snapshot.ResumeSequence
|
||||
session.LastMailboxPreflightAfterSequence = snapshot.AfterSequence
|
||||
session.LastMailboxPreflightAvailableCount = snapshot.ExpectedAvailableCount
|
||||
session.LastMailboxPreflightReturnedCount = snapshot.ExpectedReturnedCount
|
||||
session.LastMailboxPreflightSkippedCount = snapshot.ExpectedSkippedCount
|
||||
session.LastMailboxPreflightFirstSequence = snapshot.FirstExpectedSequence
|
||||
session.LastMailboxPreflightLastSequence = snapshot.LastExpectedSequence
|
||||
session.LastMailboxPreflightFirstRetained = snapshot.FirstRetainedSequence
|
||||
session.LastMailboxPreflightLastRetained = snapshot.LastRetainedSequence
|
||||
session.LastMailboxPreflightMailboxDropped = snapshot.MailboxDropped
|
||||
session.LastMailboxPreflightDiagnosticState = snapshot.DiagnosticState
|
||||
session.LastMailboxPreflightStaleCursor = snapshot.StaleCursor
|
||||
session.LastMailboxPreflightMissingDropped = snapshot.MissingDroppedCount
|
||||
session.LastMailboxPreflightRecommendedAction = snapshot.RecommendedAction
|
||||
session.LastMailboxPreflightActionHints = append([]string(nil), snapshot.ActionHints...)
|
||||
session.LastMailboxPreflightActionReason = snapshot.ActionReason
|
||||
session.LastMailboxPreflightActionContext = cloneStringAnyMap(snapshot.ActionContext)
|
||||
session.LastMailboxPreflightOperatorSummary = snapshot.OperatorSummary
|
||||
session.LastMailboxPreflightOperatorStatus = snapshot.OperatorStatus
|
||||
session.LastMailboxPreflightOperatorSeverity = snapshot.OperatorSeverity
|
||||
session.LastMailboxPreflightOperatorFields = cloneStringAnyMap(snapshot.OperatorSummaryFields)
|
||||
}
|
||||
|
||||
func cloneStringAnyMap(source map[string]any) map[string]any {
|
||||
if source == nil {
|
||||
return nil
|
||||
}
|
||||
clone := make(map[string]any, len(source))
|
||||
for key, value := range source {
|
||||
clone[key] = value
|
||||
}
|
||||
return clone
|
||||
}
|
||||
|
||||
func cloneStringInt64Map(source map[string]int64) map[string]int64 {
|
||||
if source == nil {
|
||||
return nil
|
||||
}
|
||||
clone := make(map[string]int64, len(source))
|
||||
for key, value := range source {
|
||||
clone[key] = value
|
||||
}
|
||||
return clone
|
||||
}
|
||||
|
||||
func incrementStringInt64Map(target *map[string]int64, key string) {
|
||||
key = strings.TrimSpace(key)
|
||||
if key == "" || target == nil {
|
||||
return
|
||||
}
|
||||
if *target == nil {
|
||||
*target = map[string]int64{}
|
||||
}
|
||||
(*target)[key]++
|
||||
}
|
||||
|
||||
func remoteWorkspacePreflightAttentionStatus(statusCounts map[string]int64, severityCounts map[string]int64) string {
|
||||
resyncCount := statusCounts["resync_required"]
|
||||
warnCount := severityCounts["warn"]
|
||||
if resyncCount > 1 || warnCount > 1 {
|
||||
return "repeated_resync_required"
|
||||
}
|
||||
if resyncCount > 0 || warnCount > 0 {
|
||||
return "needs_attention"
|
||||
}
|
||||
if statusCounts["ready_to_resume"] > 0 || statusCounts["caught_up"] > 0 || severityCounts["ok"] > 0 || severityCounts["info"] > 0 {
|
||||
return "clean"
|
||||
}
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
func remoteWorkspacePreflightAttentionReason(status string, statusCounts map[string]int64, severityCounts map[string]int64) string {
|
||||
switch status {
|
||||
case "repeated_resync_required":
|
||||
return "resync_required_preflight_repeated"
|
||||
case "needs_attention":
|
||||
if statusCounts["resync_required"] > 0 {
|
||||
return "resync_required_preflight_observed"
|
||||
}
|
||||
if severityCounts["warn"] > 0 {
|
||||
return "warn_preflight_observed"
|
||||
}
|
||||
return "attention_preflight_observed"
|
||||
case "clean":
|
||||
return "no_resync_required_preflight_observed"
|
||||
default:
|
||||
return "no_preflight_observed"
|
||||
}
|
||||
}
|
||||
|
||||
func remoteWorkspacePreflightRemediationChecklist(operatorStatus string, actionHints []string) []map[string]any {
|
||||
hints := map[string]bool{}
|
||||
for _, hint := range actionHints {
|
||||
hints[hint] = true
|
||||
}
|
||||
if operatorStatus == "resync_required" {
|
||||
return []map[string]any{
|
||||
{
|
||||
"step": "reset_consumer_cursor",
|
||||
"required": true,
|
||||
"satisfied": false,
|
||||
"source_hint": hints["reset_consumer_cursor"],
|
||||
},
|
||||
{
|
||||
"step": "request_full_adapter_resync",
|
||||
"required": true,
|
||||
"satisfied": false,
|
||||
"source_hint": hints["request_full_adapter_resync"],
|
||||
},
|
||||
{
|
||||
"step": "resume_from_checkpoint_after_resync",
|
||||
"required": true,
|
||||
"satisfied": false,
|
||||
"source_hint": hints["resume_from_checkpoint_after_resync"],
|
||||
},
|
||||
}
|
||||
}
|
||||
if operatorStatus == "ready_to_resume" {
|
||||
return []map[string]any{{
|
||||
"step": "resume_from_requested_cursor",
|
||||
"required": true,
|
||||
"satisfied": true,
|
||||
"source_hint": hints["resume_from_requested_cursor"],
|
||||
}}
|
||||
}
|
||||
return []map[string]any{{
|
||||
"step": "wait_for_new_mailbox_events",
|
||||
"required": true,
|
||||
"satisfied": false,
|
||||
"source_hint": hints["long_poll_after_sequence"] || hints["keep_consumer_cursor"],
|
||||
}}
|
||||
}
|
||||
|
||||
func remoteWorkspacePreflightRemediationChecklistSummary(checklist []map[string]any) map[string]any {
|
||||
total := len(checklist)
|
||||
required := 0
|
||||
satisfied := 0
|
||||
for _, item := range checklist {
|
||||
itemRequired, _ := item["required"].(bool)
|
||||
itemSatisfied, _ := item["satisfied"].(bool)
|
||||
if itemRequired {
|
||||
required++
|
||||
if itemSatisfied {
|
||||
satisfied++
|
||||
}
|
||||
}
|
||||
}
|
||||
pending := required - satisfied
|
||||
if pending < 0 {
|
||||
pending = 0
|
||||
}
|
||||
status := "not_required"
|
||||
if required > 0 && pending == 0 {
|
||||
status = "ready"
|
||||
} else if pending > 0 {
|
||||
status = "action_required"
|
||||
}
|
||||
return map[string]any{
|
||||
"status": status,
|
||||
"total_count": total,
|
||||
"required_count": required,
|
||||
"satisfied_count": satisfied,
|
||||
"pending_count": pending,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *RemoteWorkspaceFrameProbeSink) evictOldestMailboxConsumerLocked(session *remoteWorkspaceAdapterProbeSession) bool {
|
||||
@@ -1256,25 +1626,50 @@ func countMailboxConsumersLocked(sessions map[string]*remoteWorkspaceAdapterProb
|
||||
|
||||
func remoteWorkspaceAdapterRuntimeReadinessLocked(s *RemoteWorkspaceFrameProbeSink, session *remoteWorkspaceAdapterProbeSession, now time.Time) map[string]any {
|
||||
readiness := map[string]any{
|
||||
"schema_version": "rap.remote_workspace_adapter_runtime_readiness.v1",
|
||||
"adapter_runtime_id": RemoteWorkspaceFrameProbeSinkRuntimeID,
|
||||
"observed_at": now.UTC().Format(time.RFC3339Nano),
|
||||
"probe_only": true,
|
||||
"payload_traffic": "none",
|
||||
"status": "idle",
|
||||
"diagnostic_state": "waiting_for_session",
|
||||
"ready": false,
|
||||
"active_session_count": len(s.sessions),
|
||||
"terminal_session_count": len(s.terminalSessions),
|
||||
"mailbox_capacity": DefaultRemoteWorkspaceAdapterMailboxCapacity,
|
||||
"consumer_capacity": DefaultRemoteWorkspaceAdapterMailboxConsumerCapacity,
|
||||
"mailbox_read_total": s.mailboxReadTotal,
|
||||
"mailbox_resume_total": s.mailboxResumeReadTotal,
|
||||
"schema_version": "rap.remote_workspace_adapter_runtime_readiness.v1",
|
||||
"adapter_runtime_id": RemoteWorkspaceFrameProbeSinkRuntimeID,
|
||||
"observed_at": now.UTC().Format(time.RFC3339Nano),
|
||||
"probe_only": true,
|
||||
"payload_traffic": "none",
|
||||
"status": "idle",
|
||||
"diagnostic_state": "waiting_for_session",
|
||||
"ready": false,
|
||||
"active_session_count": len(s.sessions),
|
||||
"terminal_session_count": len(s.terminalSessions),
|
||||
"mailbox_capacity": DefaultRemoteWorkspaceAdapterMailboxCapacity,
|
||||
"consumer_capacity": DefaultRemoteWorkspaceAdapterMailboxConsumerCapacity,
|
||||
"mailbox_read_total": s.mailboxReadTotal,
|
||||
"mailbox_resume_total": s.mailboxResumeReadTotal,
|
||||
"mailbox_preflight_total": s.mailboxPreflightTotal,
|
||||
}
|
||||
if session == nil {
|
||||
if s.sequence == 0 {
|
||||
readiness["no_session_summary"] = map[string]any{
|
||||
"schema_version": "rap.remote_workspace_adapter_no_session_summary.v1",
|
||||
"summary_contract": []string{"status", "diagnostic_state", "active_session_count", "terminal_session_count"},
|
||||
"summary_features": map[string]bool{"status": true, "diagnostic_state": true, "active_session_count": true, "terminal_session_count": true},
|
||||
"status": "idle",
|
||||
"diagnostic_state": "waiting_for_session",
|
||||
"active_session_count": len(s.sessions),
|
||||
"terminal_session_count": len(s.terminalSessions),
|
||||
}
|
||||
}
|
||||
if s.sequence > 0 {
|
||||
readiness["last_adapter_session_id"] = s.last.AdapterSessionID
|
||||
readiness["last_session_state"] = s.last.SessionState
|
||||
lastSessionState := s.last.SessionState
|
||||
if terminal, ok := s.terminalSessions[s.last.AdapterSessionID]; ok {
|
||||
lastSessionState = terminal.State
|
||||
readiness["terminal_session_summary"] = map[string]any{
|
||||
"schema_version": "rap.remote_workspace_adapter_terminal_session_summary.v1",
|
||||
"summary_contract": []string{"adapter_session_id", "session_state", "reason", "controlled_at"},
|
||||
"summary_features": map[string]bool{"adapter_session_id": true, "session_state": true, "reason": true, "controlled_at": true},
|
||||
"adapter_session_id": s.last.AdapterSessionID,
|
||||
"session_state": terminal.State,
|
||||
"reason": terminal.Reason,
|
||||
"controlled_at": terminal.ControlledAt.Format(time.RFC3339Nano),
|
||||
}
|
||||
}
|
||||
readiness["last_session_state"] = lastSessionState
|
||||
readiness["diagnostic_state"] = "last_session_terminal_or_expired"
|
||||
}
|
||||
return readiness
|
||||
@@ -1299,6 +1694,13 @@ func remoteWorkspaceAdapterRuntimeReadinessLocked(s *RemoteWorkspaceFrameProbeSi
|
||||
readiness["mailbox_enqueued_total"] = session.MailboxEnqueued
|
||||
readiness["mailbox_read_total"] = session.MailboxRead
|
||||
readiness["mailbox_resume_read_total"] = session.MailboxResumeRead
|
||||
readiness["mailbox_preflight_total"] = session.MailboxPreflightTotal
|
||||
readiness["mailbox_preflight_operator_status_counts"] = cloneStringInt64Map(session.MailboxPreflightOperatorStatusCounts)
|
||||
readiness["mailbox_preflight_operator_severity_counts"] = cloneStringInt64Map(session.MailboxPreflightOperatorSeverityCounts)
|
||||
preflightAttentionStatus := remoteWorkspacePreflightAttentionStatus(session.MailboxPreflightOperatorStatusCounts, session.MailboxPreflightOperatorSeverityCounts)
|
||||
preflightAttentionReason := remoteWorkspacePreflightAttentionReason(preflightAttentionStatus, session.MailboxPreflightOperatorStatusCounts, session.MailboxPreflightOperatorSeverityCounts)
|
||||
readiness["preflight_attention_status"] = preflightAttentionStatus
|
||||
readiness["preflight_attention_reason"] = preflightAttentionReason
|
||||
readiness["mailbox_after_sequence_read_total"] = session.MailboxAfterSequenceRead
|
||||
readiness["mailbox_returned_total"] = session.MailboxReturnedTotal
|
||||
readiness["mailbox_skipped_total"] = session.MailboxSkippedTotal
|
||||
@@ -1315,6 +1717,66 @@ func remoteWorkspaceAdapterRuntimeReadinessLocked(s *RemoteWorkspaceFrameProbeSi
|
||||
readiness["last_after_sequence"] = session.LastMailboxAfterSequence
|
||||
readiness["last_returned_count"] = session.LastMailboxReturnedCount
|
||||
readiness["last_skipped_count"] = session.LastMailboxSkippedCount
|
||||
readiness["last_preflight_consumer_id"] = session.LastMailboxPreflightConsumerID
|
||||
readiness["last_preflight_resume_from"] = session.LastMailboxPreflightResumeFrom
|
||||
readiness["last_preflight_resume_sequence"] = session.LastMailboxPreflightResumeSequence
|
||||
readiness["last_preflight_available_count"] = session.LastMailboxPreflightAvailableCount
|
||||
readiness["last_preflight_returned_count"] = session.LastMailboxPreflightReturnedCount
|
||||
readiness["last_preflight_skipped_count"] = session.LastMailboxPreflightSkippedCount
|
||||
readiness["last_preflight_diagnostic_state"] = session.LastMailboxPreflightDiagnosticState
|
||||
readiness["last_preflight_stale_cursor"] = session.LastMailboxPreflightStaleCursor
|
||||
readiness["last_preflight_missing_dropped_count"] = session.LastMailboxPreflightMissingDropped
|
||||
readiness["last_preflight_recommended_action"] = session.LastMailboxPreflightRecommendedAction
|
||||
readiness["last_preflight_action_hints"] = append([]string(nil), session.LastMailboxPreflightActionHints...)
|
||||
readiness["last_preflight_action_reason"] = session.LastMailboxPreflightActionReason
|
||||
readiness["last_preflight_action_context"] = cloneStringAnyMap(session.LastMailboxPreflightActionContext)
|
||||
readiness["last_preflight_operator_summary"] = session.LastMailboxPreflightOperatorSummary
|
||||
readiness["last_preflight_operator_status"] = session.LastMailboxPreflightOperatorStatus
|
||||
readiness["last_preflight_operator_severity"] = session.LastMailboxPreflightOperatorSeverity
|
||||
readiness["last_preflight_operator_summary_fields"] = cloneStringAnyMap(session.LastMailboxPreflightOperatorFields)
|
||||
if session.MailboxPreflightTotal > 0 {
|
||||
remediationChecklist := remoteWorkspacePreflightRemediationChecklist(session.LastMailboxPreflightOperatorStatus, session.LastMailboxPreflightActionHints)
|
||||
remediationChecklistSummary := remoteWorkspacePreflightRemediationChecklistSummary(remediationChecklist)
|
||||
readiness["last_preflight"] = map[string]any{
|
||||
"diagnostics_schema_version": "rap.remote_workspace_adapter_mailbox_preflight_diagnostics.v1",
|
||||
"diagnostics_contract": []string{"retained_window", "remediation_checklist", "attention", "operator_counts"},
|
||||
"diagnostics_features": map[string]bool{"retained_window": true, "remediation_checklist": true, "attention": true, "operator_counts": true},
|
||||
"observed_at": session.LastMailboxPreflightAt.Format(time.RFC3339Nano),
|
||||
"consumer_id": session.LastMailboxPreflightConsumerID,
|
||||
"resume_from": session.LastMailboxPreflightResumeFrom,
|
||||
"resume_sequence": session.LastMailboxPreflightResumeSequence,
|
||||
"after_sequence": session.LastMailboxPreflightAfterSequence,
|
||||
"available_count": session.LastMailboxPreflightAvailableCount,
|
||||
"returned_count": session.LastMailboxPreflightReturnedCount,
|
||||
"skipped_count": session.LastMailboxPreflightSkippedCount,
|
||||
"first_sequence": session.LastMailboxPreflightFirstSequence,
|
||||
"last_sequence": session.LastMailboxPreflightLastSequence,
|
||||
"first_retained_sequence": session.LastMailboxPreflightFirstRetained,
|
||||
"last_retained_sequence": session.LastMailboxPreflightLastRetained,
|
||||
"mailbox_dropped_total": session.LastMailboxPreflightMailboxDropped,
|
||||
"diagnostic_state": session.LastMailboxPreflightDiagnosticState,
|
||||
"stale_cursor": session.LastMailboxPreflightStaleCursor,
|
||||
"missing_dropped_count": session.LastMailboxPreflightMissingDropped,
|
||||
"recommended_action": session.LastMailboxPreflightRecommendedAction,
|
||||
"action_hints": append([]string(nil), session.LastMailboxPreflightActionHints...),
|
||||
"action_reason": session.LastMailboxPreflightActionReason,
|
||||
"action_context": cloneStringAnyMap(session.LastMailboxPreflightActionContext),
|
||||
"remediation_checklist": remediationChecklist,
|
||||
"remediation_checklist_status": remediationChecklistSummary["status"],
|
||||
"remediation_checklist_counts": remediationChecklistSummary,
|
||||
"operator_summary": session.LastMailboxPreflightOperatorSummary,
|
||||
"operator_status": session.LastMailboxPreflightOperatorStatus,
|
||||
"operator_severity": session.LastMailboxPreflightOperatorSeverity,
|
||||
"operator_summary_fields": cloneStringAnyMap(session.LastMailboxPreflightOperatorFields),
|
||||
"mailbox_preflight_total": session.MailboxPreflightTotal,
|
||||
"mailbox_preflight_ack_total": session.MailboxPreflightAckTotal,
|
||||
"mailbox_preflight_checkpoint_total": session.MailboxPreflightCheckpointTotal,
|
||||
"preflight_attention_status": preflightAttentionStatus,
|
||||
"preflight_attention_reason": preflightAttentionReason,
|
||||
"operator_status_counts": cloneStringInt64Map(session.MailboxPreflightOperatorStatusCounts),
|
||||
"operator_severity_counts": cloneStringInt64Map(session.MailboxPreflightOperatorSeverityCounts),
|
||||
}
|
||||
}
|
||||
if !session.LastActivityAt.IsZero() {
|
||||
readiness["last_activity_at"] = session.LastActivityAt.Format(time.RFC3339Nano)
|
||||
}
|
||||
@@ -1327,6 +1789,9 @@ func remoteWorkspaceAdapterRuntimeReadinessLocked(s *RemoteWorkspaceFrameProbeSi
|
||||
if !session.LastMailboxConsumerAckAt.IsZero() {
|
||||
readiness["last_consumer_ack_at"] = session.LastMailboxConsumerAckAt.Format(time.RFC3339Nano)
|
||||
}
|
||||
if !session.LastMailboxPreflightAt.IsZero() {
|
||||
readiness["last_preflight_at"] = session.LastMailboxPreflightAt.Format(time.RFC3339Nano)
|
||||
}
|
||||
return readiness
|
||||
}
|
||||
|
||||
@@ -1445,6 +1910,9 @@ func (s *RemoteWorkspaceFrameProbeSink) Report(now time.Time) map[string]any {
|
||||
report["mailbox_after_sequence_read_total"] = s.mailboxAfterSequenceReadTotal
|
||||
report["mailbox_returned_total"] = s.mailboxReturnedTotal
|
||||
report["mailbox_skipped_total"] = s.mailboxSkippedTotal
|
||||
report["mailbox_preflight_total"] = s.mailboxPreflightTotal
|
||||
report["mailbox_preflight_ack_total"] = s.mailboxPreflightAckTotal
|
||||
report["mailbox_preflight_checkpoint_total"] = s.mailboxPreflightCheckpointTotal
|
||||
report["mailbox_consumer_capacity"] = DefaultRemoteWorkspaceAdapterMailboxConsumerCapacity
|
||||
report["mailbox_consumer_count"] = countMailboxConsumersLocked(s.sessions)
|
||||
report["mailbox_consumer_read_total"] = s.mailboxConsumerReadTotal
|
||||
@@ -1467,6 +1935,30 @@ func (s *RemoteWorkspaceFrameProbeSink) Report(now time.Time) map[string]any {
|
||||
report["last_mailbox_resume_sequence"] = s.lastMailboxResumeSequence
|
||||
report["last_mailbox_resume_consumer_id"] = s.lastMailboxResumeConsumerID
|
||||
}
|
||||
if s.mailboxPreflightTotal > 0 {
|
||||
report["last_mailbox_preflight_at"] = s.lastMailboxPreflightAt
|
||||
report["last_mailbox_preflight_adapter_session_id"] = s.lastMailboxPreflightAdapterSessionID
|
||||
report["last_mailbox_preflight_consumer_id"] = s.lastMailboxPreflightConsumerID
|
||||
report["last_mailbox_preflight_resume_from"] = s.lastMailboxPreflightResumeFrom
|
||||
report["last_mailbox_preflight_resume_sequence"] = s.lastMailboxPreflightResumeSequence
|
||||
report["last_mailbox_preflight_after_sequence"] = s.lastMailboxPreflightAfterSequence
|
||||
report["last_mailbox_preflight_available_count"] = s.lastMailboxPreflightAvailableCount
|
||||
report["last_mailbox_preflight_returned_count"] = s.lastMailboxPreflightReturnedCount
|
||||
report["last_mailbox_preflight_skipped_count"] = s.lastMailboxPreflightSkippedCount
|
||||
report["last_mailbox_preflight_first_sequence"] = s.lastMailboxPreflightFirstSequence
|
||||
report["last_mailbox_preflight_last_sequence"] = s.lastMailboxPreflightLastSequence
|
||||
report["last_mailbox_preflight_diagnostic_state"] = s.lastMailboxPreflightDiagnosticState
|
||||
report["last_mailbox_preflight_stale_cursor"] = s.lastMailboxPreflightStaleCursor
|
||||
report["last_mailbox_preflight_missing_dropped_count"] = s.lastMailboxPreflightMissingDropped
|
||||
report["last_mailbox_preflight_recommended_action"] = s.lastMailboxPreflightRecommendedAction
|
||||
report["last_mailbox_preflight_action_hints"] = append([]string(nil), s.lastMailboxPreflightActionHints...)
|
||||
report["last_mailbox_preflight_action_reason"] = s.lastMailboxPreflightActionReason
|
||||
report["last_mailbox_preflight_action_context"] = cloneStringAnyMap(s.lastMailboxPreflightActionContext)
|
||||
report["last_mailbox_preflight_operator_summary"] = s.lastMailboxPreflightOperatorSummary
|
||||
report["last_mailbox_preflight_operator_status"] = s.lastMailboxPreflightOperatorStatus
|
||||
report["last_mailbox_preflight_operator_severity"] = s.lastMailboxPreflightOperatorSeverity
|
||||
report["last_mailbox_preflight_operator_summary_fields"] = cloneStringAnyMap(s.lastMailboxPreflightOperatorFields)
|
||||
}
|
||||
if s.mailboxConsumerReadTotal > 0 {
|
||||
report["last_mailbox_consumer_id"] = s.lastMailboxConsumerID
|
||||
report["last_mailbox_consumer_read_at"] = s.lastMailboxConsumerReadAt
|
||||
@@ -1520,6 +2012,11 @@ func (s *RemoteWorkspaceFrameProbeSink) Report(now time.Time) map[string]any {
|
||||
report["current_session_mailbox_after_sequence_read_total"] = session.MailboxAfterSequenceRead
|
||||
report["current_session_mailbox_returned_total"] = session.MailboxReturnedTotal
|
||||
report["current_session_mailbox_skipped_total"] = session.MailboxSkippedTotal
|
||||
report["current_session_mailbox_preflight_total"] = session.MailboxPreflightTotal
|
||||
report["current_session_mailbox_preflight_ack_total"] = session.MailboxPreflightAckTotal
|
||||
report["current_session_mailbox_preflight_checkpoint_total"] = session.MailboxPreflightCheckpointTotal
|
||||
report["current_session_mailbox_preflight_operator_status_counts"] = cloneStringInt64Map(session.MailboxPreflightOperatorStatusCounts)
|
||||
report["current_session_mailbox_preflight_operator_severity_counts"] = cloneStringInt64Map(session.MailboxPreflightOperatorSeverityCounts)
|
||||
report["current_session_mailbox_consumer_count"] = len(session.MailboxConsumers)
|
||||
report["current_session_mailbox_consumer_read_total"] = session.MailboxConsumerReadTotal
|
||||
report["current_session_mailbox_consumer_ack_total"] = session.MailboxConsumerAckTotal
|
||||
@@ -1549,6 +2046,29 @@ func (s *RemoteWorkspaceFrameProbeSink) Report(now time.Time) map[string]any {
|
||||
report["current_session_last_mailbox_resume_sequence"] = session.LastMailboxResumeSequence
|
||||
report["current_session_last_mailbox_resume_consumer_id"] = session.LastMailboxResumeConsumerID
|
||||
}
|
||||
if session.MailboxPreflightTotal > 0 {
|
||||
report["current_session_last_mailbox_preflight_at"] = session.LastMailboxPreflightAt.Format(time.RFC3339Nano)
|
||||
report["current_session_last_mailbox_preflight_consumer_id"] = session.LastMailboxPreflightConsumerID
|
||||
report["current_session_last_mailbox_preflight_resume_from"] = session.LastMailboxPreflightResumeFrom
|
||||
report["current_session_last_mailbox_preflight_resume_sequence"] = session.LastMailboxPreflightResumeSequence
|
||||
report["current_session_last_mailbox_preflight_after_sequence"] = session.LastMailboxPreflightAfterSequence
|
||||
report["current_session_last_mailbox_preflight_available_count"] = session.LastMailboxPreflightAvailableCount
|
||||
report["current_session_last_mailbox_preflight_returned_count"] = session.LastMailboxPreflightReturnedCount
|
||||
report["current_session_last_mailbox_preflight_skipped_count"] = session.LastMailboxPreflightSkippedCount
|
||||
report["current_session_last_mailbox_preflight_first_sequence"] = session.LastMailboxPreflightFirstSequence
|
||||
report["current_session_last_mailbox_preflight_last_sequence"] = session.LastMailboxPreflightLastSequence
|
||||
report["current_session_last_mailbox_preflight_diagnostic_state"] = session.LastMailboxPreflightDiagnosticState
|
||||
report["current_session_last_mailbox_preflight_stale_cursor"] = session.LastMailboxPreflightStaleCursor
|
||||
report["current_session_last_mailbox_preflight_missing_dropped_count"] = session.LastMailboxPreflightMissingDropped
|
||||
report["current_session_last_mailbox_preflight_recommended_action"] = session.LastMailboxPreflightRecommendedAction
|
||||
report["current_session_last_mailbox_preflight_action_hints"] = append([]string(nil), session.LastMailboxPreflightActionHints...)
|
||||
report["current_session_last_mailbox_preflight_action_reason"] = session.LastMailboxPreflightActionReason
|
||||
report["current_session_last_mailbox_preflight_action_context"] = cloneStringAnyMap(session.LastMailboxPreflightActionContext)
|
||||
report["current_session_last_mailbox_preflight_operator_summary"] = session.LastMailboxPreflightOperatorSummary
|
||||
report["current_session_last_mailbox_preflight_operator_status"] = session.LastMailboxPreflightOperatorStatus
|
||||
report["current_session_last_mailbox_preflight_operator_severity"] = session.LastMailboxPreflightOperatorSeverity
|
||||
report["current_session_last_mailbox_preflight_operator_summary_fields"] = cloneStringAnyMap(session.LastMailboxPreflightOperatorFields)
|
||||
}
|
||||
if !session.LastBackpressureAt.IsZero() {
|
||||
report["current_session_last_backpressure_at"] = session.LastBackpressureAt.Format(time.RFC3339Nano)
|
||||
report["current_session_last_backpressure_reason"] = session.LastReason
|
||||
|
||||
@@ -1643,6 +1643,44 @@ func TestRemoteWorkspaceAdapterSessionControlEndpointClosesSession(t *testing.T)
|
||||
report["last_session_control_state"] != "closed" {
|
||||
t.Fatalf("control report = %+v", report)
|
||||
}
|
||||
readiness, ok := report["adapter_runtime_readiness"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("adapter runtime readiness missing from control report = %+v", report)
|
||||
}
|
||||
if readiness["schema_version"] != "rap.remote_workspace_adapter_runtime_readiness.v1" ||
|
||||
readiness["status"] != "idle" ||
|
||||
readiness["diagnostic_state"] != "last_session_terminal_or_expired" ||
|
||||
readiness["ready"] != false ||
|
||||
readiness["active_session_count"] != 0 ||
|
||||
readiness["last_adapter_session_id"] != "rap-rw-adapter-session-aaaaaaaaaaaaaaaaaaaaaaaa" ||
|
||||
readiness["last_session_state"] != "closed" {
|
||||
t.Fatalf("invalid no-active-session readiness after close = %+v", readiness)
|
||||
}
|
||||
if _, ok := readiness["adapter_session_id"]; ok {
|
||||
t.Fatalf("adapter_session_id should be absent without active session = %+v", readiness)
|
||||
}
|
||||
if _, ok := readiness["last_preflight"]; ok {
|
||||
t.Fatalf("last_preflight should be absent without active session = %+v", readiness)
|
||||
}
|
||||
terminalSummary, ok := readiness["terminal_session_summary"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("terminal session summary missing after close = %+v", readiness)
|
||||
}
|
||||
if terminalSummary["adapter_session_id"] != "rap-rw-adapter-session-aaaaaaaaaaaaaaaaaaaaaaaa" ||
|
||||
terminalSummary["schema_version"] != "rap.remote_workspace_adapter_terminal_session_summary.v1" ||
|
||||
!stringAnySliceContains(terminalSummary["summary_contract"], "adapter_session_id") ||
|
||||
!stringAnySliceContains(terminalSummary["summary_contract"], "session_state") ||
|
||||
!stringAnySliceContains(terminalSummary["summary_contract"], "reason") ||
|
||||
!stringAnySliceContains(terminalSummary["summary_contract"], "controlled_at") ||
|
||||
!boolMapValue(terminalSummary["summary_features"], "adapter_session_id") ||
|
||||
!boolMapValue(terminalSummary["summary_features"], "session_state") ||
|
||||
!boolMapValue(terminalSummary["summary_features"], "reason") ||
|
||||
!boolMapValue(terminalSummary["summary_features"], "controlled_at") ||
|
||||
terminalSummary["session_state"] != "closed" ||
|
||||
terminalSummary["reason"] != "unit test close" ||
|
||||
terminalSummary["controlled_at"] == "" {
|
||||
t.Fatalf("invalid terminal session summary after close = %+v", terminalSummary)
|
||||
}
|
||||
|
||||
resp, err = http.Post(controlURL, "application/json", bytes.NewReader([]byte(`{"action":"close","reason":"repeat close"}`)))
|
||||
if err != nil {
|
||||
@@ -1665,6 +1703,255 @@ func TestRemoteWorkspaceAdapterSessionControlEndpointClosesSession(t *testing.T)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoteWorkspaceAdapterReadinessBeforeAnySessionHasNoTerminalSummary(t *testing.T) {
|
||||
sink := NewRemoteWorkspaceFrameProbeSink()
|
||||
report := sink.Report(time.Now().UTC())
|
||||
readiness, ok := report["adapter_runtime_readiness"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("adapter runtime readiness missing from report = %+v", report)
|
||||
}
|
||||
if readiness["schema_version"] != "rap.remote_workspace_adapter_runtime_readiness.v1" ||
|
||||
readiness["status"] != "idle" ||
|
||||
readiness["diagnostic_state"] != "waiting_for_session" ||
|
||||
readiness["ready"] != false ||
|
||||
readiness["active_session_count"] != 0 ||
|
||||
readiness["terminal_session_count"] != 0 {
|
||||
t.Fatalf("invalid empty readiness = %+v", readiness)
|
||||
}
|
||||
if _, ok := readiness["last_adapter_session_id"]; ok {
|
||||
t.Fatalf("last_adapter_session_id should be absent before any session = %+v", readiness)
|
||||
}
|
||||
if _, ok := readiness["last_session_state"]; ok {
|
||||
t.Fatalf("last_session_state should be absent before any session = %+v", readiness)
|
||||
}
|
||||
if _, ok := readiness["terminal_session_summary"]; ok {
|
||||
t.Fatalf("terminal_session_summary should be absent before terminal history = %+v", readiness)
|
||||
}
|
||||
noSessionSummary, ok := readiness["no_session_summary"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("no_session_summary should be present before any session = %+v", readiness)
|
||||
}
|
||||
if noSessionSummary["schema_version"] != "rap.remote_workspace_adapter_no_session_summary.v1" ||
|
||||
!stringAnySliceContains(noSessionSummary["summary_contract"], "status") ||
|
||||
!stringAnySliceContains(noSessionSummary["summary_contract"], "diagnostic_state") ||
|
||||
!stringAnySliceContains(noSessionSummary["summary_contract"], "active_session_count") ||
|
||||
!stringAnySliceContains(noSessionSummary["summary_contract"], "terminal_session_count") ||
|
||||
!boolMapValue(noSessionSummary["summary_features"], "status") ||
|
||||
!boolMapValue(noSessionSummary["summary_features"], "diagnostic_state") ||
|
||||
!boolMapValue(noSessionSummary["summary_features"], "active_session_count") ||
|
||||
!boolMapValue(noSessionSummary["summary_features"], "terminal_session_count") ||
|
||||
noSessionSummary["status"] != "idle" ||
|
||||
noSessionSummary["diagnostic_state"] != "waiting_for_session" ||
|
||||
noSessionSummary["active_session_count"] != 0 ||
|
||||
noSessionSummary["terminal_session_count"] != 0 {
|
||||
t.Fatalf("invalid no-session summary before any session = %+v", noSessionSummary)
|
||||
}
|
||||
if _, ok := readiness["last_preflight"]; ok {
|
||||
t.Fatalf("last_preflight should be absent before any session = %+v", readiness)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoteWorkspaceAdapterReadinessSummaryExclusivity(t *testing.T) {
|
||||
sink := NewRemoteWorkspaceFrameProbeSink()
|
||||
freshReport := sink.Report(time.Now().UTC())
|
||||
freshReadiness, ok := freshReport["adapter_runtime_readiness"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("fresh readiness missing from report = %+v", freshReport)
|
||||
}
|
||||
if _, ok := freshReadiness["no_session_summary"]; !ok {
|
||||
t.Fatalf("fresh readiness should include no_session_summary = %+v", freshReadiness)
|
||||
}
|
||||
if _, ok := freshReadiness["terminal_session_summary"]; ok {
|
||||
t.Fatalf("fresh readiness should not include terminal_session_summary = %+v", freshReadiness)
|
||||
}
|
||||
|
||||
sessionID := "rap-rw-adapter-session-d1d1d1d1d1d1d1d1d1d1d1d1"
|
||||
delivery := RemoteWorkspaceFrameBatchDelivery{
|
||||
ClusterID: "cluster-1",
|
||||
ChannelID: "channel-rw",
|
||||
ResourceID: "workspace-exclusivity",
|
||||
ServiceClass: FabricServiceClassRemoteWorkspace,
|
||||
ChannelClass: FabricServiceChannelInteractive,
|
||||
AdapterContractID: "rap.rdp_worker.remote_workspace_adapter_contract_probe.v1",
|
||||
AdapterSessionID: sessionID,
|
||||
Frames: []RemoteWorkspaceFrameProbeRecord{{
|
||||
Channel: "display",
|
||||
Direction: "adapter_to_client",
|
||||
Droppable: true,
|
||||
}},
|
||||
}
|
||||
if _, err := sink.AcceptRemoteWorkspaceFrameBatchProbe(context.Background(), delivery); err != nil {
|
||||
t.Fatalf("accept frame batch: %v", err)
|
||||
}
|
||||
activeReport := sink.Report(time.Now().UTC())
|
||||
activeReadiness, ok := activeReport["adapter_runtime_readiness"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("active readiness missing from report = %+v", activeReport)
|
||||
}
|
||||
if activeReadiness["adapter_session_id"] != sessionID ||
|
||||
activeReadiness["active_session_count"] != 1 {
|
||||
t.Fatalf("invalid active readiness = %+v", activeReadiness)
|
||||
}
|
||||
if _, ok := activeReadiness["no_session_summary"]; ok {
|
||||
t.Fatalf("active readiness should not include no_session_summary = %+v", activeReadiness)
|
||||
}
|
||||
if _, ok := activeReadiness["terminal_session_summary"]; ok {
|
||||
t.Fatalf("active readiness should not include terminal_session_summary = %+v", activeReadiness)
|
||||
}
|
||||
|
||||
server := httptest.NewServer(Server{RemoteWorkspaceFrameSink: sink}.Handler())
|
||||
defer server.Close()
|
||||
body := bytes.NewReader([]byte(`{"action":"close","reason":"unit summary exclusivity close"}`))
|
||||
resp, err := http.Post(server.URL+"/mesh/v1/remote-workspace/adapter-sessions/"+sessionID+"/control", "application/json", body)
|
||||
if err != nil {
|
||||
t.Fatalf("post control: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
raw, _ := io.ReadAll(resp.Body)
|
||||
t.Fatalf("status = %d body=%s", resp.StatusCode, string(raw))
|
||||
}
|
||||
terminalReport := sink.Report(time.Now().UTC())
|
||||
terminalReadiness, ok := terminalReport["adapter_runtime_readiness"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("terminal readiness missing from report = %+v", terminalReport)
|
||||
}
|
||||
if _, ok := terminalReadiness["terminal_session_summary"]; !ok {
|
||||
t.Fatalf("terminal readiness should include terminal_session_summary = %+v", terminalReadiness)
|
||||
}
|
||||
if _, ok := terminalReadiness["no_session_summary"]; ok {
|
||||
t.Fatalf("terminal readiness should not include no_session_summary = %+v", terminalReadiness)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoteWorkspaceAdapterSessionControlTerminalReadinessStates(t *testing.T) {
|
||||
tests := []struct {
|
||||
action string
|
||||
sessionID string
|
||||
wantState string
|
||||
wantClosed int64
|
||||
wantExpired int64
|
||||
wantReset int64
|
||||
wantPrevState string
|
||||
}{
|
||||
{
|
||||
action: "expire",
|
||||
sessionID: "rap-rw-adapter-session-b0b0b0b0b0b0b0b0b0b0b0b0",
|
||||
wantState: "expired",
|
||||
wantClosed: 1,
|
||||
wantExpired: 1,
|
||||
wantPrevState: "probe_bound",
|
||||
},
|
||||
{
|
||||
action: "reset",
|
||||
sessionID: "rap-rw-adapter-session-c0c0c0c0c0c0c0c0c0c0c0c0",
|
||||
wantState: "reset",
|
||||
wantClosed: 1,
|
||||
wantReset: 1,
|
||||
wantPrevState: "probe_bound",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.action, func(t *testing.T) {
|
||||
sink := NewRemoteWorkspaceFrameProbeSink()
|
||||
delivery := RemoteWorkspaceFrameBatchDelivery{
|
||||
ClusterID: "cluster-1",
|
||||
ChannelID: "channel-rw",
|
||||
ResourceID: "workspace-" + tt.action,
|
||||
ServiceClass: FabricServiceClassRemoteWorkspace,
|
||||
ChannelClass: FabricServiceChannelInteractive,
|
||||
AdapterContractID: "rap.rdp_worker.remote_workspace_adapter_contract_probe.v1",
|
||||
AdapterSessionID: tt.sessionID,
|
||||
Frames: []RemoteWorkspaceFrameProbeRecord{{
|
||||
Channel: "display",
|
||||
Direction: "adapter_to_client",
|
||||
Droppable: true,
|
||||
}},
|
||||
}
|
||||
if _, err := sink.AcceptRemoteWorkspaceFrameBatchProbe(context.Background(), delivery); err != nil {
|
||||
t.Fatalf("accept frame batch: %v", err)
|
||||
}
|
||||
server := httptest.NewServer(Server{RemoteWorkspaceFrameSink: sink}.Handler())
|
||||
defer server.Close()
|
||||
|
||||
body := bytes.NewReader([]byte(fmt.Sprintf(`{"action":%q,"reason":"unit terminal readiness"}`, tt.action)))
|
||||
resp, err := http.Post(server.URL+"/mesh/v1/remote-workspace/adapter-sessions/"+tt.sessionID+"/control", "application/json", body)
|
||||
if err != nil {
|
||||
t.Fatalf("post control: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
raw, _ := io.ReadAll(resp.Body)
|
||||
t.Fatalf("status = %d body=%s", resp.StatusCode, string(raw))
|
||||
}
|
||||
var result RemoteWorkspaceAdapterSessionControlResult
|
||||
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
||||
t.Fatalf("decode control result: %v", err)
|
||||
}
|
||||
if !result.Accepted ||
|
||||
result.Action != tt.action ||
|
||||
result.AdapterSessionID != tt.sessionID ||
|
||||
result.PreviousState != tt.wantPrevState ||
|
||||
result.SessionState != tt.wantState ||
|
||||
result.ActiveSessions != 0 {
|
||||
t.Fatalf("control result = %+v", result)
|
||||
}
|
||||
|
||||
report := sink.Report(time.Now().UTC())
|
||||
if report["active_session_count"] != 0 ||
|
||||
report["session_closed_total"] != tt.wantClosed ||
|
||||
report["session_expired_total"] != tt.wantExpired ||
|
||||
report["session_reset_total"] != tt.wantReset ||
|
||||
report["last_controlled_adapter_session_id"] != tt.sessionID ||
|
||||
report["last_session_control_action"] != tt.action ||
|
||||
report["last_session_control_state"] != tt.wantState {
|
||||
t.Fatalf("terminal control report = %+v", report)
|
||||
}
|
||||
readiness, ok := report["adapter_runtime_readiness"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("adapter runtime readiness missing from report = %+v", report)
|
||||
}
|
||||
if readiness["status"] != "idle" ||
|
||||
readiness["diagnostic_state"] != "last_session_terminal_or_expired" ||
|
||||
readiness["ready"] != false ||
|
||||
readiness["active_session_count"] != 0 ||
|
||||
readiness["last_adapter_session_id"] != tt.sessionID ||
|
||||
readiness["last_session_state"] != tt.wantState {
|
||||
t.Fatalf("invalid terminal readiness = %+v", readiness)
|
||||
}
|
||||
if _, ok := readiness["adapter_session_id"]; ok {
|
||||
t.Fatalf("adapter_session_id should be absent without active session = %+v", readiness)
|
||||
}
|
||||
if _, ok := readiness["last_preflight"]; ok {
|
||||
t.Fatalf("last_preflight should be absent without active session = %+v", readiness)
|
||||
}
|
||||
if _, ok := readiness["no_session_summary"]; ok {
|
||||
t.Fatalf("no_session_summary should be absent for terminal session history = %+v", readiness)
|
||||
}
|
||||
terminalSummary, ok := readiness["terminal_session_summary"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("terminal session summary missing = %+v", readiness)
|
||||
}
|
||||
if terminalSummary["adapter_session_id"] != tt.sessionID ||
|
||||
terminalSummary["schema_version"] != "rap.remote_workspace_adapter_terminal_session_summary.v1" ||
|
||||
!stringAnySliceContains(terminalSummary["summary_contract"], "adapter_session_id") ||
|
||||
!stringAnySliceContains(terminalSummary["summary_contract"], "session_state") ||
|
||||
!stringAnySliceContains(terminalSummary["summary_contract"], "reason") ||
|
||||
!stringAnySliceContains(terminalSummary["summary_contract"], "controlled_at") ||
|
||||
!boolMapValue(terminalSummary["summary_features"], "adapter_session_id") ||
|
||||
!boolMapValue(terminalSummary["summary_features"], "session_state") ||
|
||||
!boolMapValue(terminalSummary["summary_features"], "reason") ||
|
||||
!boolMapValue(terminalSummary["summary_features"], "controlled_at") ||
|
||||
terminalSummary["session_state"] != tt.wantState ||
|
||||
terminalSummary["reason"] != "unit terminal readiness" ||
|
||||
terminalSummary["controlled_at"] == "" {
|
||||
t.Fatalf("invalid terminal session summary = %+v", terminalSummary)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoteWorkspaceAdapterSessionControlRejectsInvalidRequests(t *testing.T) {
|
||||
sink := NewRemoteWorkspaceFrameProbeSink()
|
||||
server := httptest.NewServer(Server{RemoteWorkspaceFrameSink: sink}.Handler())
|
||||
@@ -3064,6 +3351,19 @@ func TestRemoteWorkspaceAdapterSessionMailboxPreflightIsReadOnly(t *testing.T) {
|
||||
}
|
||||
if preflight.ResumeFrom != "checkpoint" ||
|
||||
preflight.ResumeSequence != 2 ||
|
||||
preflight.DiagnosticState != "ready" ||
|
||||
preflight.RecommendedAction != "resume_from_cursor" ||
|
||||
preflight.ActionReason != "cursor_window_available" ||
|
||||
preflight.OperatorSummary != "consumer cursor can resume from requested window" ||
|
||||
preflight.OperatorStatus != "ready_to_resume" ||
|
||||
preflight.OperatorSeverity != "ok" ||
|
||||
anyInt64(preflight.ActionContext["resume_sequence"]) != 2 ||
|
||||
anyInt64(preflight.ActionContext["first_retained_sequence"]) != 1 ||
|
||||
preflight.OperatorSummaryFields["diagnostic_state"] != "ready" ||
|
||||
preflight.OperatorSummaryFields["recommended_action"] != "resume_from_cursor" ||
|
||||
preflight.OperatorSummaryFields["operator_status"] != "ready_to_resume" ||
|
||||
preflight.OperatorSummaryFields["operator_severity"] != "ok" ||
|
||||
!stringSliceContains(preflight.ActionHints, "resume_from_requested_cursor") ||
|
||||
preflight.ExpectedAvailableCount != 1 ||
|
||||
preflight.ExpectedReturnedCount != 1 ||
|
||||
preflight.ExpectedSkippedCount != 2 ||
|
||||
@@ -3079,6 +3379,547 @@ func TestRemoteWorkspaceAdapterSessionMailboxPreflightIsReadOnly(t *testing.T) {
|
||||
reportAfter["current_session_mailbox_consumer_ack_total"] != reportBefore["current_session_mailbox_consumer_ack_total"] {
|
||||
t.Fatalf("preflight mutated report before=%+v after=%+v", reportBefore, reportAfter)
|
||||
}
|
||||
if reportAfter["mailbox_preflight_total"] != int64(2) ||
|
||||
reportAfter["mailbox_preflight_ack_total"] != int64(1) ||
|
||||
reportAfter["mailbox_preflight_checkpoint_total"] != int64(1) ||
|
||||
reportAfter["last_mailbox_preflight_adapter_session_id"] != sessionID ||
|
||||
reportAfter["last_mailbox_preflight_consumer_id"] != "rdp-worker-probe" ||
|
||||
reportAfter["last_mailbox_preflight_resume_from"] != "checkpoint" ||
|
||||
reportAfter["last_mailbox_preflight_resume_sequence"] != int64(2) ||
|
||||
reportAfter["last_mailbox_preflight_available_count"] != 1 ||
|
||||
reportAfter["last_mailbox_preflight_returned_count"] != 1 ||
|
||||
reportAfter["last_mailbox_preflight_skipped_count"] != 2 ||
|
||||
reportAfter["current_session_mailbox_preflight_total"] != int64(2) ||
|
||||
reportAfter["current_session_mailbox_preflight_ack_total"] != int64(1) ||
|
||||
reportAfter["current_session_mailbox_preflight_checkpoint_total"] != int64(1) ||
|
||||
mapInt64Value(reportAfter["current_session_mailbox_preflight_operator_status_counts"], "ready_to_resume") != 2 ||
|
||||
mapInt64Value(reportAfter["current_session_mailbox_preflight_operator_severity_counts"], "ok") != 2 ||
|
||||
reportAfter["current_session_last_mailbox_preflight_resume_from"] != "checkpoint" ||
|
||||
reportAfter["current_session_last_mailbox_preflight_resume_sequence"] != int64(2) ||
|
||||
reportAfter["current_session_last_mailbox_preflight_returned_count"] != 1 ||
|
||||
reportAfter["current_session_last_mailbox_preflight_recommended_action"] != "resume_from_cursor" ||
|
||||
reportAfter["last_mailbox_preflight_operator_summary"] != "consumer cursor can resume from requested window" ||
|
||||
reportAfter["last_mailbox_preflight_operator_status"] != "ready_to_resume" ||
|
||||
reportAfter["last_mailbox_preflight_operator_severity"] != "ok" ||
|
||||
reportAfter["current_session_last_mailbox_preflight_operator_summary"] != "consumer cursor can resume from requested window" ||
|
||||
reportAfter["current_session_last_mailbox_preflight_operator_status"] != "ready_to_resume" ||
|
||||
reportAfter["current_session_last_mailbox_preflight_operator_severity"] != "ok" {
|
||||
t.Fatalf("invalid preflight telemetry report = %+v", reportAfter)
|
||||
}
|
||||
readiness, ok := reportAfter["adapter_runtime_readiness"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("adapter runtime readiness missing from report = %+v", reportAfter)
|
||||
}
|
||||
if readiness["mailbox_preflight_total"] != int64(2) ||
|
||||
readiness["last_preflight_consumer_id"] != "rdp-worker-probe" ||
|
||||
readiness["last_preflight_resume_from"] != "checkpoint" ||
|
||||
readiness["last_preflight_resume_sequence"] != int64(2) ||
|
||||
readiness["last_preflight_returned_count"] != 1 ||
|
||||
readiness["last_preflight_skipped_count"] != 2 ||
|
||||
readiness["last_preflight_recommended_action"] != "resume_from_cursor" ||
|
||||
readiness["last_preflight_action_reason"] != "cursor_window_available" ||
|
||||
readiness["last_preflight_operator_summary"] != "consumer cursor can resume from requested window" ||
|
||||
readiness["last_preflight_operator_status"] != "ready_to_resume" ||
|
||||
readiness["last_preflight_operator_severity"] != "ok" ||
|
||||
mapInt64Value(readiness["mailbox_preflight_operator_status_counts"], "ready_to_resume") != 2 ||
|
||||
mapInt64Value(readiness["mailbox_preflight_operator_severity_counts"], "ok") != 2 ||
|
||||
readiness["preflight_attention_status"] != "clean" ||
|
||||
readiness["preflight_attention_reason"] != "no_resync_required_preflight_observed" {
|
||||
t.Fatalf("invalid preflight readiness = %+v", readiness)
|
||||
}
|
||||
lastPreflight, ok := readiness["last_preflight"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("last preflight rollup missing from readiness = %+v", readiness)
|
||||
}
|
||||
if lastPreflight["consumer_id"] != "rdp-worker-probe" ||
|
||||
lastPreflight["diagnostics_schema_version"] != "rap.remote_workspace_adapter_mailbox_preflight_diagnostics.v1" ||
|
||||
!stringAnySliceContains(lastPreflight["diagnostics_contract"], "retained_window") ||
|
||||
!stringAnySliceContains(lastPreflight["diagnostics_contract"], "remediation_checklist") ||
|
||||
!stringAnySliceContains(lastPreflight["diagnostics_contract"], "attention") ||
|
||||
!stringAnySliceContains(lastPreflight["diagnostics_contract"], "operator_counts") ||
|
||||
!boolMapValue(lastPreflight["diagnostics_features"], "retained_window") ||
|
||||
!boolMapValue(lastPreflight["diagnostics_features"], "remediation_checklist") ||
|
||||
!boolMapValue(lastPreflight["diagnostics_features"], "attention") ||
|
||||
!boolMapValue(lastPreflight["diagnostics_features"], "operator_counts") ||
|
||||
lastPreflight["resume_from"] != "checkpoint" ||
|
||||
lastPreflight["operator_status"] != "ready_to_resume" ||
|
||||
lastPreflight["operator_severity"] != "ok" ||
|
||||
lastPreflight["recommended_action"] != "resume_from_cursor" ||
|
||||
!preflightChecklistContains(lastPreflight["remediation_checklist"], "resume_from_requested_cursor", true, true) ||
|
||||
lastPreflight["remediation_checklist_status"] != "ready" ||
|
||||
anyInt64(preflightChecklistCountsValue(lastPreflight["remediation_checklist_counts"], "required_count")) != 1 ||
|
||||
anyInt64(preflightChecklistCountsValue(lastPreflight["remediation_checklist_counts"], "satisfied_count")) != 1 ||
|
||||
anyInt64(preflightChecklistCountsValue(lastPreflight["remediation_checklist_counts"], "pending_count")) != 0 ||
|
||||
mapInt64Value(lastPreflight["operator_status_counts"], "ready_to_resume") != 2 ||
|
||||
mapInt64Value(lastPreflight["operator_severity_counts"], "ok") != 2 ||
|
||||
lastPreflight["preflight_attention_status"] != "clean" ||
|
||||
lastPreflight["preflight_attention_reason"] != "no_resync_required_preflight_observed" ||
|
||||
anyInt64(lastPreflight["resume_sequence"]) != 2 ||
|
||||
anyInt64(lastPreflight["first_retained_sequence"]) != 1 ||
|
||||
anyInt64(lastPreflight["last_retained_sequence"]) != 3 ||
|
||||
anyInt64(lastPreflight["mailbox_dropped_total"]) != 0 ||
|
||||
anyInt64(lastPreflight["mailbox_preflight_total"]) != 2 {
|
||||
t.Fatalf("invalid last preflight rollup = %+v", lastPreflight)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoteWorkspaceAdapterSessionReadinessBeforePreflight(t *testing.T) {
|
||||
sink := NewRemoteWorkspaceFrameProbeSink()
|
||||
sessionID := "rap-rw-adapter-session-a0a0a0a0a0a0a0a0a0a0a0a0"
|
||||
delivery := RemoteWorkspaceFrameBatchDelivery{
|
||||
ClusterID: "cluster-1",
|
||||
ChannelID: "channel-rw",
|
||||
ResourceID: "workspace-before-preflight",
|
||||
ServiceClass: FabricServiceClassRemoteWorkspace,
|
||||
ChannelClass: FabricServiceChannelInteractive,
|
||||
AdapterContractID: "rap.rdp_worker.remote_workspace_adapter_contract_probe.v1",
|
||||
AdapterSessionID: sessionID,
|
||||
Frames: []RemoteWorkspaceFrameProbeRecord{{
|
||||
Channel: "display",
|
||||
Direction: "adapter_to_client",
|
||||
Droppable: true,
|
||||
}},
|
||||
}
|
||||
if _, err := sink.AcceptRemoteWorkspaceFrameBatchProbe(context.Background(), delivery); err != nil {
|
||||
t.Fatalf("accept frame batch: %v", err)
|
||||
}
|
||||
|
||||
report := sink.Report(time.Now().UTC())
|
||||
if report["mailbox_preflight_total"] != int64(0) ||
|
||||
report["current_session_mailbox_preflight_total"] != int64(0) {
|
||||
t.Fatalf("unexpected preflight totals before preflight = %+v", report)
|
||||
}
|
||||
readiness, ok := report["adapter_runtime_readiness"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("adapter runtime readiness missing from report = %+v", report)
|
||||
}
|
||||
if readiness["adapter_session_id"] != sessionID ||
|
||||
readiness["mailbox_preflight_total"] != int64(0) ||
|
||||
readiness["preflight_attention_status"] != "unknown" ||
|
||||
readiness["preflight_attention_reason"] != "no_preflight_observed" {
|
||||
t.Fatalf("invalid no-preflight readiness = %+v", readiness)
|
||||
}
|
||||
if _, ok := readiness["last_preflight"]; ok {
|
||||
t.Fatalf("last preflight rollup should be absent before preflight = %+v", readiness["last_preflight"])
|
||||
}
|
||||
if readiness["last_preflight_diagnostic_state"] != "" ||
|
||||
readiness["last_preflight_recommended_action"] != "" ||
|
||||
len(readiness["last_preflight_action_hints"].([]string)) != 0 {
|
||||
t.Fatalf("last preflight flat fields should be empty before preflight = %+v", readiness)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoteWorkspaceAdapterSessionMailboxPreflightReportsStaleCursorGap(t *testing.T) {
|
||||
sink := NewRemoteWorkspaceFrameProbeSink()
|
||||
sessionID := "rap-rw-adapter-session-adadadadadadadadadadadad"
|
||||
delivery := RemoteWorkspaceFrameBatchDelivery{
|
||||
ClusterID: "cluster-1",
|
||||
ChannelID: "channel-rw",
|
||||
ResourceID: "workspace-stale-0",
|
||||
ServiceClass: FabricServiceClassRemoteWorkspace,
|
||||
ChannelClass: FabricServiceChannelInteractive,
|
||||
AdapterContractID: "rap.rdp_worker.remote_workspace_adapter_contract_probe.v1",
|
||||
AdapterSessionID: sessionID,
|
||||
Frames: []RemoteWorkspaceFrameProbeRecord{{
|
||||
Channel: "display",
|
||||
Direction: "adapter_to_client",
|
||||
Droppable: true,
|
||||
}},
|
||||
}
|
||||
if _, err := sink.AcceptRemoteWorkspaceFrameBatchProbe(context.Background(), delivery); err != nil {
|
||||
t.Fatalf("accept initial frame batch: %v", err)
|
||||
}
|
||||
server := httptest.NewServer(Server{RemoteWorkspaceFrameSink: sink}.Handler())
|
||||
defer server.Close()
|
||||
|
||||
resp, err := http.Get(server.URL + "/mesh/v1/remote-workspace/adapter-sessions/" + sessionID + "/mailbox?consumer_id=rdp-worker-probe&ack_sequence=1&limit=1")
|
||||
if err != nil {
|
||||
t.Fatalf("seed ack cursor: %v", err)
|
||||
}
|
||||
resp.Body.Close()
|
||||
for i := 1; i <= DefaultRemoteWorkspaceAdapterMailboxCapacity+2; i++ {
|
||||
delivery.ResourceID = fmt.Sprintf("workspace-stale-%d", i)
|
||||
if _, err := sink.AcceptRemoteWorkspaceFrameBatchProbe(context.Background(), delivery); err != nil {
|
||||
t.Fatalf("accept overflow frame batch %d: %v", i, err)
|
||||
}
|
||||
}
|
||||
|
||||
resp, err = http.Get(server.URL + "/mesh/v1/remote-workspace/adapter-sessions/" + sessionID + "/mailbox/preflight?consumer_id=rdp-worker-probe&resume_from=ack&limit=3")
|
||||
if err != nil {
|
||||
t.Fatalf("get stale preflight: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
var preflight RemoteWorkspaceAdapterMailboxPreflightSnapshot
|
||||
if err := json.NewDecoder(resp.Body).Decode(&preflight); err != nil {
|
||||
t.Fatalf("decode stale preflight: %v", err)
|
||||
}
|
||||
if preflight.ResumeFrom != "ack" ||
|
||||
preflight.ResumeSequence != 1 ||
|
||||
preflight.MailboxDepth != DefaultRemoteWorkspaceAdapterMailboxCapacity ||
|
||||
preflight.MailboxDropped != 3 ||
|
||||
preflight.ExpectedAvailableCount != DefaultRemoteWorkspaceAdapterMailboxCapacity ||
|
||||
preflight.ExpectedReturnedCount != 3 ||
|
||||
preflight.ExpectedSkippedCount != 0 ||
|
||||
preflight.FirstExpectedSequence != 4 ||
|
||||
preflight.LastExpectedSequence != 6 ||
|
||||
preflight.FirstRetainedSequence != 4 ||
|
||||
preflight.LastRetainedSequence != 19 ||
|
||||
preflight.DiagnosticState != "stale_cursor_gap" ||
|
||||
!preflight.StaleCursor ||
|
||||
preflight.MissingDroppedCount != 2 ||
|
||||
preflight.RecommendedAction != "reset_consumer_and_resync" ||
|
||||
preflight.ActionReason != "consumer_cursor_before_first_retained_sequence" ||
|
||||
preflight.OperatorSummary != "stale cursor gap: reset consumer and resync before resume" ||
|
||||
preflight.OperatorStatus != "resync_required" ||
|
||||
preflight.OperatorSeverity != "warn" ||
|
||||
anyInt64(preflight.ActionContext["resume_sequence"]) != 1 ||
|
||||
anyInt64(preflight.ActionContext["first_retained_sequence"]) != 4 ||
|
||||
anyInt64(preflight.ActionContext["missing_dropped_count"]) != 2 ||
|
||||
preflight.OperatorSummaryFields["diagnostic_state"] != "stale_cursor_gap" ||
|
||||
preflight.OperatorSummaryFields["recommended_action"] != "reset_consumer_and_resync" ||
|
||||
preflight.OperatorSummaryFields["operator_status"] != "resync_required" ||
|
||||
preflight.OperatorSummaryFields["operator_severity"] != "warn" ||
|
||||
anyInt64(preflight.OperatorSummaryFields["missing_dropped_count"]) != 2 ||
|
||||
!stringSliceContains(preflight.ActionHints, "reset_consumer_cursor") ||
|
||||
!stringSliceContains(preflight.ActionHints, "request_full_adapter_resync") ||
|
||||
!stringSliceContains(preflight.ActionHints, "resume_from_checkpoint_after_resync") {
|
||||
t.Fatalf("stale preflight = %+v", preflight)
|
||||
}
|
||||
resp, err = http.Get(server.URL + "/mesh/v1/remote-workspace/adapter-sessions/" + sessionID + "/mailbox/preflight?consumer_id=rdp-worker-probe&resume_from=ack&limit=3")
|
||||
if err != nil {
|
||||
t.Fatalf("get repeated stale preflight: %v", err)
|
||||
}
|
||||
resp.Body.Close()
|
||||
report := sink.Report(time.Now().UTC())
|
||||
if report["last_mailbox_preflight_diagnostic_state"] != "stale_cursor_gap" ||
|
||||
report["last_mailbox_preflight_stale_cursor"] != true ||
|
||||
report["last_mailbox_preflight_missing_dropped_count"] != 2 ||
|
||||
report["last_mailbox_preflight_recommended_action"] != "reset_consumer_and_resync" ||
|
||||
report["last_mailbox_preflight_action_reason"] != "consumer_cursor_before_first_retained_sequence" ||
|
||||
report["last_mailbox_preflight_operator_summary"] != "stale cursor gap: reset consumer and resync before resume" ||
|
||||
report["last_mailbox_preflight_operator_status"] != "resync_required" ||
|
||||
report["last_mailbox_preflight_operator_severity"] != "warn" ||
|
||||
report["current_session_last_mailbox_preflight_diagnostic_state"] != "stale_cursor_gap" ||
|
||||
report["current_session_last_mailbox_preflight_stale_cursor"] != true ||
|
||||
report["current_session_last_mailbox_preflight_missing_dropped_count"] != 2 ||
|
||||
report["current_session_last_mailbox_preflight_recommended_action"] != "reset_consumer_and_resync" ||
|
||||
report["current_session_last_mailbox_preflight_operator_summary"] != "stale cursor gap: reset consumer and resync before resume" ||
|
||||
report["current_session_last_mailbox_preflight_operator_status"] != "resync_required" ||
|
||||
report["current_session_last_mailbox_preflight_operator_severity"] != "warn" ||
|
||||
mapInt64Value(report["current_session_mailbox_preflight_operator_status_counts"], "resync_required") != 2 ||
|
||||
mapInt64Value(report["current_session_mailbox_preflight_operator_severity_counts"], "warn") != 2 {
|
||||
t.Fatalf("stale preflight report = %+v", report)
|
||||
}
|
||||
readiness, ok := report["adapter_runtime_readiness"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("adapter runtime readiness missing from report = %+v", report)
|
||||
}
|
||||
if readiness["last_preflight_diagnostic_state"] != "stale_cursor_gap" ||
|
||||
readiness["last_preflight_stale_cursor"] != true ||
|
||||
readiness["last_preflight_missing_dropped_count"] != 2 ||
|
||||
readiness["last_preflight_recommended_action"] != "reset_consumer_and_resync" ||
|
||||
readiness["last_preflight_action_reason"] != "consumer_cursor_before_first_retained_sequence" ||
|
||||
readiness["last_preflight_operator_summary"] != "stale cursor gap: reset consumer and resync before resume" ||
|
||||
readiness["last_preflight_operator_status"] != "resync_required" ||
|
||||
readiness["last_preflight_operator_severity"] != "warn" ||
|
||||
mapInt64Value(readiness["mailbox_preflight_operator_status_counts"], "resync_required") != 2 ||
|
||||
mapInt64Value(readiness["mailbox_preflight_operator_severity_counts"], "warn") != 2 ||
|
||||
readiness["preflight_attention_status"] != "repeated_resync_required" ||
|
||||
readiness["preflight_attention_reason"] != "resync_required_preflight_repeated" {
|
||||
t.Fatalf("stale preflight readiness = %+v", readiness)
|
||||
}
|
||||
lastPreflight, ok := readiness["last_preflight"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("stale last preflight rollup missing from readiness = %+v", readiness)
|
||||
}
|
||||
if lastPreflight["diagnostic_state"] != "stale_cursor_gap" ||
|
||||
lastPreflight["diagnostics_schema_version"] != "rap.remote_workspace_adapter_mailbox_preflight_diagnostics.v1" ||
|
||||
!stringAnySliceContains(lastPreflight["diagnostics_contract"], "retained_window") ||
|
||||
!stringAnySliceContains(lastPreflight["diagnostics_contract"], "remediation_checklist") ||
|
||||
!stringAnySliceContains(lastPreflight["diagnostics_contract"], "attention") ||
|
||||
!stringAnySliceContains(lastPreflight["diagnostics_contract"], "operator_counts") ||
|
||||
!boolMapValue(lastPreflight["diagnostics_features"], "retained_window") ||
|
||||
!boolMapValue(lastPreflight["diagnostics_features"], "remediation_checklist") ||
|
||||
!boolMapValue(lastPreflight["diagnostics_features"], "attention") ||
|
||||
!boolMapValue(lastPreflight["diagnostics_features"], "operator_counts") ||
|
||||
lastPreflight["operator_status"] != "resync_required" ||
|
||||
lastPreflight["operator_severity"] != "warn" ||
|
||||
lastPreflight["recommended_action"] != "reset_consumer_and_resync" ||
|
||||
lastPreflight["action_reason"] != "consumer_cursor_before_first_retained_sequence" ||
|
||||
!preflightChecklistContains(lastPreflight["remediation_checklist"], "reset_consumer_cursor", true, false) ||
|
||||
!preflightChecklistContains(lastPreflight["remediation_checklist"], "request_full_adapter_resync", true, false) ||
|
||||
!preflightChecklistContains(lastPreflight["remediation_checklist"], "resume_from_checkpoint_after_resync", true, false) ||
|
||||
lastPreflight["remediation_checklist_status"] != "action_required" ||
|
||||
anyInt64(preflightChecklistCountsValue(lastPreflight["remediation_checklist_counts"], "required_count")) != 3 ||
|
||||
anyInt64(preflightChecklistCountsValue(lastPreflight["remediation_checklist_counts"], "satisfied_count")) != 0 ||
|
||||
anyInt64(preflightChecklistCountsValue(lastPreflight["remediation_checklist_counts"], "pending_count")) != 3 ||
|
||||
mapInt64Value(lastPreflight["operator_status_counts"], "resync_required") != 2 ||
|
||||
mapInt64Value(lastPreflight["operator_severity_counts"], "warn") != 2 ||
|
||||
lastPreflight["preflight_attention_status"] != "repeated_resync_required" ||
|
||||
lastPreflight["preflight_attention_reason"] != "resync_required_preflight_repeated" ||
|
||||
anyInt64(lastPreflight["missing_dropped_count"]) != 2 ||
|
||||
anyInt64(lastPreflight["first_retained_sequence"]) != 4 ||
|
||||
anyInt64(lastPreflight["last_retained_sequence"]) != 19 ||
|
||||
anyInt64(lastPreflight["mailbox_dropped_total"]) != 3 ||
|
||||
anyInt64(lastPreflight["resume_sequence"]) != 1 {
|
||||
t.Fatalf("invalid stale last preflight rollup = %+v", lastPreflight)
|
||||
}
|
||||
}
|
||||
|
||||
func preflightChecklistCountsValue(value any, key string) any {
|
||||
switch counts := value.(type) {
|
||||
case map[string]any:
|
||||
return counts[key]
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func mapInt64Value(value any, key string) int64 {
|
||||
switch items := value.(type) {
|
||||
case map[string]int64:
|
||||
return items[key]
|
||||
case map[string]any:
|
||||
return anyInt64(items[key])
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
func boolMapValue(value any, key string) bool {
|
||||
switch items := value.(type) {
|
||||
case map[string]bool:
|
||||
return items[key]
|
||||
case map[string]any:
|
||||
item, _ := items[key].(bool)
|
||||
return item
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func preflightDiagnosticsContractCompatible(rollup map[string]any) bool {
|
||||
for _, feature := range []string{"retained_window", "remediation_checklist", "attention", "operator_counts"} {
|
||||
if !stringAnySliceContains(rollup["diagnostics_contract"], feature) || !boolMapValue(rollup["diagnostics_features"], feature) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func terminalSessionSummaryContractCompatible(summary map[string]any) bool {
|
||||
for _, feature := range []string{"adapter_session_id", "session_state", "reason", "controlled_at"} {
|
||||
if !stringAnySliceContains(summary["summary_contract"], feature) || !boolMapValue(summary["summary_features"], feature) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func noSessionSummaryContractCompatible(summary map[string]any) bool {
|
||||
for _, feature := range []string{"status", "diagnostic_state", "active_session_count", "terminal_session_count"} {
|
||||
if !stringAnySliceContains(summary["summary_contract"], feature) || !boolMapValue(summary["summary_features"], feature) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func stringAnySliceContains(value any, want string) bool {
|
||||
switch items := value.(type) {
|
||||
case []string:
|
||||
for _, item := range items {
|
||||
if item == want {
|
||||
return true
|
||||
}
|
||||
}
|
||||
case []any:
|
||||
for _, item := range items {
|
||||
if item == want {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func preflightChecklistContains(value any, step string, required bool, satisfied bool) bool {
|
||||
switch items := value.(type) {
|
||||
case []map[string]any:
|
||||
for _, item := range items {
|
||||
if item["step"] == step && item["required"] == required && item["satisfied"] == satisfied && item["source_hint"] == true {
|
||||
return true
|
||||
}
|
||||
}
|
||||
case []any:
|
||||
for _, raw := range items {
|
||||
item, ok := raw.(map[string]any)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if item["step"] == step && item["required"] == required && item["satisfied"] == satisfied && item["source_hint"] == true {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func stringSliceContains(items []string, want string) bool {
|
||||
for _, item := range items {
|
||||
if item == want {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func anyInt64(value any) int64 {
|
||||
switch v := value.(type) {
|
||||
case int:
|
||||
return int64(v)
|
||||
case int64:
|
||||
return v
|
||||
case float64:
|
||||
return int64(v)
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoteWorkspacePreflightDiagnosticsContractCompatibility(t *testing.T) {
|
||||
compatible := map[string]any{
|
||||
"diagnostics_contract": []string{"retained_window", "remediation_checklist", "attention", "operator_counts"},
|
||||
"diagnostics_features": map[string]bool{"retained_window": true, "remediation_checklist": true, "attention": true, "operator_counts": true},
|
||||
}
|
||||
if !preflightDiagnosticsContractCompatible(compatible) {
|
||||
t.Fatalf("expected contract/features to be compatible")
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
rollup map[string]any
|
||||
}{
|
||||
{
|
||||
name: "missing contract item",
|
||||
rollup: map[string]any{
|
||||
"diagnostics_contract": []string{"retained_window", "remediation_checklist", "attention"},
|
||||
"diagnostics_features": map[string]bool{"retained_window": true, "remediation_checklist": true, "attention": true, "operator_counts": true},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "missing feature flag",
|
||||
rollup: map[string]any{
|
||||
"diagnostics_contract": []string{"retained_window", "remediation_checklist", "attention", "operator_counts"},
|
||||
"diagnostics_features": map[string]bool{"retained_window": true, "remediation_checklist": true, "attention": true},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "false feature flag",
|
||||
rollup: map[string]any{
|
||||
"diagnostics_contract": []string{"retained_window", "remediation_checklist", "attention", "operator_counts"},
|
||||
"diagnostics_features": map[string]bool{"retained_window": true, "remediation_checklist": true, "attention": true, "operator_counts": false},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if preflightDiagnosticsContractCompatible(tt.rollup) {
|
||||
t.Fatalf("expected incompatible contract/features for %+v", tt.rollup)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoteWorkspaceTerminalSessionSummaryContractCompatibility(t *testing.T) {
|
||||
compatible := map[string]any{
|
||||
"summary_contract": []string{"adapter_session_id", "session_state", "reason", "controlled_at"},
|
||||
"summary_features": map[string]bool{"adapter_session_id": true, "session_state": true, "reason": true, "controlled_at": true},
|
||||
}
|
||||
if !terminalSessionSummaryContractCompatible(compatible) {
|
||||
t.Fatalf("expected summary contract/features to be compatible")
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
summary map[string]any
|
||||
}{
|
||||
{
|
||||
name: "missing contract item",
|
||||
summary: map[string]any{
|
||||
"summary_contract": []string{"adapter_session_id", "session_state", "reason"},
|
||||
"summary_features": map[string]bool{"adapter_session_id": true, "session_state": true, "reason": true, "controlled_at": true},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "missing feature flag",
|
||||
summary: map[string]any{
|
||||
"summary_contract": []string{"adapter_session_id", "session_state", "reason", "controlled_at"},
|
||||
"summary_features": map[string]bool{"adapter_session_id": true, "session_state": true, "reason": true},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "false feature flag",
|
||||
summary: map[string]any{
|
||||
"summary_contract": []string{"adapter_session_id", "session_state", "reason", "controlled_at"},
|
||||
"summary_features": map[string]bool{"adapter_session_id": true, "session_state": true, "reason": true, "controlled_at": false},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if terminalSessionSummaryContractCompatible(tt.summary) {
|
||||
t.Fatalf("expected incompatible summary contract/features for %+v", tt.summary)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoteWorkspaceNoSessionSummaryContractCompatibility(t *testing.T) {
|
||||
compatible := map[string]any{
|
||||
"summary_contract": []string{"status", "diagnostic_state", "active_session_count", "terminal_session_count"},
|
||||
"summary_features": map[string]bool{"status": true, "diagnostic_state": true, "active_session_count": true, "terminal_session_count": true},
|
||||
}
|
||||
if !noSessionSummaryContractCompatible(compatible) {
|
||||
t.Fatalf("expected no-session summary contract/features to be compatible")
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
summary map[string]any
|
||||
}{
|
||||
{
|
||||
name: "missing contract item",
|
||||
summary: map[string]any{
|
||||
"summary_contract": []string{"status", "diagnostic_state", "active_session_count"},
|
||||
"summary_features": map[string]bool{"status": true, "diagnostic_state": true, "active_session_count": true, "terminal_session_count": true},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "missing feature flag",
|
||||
summary: map[string]any{
|
||||
"summary_contract": []string{"status", "diagnostic_state", "active_session_count", "terminal_session_count"},
|
||||
"summary_features": map[string]bool{"status": true, "diagnostic_state": true, "active_session_count": true},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "false feature flag",
|
||||
summary: map[string]any{
|
||||
"summary_contract": []string{"status", "diagnostic_state", "active_session_count", "terminal_session_count"},
|
||||
"summary_features": map[string]bool{"status": true, "diagnostic_state": true, "active_session_count": true, "terminal_session_count": false},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if noSessionSummaryContractCompatible(tt.summary) {
|
||||
t.Fatalf("expected incompatible no-session summary contract/features for %+v", tt.summary)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoteWorkspaceAdapterSessionMailboxPreflightRejectsInvalidRequests(t *testing.T) {
|
||||
@@ -3145,6 +3986,57 @@ func TestRemoteWorkspaceAdapterSessionMailboxPreflightRejectsInvalidRequests(t *
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoteWorkspacePreflightAttentionReasonSummaries(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
statusCounts map[string]int64
|
||||
severityCounts map[string]int64
|
||||
wantStatus string
|
||||
wantReason string
|
||||
}{
|
||||
{
|
||||
name: "clean ready",
|
||||
statusCounts: map[string]int64{"ready_to_resume": 1},
|
||||
severityCounts: map[string]int64{"ok": 1},
|
||||
wantStatus: "clean",
|
||||
wantReason: "no_resync_required_preflight_observed",
|
||||
},
|
||||
{
|
||||
name: "single resync",
|
||||
statusCounts: map[string]int64{"resync_required": 1},
|
||||
severityCounts: map[string]int64{"warn": 1},
|
||||
wantStatus: "needs_attention",
|
||||
wantReason: "resync_required_preflight_observed",
|
||||
},
|
||||
{
|
||||
name: "repeated resync",
|
||||
statusCounts: map[string]int64{"resync_required": 2},
|
||||
severityCounts: map[string]int64{"warn": 2},
|
||||
wantStatus: "repeated_resync_required",
|
||||
wantReason: "resync_required_preflight_repeated",
|
||||
},
|
||||
{
|
||||
name: "none observed",
|
||||
statusCounts: map[string]int64{},
|
||||
severityCounts: map[string]int64{},
|
||||
wantStatus: "unknown",
|
||||
wantReason: "no_preflight_observed",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
status := remoteWorkspacePreflightAttentionStatus(tt.statusCounts, tt.severityCounts)
|
||||
if status != tt.wantStatus {
|
||||
t.Fatalf("status=%q want %q", status, tt.wantStatus)
|
||||
}
|
||||
reason := remoteWorkspacePreflightAttentionReason(status, tt.statusCounts, tt.severityCounts)
|
||||
if reason != tt.wantReason {
|
||||
t.Fatalf("reason=%q want %q", reason, tt.wantReason)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFabricServiceChannelVPNPacketIngressHonorsDisabledBackendRelayPolicy(t *testing.T) {
|
||||
publicKey, privateKey, err := ed25519.GenerateKey(nil)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user