Skip to content

fix(harness): report background task health truthfully #5237

Closed

Description

@liugddx

Background tasks can report running even when their endpoint is not listening or reachable. Add explicit lifecycle states, endpoint health checks, PID and bind address, startup and exit logs, and prevent unverified ready claims. Relates to #5213

Activity

  1. liugddx commented on Sep 12, 2026

    @liugddx
    MemberAuthor

    Observed evidence from the H5 session: the background-task wrapper reported status running for a Python HTTP server, while a later curl request to 127.0.0.1:8765 returned connection refused. This proves process state alone was insufficient evidence of endpoint readiness. It does not prove the root cause; implementation must expose the cause.

  2. liugddx commented on Sep 13, 2026

    @liugddx
    MemberAuthor

    #5216 is now merged. The remaining harness gap is still independent: background-task status must distinguish process tracking from endpoint readiness, expose lifecycle/health evidence, and prevent unverified ready claims. This issue remains open for a dedicated harness implementation.

  3. Dante-dan commented on Sep 13, 2026

    @Dante-dan
    Contributor

    I traced the misleading state to the managed Bash lifecycle: ShellRunProcessManager marks a durable run as running after the child process spawns, while the canonical shell_run result currently exposes neither the child PID nor endpoint-readiness evidence. I would keep running as a process-lifecycle fact instead of redefining it as “ready.”

    Proposed implementation:

    1. Add an optional, strict health_check declaration for background Bash. It will accept a bounded loopback HTTP endpoint (127.0.0.1 or ::1, explicit port/path, no credentials/query/fragment) and reject foreground or non-loopback use. The runtime will not guess a bind address by parsing arbitrary shell commands.
    2. Persist and project the spawned PID, declared host/port, and endpoint state separately from process state. The endpoint state will distinguish checking, healthy (successful HTTP response), listening (HTTP responded but was unhealthy), and unreachable, with a check timestamp and safe status/cause fields but no response body.
    3. Make the initial background handoff perform the bounded check, and refresh it when an active task is read. Process exit wins the race and remains represented by the existing terminal status, exit code, timestamps, and captured stdout/stderr. Only health_check.status === "healthy" supports a ready claim.
    4. Extend the canonical record/result validation rather than adding a parallel status source. Focused coverage will include a spawned process with no listener, a delayed healthy listener, non-2xx listening, exit before readiness, invalid/non-loopback declarations, persistence/projection, and the unchanged no-health-check path.

    This stays separate from the broader capability preflight and managed Artifact preview work in #5234/#5238, and preserves the Browser/file-URL boundaries established around #5216.

    Automated contribution proposal generated with Codex.

  4. Dante-dan commented on Sep 13, 2026

    @Dante-dan
    Contributor

    take

  5. liugddx commented on Sep 13, 2026

    @liugddx
    MemberAuthor

    Implemented in PR #5261. The change keeps process tracking and endpoint readiness separate, persists/exposes the native PID, adds policy-controlled HTTP(S) probing via BackgroundTaskHealth, fails closed for privacy/credential restrictions, and includes focused regression tests. CI is running.

  6. Astro-Han commented on Sep 17, 2026

    @Astro-Han
    Contributor

    This was implemented by #5261, merged as bf6e94229. packages/runtime/src/background-task-health-tool.ts keeps process lifecycle separate from endpoint readiness, persists and exposes the native PID and the declared host/port, performs a bounded loopback probe, and reports the endpoint state rather than inferring readiness from a spawned process, with regression coverage in packages/runtime/src/__tests__/background-task-health-tool.test.ts. Closing as completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions