Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .agents/skills/dsh-dev/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ A saved AX model id may disappear from the pinned native catalog. Preserve the l

## Pitfall log

DSH 0.2.2-rc.1 can report the gateway wording `Input too long: model limit N tokens, requested M tokens` as `INVALID_REQUEST`, bypassing native overflow recovery. Tobs handles that precise missed case through its owned `agent/request-error` listener and the public compaction Service. In a real Preset, resolve the isolated Provider with `agentPresets.serviceFor(agent, 'compaction')`; a flat Context test with `agent.ctx.get('compaction')` does not prove this lookup. Verify the before/after Host path with `scripts/e2e-context-overflow.mjs`, await the native Session Store flush checkpoint and verify the exact replacement through a read-only Session persistence handle before retrying, retain the replaced request context and committed reply evidence, and keep DSH dependency bytes unchanged (#4253).

### Windows background command consoles (#3565)

On a detached Windows DSH Host, a console executable launched by `execFile` without
Expand Down
2 changes: 1 addition & 1 deletion .agents/skills/verify-deepseekbot/features/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ One file per user-facing feature. Each file has four sections: `Sub-features`, `
| Bot-to-Bot Group mentions and wake | yes | `scripts/e2e-llm-scenarios.mjs` (nightly) | [bot-group-mention.md](bot-group-mention.md) |
| Group send review | yes for A/B; no for direct tools | `scripts/e2e-group-send-review.mjs`, `scripts/e2e-group-peer-review.mjs`, `scripts/e2e-group-busy-review.mjs`, `scripts/e2e-group-responsibility.mjs` | [group-send-review.md](group-send-review.md) |
| Group invitation candidates | no | `verify-app` Group Members path | [group-invitations.md](group-invitations.md) |
| Conversation timeline: static ordinary avatars, memory display, new-messages divider, return to latest, bidirectional pages, kept place, folding, image preview, reactions, search, member mention, iOS/Android raw-source selection, GenUI documents and reports | for replies; GenUI model optional | `scripts/e2e-timeline-navigation.mjs`, `scripts/e2e-genui-reports.mjs`, `scripts/e2e-genui-documents.mjs` | [conversation-timeline.md](conversation-timeline.md) |
| Conversation timeline: static ordinary avatars, memory display, new-messages divider, return to latest, bidirectional pages, kept place, folding, image preview, reactions, search, member mention, iOS/Android raw-source selection, GenUI documents and reports | for replies; GenUI model optional | `scripts/e2e-context-overflow.mjs`, `scripts/e2e-timeline-navigation.mjs`, `scripts/e2e-genui-reports.mjs`, `scripts/e2e-genui-documents.mjs` | [conversation-timeline.md](conversation-timeline.md) |
| PersonaBot creation and restart persistence | for Bot-created Bots | `scripts/e2e-personabot-create.mjs` (CI) | [personabot-create.md](personabot-create.md) |
| Stop a working Bot (Web Client) | yes | `scripts/e2e-web-stop.mjs` | [bot-stop.md](bot-stop.md) |
| Phone pairing, QR images, app variants and LAN/Tailscale guidance | no | `scripts/e2e-mobile-pairing-web.mjs`, `scripts/e2e-device-pairing.mjs`, `scripts/e2e-mobile-sim.mjs`, `scripts/e2e-mobile-pair-android.mjs`, `scripts/e2e-phone-recovery.mjs` | [phone-pairing.md](phone-pairing.md) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ For the Web document's large-text journey, use Harness Settings → General →

## How to get to it (user POV)

- **Automatic gateway overflow recovery (#4253):** launch an isolated Host with `verify-app launch --no-ax-model` and `DSH_OVERFLOW_FIXTURE_KEY` set to a dummy local value; run `scripts/e2e-context-overflow.mjs` with `BH_E2E_INSTANCE` pointing at that instance. The local HTTP fixture seeds a Bot DM, returns the incident's token-limit rejection, then serves the native summary and reply. Verify `OVERFLOW_RECOVERED` commits, one summary request occurs, and the committed reply stays in the original Session. At the first retry, the fixture reads the persisted Session summary and replacement, records their sequence numbers, and verifies the request contains the summary without the old seed. Set `BH_E2E_EXPECT=blocked` against the base build for the before control. No real provider key or IM destination is used; stop this task's Host afterward. This is a CLI/Host journey, not visual or live-provider qualification.

- Open Bot settings → Messaging to enable Auto-collapse long messages. Long messages start expanded; when folding is enabled, Show all reveals the full body.

- In a Bot DM with Memory updates from another conversation, open its Channel menu → Show what this Bot did elsewhere → Memory display: Compact / Detailed. The same choice is under Channel settings → Show what this Bot did elsewhere → Memory display. Hide Memory updates to disable the choice; show them again to restore it.
Expand Down
1 change: 1 addition & 0 deletions apps/docs/test/docs-reference.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ describe("generated developer reference", () => {
{ name: "agent/inbox/discarded", direction: "consumes", operation: "on" },
{ name: "agent/pre-step", direction: "consumes", operation: "on" },
{ name: "agent/request-error", direction: "consumes", operation: "on" },
{ name: "agent/request-error", direction: "consumes", operation: "on" },
{ name: "agent/status", direction: "consumes", operation: "on" },
{ name: "agent/status", direction: "consumes", operation: "on" },
{ name: "approval/request", direction: "consumes", operation: "on" },
Expand Down
11 changes: 11 additions & 0 deletions changes/4253-context-overflow-recovery.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
section: Fixed
---

## en

- Bots now recover from gateway token-limit errors that DSH reports as ordinary invalid requests: Tobs requests native context compaction and retries once after committed progress, instead of repeatedly failing until paused ([#4253](https://github.com/BotHarness/DeepSeekBot/issues/4253)).

## zh

- 修复网关上下文超限错误被 DSH 归类为普通无效请求后 Bot 连续失败直至暂停的问题:Tobs 调用原生上下文压缩,在确认变更已提交后重试一次([#4253](https://github.com/BotHarness/DeepSeekBot/issues/4253))。
2 changes: 2 additions & 0 deletions docs/architecture/botharness-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ application-defined Memory Service 使用 `Consumer → Service Definition → P

Idle Compaction(#2310):当前 Orchestrator Session 没有进行中的轮次、也没有待处理的 Bot Inbox Admission 时,Host 按最后一次模型回答的时间,在该线路提示缓存寿命的一半(最少 15 分钟)经 DSH 命令注册表为该 Agent 执行 `/compact`(`compactNow`;compaction 服务隔离在每个 Agent 的 preset 组内,Host 无法直接取得),只压缩超过该线路 DSH 默认自动压缩阈值一半的会话;摘要格式与 `compaction/end` 刷新 Soul/Core Memory 的行为不变,期间到达的 Human 消息由 DSH 排队到压缩结束。缓存寿命依次取 Host 设置中的每线路值、模型目录、观测(请求前空闲间隔与该请求缓存命中率)与 DeepSeek 的 2 小时默认值,不足 15 分钟或未知则跳过。Assignment 与审批复核会话不参与,聊天中不显示;每次执行写入 `usage_idle_compactions` 并在 Bot 活动中返回。开关与每线路寿命是 Profile 级 Host 设置,Web 设置页与 `deepseekbot idle-compaction*` 共用同一 bridge 方法。

Tobs also handles the explicit gateway wording `Input too long: model limit N tokens, requested M tokens` when DSH reports it as `INVALID_REQUEST` (#4253). Its application-defined `agent/request-error` listener applies only to Tobs-owned Sessions, delegates existing recovery first, and resolves the native compaction Provider through `agentPresets.serviceFor(agent, 'compaction')` on isolated Presets. It calls `compactIfNeeded(..., 'context-overflow', signal)` without modifying the Provider or DSH failure. A retry requires Session surface replacement and a successful native Session Store flush checkpoint plus an exact readback of that Session replacement through a read-only persistence handle and is limited to one recovery attempt per Agent turn/step. Cancellation, unavailable services and failures without replacement retain the original request failure; bounded developer records contain identifiers, phase, duration and outcome, never the provider error text.

Message action presentation is owned by the Web `ds/action-button` and native `primitives/button` adapters; standalone failed reads use their platform ReadFailure module. The shared application-defined `session-maintenance` controller scopes in-flight state and outcomes to the Host client and Bot DM, so error cards and usage panels cannot submit competing maintenance operations. These modules do not own approvals, read retries or durable Session state.

Orchestrator context recovery reuses the application-defined Bot Runtime queue and canonical Channel failure reference. Web and mobile failure cards maintain the current Bot DM Orchestrator Session by compacting or replacing it, without retrying any message. The CLI recovery-and-retry path can still re-admit only the original safely retryable Human DM. The owner refuses busy Bots, stale Session references and requests that already began external effects; arrivals during maintenance queue normally. Explicit replacement archives the old Session and preserves Channel history, Memory and independent Assignments (ADR-0024). The Web `/new` command performs replacement without retry. Model-declared context capacity comes from DSH Model Info; native automatic compaction remains enabled by default. Unknown capacity uses an explicitly estimated 200,000-token fallback with output reservation and safety headroom, compacting balanced native Session regions before the next model step. The read-only `botContext` query and `bot-context` CLI expose current Session token estimates and capacity; the existing Web composer chip displays them while retaining cumulative usage in the details popover. That popover exposes explicit compact/new maintenance only in the Bot Human DM. Failed-turn feedback freezes a redacted, bounded projection of the canonical failed turn input and tool call/result records in the existing feedback preview token, then passes it to the existing uploader only on explicit submit. Missing turn correlation refuses; full diagnostic ZIPs remain download-only.
Expand Down
2 changes: 2 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"devDependencies": {
"@deepseek-ai/cordis": "4.1.0",
"@deepseek-ai/dsh-agent": "0.2.2-rc.1",
"@deepseek-ai/dsh-agent-preset-registry": "0.2.2-rc.1",
"@deepseek-ai/dsh-api-gateway": "0.2.2-rc.1",
"@deepseek-ai/dsh-api-remote-access": "0.2.2-rc.1",
"@deepseek-ai/dsh-attachment": "0.2.2-rc.1",
Expand All @@ -56,6 +57,7 @@
"@deepseek-ai/dsh-schedule": "0.2.2-rc.1",
"@deepseek-ai/dsh-scope": "0.2.2-rc.1",
"@deepseek-ai/dsh-session": "0.2.2-rc.1",
"@deepseek-ai/dsh-session-persistence": "0.2.2-rc.1",
"@deepseek-ai/dsh-session-projection": "0.2.2-rc.1",
"@deepseek-ai/dsh-settings": "0.2.2-rc.1",
"@deepseek-ai/dsh-shell": "0.2.2-rc.1",
Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
type PricedSurface,
} from './runtime/context-window.js';
import { createBotRequestRetry } from './runtime/bot-request-retry.js';
import { createContextOverflowRecovery } from './runtime/context-overflow-recovery.js';
import { messageText, systemPromptFromLog } from './runtime/prompt-inspection.js';

import { createWindowZoomSetup, WINDOW_ZOOM_SETUP_PATH } from './window-zoom/setup.js';
Expand Down Expand Up @@ -2451,6 +2452,14 @@ export function apply(ctx: Context, config: BotHarnessConfig): void {
}),
{ global: true },
);
const contextOverflowRecovery = createContextOverflowRecovery({
isBotSession: (sessionId) => core.ownership.resolve(sessionId) !== undefined,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
log: (event) =>
ctx.logger[event['outcome'] === 'declined' ? 'warn' : 'info'](
`context-overflow-recovery ${JSON.stringify(event)}`,
),
});
ctx.on('agent/request-error', contextOverflowRecovery, { global: true, prepend: true });
const approvalTemplates = createApprovalTemplateLibrary(
join(dshHome, 'botharness', 'approval-templates'),
);
Expand Down
120 changes: 120 additions & 0 deletions packages/core/src/runtime/context-overflow-recovery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import type { Agent, RequestErrorAction } from '@deepseek-ai/dsh-agent';
import type {} from '@deepseek-ai/dsh-agent-preset-registry';
import type { LlmFailure } from '@deepseek-ai/dsh-llm';
import type {} from '@deepseek-ai/dsh-session-persistence';
import { isDeepStrictEqual } from 'node:util';

export interface ContextOverflowRequest {
agent: Pick<Agent, 'session' | 'ctx' | 'options'>;
turn: number;
step: number;
provider: string;
failure: LlmFailure;
signal: AbortSignal;
}

export interface ContextOverflowRecoveryOptions {
isBotSession(sessionId: string): boolean;
log(event: Record<string, unknown>): void;
}

const TOKEN_LIMIT =
/\b(?:input|prompt|request)\s+(?:is\s+)?too\s+(?:long|large):\s*model\s+limit\s+\d+\s+tokens?,\s*requested\s+\d+\s+tokens?\b/i;

export function createContextOverflowRecovery(options: ContextOverflowRecoveryOptions) {
const attempted = new WeakMap<object, { turn: number; step: number }>();
return async (
request: ContextOverflowRequest,
next: () => Promise<RequestErrorAction>,
): Promise<RequestErrorAction> => {
const { agent, turn, step, failure, signal } = request;
if (
failure.code !== 'INVALID_REQUEST' ||
!TOKEN_LIMIT.test(failure.message) ||
signal.aborted ||
!options.isBotSession(agent.session.id)
)
return next();
const delegated = await next();
if (delegated !== undefined || signal.aborted) return delegated;
const previous = attempted.get(agent);
if (previous?.turn === turn && previous.step === step) return undefined;
const presets = agent.ctx.get('agentPresets');
const compaction =
typeof presets?.serviceFor === 'function'
? presets.serviceFor(agent, 'compaction')
: agent.ctx.get('compaction');
if (compaction === undefined) {
options.log({
event: 'skipped',
outcome: 'declined',
reason: 'compaction-unavailable',
sessionId: agent.session.id,
});
return undefined;
}
attempted.set(agent, { turn, step });
const generation = agent.session.surface.replaceGeneration;
const startedAt = Date.now();
const event = { sessionId: agent.session.id, turn, step, provider: request.provider };
options.log({ event: 'started', ...event });
let failed = false;
try {
await compaction.compactIfNeeded(agent, 'context-overflow', signal);
} catch {
failed = true;
}
const progress = agent.session.surface.replaceGeneration > generation;
let persisted = false;
let flushFailed = false;
if (progress && !signal.aborted) {
try {
const sessions = agent.ctx.get('sessions');
const storage = agent.ctx.get('sessionPersistence');
const replacement = agent.session
.snapshotEvents()
.findLast(
(entry) => typeof entry.surfaceOp === 'object' && entry.surfaceOp.op === 'replace',
);
if (
storage &&
replacement &&
sessions &&
'flush' in sessions &&
typeof sessions.flush === 'function' &&
(await sessions.flush(agent.session)) === true
) {
const reader = await storage.open(agent.session.id, 'read', { signal });
try {
const stored = await reader.read(replacement.seq, 1, { signal });
persisted = isDeepStrictEqual(stored.events[0], replacement);
} finally {
await reader.close();
}
}
} catch {
persisted = false;
flushFailed = true;
}
}
const retry = progress && persisted && !signal.aborted;
options.log({
event: 'finished',
...event,
durationMs: Date.now() - startedAt,
outcome: retry ? 'retry' : 'declined',
reason: signal.aborted
? 'cancelled'
: progress
? flushFailed
? 'persistence-failed'
: persisted
? 'context-replaced'
: 'persistence-unavailable'
: failed
? 'compaction-failed'
: 'no-progress',
});
return retry ? { kind: 'retry' } : undefined;
};
}
Loading
Loading