mirror of
https://github.com/deepseek-ai/deepseek-harness.git
synced 2026-09-09 04:02:35 +00:00
The loop appends step/start before system/message and the entered user messages. Capturing nodes at step/start therefore omits inputs already included in the provider's successful usage, then adds those inputs back as a positive surface delta. Prompt replacement can also incorrectly add or subtract the difference from the prior prompt on a completed call. Snapshot the current priced surface immediately before assistant/message commits. Keep provider output separate from the durable assistant node so listener rewrites retain their signed delta. The invariant is zero delta immediately after an unchanged successful output: provider usage already includes every admitted prompt input. Later appends/replacements still produce signed deltas, and low or absent usage keeps heuristic fallback. Delete stepStart.nodes rather than adding prompt-specific corrections or another request snapshot: the existing transactional surface fold already contains the successful request inputs, including replacements made during same-step retry recovery. Keep turn/step state and all overlap, mismatch, and late-assistant lifecycle validation. Retry attempts are log-only and request middleware changes configuration; injected messages remain queued until admission. No loop, event format, projection, or retry policy changes. Exercise the real loop with reported usage and initial, growing, shrinking, and empty prompts; same-step failed attempt plus retry prompt replacement; request middleware; eager observation and fresh seeded replay. The two regressions fail before the fix with spurious deltas of +48 and +18 tokens. Retain existing durable-output rewrite, route repricing, missing/low usage, transactional failure, and lifecycle tests. Update README EN/ZH and the existing system-prompt surface-node Agent Note, including pairing records. Validation (dedicated worktree, no full unit suite): - pnpm exec vitest run packages/llm/token-meter/tests packages/compaction/compaction-basic/tests/compaction-loop-repro.spec.ts --coverage --coverage.include='packages/llm/token-meter/src/index.ts' 118 passed; exact changed runtime file 100% statements/branches/functions/lines. - pnpm exec vitest run packages/core/agent-loop/tests/request-reconstruction.spec.ts packages/compaction/compaction-basic/tests/compaction-basic.spec.ts packages/compaction/compaction-basic/tests/loader-composition.spec.ts 118 passed, including retry reconstruction and real Loader composition. - pnpm run doc-sync: 33 gates passed. - pnpm run test:docs: 15 gates passed. - pnpm run lint: passed, 0 warnings/errors. - git diff --cached --check: passed. Baseline normalize.ts comment conflict marker is intentionally untouched.