DeepSeek-Reasonix icon indicating copy to clipboard operation
DeepSeek-Reasonix copied to clipboard

Add Memory v5 execution compiler / 新增 Memory v5 执行记忆编译器

Open SivanCola opened this issue 5 months ago • 1 comments

Summary

  • add a local Memory v5 execution compiler runtime with Planner IR, execution traces, strategy learning, graph state, noise filtering, and truth-locked tool-result memories
  • bind the compiler to the agent runtime by replacing eligible user turns with a cache-safe execution contract instead of appending IR as side context
  • add a v5.2 stability layer: bounded IR explanations, canonical IR ordering, fixed contract shape, split runtime/learning/debug traces, deterministic strategy exploration, usage-decayed strategy scoring, gated mutation rollback, and long-term drift control
  • add a v5.3 equilibrium layer: IR/execution semantic drift validation, adaptive deterministic exploration rates, and strategy debias scoring with novelty bonus, usage penalty, and context fit
  • add a v5.4 control stability layer: explicit Memory v5 compiler citation labeling, hard/soft IR drift validation, deterministic oscillation damping for exploration, and mutation feedback cooldown to prevent resonance
  • add a v5.5 control hierarchy layer: control policy reports, adaptive control gain for mutation cooldown, semantic shift monitoring across recent traces, and bounded control reports in local learning state
  • add a v5.6 distributed control plane: specialized stability/exploration/mutation/semantic control nodes, control graph edges, dynamic node weighting, weighted consensus arbitration, conflict resolution, no-SPOF fallback coverage, deterministic decisions, and bounded variance checks
  • add a v5.7 global equilibrium layer: stability windows over recent control decisions, system-level oscillation detection, anti-centralization guards, bounded active control nodes, equilibrium policy filtering, and compact equilibrium trace feedback
  • add a v5.8 typed control semantics layer: typed DECISION/CONSTRAINT/WEIGHT/OBSERVATION signals, semantic router validation, layer guards, and formal separation so control emits decisions while equilibrium emits only constraints/weights
  • add a v5.9 production hardening layer: sandboxed execution contexts, strict resource budgets, global snapshots and restore, rollback anomaly detection, and deterministic canary rollout policies around the compiler runtime
  • harden v5.9 with v5.9.1 safety fixes: goroutine containment and strict context cloning for sandbox boundaries, pre-execution budget reservation with commit-time accounting, atomic snapshot barriers with state hashes, canary-vs-baseline behavior diffs, rollback failure taxonomy, and an explicit production-hardening enforcement authority
  • harden v5.9.1 with v5.9.2 causal safety fixes: coordinated global budget reservations to prevent ghost commits and aggregate over-reservation, sandbox escape-class reporting with active vs residual risk separation, canary behavioral causal attribution, and causal trace edges for canary divergence
  • add a v5.9.3 causal compression layer: bounded causal graph summaries, anchor-edge retention, execution trace summarization, control graph abstraction, and priority-based memory graph folding to reduce long-run observability complexity without losing causal counts or primary causes
  • add a v5.9.4 causal compression bias-correction layer: deterministic long-tail causal retention, cross-graph alignment reporting, and temporal truth-lock importance decay to prevent anchor dominance and cross-layer semantic drift
  • add a v5.9.5 causal signal dynamics monitor: hierarchy-gradient tracking, entropy-band detection, capped graph-coupling strength, graph-independence status, and deterministic amplification/entropy-spike hints to detect over-regularized causal compression without changing execution inputs
  • add a v5.9.6 observer-loop suppression layer: lagged read-only observation projections, current-trace exclusion for feedback, observer feedback eligibility gates, and a global damping envelope for oscillating causal dynamics hints
  • surface turn-level Memory v5 compiler citations in assistant messages, live events, restored history, and the desktop transcript UI without adding them to model prompts or provider request payloads
  • fix review feedback around recovered tool failures, raw user-goal classification, same-workspace runtime serialization, private trace permissions, and live multi-tab toggle propagation
  • add a Settings > General toggle for Memory v5, defaulting to enabled, plus config docs and regression coverage

Cache and prompt stability

Cache-impact: low - Memory v5 keeps the stable system prompt, tool schema, and provider prefix unchanged; learned state only replaces the current user turn when useful, and the contract uses canonical ordering, fixed fields, bounded arrays, and compact IR explanations. The memory-citation UI metadata is stored only in local events/session history and provider request builders explicitly drop it. The v5.6 distributed control plane, v5.7 global equilibrium layer, v5.8 typed control semantics layer, v5.9 production hardening layer, v5.9.1 safety fixes, v5.9.2 causal safety fixes, v5.9.3 causal compression layer, v5.9.4 compression bias-correction layer, v5.9.5 causal signal dynamics monitor, and v5.9.6 observer-loop suppression layer change only local compiler/control/runtime arbitration, bounded trace metadata, snapshots, rollback state, canary policy, budget reservations and coordinator metadata, sandbox isolation and escape-class metadata, canary causal attribution, causal compression summaries, and priority-based local memory graph retention; control node signals, typed semantic signals, stability windows, oscillation scores, equilibrium adjustments, sandbox state, budget decisions, canary diffs, canary causal attribution, compression reports, deterministic long-tail retention metadata, cross-graph alignment reports, graph-coupling caps, causal hierarchy-gradient and entropy-band diagnostics, observer-loop lagged projection metadata, global damping envelope reports, truth-lock decay metadata, failure taxonomy, and snapshot data are not injected into the system prompt, tool schema, or provider request payloads. Cache-guard: scripts/check-cache-impact.sh with this PR body, provider request leak guards in go test ./internal/provider/openai ./internal/provider/anthropic, plus full go test ./..., cd desktop && go test ./..., cd desktop/frontend && npm run typecheck, and cd desktop/frontend && npm test. System-prompt-review: Self-reviewed against the cache-first rules; touched boot/config files do not add dynamic data to the system prompt and preserve stable prefix behavior.

Tests

  • go test ./internal/runtime/... ./internal/memorycompiler
  • go test ./internal/controlsemantics/... ./internal/equilibrium/... ./internal/controlplane/... ./internal/memorycompiler ./internal/runtime/...
  • go test ./internal/controlsemantics/... ./internal/equilibrium/... ./internal/controlplane/... ./internal/memorycompiler
  • go test ./internal/equilibrium/... ./internal/controlplane/... ./internal/memorycompiler
  • go test ./internal/controlplane/... ./internal/memorycompiler
  • go test ./internal/agent ./internal/eventwire ./internal/provider/openai ./internal/provider/anthropic
  • go test ./...
  • cd desktop && go test . -run 'TestHistoryMessages|TestSetMemoryCompiler|TestApplyMemoryCompiler'
  • cd desktop && go test ./...
  • cd desktop/frontend && npm run typecheck
  • cd desktop/frontend && npx tsx src/__tests__/history-tool-status.test.ts
  • cd desktop/frontend && npm test
  • PR_BODY="$(gh pr view 5217 --repo esengine/DeepSeek-Reasonix --json body -q .body)" scripts/check-cache-impact.sh

SivanCola avatar Jun 24 '26 06:06 SivanCola

~~Harness界的又一座高山~~

Zhuocheng-Lang avatar Jun 24 '26 07:06 Zhuocheng-Lang

Memory v5 PR update (2026-06-24)

Pushed conflict resolution in 5b78ad188 by merging the latest main-v2 into this branch.

Conflict resolution:

  • Resolved internal/agent/agent.go by keeping Memory v5 runtime wiring while adopting the latest centralized plan-mode policy and allowlist shape from main-v2.
  • GitHub checks completed successfully and the PR is now merged into main-v2.
  • Merge commit: b193d426.

Verified locally:

  • git diff --check
  • go test ./internal/agent ./internal/event ./internal/eventwire ./internal/memorycompiler
  • go test ./internal/cli ./internal/control ./internal/i18n
  • go test ./internal/planmode ./internal/plugin ./internal/tool/builtin ./internal/boot
  • go test ./internal/config ./internal/provider/openai ./internal/provider/anthropic
  • PR_BODY="$(gh pr view 5217 --repo esengine/DeepSeek-Reasonix --json body -q .body)" scripts/check-cache-impact.sh
  • CLI smoke: reasonix config memory-v5 off, then reasonix config memory-v5 status

GitHub status observed after the push:

  • state=MERGED
  • All observed GitHub checks completed successfully, including cache-impact, label, CI, race, desktop, coverage, lint, govulncheck, and CodeQL analysis.

SivanCola avatar Jun 24 '26 17:06 SivanCola

Pushed 5ae787e. Bullets 1, 3, and 4 are fixed in full; bullet 2 is partially addressed with one open design point noted below. Re-verified on that head.

1. outcomeFor — tool-free successful turns learned as failures A turn with err == nil and no tool records now returns success (a no-tool turn is a successful plain-text answer, not a partial success), so updateStrategy no longer counts it as a failure. Regression test TestNoToolSuccessfulTurnIsSuccess asserts no strategy accrues failures across repeated no-tool turns.

3. runtime.go:1351 — empty-IR turns reserve the whole tool budget Removed the usage.ToolCalls = MaxToolCalls override for empty/un-useful IR. The turn now reserves only its actual IR steps (zero for an empty IR), so a concurrent same-workspace tab is no longer denied with global reservation tool call budget exceeded before doing any work. Regression test TestEmptyIRDoesNotReserveFullToolBudget.

4. consensus.go:121 — dominant-node cap against pre-cap total The cap now bounds each node to maxNodeShare of the post-cap total (solving w/(w+others) == maxNodeShare, iterating since capping one node lowers the total for the rest). [100, 1] now resolves to a dominant share of 0.55, not ~0.98. Added the package's first regression tests: TestCapDominantWeightsBoundsPostCapShare, ...HandlesMultipleLargeNodes, ...LeavesBalancedUntouched.

2. agent.go:719 / referenced context — partially addressed; one open point Done: goal classification now strips the Referenced context: preamble and <file>/<dir>/<resource>/<image> blocks (stripReferencedContext), so Memory v5 learns from the user prompt rather than the file contents. Test TestStripReferencedContextForGoalOnly.

Not done yet: I kept source_event as the full expanded input rather than fully splitting it from the model-visible input. Reasoning — the compiled contract replaces the user turn, so source_event is currently the only place the model sees the referenced files; stripping it without a compensating channel would blind the model to @-referenced content. The full split you describe (clean source_event + referenced context delivered to the model out-of-band) is the better end state, but it needs a change to the contract-replacement path in Agent.Run (e.g. input = referencedPrefix + compiledContract). As shipped, goal classification and strategy learning are clean, but a reference turn's contract still embeds file contents in source_event (larger contract on those turns).

I'm happy to do the full split if you'd prefer a clean source_event over the smaller change — agent already imports memorycompiler, so exposing a (prefix, prompt) splitter there is straightforward. Flagging it as a design call rather than assuming.

Verification: go test ./internal/memorycompiler/... ./internal/controlplane/... ./internal/agent and go test -race on the changed packages pass; the four regression tests above cover bullets 1–4.

SivanCola avatar Jun 24 '26 18:06 SivanCola