Skip to content

feat(harness): establish bounded native Prime SDK session host #5

Description

@rynfar

Outcome

Add the next internal layer after #4: a bounded asynchronous Prime SDK session host that can create, attach, observe, and authoritatively dispose one client-owned native Prime session. This is a host-only contract slice. It does not register a Comet harness or expose a user-visible provider.

Parent umbrella: #1
Merged daemon foundation: #3 / #4
Prime SDK ingress dependency: pylon-code/prime-agent#13
Prime reviewed-upstream gate: pylon-code/prime-agent#8
Prime snapshot/worker-integrity gate: pylon-code/prime-agent#11
Pylon consumer: pylon-code/pylon#114

Dependency gate

Production session-host work is blocked on the reviewed public proof/options contract produced by Prime zeronsh#13, which must let Comet enforce a finite inbound byte limit before DaemonClient connects. The exact export and constructor contract must be cross-reviewed on zeronsh#13; do not pre-decide it here. Never infer safety from package version, branch, constructor arity, method presence, daemon schema, or server capability. Stock 0.8.1 must fail locally before session creation because its public client attaches the JSONL reader without a limit.

Prime zeronsh#8, zeronsh#11, and zeronsh#13 are all prerequisites to the production merge and real smoke. The reproducibly identified fork artifact must contain one reviewed Prime tracker head with the accepted outcomes from all three; this issue does not prescribe their internal merge order. Deterministic fake-SDK infrastructure may be developed earlier, but it cannot be presented or merged as a production session path.

This slice still keeps reconnect/recovery disabled. zeronsh#11 is required here because even the initial attach consumes snapshot transfer and this issue claims authoritative worker/descriptor settlement; reconnect and saved-session recovery remain separate later work.

Contract

  • Continue loading only the already validated public root ESM export.
  • Require DaemonClient, DaemonAgentConnection.attach, and the reviewed public bounded-ingress proof/options contract from Prime Interest in adding Grok Build support? zeronsh/comet#13.
  • Construct the client with a reviewed finite inbound byte limit before connecting, and verify support through that explicit public contract rather than an ignored extra JavaScript argument.
  • Use one long-lived asynchronous Node host with correlation IDs that separately demultiplexes command responses and unsolicited session events. Never reuse the foundation bridge's request/next-line bootstrap shape.
  • Create a client_owned session with a bounded, allowlisted runtime config rooted in the local working directory and private Prime session tree.
  • Validate the create result before attach. Use ownedSession: true, disable reconnect for this slice, and set supportsExtensionUi: false until Comet implements that request/response surface.
  • Let the public DaemonAgentConnection advertise its documented attach-side capabilities. A daemon hello offer alone never proves the negotiated intersection.
  • Keep correlated prompt lifecycle inactive and unexposed in Comet even if the fork SDK internally auto-advertises it after seeing a server offer. supportsCorrelatedPromptLifecycle() is server-offer evidence only. A later prompt issue needs an approved public negotiated-capability proof before it can use the extension.
  • Obtain and validate the initial snapshot/cursor without publishing raw Prime payloads.
  • Expose only a non-serializable internal PrimeSessionLease and bounded normalized host events. activeSessionId, native sessionId, sessionFile, socket paths, package paths, environment values, and raw payloads must remain inside crates/harness/src/prime/**.
  • Never place a native Prime identifier in RunRequest.resume, AgentEvent::*::session_id, a Comet document, RPC, log, or error. Durable resume needs a later opaque Comet-handle-to-local-Prime mapping design.

Lifecycle and process ownership

  • Bound every host command, frame, pending-request count, event queue, startup, attach, snapshot, disposal, and child-process wait.
  • Isolate the SDK host with an explicit environment, finite V8 heap, owned process group, cancellation handoff, and privacy-safe typed errors.
  • If creation succeeds but attach or caller cancellation fails, issue bounded complete_owned_session cleanup.
  • Normal close must obtain a validated successful owning-client complete_owned_session response before DaemonAgentConnection.dispose(), then close the client and reap the SDK host. dispose() alone is not proof because it swallows completion errors. A successful supervisor response is meaningful only because it awaits worker stop, removes the worker, and deletes its descriptor.
  • Dropping or cancelling a Rust future must transfer both the SDK-host process and any created native-session cleanup obligation to a bounded reaper. Killing only the Node host is not proof that a detached Prime worker stopped.
  • On SDK-host crash, a different bootstrap client cannot complete the session because the supervisor enforces ownerClientId. The reaper must wait for the daemon's client-disconnect cleanup and prove the worker/descriptor is absent. If it cannot prove absence, poison and shut down this private daemon and return cleanup-uncertain; never report clean disposal.
  • Do not shut down the daemon while a session lease is live except for that fail-closed poisoned-owner recovery. Reconcile worker/descriptor state before reporting clean disposal.

Tests

Use deterministic local fake public-SDK/daemon fixtures with no model, credential, network, or active Prime checkout dependency. Cover:

  • response/event interleaving, reverse-order concurrent responses, and event-before-response;
  • duplicate, unknown, and stale response IDs; EOF/overflow rejecting all waiters; close/cancel overtaking an in-flight operation rather than waiting behind a global promise queue;
  • reviewed bounded-ingress proof/options contract required before create;
  • constructor byte limit forwarded to the SDK;
  • stock server offers versus attach-side client capability advertisement;
  • create/attach/initial snapshot success;
  • unknown events and capabilities degrading locally without raw forwarding;
  • oversized/no-newline control frames and bounded event queues;
  • timeout and cancellation at connect, create, attach, snapshot, and dispose;
  • attach failure after create invokes owning-client complete_owned_session and validates the response;
  • host crash waits for client-disconnect cleanup and proves worker/descriptor absence; unverifiable cleanup poisons/shuts down the daemon and returns cleanup-uncertain;
  • graceful and forced SDK-host descendant cleanup;
  • native identifiers and raw payloads absent from surfaced events/errors;
  • authoritative owned-worker/descriptor settlement before success;
  • a real smoke only against the exact reviewed artifact containing Use native word-editing shortcuts on every platform zeronsh/comet#8/Add workspace file mentions to the composer zeronsh/comet#11/Interest in adding Grok Build support? zeronsh/comet#13.

Initial ownership

No branch or worktree is claimed yet. After the dependency gate is satisfied, use a fresh Comet worktree from origin/main and declare the exact branch, files, tests, dependencies, and merge order here before editing.

Expected area: crates/harness/src/prime/session/**, a dedicated session-host shim, focused changes to the existing Prime foundation seams, and focused tests only.

Non-goals

  • HarnessId::PrimeAgent, registry/settings/model/UI integration
  • prompts or assistant streaming
  • steering, follow-ups, interruption, or correlated prompt settlement
  • extension UI, MCP, resources, compaction, refinement, goals, heartbeats, or schedules
  • reconnect, resume, snapshot recovery, or cross-device session migration
  • native subagent projection
  • sandbox or approval policy (loading Prime runtime resources is not supervision)
  • ACP fallback

Merge order

  1. Record one reviewed Prime tracker head containing the accepted Use native word-editing shortcuts on every platform zeronsh/comet#8, Add workspace file mentions to the composer zeronsh/comet#11, and Interest in adding Grok Build support? zeronsh/comet#13 outcomes, then produce a reproducibly identified artifact. The exact internal Prime merge order is owned by that tracker.
  2. Implement this host-only Comet slice and cross-review the public SDK contract with both Comet and Pylon consumers.
  3. Add prompt/event normalization in a separate Comet issue; reconnect and recovery remain disabled until their own contract review.
  4. Design the host-private opaque resume mapping before HarnessId::PrimeAgent registration.

Acceptance

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions