Skip to content

refactor(agents): extract before-agent-run gate - #106867

Merged
steipete merged 1 commit into
mainfrom
codex/refactor-attempt-prompt-context-phase
Jul 13, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/refactor-attempt-prompt-context-phase

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

runEmbeddedAttempt still owned the complete before_agent_run fail-closed gate: hook dispatch, cloned input assembly, blocked-turn persistence, retry idempotency, and caller state projection. This kept another separable lifecycle phase inside the hot orchestration function.

Related: #72072

Why This Change Was Made

The gate now lives in attempt-before-agent-run.ts. The extracted helper preserves cloned hook messages, fail-closed hook errors, explicit block attribution, redacted transcript persistence, the owned session write lock, and idempotent retry behavior. attempt.ts now only applies the returned block outcome to orchestration state.

Focused tests cover no-hook, passing-hook clone isolation, explicit block persistence across retries, and thrown-hook fail-closed behavior.

User Impact

No intended behavior change. The refactor removes 83 lines from attempt.ts (2,441 to 2,358 LOC) and makes the security-sensitive gate independently testable.

Evidence

  • Blacksmith Testbox tbx_01kxesb7sj1t81j7wfhtzft72k: 219 focused tests passed across the new helper, attempt runner, context-engine attempt path, and hook lifecycle gates.
  • Blacksmith Testbox: pnpm tsgo:core passed.
  • Blacksmith Testbox: pnpm check:test-types passed.
  • Blacksmith Testbox: scoped pnpm check:changed passed, including the TypeScript LOC ratchet, formatting, core/test types, lint, and runtime guards.
  • Fresh autoreview: clean, no accepted/actionable findings; correctness 0.97.
  • git diff --check passed.
  • Final conflict-free rebase covered only unrelated paths; hosted CI was not awaited per maintainer instruction.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Jul 13, 2026
@steipete

steipete commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Land-ready proof for head f98266faecb:

  • Blacksmith Testbox tbx_01kxesb7sj1t81j7wfhtzft72k: corepack pnpm test src/agents/embedded-agent-runner/run/attempt-before-agent-run.test.ts src/agents/embedded-agent-runner/run/attempt.test.ts src/agents/embedded-agent-runner/run/attempt.spawn-workspace.context-engine.test.ts src/plugins/hook-lifecycle-gates.test.ts — 219 passed.
  • Blacksmith Testbox: corepack pnpm tsgo:core — passed.
  • Blacksmith Testbox: corepack pnpm check:test-types — passed.
  • Blacksmith Testbox: scoped corepack pnpm check:changed — passed in 2m18s.
  • Fresh structured autoreview — clean; no accepted/actionable findings, correctness 0.97.
  • git diff --check — passed.
  • attempt.ts: 2,441 → 2,358 LOC; extracted helper: 121 LOC.

Known proof gap: hosted CI intentionally not awaited. Testbox proof predates the final conflict-free rebase over 14 commits that touched no files in this PR.

@steipete
steipete force-pushed the codex/refactor-attempt-prompt-context-phase branch from 4e09f66 to f98266f Compare July 13, 2026 22:40
@steipete
steipete merged commit 3e5d8cd into main Jul 13, 2026
17 of 20 checks passed
@steipete
steipete deleted the codex/refactor-attempt-prompt-context-phase branch July 13, 2026 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant