{"record":{"id":"1eddef848c61fe71","repo":"slimtoolkit/slim","slug":"ptmon-unexpected-target-app-state-q","errorCode":null,"errorMessage":"ptmon: unexpected target app state %q","messagePattern":"ptmon: unexpected target app state %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/app/sensor/monitor/ptrace/monitor.go","lineNumber":125,"sourceCode":"\tif err != nil {\n\t\treturn errors.SE(\"sensor.ptrace.Run/ptrace.Run\", \"call.error\", err)\n\t}\n\tm.app = app\n\n\tappState := <-app.StateCh\n\tlogger.\n\t\tWithField(\"state\", appState).\n\t\tDebugf(\"pta state watcher - new target app state\")\n\n\tif appState == ptrace.AppFailed {\n\t\t// Don't need to wait for the 'done' state.\n\t\tlogger.Error(\"pta state watcher - target app failed\")\n\t\treturn fmt.Errorf(\"ptmon: target app startup failed: %q\", appState)\n\t}\n\tif appState != ptrace.AppStarted {\n\t\t// Cannot really happen.\n\t\tlogger.Error(\"pta state watcher - unexpected target app state\")\n\t\treturn fmt.Errorf(\"ptmon: unexpected target app state %q\", appState)\n\t}\n\n\t// The sync part of the start was successful.\n\n\t// Tracking the completetion of the monitor.\n\tgo func() {\n\t\tlogger := m.logger.WithField(\"op\", \"sensor.pt.monitor.completetion.monitor\")\n\t\tlogger.Info(\"call\")\n\t\tdefer logger.Info(\"exit\")\n\n\t\tappState := <-app.StateCh\n\t\tif appState == ptrace.AppDone {\n\t\t\tm.status.report = <-app.ReportCh\n\t\t} else {\n\t\t\tm.status.err = fmt.Errorf(\"ptmon: target app failed with state %q\", appState)\n\t\t}\n\n\t\t// Monitor is done.","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/app/sensor/monitor/ptrace/monitor.go#L107-L143","documentation":"After checking for AppFailed, Start() verifies the app state is exactly ptrace.AppStarted. Any other state is considered an internal invariant violation (\"cannot really happen\") and returns this error. It guards against unexpected state machine transitions from the ptrace app watcher.","triggerScenarios":"Receiving a state on app.StateCh that is neither AppFailed nor AppStarted during Start() — e.g. AppDone arriving synchronously, or a state value from an incompatible app implementation/version.","commonSituations":"Rare; typically seen after code changes to the ptrace state machine, mixed library versions, or a race where the app finishes/fails before the watcher processes the first state.","solutions":["Note the reported state value and confirm it against the ptrace package's state constants (AppStarted, AppFailed, AppDone).","Re-run; if reproducible, check that all slim toolkit components are built from the same version.","Report as a bug with the state value if it persists on a clean run."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := ptMon.Start(ctx); err != nil {\n    if strings.Contains(err.Error(), \"unexpected target app state\") {\n        log.Errorf(\"ptrace state machine invariant violated (report a bug): %v\", err)\n    }\n    return err\n}","preventionTips":["Keep all slim toolkit components on the same build/version.","Avoid modifying or wrapping the ptrace app state channel.","If reproducible, file a bug including the reported state value."],"tags":["ptrace","state-machine","invariant"],"backgroundTag":"unexpected-state","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}