DeepSeek Harness

DeepSeek Harness: When Should I Use a PTY?

· 7 min read · 中文版

Use a DeepSeek Harness PTY session when a command needs an ongoing terminal interaction: send input, observe terminal output, and continue in the same owner-scoped session. For a bounded noninteractive command, a collected subprocess is often a simpler fit.

DeepSeek Harness: What does a PTY session provide?

The terminal reference describes a persistent terminal session with a backend, an owner, a session identity, retained scrollback and operations to send, read, signal and close. This is useful for a prompt that needs a response or a program whose terminal interaction spans multiple exchanges. The top-level shell can remain running after one send returns.

The subprocess reference describes a different interface for managed child processes, including batch input and collected streams, raw pipes for protocols, and inherited output for pass-through diagnostics. Choose according to the interaction and output contract; a process being long-running alone does not prove that it needs a terminal.

Choose an interaction style, send or collect output, then close owned resources

DeepSeek Harness: How does PTY differ from collected output?

NeedPTY sessionManaged subprocess
Multiple interactive exchangesSend again to the same live sessionPipe input when the consumer's contract supports it
Output viewBounded rendered viewport and retained scrollbackExplicit stream dispositions, including bounded collection
CompletionSend wait reason and top-level session status are separateConsumer observes its process and configured streams
Recovery of excess outputScrollback can be truncatedCollected output may have a full-stream spill path when available
OwnershipExact agent owner controls access and cleanupConsumer owns the managed subprocess lifecycle

In collected mode, the in-memory text is the tail when truncated. A spillPath may point to the complete stream when truncation occurred and a spill file is available. The spill itself has a cap; it is not guaranteed for every consumer. A terminal's bounded scrollback and a subprocess spill are different facilities, so select the path that preserves the evidence your task needs.

DeepSeek Harness: How should I use an interactive session?

  1. Check that the current profile exposes a suitable terminal backend and that an interactive session is warranted. The service lists registered backend types; the source does not guarantee that every profile has one.
  2. Open a session for the owning agent with the chosen backend. The service publishes it only after setup succeeds; a failed setup is not a published session. Save the returned identity for subsequent operations.
  3. Send the first input and inspect both the returned wait reason and session status. Only one send can be active in a live session at a time. A result can return control while the shell is still running.
  4. If the program requests more input, send the appropriate response in the same session. Read retained output in bounded pages when needed, and check truncated rather than assuming the visible viewport contains everything.
  5. Close the owned session when finished and await cleanup. If interruption is required, the service can signal the verified foreground process group; inspect the result instead of assuming every descendant has exited.

This is an operational sequence, not a promise that a particular model-facing tool or parameter is present in every profile. The reference names terminal_open for the initial bounded output, while the exact available tool schema must be checked in the installed composition.

DeepSeek Harness: What does a send result actually mean?

A send returns a waitReason: stdin_read, inferred_idle, timeout, or session_exit. The reason says why that send returned; it is independent of sessionStatus, which reports whether the top-level process is running or exited, with an exit code and signal when applicable. Silence or timeout can return while the shell remains alive. session_exit refers to the top-level shell, not an arbitrary foreground child.

This distinction matters for interactive programs. An idle-looking screen is a reason to inspect the session and decide whether more input is appropriate; it is not proof that the command finished successfully. Likewise, an exited shell status describes the shell, not a complete audit of every external effect. Retain the relevant output and verify the task's own result.

The backend's send operation has a consuming output cursor for background job integration, while a separate read operation pages retained session scrollback. Both are bounded. If output was dropped from the operation or scrollback, truncated signals that the returned view is incomplete. Do not infer a missing error from an incomplete viewport.

DeepSeek Harness: What happens on reload or cleanup?

The terminal service attaches awaited cleanup to the exact agent owner scope and rejects operations by a foreign owner. An optional session name is display metadata local to the owner; a name or guessed identity is not authorization. The service keeps sessions alive across backend or tool-plugin reload, but terminal state and raw bytes are process-local. Model input and bounded returned output can be durable through existing tool call and result paths, not a duplicate durable PTY stream.

Closing a session waits for cleanup of the captured owned process tree and removes it after quiescence. A backend that cannot clean partial startup resources reports TerminalBackendCleanupError; the contract preserves that cleanup failure without replacing the caller's cancellation reason. Neither a send timeout nor a tool reload should be treated as an implicit close.

The distinction also matters for protocol clients. The subprocess reference describes raw pipes for framed protocols and collection for bounded batch output. A rendered terminal viewport is not a substitute for the raw protocol stream. Before selecting a path, decide whether the caller needs interactive terminal behavior, machine-readable framing, or recoverable bulk output. If a send has returned but the session remains running, record that fact and retain its identity until the owner closes it; the return itself is not a lifecycle handoff.

DeepSeek Harness: What are the limits and safety boundaries?

A PTY makes interaction possible; it does not establish that a command is safe or that it is confined. Check the actual execution and permission policy before running commands. Avoid sending credentials or private output into a session unless the task and environment require it; returned tool records can persist. Review any transcript before sharing.

The references do not promise unlimited scrollback, durable terminal state across process restart, universal backend availability, or that idle detection proves application completion. When complete logs or machine-framed protocol streams matter, examine the subprocess consumer's explicit stream and spill contract. Test the actual environment rather than assuming every terminal-oriented program behaves identically.

DeepSeek Harness: What do these terms mean?

  • PTY: a pseudo-terminal used for a persistent interactive session.
  • Owner: the exact agent whose scope controls access and cleanup.
  • Wait reason: why a send returned control, separate from process status.
  • Scrollback: bounded retained terminal output read in pages.
  • Spill: optional storage for collected subprocess output beyond its in-memory tail.

Frequently asked questions

Does a timeout mean the shell exited?

No. A send can time out while the top-level shell is still running.

Is terminal scrollback unlimited?

No. Retained output and returned views are bounded and may be truncated.

Does a PTY prove a command is safe?

No. Check the actual execution and permission policy.

Sources

Every claim in this article was checked against the sources below. Community discussions are user reports, not official behavior.

  1. Persistent PTY sessions
  2. Subprocess

This is an independent community article, not official DeepSeek documentation. Listing a plugin in the registry is not a security review.

← Back to all articles