Add auto refine review hook - #201
Merged
Merged
Conversation
sethkarten
marked this pull request as ready for review
June 18, 2026 20:50
# Conflicts: # packages/coding-agent/CHANGELOG.md # packages/coding-agent/src/core/prompts/rlm.ts # packages/coding-agent/test/system-prompt.test.ts
# Conflicts: # packages/coding-agent/CHANGELOG.md
- abort/discard auto-refine on session disposal (signal plumbed into the review call; disposed checks around every await; timers invalidated) - stamp the review cooldown on failed reviews/refines and make the pending path respect it, so a persistently failing gate can't burn an LLM call every turn; unify the pending/fresh execution paths and drop the dead pending branchVersion field - re-check refine idleness adjacent to agent.prompt handoffs (extension hooks can suspend between guard and start) - kernel: local harness writes without a session store now raise an instructive error instead of vanishing in memory (reads still work, global_=True still persists); empty RLM_* env vars treated as unset; global-target pinning skips explicit dirs that merely alias the env resolution - dedupe merged-state/history loading; fix stale appendGlobalRefinement docstring
kevinjosethomas
approved these changes
Jul 1, 2026
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 3 total unresolved issues (including 2 from previous reviews).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 99c4b0c. Configure here.
zhengr
pushed a commit
to zhengr/prime-agent
that referenced
this pull request
Aug 8, 2026
zhengr
pushed a commit
to zhengr/prime-agent
that referenced
this pull request
Aug 8, 2026
* feat(coding-agent): add auto refine review hook * fix(coding-agent): keep auto refine model stable * fix(coding-agent): defer auto refine during compaction continuations * fix(coding-agent): keep auto refine reviews pending safely * fix(coding-agent): guard pending auto refine application * fix(coding-agent): clear auto refine state on branch navigation * docs(coding-agent): guide refine scope decisions * feat(coding-agent): split harness state into local and global scopes * fix(coding-agent): target refine rollback scope from history * fix(coding-agent): record auto refine cooldown after branch changes * fix(coding-agent): harden auto refine scope handling * Clarify refine as continual harness state * Strengthen continual harness refine language * Balance continual harness and RLM wording * Fix auto-refine review comments * Fix refine scope status label * Address follow-up auto-refine comments * Preserve refine scope defaults across clients * Preserve refine scope defaults in servers * Normalize refine display ids by scope * Use original local harness for refine rollback * Harden auto-refine state routing * Preserve explicit harness dir on cache hits * Fix auto refine review issues * fix(runtime): route in-memory global harness writes Fixes PrimeIntellect-ai#201 * fix(runtime): keep global harness writes global Fixes PrimeIntellect-ai#201 * fix review findings: lazy kernel harness binding, refine turn guard, scope routing - resolve rlm.harness lazily per access so forkserver preimport and post-fork env changes don't freeze an in-memory store; scope-prefixed display ids now route to the right store in kernel CRUD; env-default state no longer has its global target redirected by later explicit-dir cache hits - block new agent turns while a refine pass has session events detached so concurrent prompts aren't lost from the transcript - align kernel RLM_HARNESS_STATE_DIR with the dir the host reads (subagents wrote local entries nothing read); fix rollback ordering for non-persisted sessions; keep legacy scope-less rollbacks global when the recorded path is the global store; document scope-prefix and read-only-global rules in the refinement prompts; update env var docs * fix(coding-agent): preserve auto-refine after compaction * fix(coding-agent): align host harness path fallback * fix(coding-agent): serialize refine and cancel stale continuations * harden auto-refine lifecycle and kernel harness fallbacks - abort/discard auto-refine on session disposal (signal plumbed into the review call; disposed checks around every await; timers invalidated) - stamp the review cooldown on failed reviews/refines and make the pending path respect it, so a persistently failing gate can't burn an LLM call every turn; unify the pending/fresh execution paths and drop the dead pending branchVersion field - re-check refine idleness adjacent to agent.prompt handoffs (extension hooks can suspend between guard and start) - kernel: local harness writes without a session store now raise an instructive error instead of vanishing in memory (reads still work, global_=True still persists); empty RLM_* env vars treated as unset; global-target pinning skips explicit dirs that merely alias the env resolution - dedupe merged-state/history loading; fix stale appendGlobalRefinement docstring * fix(coding-agent): cancel stale auto-refine work * fix(coding-agent): preserve auto-refine cooldown checkpoints * fix(coding-agent): keep manual compact continuations safe * fix(coding-agent): guard stale refine completion * fix(coding-agent): restore continuation after manual compact * fix(coding-agent): preserve manual compact continuation * fix(coding-agent): fall back to turn refine when compact disabled --------- Co-authored-by: Kevin Thomas <kevin.jt2007@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Adds an opt-in automatic refine review hook that asks whether existing /refine should run after configured turn intervals or compaction checkpoints.\n\nValidation:\n- npx tsx ../../node_modules/vitest/dist/cli.js --run test/suite/agent-session-queue.test.ts\n- npm run check
Note
Add auto-refine review hook and local/global harness scope to
AgentSessionautoRefineReviewerhook toAgentSessionConfigthat gates automatic/refineruns (triggered by turn intervals or compaction) through an LLM or custom callback, returning whether to proceed and optional instructions.HarnessStateentries carry ascopefield, CRUD methods accept aglobal_flag, and subprocess environments now receive bothRLM_HARNESS_STATE_DIR(local) andRLM_GLOBAL_HARNESS_STATE_DIR./refinecommand gains a--globalflag in interactive mode; the flag propagates through the RPC, daemon, and in-process connection layers.AgentSession._refinemerges global and session-local harness states for planning and persists edits to the appropriate directory based on scope.scopeonHarnessEntryandglobal_oncreate_memory/get_harness_statebefore marking ready.RLM_HARNESS_STATE_DIRsemantics have changed (now local-only, was formerly global).Changes since #201 opened
AgentSession._localHarnessStateDir()helper method and refactoredAgentSessionsystem prompt builder,AgentSession._autoRefineAllowedForSession(),AgentSession._reviewAutoRefine(),AgentSession.refine(), andAgentSession._rlmKernelEnv()to use the helper for resolving local harness state directories [ceba951]AgentSessionsystem prompt [ceba951]AgentSession.refinecalls to ensure only one refine operation executes at a time [8f9ab3f]AgentSession[8f9ab3f]AgentSession[027d0a9]AgentSession[027d0a9]rlmpackage [027d0a9]AgentSession[027d0a9]appendGlobalRefinementutility incoding-agentrefinement module [027d0a9]AgentSession._invalidatePendingAutoRefineForBranchChangeto async and extended to abort any in-progress auto-refine review via controller, discard pending auto-refine state with cancellation of post-compaction continuation, reset assistant turn count and increment branch version, then wait for refine to become idle before proceeding [47689c9]AgentSession[47689c9]AgentSession._maybeAutoRefineto set compact auto-refine pending flag to true when no model is selected and reason is 'compact' [47689c9]agent-session-queue.test.tstest suite to reflect async signature of_invalidatePendingAutoRefineForBranchChangeand added test coverage for compact auto-refine pending state when no model is selected [47689c9]AbortSignalsupport to auto-refine review flow [f9c1109]AgentSession.compactmethod to defer cancellation of scheduled post-compaction continuations until after confirming the compaction process will proceed, preventing premature cancellation when compaction is skipped or aborted [99c4b0c]AgentSession._refinemethod abortable and disposal-aware [679f3ac]AgentSession.compactmethod to reschedule post-compaction continuations and trigger auto-refine after successful manual compaction [4000abe]AgentSession[4000abe]AgentSession._cancelPostCompactionContinue()after compaction abort check [4b205e9]AgentSession._maybeAutoRefinemethod to fall back to turn-interval review when compact auto-refine is disabled [97a495f]Macroscope summarized f239702.
Note
High Risk
Harness persistence semantics and
RLM_HARNESS_STATE_DIRmeaning changed (local vs former global default), with broad session/refine/compaction interaction; incorrect scope or rollback targeting could corrupt learned state across sessions.Overview
Introduces an opt-in auto-refine path (settings default off) that, on main persisted sessions only, runs a model-backed or injectable review gate after assistant-turn intervals and compaction, then may invoke
/refinewith local-first instructions while respecting cooldowns, busy-agent deferral, branch invalidation, and coordination with post-compactioncontinue.Continual harness storage is split into local (session artifact /
RLM_HARNESS_STATE_DIR) vs global (RLM_GLOBAL_HARNESS_STATE_DIR); the system prompt and planning merge both,/refineacceptsglobal/--global, rollbacks honor recorded paths and scope, and kernel/Python harness CRUD defaults local withglobal_=Truefor cross-session writes.AgentSessionserializes concurrent refines, waits for refine idle before new turns, and aborts in-flight refine on dispose.Docs, prompts, slash-command copy, and bootstrap readiness checks are updated for the new terminology and env semantics.
Reviewed by Cursor Bugbot for commit 97a495f. Bugbot is set up for automated code reviews on this repo. Configure here.