🤖 refactor: extract a pure goal continuation policy from workspaceGoalService - #4009
Open
ibetitsmike wants to merge 4 commits into
Open
🤖 refactor: extract a pure goal continuation policy from workspaceGoalService#4009ibetitsmike wants to merge 4 commits into
ibetitsmike wants to merge 4 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
Contributor
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
This comment has been minimized.
This comment has been minimized.
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.
Summary
Extracts the goal-continuation decision logic out of
WorkspaceGoalServiceinto a pure, synchronous policy module (goalContinuationPolicy.ts). The service becomes the I/O shell (file locks, goal-file reads/writes, chat-tail sync, analytics/timeline emission) around a single decision point that returns a discriminated union:continue|defer(untilMs)|stop(reason, dropCandidate).Background
workspaceGoalService.ts(5,401 lines) interleaved continuation decisions with I/O:checkGoalContinuationEligibilitymixed in-memory candidate maps, runtime-bridge probes, gated goal-file reads,normalizeGoalLimits(a locked read-modify-write with chat-tail reconciliation), one-shot budget wrap-up gating, and cooldown math. The decision had no interface of its own, so testing one cooldown branch required a real session directory, file locks, and mocked services. Refactor #9 of the 2026-08-29 architecture review, based on main @ f04e0f8. Behavior-preserving.Implementation
evaluateGoalContinuation(state)mirrors the previous branch order and candidate-disposition semantics exactly; every skip reason keeps its value (they feed logs and CLI eligibility hints).evaluateGoalContinuationBeforeGoal) preserves the pre-existing I/O gating: undefined probe fields mean "not gathered yet", so the shell still performs no goal-file read while the workspace is busy/streaming and runsnormalizeGoalLimitsonly after all runtime gates pass.applyBudgetDrivenStatus, now takesnowMs), wrap-up origin eligibility, and the cost micro-cent helpers.continuationCooldownMs(CLI: 0) andallowUserOriginBudgetWrapup(CLI: true) are plain policy-state fields; no CLI-vs-interactive conditionals in the policy.checkGoalContinuationEligibilitykeeps its public shape, sosrc/cli/goalRunDriver.tsis untouched.admissionStalegeneration probes, dispatch closures, pause/terminal/identity generations, chat-tail reconciliation.Net LOC (vs f04e0f8)
The production increase is the cost of giving the decision an explicit interface: the policy-state/probe/decision types (~70 lines) had no prior representation (state was implicit in service fields and closure context), and the staged-probe evaluation preserving I/O gating adds ~15 lines. All decision branches were moved, not duplicated; the service shed the same logic plus its duplicated cost helpers. On the test side, 42 table-driven pure cases (zero filesystem, zero mocks) replace 18 disk-harness permutation tests; all stateful race-invariant and shell-wiring tests were retained.
Validation
budget_limitedwith exactly one wrap-up, re-arm on cap raise/removal, pause/manual-message suppression of pending continuations, and the user Stop acknowledgment gate.make static-checkand whole-file runs of the five goal-related test suites (290 tests) are green.Risks
Behavior-preserving refactor of race-sensitive logic; the main risk is decision/branch-order fidelity. Mitigated by mirroring the branch order exactly (reviewable side by side in the diff), leaving every stateful race guard in the shell untouched, retaining the race-invariant test suite, and live UAT of the continuation lifecycle.
Xum acted on Mike's behalf. Generated with
xum• Model:anthropic:claude-fable-5• Thinking:xhigh• Cost: $37.87