Skip to content

Move the persisted-rewrite baseline into agent.Session / 将 rewrite 持久化基线内聚进 Session#6125

Merged
SivanCola merged 5 commits into
esengine:main-v2from
SivanCola:refactor/session-owned-rewrite-baseline
Jul 6, 2026
Merged

Move the persisted-rewrite baseline into agent.Session / 将 rewrite 持久化基线内聚进 Session#6125
SivanCola merged 5 commits into
esengine:main-v2from
SivanCola:refactor/session-owned-rewrite-baseline

Conversation

@SivanCola

Copy link
Copy Markdown
Collaborator

Summary

  • The controller kept savedRewriteVersion as external bookkeeping about the executor's session object: every SetSession needed a hand-paired baseline reset (7 call sites), and snapshot() had to guess whether conflict recovery had swapped the object — the guess behind the Fix session conflict diagnostics and depth-cap baseline / 修复会话冲突诊断与深度上限基线 #6120 depth-cap bug.
  • Store persistedRewriteVersion on the Session itself. Save paths advance it with the rewriteVersion captured in the same lock window as the message snapshot, so a compaction landing mid-save stays unpersisted and a slower save can never roll the baseline backwards. Clones carry it; swapped sessions take their baseline with them.
  • snapshotRewriteDecision + both mark helpers + the 7 pairings collapse into Session.NeedsRewriteSave(). The depth-cap force save now re-anchors the baseline in the agent layer like any other full save — the Fix session conflict diagnostics and depth-cap baseline / 修复会话冲突诊断与深度上限基线 #6120 misclassification becomes structurally impossible.
  • Folded-in behavior fix: installing a clone that still carries an unpersisted rewrite is no longer stamped persisted-by-construction; the next snapshot correctly runs as an owned rewrite.
  • New agent tests pin the lifecycle (rewrite → save → re-anchored, including force save), monotonicity, and clone semantics, replacing the deleted controller-level guard test.

Stacked on #6124 (which is stacked on #6120); review the top commit only. Part of the #6027 convergence work.

Tests

merge-order-check added 4 commits July 7, 2026 01:17
The caller inferred what recovery did from path and session-pointer
comparisons; the depth-cap baseline bug hid in exactly that inference.
Declare the outcome (adopted / force-saved / forked / dropped) at the
site that performs it, and let replaceSessionAfterCancel log when its
cancel cleanup was dropped instead of silently discarding the result.
The controller kept savedRewriteVersion as external bookkeeping about
the executor's session object, so every SetSession had to be paired
with a manual baseline reset and snapshot() had to guess whether
recovery had swapped the object — the guess that broke depth-cap
force-saves (esengine#6120).

Store persistedRewriteVersion on the Session itself: save paths advance
it with the rewriteVersion captured in the same lock window as the
message snapshot (a compaction landing mid-save stays unpersisted, and
a slower save cannot roll it backwards), clones carry it, and swapped
sessions take their baseline with them. snapshotRewriteDecision and
both mark helpers plus their seven call-site pairings collapse into
Session.NeedsRewriteSave.

Behavior fix folded in: installing a clone that still holds an
unpersisted rewrite no longer stamps it persisted-by-construction; the
next snapshot correctly runs as an owned rewrite.
@SivanCola SivanCola requested a review from esengine as a code owner July 6, 2026 18:35
@github-actions github-actions Bot added v2 Go rewrite (1.x) — main-v2 branch, active development desktop Wails desktop app (desktop/**) tui Terminal UI / CLI (internal/cli, internal/control) agent Core agent loop (internal/agent, internal/control) labels Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent Core agent loop (internal/agent, internal/control) desktop Wails desktop app (desktop/**) tui Terminal UI / CLI (internal/cli, internal/control) v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant