This commit is contained in:
2026-05-14 23:30:34 +03:00
parent 26cb65e936
commit 04c46042d9
239 changed files with 34102 additions and 438 deletions
@@ -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