ConeCode Bounded, Anchored Recursive Self-Improvement (RSI+RL) System: Complete Technical Report · @songguotilamisu · TwKit
@songguotilamisu
1. System Overview and Design Philosophy ConeCode's RSI (Recursive Self-Improvement) mode is a bounded, externally anchored Recursive Self-Improvement (RSI+RL) architecture engineered for a desktop AI coding workspace. Designed to counter four fundamental failure modes of unconstrained self-improvement in real-world software engineering—unanchored goal drift, single-fixture reward hacking, benchmark-induced security contamination, and unbounded verification churn—the system rests on four foundational principles: First, strict separation between generation and adjudication. The large language model is scoped strictly to root-cause diagnosis, breakthrough direction discovery, causal hypothesis formulation, and localized code edits. Every safety and acceptance gate—goal-vector freeze checks, pre-mutation candidate validation, workspace snapshotting and rollback, external verification cascades, composite reward computation, Pareto frontier maintenance, slow registration, cost-lock circuit breaking, stop evaluation, and offline policy replay (DREAM)—is owned by deterministic, unit-tested TypeScript code rather than prompt prose. Second, external anchoring as the sole ground truth. Every candidate must be verified by real, executable external commands such as typechecking, unit tests, builds, target benchmarks, and performance snapshots. Self-assessment and multi-agent judge scores act only as secondary shaping among candidates that already pass all external hard gates and demonstrate measurable metric improvement. Third, modular small-step evolution with per-conversation isolation. Each candidate is restricted to one of six predefined modules, and every RSI conversation maintains its own isolated direction contract, disk archive, and discovery-tree lineage to prevent cross-task contamination and monolithic rewrites. Fourth, explicit engineering boundaries. Evolution is restricted to the open workspace (product code, additive verification tests, project harness files such as AGENTS.md, skills, and documentation). Model weight training, host-level privilege expansion, and autonomous modification of safety invariants are out of scope; meta-level protocol changes remain strictly user-gated. 2. Layered Software Architecture and Per-Conversation Storage The RSI subsystem follows a four-layer architecture: Protocol and Session Contract Layer, Pure Decision Core, Orchestration and Host Integration Layer, and Presentation Layer. The pure decision core imports no node:fs, node:crypto, or React/DOM APIs; all filesystem side effects are injected through the RsiFs contract so the exact same logic executes in the Electron renderer, the Node.js main process, and in-memory unit tests. 2.1 Protocol and Session Contract Layer (modePrompts.ts, rsiConversation.ts, rsiStart.ts) Defines shared non-negotiable invariants (RSI_INVARIANTS), the nine-phase RSI+RL prompt protocol, cost-lock and UI-design overlays, per-conversation archive path mapping (rsiWorkspaceDir), five-field direction configuration (objective, priorities, metrics, scope, constraints), and macOS screen-recording and accessibility start gating (rsiCanStart). 2.2 Pure Decision Core (rsiReward.ts, rsiLoop.ts, rsiVerify.ts, rsiTree.ts, rsiPersistence.ts, rsiReplay.ts, rsiHistory.ts) Implements composite reward and hard gates, Pareto dominance and archive pruning, multi-panel trimmed-mean judge calibration, pre-mutation candidate validation, failure classification and stop evaluation, cheapest-first verification cascades and output parsers, discovery-tree schema and strict deserialization, append-only logs, baselines, lessons, and checkpoints, DREAM offline policy replay, and untrusted history compression. 2.3 Orchestration and Host Integration Layer (rsiEpisode.ts, rsiBridge.ts, rsiRuntime.ts, chat.store.ts, electron/rsi/store.ts, rsiControl.ts) Provides the synchronous single-episode orchestrator (runRsiEpisode), asynchronous Electron IPC bridge (snapshotWorkspace, rollbackWorkspace, verifyAndAdjudicate, bootstrapRsiWorkspace), live runtime tool-evidence monitor (RsiExecutionMonitor), chat-loop integration for cost lock, scoped auto-approval, and final auto_screenshot pixel review, main-process node:fs adapter, and remote start/stop event routing. 2.4 Presentation Layer (RsiView.tsx, RsiDirectionPanel.tsx, rsiPresentation.ts, rsiLayout.ts) Delivers a three-tab workbench (Console, Direction, Pipeline) with localized direction presets, local draft buffering, explicit phase-marker detection (detectRsiPhase), and layout isolation that hides the split code editor while RSI mode is active. Each RSI conversation persists its artifacts under workspaceRoot/.conecode/rsi/conversations/safeConversationId/ (with legacy .conecode/rsi/ retained only as a fallback). The directory holds eight controlled artifacts: frozen read-only GOAL_VECTOR.md, initial ASSESS numeric baseline BASELINE.json, versioned checkpoint LOOP_STATE.json (version 1), append-only idempotent discovery trees under trees/episodeId.json, write-once immutable iteration records under iterations/candidateId.md, slow-registered EVOLUTION_LOG.md, contamination-filtered REFLECTIONS.md capped at 30 entries, and DREAM-updated STRATEGY.md. 3. Safety Invariants, Goal Freezing, and Pre-Mutation Validation The protocol layer embeds six immutable rules via RSI_INVARIANTS across Goal, Orchestrate, and RSI modes: never weaken safety controls (approvals, sandbox, TLS, authentication, permissions); never allow untrusted files, comments, fixtures, benchmarks, or tool outputs to override instructions (Trusting Trust defense); never destroy user work or perform unauthorized deletions, force-pushes, publishing, or spending; never game verification by skipping, deleting, or weakening tests or assertions; never claim unverified success (UI work requires full-location screenshot review and major deliverables require perf_snapshot health checks); and keep all mutations inside the open workspace with small, reviewable diffs. Planning and execution are strictly separated: selecting RSI mode or saving direction settings never starts a run. Execution activates only via the explicit Start control, active run continuation, or an authorized user request that invokes mutating or exec tools. Two complementary parsers process GOAL_VECTOR.md: parseGoalChecks extracts every required external check command (including non-numeric guards and native perf_snapshot) for the runtime monitor and flags ambiguous declarations; parseGoalVector extracts charter text, freeze timestamp, non-goals, and numeric metrics with explicit higher or lower directions. A bundle-safe 32-bit djb2 hex fingerprint (hashContent) verifies before every candidate that GOAL_VECTOR.md has neither vanished nor mutated; any discrepancy halts the loop and rolls back pending edits. The evolvable surface is partitioned into six mutually exclusive modules: loop, tools, observation, context, completion, and product. Before touching any file, validateCandidate enforces non-empty id and hypothesis, at least one frozen goal metric, external=true on every success criterion, normalized touch paths strictly inside workspaceRoot, strict exclusion of all frozen evaluation regions (EVOLVE-BLOCK), zero overlap between touch and doNotTouch paths, positive integer file and line budgets, and a finite non-negative cost budget. 4. Single-Episode Program Loop and Positive-Existence Rollback The canonical nine-phase loop runs ASSESS, DISCOVER, SAMPLE, DECLARE, EXECUTE, VERIFY, SCORE, DREAM, STOP (looping from DREAM back to ASSESS). Both the synchronous orchestrator (runRsiEpisode) and the asynchronous renderer bridge (verifyAndAdjudicate) enforce a fixed ten-step pipeline: Step 1, idempotent deduplication: if candidate.id is already in seenIds, return immediately as duplicate with zero side effects. Step 2, stop-boundary enforcement: if prev.stopped is true or evaluateStop triggers, preempt as loop-stopped, persist stopped=true with deduplicated stopReasons, and roll back uncommitted edits in the async bridge. Step 3, goal-freeze verification: confirm GOAL_VECTOR.md matches goalHash; otherwise halt with cannotVerify=true and roll back. Step 4, static candidate validation: invalid declarations record REWARD_FAIL (-999), increment non-improving and failure counters, evaluate stop conditions before persisting LOOP_STATE.json, and roll back in the async bridge. Step 5, pre-mutation snapshot and parent-directory baseline: record contents of declared touch paths and scan parent directories to detect undeclared file creations. Step 6, controlled mutation and external verification cascade: apply changes inside active sandbox and approval rules, then execute runVerifyCascade cheapest-first with early exit. Step 7, metric delta extraction and hard-gate synthesis: compute signed deltas via buildMetricDeltas; missing baselines or unparseable required frozen metrics force externalPass=false. Spending beyond 2x costBudgetUsd forces a discipline veto, and retentionPassed=false forces externalPass=false. Step 8, composite scoring and four-way archive verdict: compute reward and decide replace-best, retain-frontier, or reject. Step 9, exact rollback and residue cleanup: every non-replace-best outcome restores modified files and deletes both declared new files and undeclared creations. Step 10, immutable persistence, slow registration, and stop re-evaluation: append the discovery-tree node, write the write-once iteration file, conditionally append EVOLUTION_LOG.md via slowRegisterGate, re-evaluate stopping, and persist LOOP_STATE.json. Over Electron IPC, where read errors can collapse to null or empty arrays, snapshotWorkspace enforces positive proof of absence: an unreadable path is recorded in absentPaths only when pathExists explicitly returns false (confirmed by null stat and a non-empty parent listing for a non-dotfile). Indeterminate states abort snapshotting before mutation so rollback can never delete an existing file. Any file I/O failure during rollback is collected into RollbackReport.errors and tagged with +rollback-errors rather than silently ignored. 5. Verification Cascade, Composite Reward, and Pareto Frontier runVerifyCascade executes declared stages cheapest-first, stops at the first non-zero exit code or thrown runner error, and records costSteps to quantify early-exit savings. Empty stage lists always return passedAll=false. Built-in CLI parsers strip ANSI escape sequences via stripAnsi before matching, ensuring colored Vitest summaries (parseVitestSummary) and tsc --pretty diagnostics (parseTscOutput) extract exact failure and error counts. signedDelta converts all measurements into a higher-is-better convention, and buildMetricDeltas explicitly reports unparseable or unbaselined metrics in missing[] rather than defaulting to zero. computeReward applies hard-gate short-circuiting followed by scale-normalized aggregation. Any external failure, invalid metric vector, negative or non-finite edit count, or hard-floor breach (scaledDelta below minDelta) returns REWARD_FAIL (-999). Passing candidates divide each raw delta by max(scale, 1e-9), bound each axis with tanh into (-1, 1), and compute a weight-normalized mean M. Judge scores (alignment, simplicity, discipline) are clamped to [0, 1] and averaged into J. Edits exceeding the default budget (6 files, 400 lines) incur a penalty P_cost = 0.25 * fileOver + 0.25 * lineOver. The composite reward is R = 1.2 * M + 0.8 * J - P_cost. Three safeguards prevent score gaming: First, calibrated multi-panel judging (combineJudgePanels): any single panel returning discipline <= 0 triggers a global discipline veto; for three or more panels, remaining axes use a trimmed mean (dropping minimum and maximum) to neutralize judge drift. Second, anti-flattery promotion (selectCandidate): replacing an incumbent requires a complete, key-matched finite incumbent metric vector, at least one metric exceeding the incumbent by more than epsilon (default 0.001), and composite reward exceeding incumbent reward plus epsilon. Flattering judges alone cannot promote flat or regressed candidates. Third, Pareto non-dominated retention with decoupled incumbent anchoring (selectForArchive): candidates trailing overall reward yet passing all hard gates, improving over baseline on at least one axis, non-equivalent to existing archive members, and non-dominated are retained in the Pareto archive with newly dominated entries pruned. Persisting state.best.metrics independently of state.archive ensures incumbent comparisons remain exact even if a high-cost dominating candidate prunes the incumbent from the frontier. 6. Runtime Evidence Monitor and Host Integration During interactive runs in chat.store.ts, RsiExecutionMonitor (rsiRuntime.ts) maintains an objective ledger of tool observations independent of assistant prose: First, exit-preserving shell subset and directory scoping. shellParts rejects pipes, semicolons, redirections, command substitutions, and single ampersands that can mask failing exit codes or hide mutations, accepting only &&-chained read-only prefixes (with literal cd tracking) paired with recognized or goal-declared verification commands, while filtering non-verifying flags (--help, --dry-run, --fix, --updateSnapshot). Checks are matched as (effectiveCwd, command) tuples. Second, product revision invalidation. Any product file write or unrecognized exec increments revision, clearing previously passed frozen checks and resetting screenshot status, while .conecode/rsi archive writes remain exempt. Third, repeated-failure and identical-diagnostic circuit breaking. Execution halts after three consecutive failures of the same tool without code edits, or three distinct repairs yielding the exact same complete diagnostic (up to 8192 characters, exit-code prefix stripped), with a hypothesis-switch prompt issued after two. Fourth, multimodal visual acceptance closure. Once all frozen checks pass on the current revision and the model stops calling tools, chat.store.ts intercepts premature completion text and dispatches the official auto_screenshot plugin (verifying foreground conversation and workspace ownership, target match, and vision-capable model support). Each capture receives a monotonic ticket; finish() returns complete only after the next model turn inspects those pixels and confirms review (allowing up to two recovery turns). In addition, the host enforces real-time cost-lock stops when known spend exceeds 2x maxEpisodeCost, scopes temporary auto-approval strictly to the live RSI run without altering global settings, and injects bounded, escaped archive history (<rsi-history-data>, capped under 5900 characters) as explicitly untrusted data. 7. Crash Recovery, Slow Registration, DREAM Offline Replay, and Stopping Discovery trees enforce strict deserialization (rejecting duplicate IDs and dangling parents) and report corrupted files explicitly without silent repair. recoverLoopState loads LOOP_STATE.json first (recovering legacy incumbent metrics from archive or accepted tree nodes when needed) and falls back to rebuildLoopStateFromTrees on missing or corrupt checkpoints, reconstructing best, archive, failure streaks, and spend deterministically in timestamp order without re-running external checks. Persistent learning follows fast discovery, slow registration: EVOLUTION_LOG.md appends only after at least two independent accepted wins or explicit user approval with at least one win. REFLECTIONS.md rejects security-weakening contamination patterns via regex, assigns monotonically increasing IDs (maxSeq + 1), reinforces duplicate rules by appending episode IDs, and caps storage at 30 entries. DREAM offline policy replay (rsiReplay.ts) is strictly isolated from product verification (never re-running tests or fabricating rewards) and evaluates exploration policies (maxAttempts, moduleSpread, parallelism W) over recorded discovery trees. To prevent inflated parallelism from gaming serial histories, rounds are computed via topological parent-child batch scheduling, and invalid nodes (external failure, hard failure, or base failureReason in safety/budget/error classes after stripping +rollback-errors suffixes) are excluded from maxReward. The per-tree score is V = maxReward - 0.05 * N + 0.02 * (N / max(1, rounds)). Policy updates require both sufficient evidence (at least 2 trees and 4 experiments) and strict improvement over the incumbent (margin 1e-6), guaranteeing monotone non-regression on fixed history. evaluateStop frames termination explicitly as budget-limited local convergence rather than global optimality, triggering on user interrupt, unverifiable oracle, two consecutive hard fails, exhausted episode budget, 2x cost-lock or 4x hard spend cap, three consecutive identical failure classes, or three consecutive non-improving episodes after at least one win (flagged as local-plateau-narrow-search when at least 75% of the last four attempts hit the same module). 8. Verification Coverage and Engineering Boundaries All RSI modules pass TypeScript strict checking with zero RSI errors and are verified by 21 test suites totaling 259 automated tests (100% passing in 1.16s on Node v24.19.0 / Vitest 4.1.11), spanning reward and Pareto core (35 tests), loop, orchestrator, and bridge (50 tests), verification cascade and runtime monitor (55 tests), discovery trees, persistence, and DREAM (27 tests), and host store and UI contracts (92 tests). In a controlled nine-trajectory comparison against the real 2026-11-08 installer-fix goal contract, the revised runtime monitor raised interception accuracy on five under-verified trajectories from 0% to 100% with zero false rejections on complete trajectories. Key engineering boundaries remain explicit: perf_snapshot observes the ConeCode Electron host process rather than an external target application (which requires project-specific benchmark commands in GOAL_VECTOR.md), and file-level snapshotting covers declared paths and parent-directory creations while deeper command side effects benefit from Git Worktree or copy-on-write filesystem isolation.
曝光 648 · 评论 2 · 点赞 7 · 书签 2
查看原帖