slimtoolkit/slim · error

ptmon: target app failed with state %q

Error message

ptmon: target app failed with state %q

What it means

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().

Source

Thrown at pkg/app/sensor/monitor/ptrace/monitor.go:140

	if appState != ptrace.AppStarted {
		// Cannot really happen.
		logger.Error("pta state watcher - unexpected target app state")
		return fmt.Errorf("ptmon: unexpected target app state %q", appState)
	}

	// The sync part of the start was successful.

	// Tracking the completetion of the monitor.
	go func() {
		logger := m.logger.WithField("op", "sensor.pt.monitor.completetion.monitor")
		logger.Info("call")
		defer logger.Info("exit")

		appState := <-app.StateCh
		if appState == ptrace.AppDone {
			m.status.report = <-app.ReportCh
		} else {
			m.status.err = fmt.Errorf("ptmon: target app failed with state %q", appState)
		}

		// Monitor is done.
		close(m.doneCh)
	}()

	return nil
}

func (m *monitor) Cancel() {
	m.cancel()
}

func (m *monitor) Done() <-chan struct{} {
	return m.doneCh
}

func (m *monitor) Status() (*report.PtMonitorReport, error) {

View on GitHub (pinned to 81940d17fa)

Solutions

  1. Read the quoted state in the message to identify how the app terminated.
  2. Inspect the app's captured stdout/stderr logs in the artifacts directory for the crash cause.
  3. Fix the target application's crash (check exit codes, OOM killer via dmesg, missing resources).
  4. If the app legitimately exits abnormally, treat this as an expected non-critical monitor error.
Defensive patterns

Strategy: type-guard

Type guard

report, err := ptMon.Status()
if err != nil && strings.Contains(err.Error(), "target app failed with state") {
    // app terminated abnormally; inspect state quoted in err.Error()
    state := extractQuoted(err.Error())
    log.Warnf("app ended in state %s; check app logs in artifacts dir", state)
}

Try / catch

report, err := ptMon.Status()
if err != nil {
    if strings.Contains(err.Error(), "target app failed with state") {
        // degrade gracefully: use partial report if available
        log.Warnf("ptrace monitor ended abnormally: %v", err)
    } else {
        return err
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31). Data as JSON: /api/errors/e417cd16b1a4a1f5. Report an issue: GitHub.