Skip to content

Job.emit_result final-state assignment is a tautology that hides a state machine gap #52

@nficano

Description

@nficano

src/arcp/_runtime/job.py:114 writes self.state = payload.final_status if payload.final_status != "success" else "success", which is equivalent to the unconditional self.state = payload.final_status. The conditional has no behavioral effect because both branches assign the same value. Reading the surrounding code suggests the original intent was probably to gate the assignment on a successful terminal status (mirroring how _finalize_failure at src/arcp/_runtime/_job_runner.py:104 separately sets job.state = "timed_out" after emit_result), but the current form does neither. The dead conditional is also confusing for static analysis: pyright cannot exclude either branch, and a contributor following the logic will assume an asymmetry exists where none does. Combined with the payload.final_status literal type at src/arcp/_messages/execution.py, the runtime can write state = "cancelled" here even when _finalize_cancelled already set it; the redundant write is harmless but the conditional is a code smell.

Fix prompt: Replace src/arcp/_runtime/job.py:114 with self.state = payload.final_status and remove the unreachable branch. If the intent was to gate on success only, restore that intent explicitly with if payload.final_status == "success": self.state = "success" and add a comment explaining why non-success branches are owned by _finalize_failure. Either way, add a parametrized unit test that drives Job.emit_result with each final_status literal ("success", "error", "cancelled", "timed_out") and asserts the resulting job.state matches expectations. While in this file, audit _finalize_failure at src/arcp/_runtime/_job_runner.py:101 for the symmetric assignment and document who owns the final transition.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions