Skip to content

refactor(agent): group per-turn host flags into an embedded perTurnState - #7795

Merged
esengine merged 1 commit into
main-v2from
refactor/agent-turn-state
Aug 7, 2026
Merged

refactor(agent): group per-turn host flags into an embedded perTurnState#7795
esengine merged 1 commit into
main-v2from
refactor/agent-turn-state

Conversation

@esengine

@esengine esengine commented Aug 7, 2026

Copy link
Copy Markdown
Owner

Continues the agent god-object cleanup (#7786, #7788). Agent had ~99 flat fields; eleven of them are host state valid for exactly one Agent.Run, reset one by one in beginRunTurn — adding such a field meant remembering to reset it by hand.

What

  • New perTurnState struct (run_loop.go) embedded in Agent: delivery expectations (deliveryCriteriaEstablished/TaskExpected/MutationExpected/PersistentExpected/ScopeActive), readinessRecovered, recoveryTaskSummary, blockedTurnStreak, loopGuardArmed/loopGuardReceiptMark, repeatSuccessCounts.
  • beginRunTurn zeroes the whole struct in a single assignment before computing the new turn's values; the scattered hand-resets are deleted. A field added to perTurnState can never be forgotten in the reset.
  • Field promotion keeps every existing access site (a.deliveryTaskExpected etc.) unchanged — the diff is ±60 lines of declarations, no call-graph changes.
  • Deliberately NOT moved (cross-turn by design): deliveryScopeID, deliveryCheckpoint, deliveryRecoveryPending, preserveEvidenceOnce, repeatFailureCounts/Scope, stormSig/stormCount, missingReasoning*.

Verification

  • gofmt clean, go vet ./internal/agent/... clean
  • go test -race ./internal/agent/ green
  • Full go test ./... green (English locale)

Cache-impact: none - host-side field grouping; no provider request shaping, cache_control, or usage accounting paths touched.
Cache-guard: existing coverage - cache_shape_test.go and the full agent race suite pass unchanged.
Documentation-impact: none - internal state reorganization with identical behavior; no docs describe these fields.

Eleven fields that are valid for exactly one Agent.Run (delivery
expectations, readinessRecovered, recoveryTaskSummary, loop-guard and
blocked-streak counters, repeatSuccessCounts) were flat Agent fields
reset one by one in beginRunTurn — adding such a field meant
remembering to reset it by hand. They now live in an embedded
perTurnState value that beginRunTurn zeroes in a single assignment;
field promotion keeps every access site unchanged. Cross-turn state
(delivery checkpoint/scope, repeat-failure budgets, storm counters)
stays directly on Agent.
@esengine
esengine requested a review from SivanCola as a code owner August 7, 2026 00:15
@github-actions github-actions Bot added agent Core agent loop (internal/agent, internal/control) v2 Go rewrite (1.x) — main-v2 branch, active development labels Aug 7, 2026
@esengine
esengine merged commit 3f64e33 into main-v2 Aug 7, 2026
23 checks passed
@esengine
esengine deleted the refactor/agent-turn-state branch August 7, 2026 00:39
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) 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