dsh-resource-lease: Reclaiming Orphaned Agent Resources via Lease Mechanism

Preface

When running Agents in DeepSeek Harness (DSH), a common occurrence is that after the model calls browser_tab_new, dispatches bash or subagents to the background, or starts temporary processes and ports within run_code, these resources remain on the host machine even after the session ends or the task is interrupted. Relying on prompt reminders to “remember to close them” is unstable and insufficient as the sole governance mechanism.

dsh-resource-lease (maintained by r-ayin) turns “register upon opening, reclaim upon expiration or session end” into a plugin mechanism: resources are written to a lease table automatically or manually upon opening, owned by the current session with a TTL; reclamation is triggered by multiple paths such as session disposal, periodic scanning, and startup compensation, independent of whether the model remembers to clean up. The plugin is categorized as admin-security on SkillHub, current version v0.0.1, license MIT.

What This Is

In one sentence: Resource Lease Governance — registering browser tabs, background jobs, processes, and ports awaiting reclamation as “session-owned leases,” using TTL and sweep logic to automatically reclaim them; entries requiring long-term retention can be upgraded to pinned.

DSH community plugins are collected by independent directory sites and have no official affiliation with DeepSeek / High-Flyer; please review the source code and license yourself before installation. The plugin executes reclamation (closing tabs, killing jobs, sending SIGTERM to processes) under the current dsh process permissions, with the same scope of authority as the host.

Three Layers of Defense

Below is an explanation layered from registration, reclamation, to policy, following the design in the README.

1. Automatic Registration (Zero Prompt Dependency)

Through tools/result observation hooks, leases are written when resources are created, eliminating the need to repeatedly emphasize “register resources” in prompts:

Source Lease Type Default TTL
browser_tab_new browser-tab (tabId + session) 240 minutes
bash / subagent / workflow with run_in_background job (jobId) 360 minutes
run_code and other resources Requires Agent to call lease_register Based on registration parameters

lease_register supports kind=process|port|custom; process/port require a pid.

2. Automatic Reclamation (Multi-trigger Redundancy)

  1. Normal Session End: Closes all session-level leases under that session upon session/disposed.
  2. Daemon Periodic Sweep: Processes expired leases every 60s by default (a fallback when the session hangs).
  3. Startup Compensation: Sweeps expired accounts approximately 10s after host startup; the registry is persisted in ~/.dsh/resource-lease/leases.json (allowing reclamation of leftover items after a reboot).
  4. Browser Idle Closure: When autoCloseBrowser is true, calls the browser close only if idle for 10 minutes AND a check confirms no unregistered tabs; does not close if unregistered tabs exist, to avoid accidentally harming a shared Chrome instance.

Reclamation execution paths (as verified in the README):

  • Browser tab → ctx.tools.execute('browser_tab_close')
  • Job → ctx.jobs.kill(jobId, sessionId, reason) (README notes that relying solely on the Agent-scoped job_kill tool is not recommended)
  • Process/Port → process.kill(pid, SIGTERM)
  • If the resource no longer exists (not found / ESRCH / already-finished), it is treated as success; 'unknown tool' does not count as success — after 3 consecutive failures, it is marked failed and retries stop, allowing manual handling in the panel.

3. Classification Policy

  • session (default): Automatically reclaimed upon session end or TTL expiration.
  • pinned: Upgraded via lease_pin when the user indicates “keep this,” exempt from automatic reclamation.
  • system: Whitelist (e.g., cron/watchdog, external Chrome, and other unregistered items are naturally exempt).

Agent Tool Surface

Tool Purpose
lease_list List leases; defaults to active items in the current session, all=true to view all
lease_register Manually register process/port/custom
lease_pin Upgrade or downgrade to pinned
lease_release Close immediately; closes pinned items when force=true
lease_sweep Sweep immediately; can specify sessionId to clear only that session

Typical flow: After starting a background service, use lease_register to register the port and pid → use lease_list to verify at the end of the task → lease_release temporary resources, lease_pin for long-term retention.

Conversation Panel

The plugin provides a “Resource Leases” panel in the conversation.view slot: an active lease table, individual close/pin controls, and expired sweeping, auto-refreshing approximately every 10s. The host HTTP API paths are /resource-lease/api/{leases,release,pin,sweep}.

Configuration

Default behavior can be overridden via the cordis.patch.yml included in the package. Items provided in the README include:

Config Item Meaning (README Default)
sweepIntervalMs Sweep interval, 60s
tabTtlMinutes Browser tab TTL, 240 minutes
jobTtlMinutes Background job TTL, 360 minutes
autoCloseBrowser Whether to enable browser idle closing
browserIdleCloseMs Browser idle threshold, 10 minutes
keepClosedHours Retention for closed records, 72 hours

After modification, simply reload the configuration according to your current DSH plugin loading method.

Installation and Build

The fetched materials do not provide a single-line dsh plugin add … installation command from SkillHub or the README, so no command will be constructed based on the repository name here. Please install to your DSH environment following the instructions on the SkillHub Directory Page or the GitHub Repository.

If you need to build from source (README states that offline building is possible and npm install dependency installation is not the main path):

# Host side
bash scripts/build.sh
# DSH_CHECKOUT automatically detects ~/dsh-harness

# Client
bash scripts/build-client.sh
# tsc outputs CJS, wrapped with a manual __ModuleLoader__

# Development Hot Reload (DSH built-in process)
dev_build_plugin → dev_inject_plugin / dev_reload_package

The scripts.build in package.json also points to bash scripts/build.sh.

Use Cases and Notes

Suitable for: Development and operations scenarios involving long-running Agents, frequent browser debugging, massive run_in_background jobs, or local temporary services; when you need a clear view of “what the current session is occupying” and want to wrap up via UI or tools.

Notes:

  1. Automatic registration covers the hook paths listed in the README; other resources must be registered via lease_register, otherwise they will not enter the lease table.
  2. Browser instance-wide closing has a “no unregistered tabs” safety gate, but it cannot replace your tab management habits in shared environments.
  3. Pinned resources are only released via lease_release (with force=true) or manual operation.
  4. Check the source code and MIT license before installation; reclamation actions run with the same permissions as dsh, please assess the impact in production environments.

Conclusion

dsh-resource-lease organizes the tabs, jobs, processes, and ports left behind by Agents into queryable, TTL-based, and pinnable leases. It utilizes multiple paths—session disposal, periodic sweeping, and startup compensation—for reclamation, and exposes tools along with the “Resource Leases” panel. If you are currently managing the lifecycle of semi-automatic resources in DSH, you can install it from the directory page or the repository README and verify cordis.patch.yml.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye