Code review and fixes.

This commit is contained in:
Storm Dragon committed 2026-11-02 23:37:45 -05:00
1 parent f2a35a9305
commit 60f7f7a2e9
12 files changed
+185 -34

No files matched your search

+20 -15
View File
@@ -23,9 +23,10 @@ type helperDiagnostics struct {
window time.Time
seen map[string]bool
suppressed atomic.Uint64
// onReady, when set before logRecords starts, receives each valid
// ready record so the manager can act on it. It runs on the logging
// worker and must only record state, never supervise processes.
// onReady is installed before the first Write and receives valid ready
// records before diagnostic throttling. It runs on the stderr copier
// (or finish for a final partial line) and must only publish bounded
// state, never log, block, or supervise processes.
onReady func(helperReady)
}
@@ -92,6 +93,15 @@ func (output *helperDiagnostics) queueLine(line string) {
if !strings.HasPrefix(line, "wine-access: ") {
return
}
// Readiness controls exclusion fallback and must survive a full queue,
// diagnostic throttling, and a slow log sink. The line buffer above
// bounds parsing independently of how many diagnostics are retained.
record := strings.TrimPrefix(line, "wine-access: ")
if output.onReady != nil {
if ready, valid := parseHelperReady(record); valid {
output.onReady(ready)
}
}
now := time.Now()
if now.Sub(output.window) >= 10*time.Second {
output.window = now
@@ -103,7 +113,7 @@ func (output *helperDiagnostics) queueLine(line string) {
}
output.seen[line] = true
select {
case output.lines <- strings.TrimPrefix(line, "wine-access: "):
case output.lines <- record:
default:
output.suppressed.Add(1)
}
@@ -136,18 +146,14 @@ func (output *helperDiagnostics) logRecords(logger *slog.Logger) {
reportSuppressed()
return
}
if ready, valid := logHelperRecord(logger, line); valid && output.onReady != nil {
output.onReady(ready)
}
logHelperRecord(logger, line)
case <-ticker.C:
reportSuppressed()
}
}
}
// logHelperRecord logs one helper diagnostic line and returns the parsed
// ready record when the line was a valid one.
func logHelperRecord(logger *slog.Logger, line string) (helperReady, bool) {
func logHelperRecord(logger *slog.Logger, line string) {
if body, found := strings.CutPrefix(line, "identity "); found {
var identity struct {
Version string `json:"version"`
@@ -156,17 +162,17 @@ func logHelperRecord(logger *slog.Logger, line string) (helperReady, bool) {
}
if err := json.Unmarshal([]byte(body), &identity); err != nil || identity.Version == "" || identity.Revision == "" {
logger.Warn("Invalid Wine helper identity record")
return helperReady{}, false
return
}
logger.Info("Wine accessibility helper identity", "version", identity.Version,
"revision", identity.Revision, "modified", identity.Modified)
return helperReady{}, false
return
}
if strings.HasPrefix(line, "ready ") {
status, valid := parseHelperReady(line)
if !valid {
logger.Warn("Invalid Wine helper initialization record")
return helperReady{}, false
return
}
logger.Info("Wine accessibility helper initialized", "reader", status.Reader,
"controls_enabled", status.ControlsEnabled, "controller", status.Controller,
@@ -174,7 +180,7 @@ func logHelperRecord(logger *slog.Logger, line string) (helperReady, bool) {
"win_events", status.WinEvents, "menu_hook", status.MenuHook,
"input_hook", status.InputHook, "host32_started", status.Host32Started,
"control_poll", status.ControlPoll, "hook_exclusions", status.HookExclusions)
return status, true
return
}
// The plain exclusion-count line is expected startup evidence (it is
// emitted even when the helper then exits early), while a rejected
@@ -187,7 +193,6 @@ func logHelperRecord(logger *slog.Logger, line string) (helperReady, bool) {
} else {
logger.Warn("Wine accessibility helper diagnostic", "diagnostic", line)
}
return helperReady{}, false
}
func hookExclusionCountLine(line string) bool {