dsh-brake: DSH Agent Session Infinite Loop Detection and Braking

Introduction

When running agents in DSH, the model sometimes repeatedly calls the same tool with the same parameters, or falls into a fixed sequence loop like “grep → curl → read → bash”. Large blocks of identical text are also repeatedly injected into the context. Such behavior doesn’t necessarily cause immediate errors, but it lengthens the session, wastes quota, and hinders the debugging of real issues. Relying solely on prompt reminders is often unstable; observing at the harness layer and injecting hints before the next request is a more controllable approach. dsh-brake is a DSH plugin designed for this specific pain point: by default, it only reminds, but it can optionally be configured to deny confirmed duplicate calls before execution.

What is this

dsh-brake (GitHub: Mlte0907/dsh-brake) is released by maintainer Mlte0907 and categorized under admin-security in the community directory. The plugin listens to executed tool calls and newly injected context. When it detects “repetition of the same type of work without progress,” it appends a plugin-sourced notice to the next model request. The optional deny mode implements a monotonic guard on exactly identical call identities after the repetition count reaches a threshold, rejecting their execution.

The current package version is 0.2.0, with the entry point at lib/index.js. It hooks into DSH’s waterfall and guard contracts via a Cordis patch (cordis.patch.yml).

Core Features

The following describes the three types of detection and optional rejection outlined in the README. All thresholds are configurable.

Repeated Monotonic Calls

This feature counts cumulative occurrences of the same tool name and normalized identical parameters across multiple executions. The first warning appears after callWarnCount (default 6) repetitions. It does not warn on every single call in the same repetition chain; instead, it re-warns only after another callReWarnEvery (default 5) repetitions.

Sequence Loops

Detects if a window of distinct calls of length sequenceLength (default 4, min 2) is looping, such as the recurring cycle of grep → curl → read → bash. The sequence identity includes parameters; changing a query is considered a different sequence. A warning is issued after the sequence repeats sequenceCount (default 3) times.

Repeated Context Text

Performs a fingerprint (FNV-1a) on injected text after newline normalization, requiring a minimum length of minimumDuplicateChars (default 80). It counts duplicates across different message IDs or within the same message within a duplicateTextWindowMs (default 120000 ms) timeframe. It deduplicates by message ID, so history replays do not accumulate counts. The same fingerprint is throttled by duplicateTextCooldownMs (default 30000 ms). Warnings specify the observed source.

Optional Rejection (Deny Mode)

When mode: 'deny', in addition to the warnings above, ctx.tools.guard will reject the execution of that exact duplicate call before it runs if the post-execution count for a call identity reaches callDenyCount (must be greater than callWarnCount, default 10). Sequence loops and repeated text are only warned about and are not subject to denial. Human messages sent by the user reset all counts for that agent.

Warnings enter the next request history with the user role and plugin source (kind: 'plugin', plugin: 'dsh-brake', form: 'notice'). Detection is read-only regarding execution and inbox; it does not rewrite tool results or delete log content.

Installation and Activation

The installation commands are sourced from the repository README. A local plugin package path is required (this is not the dsh plugin add github:... form).

  1. Navigate to your DSH profile directory (example uses the web profile):
cd ~/.dsh/profiles/web   # or your profile directory
  1. Use pnpm to add the local dsh-brake package to the profile:
pnpm add /path/to/dsh-brake
  1. In the profile’s package.json, add "dsh-brake" to the dsh.profile.bundles array.

  2. Add a plugin entry to the profile’s Cordis configuration and fill in the config (invalid values will throw an error during plugin loading and will not silently fall back). Example:

- id: dsh-brake
  config:
    mode: remind                 # remind | deny
    callWarnCount: 6             # repeats before the first call warning
    callDenyCount: 10            # deny-mode threshold; must be > callWarnCount
    callReWarnEvery: 5           # repeats between re-warnings on one chain
    sequenceLength: 4            # calls per sequence (min 2)
    sequenceCount: 3             # sequence repetitions before a warning
    duplicateTextThreshold: 3    # injections within the window before a warning
    duplicateTextWindowMs: 120000
    duplicateTextCooldownMs: 30000
    minimumDuplicateChars: 80

Typical Usage and Verification

For daily development, start with mode: remind to observe if the agent receives short notices during repeated calls or sequence loops. If necessary, change mode to deny and increase callDenyCount to avoid accidentally blocking calls that are still part of the agent’s exploration.

The repository includes dependency-free Node tests. Run them in the plugin directory (requires the ability to resolve @deepseek-ai/dsh-llm from that directory, which is usually satisfied in a DSH profile checkout environment):

node test/test-brake.js

The tests cover thresholds, throttling, parameter identity, deny scope, repeated text counting and ID deduplication, human message resets, preservation of downstream decisions, and fail-loud configuration behavior.

The repeat-tool-reminder in the same repository focuses on escalating reminders for continuous identical tool+parameter chains; dsh-brake additionally covers sequence loops, repeated context, and optional rejection. Both can be enabled simultaneously.

Use Cases and Notes

This is suitable for running coding agents for extended periods in local or team profiles, especially when concerned about tool-level infinite loops or context bloat. The plugin runs with the current DSH process permissions. You should review the source code and license before installation (if the README does not list a separate license field, refer to the repository).

Known Limitations (from the README):
Near-duplicate text (changing only a few words) is not detected; it only recognizes normalized exact fingerprints. Deny applies only to exact call identities. Streaming output is not monitored; assistant text is only observable after submission. The implementation assumes DSH’s tools/post-execute, agent/pre-step, and ctx.tools.guard contracts and has not been verified on other Cordis hosts. Full integration testing with agent-loop + Loader is still considered deferred work.

The community plugin directory site (SkillHub) is not officially affiliated with DeepSeek or High-Flyer; it is an independent index within the “everything is a plugin” ecosystem.

Links

  • Directory Page: https://www.skillhub.cn/plugins/Mlte0907/dsh-brake
  • Source Code & Docs: https://github.com/Mlte0907/dsh-brake

Through the steps above, you can implement configurable reminders or hard brakes for agent infinite loops at the harness layer, without relying entirely on the model’s self-awareness to stop.

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

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

Xiaoye