Skip to content

handleCancel/handleInterrupt resolve targets by linear scan, and interrupt silently no-ops on unknown targets (§7.4) #95

@nficano

Description

@nficano

Category: spec-conformance Severity: minor
Location: Sources/ARCP/Runtime/JobManager.swift:304-318, 354-359
Spec: ARCP v1.1 §7.4

What

Two issues in one path. (1) handleInterrupt returns silently when the target job is unknown — no cancel.refused/nack — so a client that interrupts a finished or unknown job waits forever with no signal. (2) Both handlers resolve the job by jobs.keys.first(where: { $0.rawValue == payload.targetId }) (O(n) linear scan) instead of constructing JobId(payload.targetId) and a dictionary lookup. The scan is also subtly wrong: it cannot distinguish "job belongs to another session" from "no such job", which matters once cross-session targeting is possible.

Evidence

guard payload.target == .job,
    let jobId = jobs.keys.first(where: { $0.rawValue == payload.targetId })
else {
    return   // handleInterrupt: silent no-op, no ack/refusal to the client
}

Proposed fix

  1. Replace the linear scan with let jobId = JobId(payload.targetId); guard let record = jobs[jobId] else { ...send refusal... }.
  2. In handleInterrupt, send a cancel.refused (or nack) with NOT_FOUND when the target is unknown, mirroring handleCancel.

Acceptance criteria

  • Interrupting an unknown/terminal job yields an explicit refusal envelope.
  • Job lookup is O(1).

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