{"record":{"id":"e417cd16b1a4a1f5","repo":"slimtoolkit/slim","slug":"ptmon-target-app-failed-with-state-q","errorCode":null,"errorMessage":"ptmon: target app failed with state %q","messagePattern":"ptmon: target app failed with state %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/app/sensor/monitor/ptrace/monitor.go","lineNumber":140,"sourceCode":"\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.\n\t\tclose(m.doneCh)\n\t}()\n\n\treturn nil\n}\n\nfunc (m *monitor) Cancel() {\n\tm.cancel()\n}\n\nfunc (m *monitor) Done() <-chan struct{} {\n\treturn m.doneCh\n}\n\nfunc (m *monitor) Status() (*report.PtMonitorReport, error) {","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/app/sensor/monitor/ptrace/monitor.go#L122-L158","documentation":"A goroutine in the ptrace monitor consumes app.StateCh: on AppDone it records the final report, otherwise it stores this error in m.status.err. It means the target app terminated in a state other than clean completion, and the error surfaces later via Status().","triggerScenarios":"The traced app transitions to any state other than AppDone while the monitor is running — e.g. AppFailed after a startup that initially succeeded, or an abnormal termination state.","commonSituations":"Target app crashing mid-run (segfault, OOM kill), being killed by a signal, exiting with a failure code under supervision, or ptrace losing track of the process.","solutions":["Read the quoted state in the message to identify how the app terminated.","Inspect the app's captured stdout/stderr logs in the artifacts directory for the crash cause.","Fix the target application's crash (check exit codes, OOM killer via dmesg, missing resources).","If the app legitimately exits abnormally, treat this as an expected non-critical monitor error."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":"report, err := ptMon.Status()\nif err != nil && strings.Contains(err.Error(), \"target app failed with state\") {\n    // app terminated abnormally; inspect state quoted in err.Error()\n    state := extractQuoted(err.Error())\n    log.Warnf(\"app ended in state %s; check app logs in artifacts dir\", state)\n}","tryCatchPattern":"report, err := ptMon.Status()\nif err != nil {\n    if strings.Contains(err.Error(), \"target app failed with state\") {\n        // degrade gracefully: use partial report if available\n        log.Warnf(\"ptrace monitor ended abnormally: %v\", err)\n    } else {\n        return err\n    }\n}","preventionTips":["Capture and review the app's stdout/stderr artifacts to catch crashes early.","Watch for OOM kills (dmesg) and signal-based terminations of the target.","Ensure the target app handles its own errors instead of crashing mid-run."],"tags":["ptrace","process","crash"],"backgroundTag":"target-process-abnormal-exit","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}