Skip to content

SubscriptionManager.rebind_session scans every job subscription on resume #63

@nficano

Description

@nficano

Summary

Second-pass performance/code-quality audit finding. Resuming a session calls SubscriptionManager.rebind_session, which scans every job's subscription list to find entries owned by the resumed session.

Evidence

  • lib/arcp/runtime/session_actor.rb:140 marks the resume token as reconnected.
  • lib/arcp/runtime/session_actor.rb:141 calls @runtime.subscription_manager.rebind_session(@session_id, @outbox).
  • lib/arcp/runtime/subscription_manager.rb:58 defines rebind_session.
  • lib/arcp/runtime/subscription_manager.rb:60 iterates every @subs value.
  • lib/arcp/runtime/subscription_manager.rb:61 through lib/arcp/runtime/subscription_manager.rb:63 scans each job's subscription entries to replace matching session queues.

Why it matters

Resume cost is O(total subscriptions across all jobs), even when the session owns only a few subscriptions. On a runtime with many jobs/subscribers, one reconnect can stall subscription management work under the mutex.

Proposed fix

Maintain a secondary index from session_id to the affected [job_id, entry] records, or store subscription records as objects keyed by subscription id and index them by session. Rebinding should touch only subscriptions owned by the resumed session.

Acceptance criteria

  • Rebinding a session is proportional to that session's subscriptions, not all runtime subscriptions.
  • register_owner, attach, detach, clear, and rebind_session keep the primary and secondary indexes consistent.
  • A regression test creates many unrelated subscriptions and verifies rebind_session only rewrites the resumed session's entries.

Metadata

Metadata

Assignees

No one assigned

    Labels

    audit/clean-codeAudit: clean-code violationaudit/perfAudit: performance / efficiencysev/majorSeverity: major

    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