fix: remove machine-initiated context compaction - #384
Conversation
Replace the quality-sweep /compact submission with a warning log and an unsubmitted, route-guarded nudge while preserving degraded detection. Co-Authored-By: cmuxlayerCodex running gpt-5.6-sol <noreply@anthropic.com>
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_ef40b786-d8e1-47af-b4de-ff1a62740553) |
📝 WalkthroughWalkthroughThe agent engine now logs context-limit warnings for all degraded agents. Root agents receive a route-validated checkpoint nudge instead of automatic ChangesContext-limit handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/agent-engine.ts (1)
3827-3858: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winRetry the root-agent nudge after a delivery failure.
Lines 3827-3831 set
qualityto"degraded"before the nudge is sent. IfresolveAgentIoRoute,beforeMutation, orclient.sendfails, Lines 3861-3863 swallow the error. The next sweep skips this block because the agent is already degraded. The root agent then never receives the checkpoint nudge.Track successful nudge delivery separately. Attempt the nudge on later high-context sweeps until it succeeds. Add a regression test with one rejected send followed by a successful retry.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/agent-engine.ts` around lines 3827 - 3858, Track root-agent nudge delivery independently from the agent’s degraded quality state in the context-limit handling flow around resolveAgentIoRoute and client.send. Preserve the pending-nudge state when route resolution, beforeMutation, or send fails, and retry it on subsequent high-context sweeps until delivery succeeds; clear the state only after successful delivery. Add a regression test covering a rejected send followed by a successful retry.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/agent-engine.ts`:
- Around line 3827-3858: Track root-agent nudge delivery independently from the
agent’s degraded quality state in the context-limit handling flow around
resolveAgentIoRoute and client.send. Preserve the pending-nudge state when route
resolution, beforeMutation, or send fails, and retry it on subsequent
high-context sweeps until delivery succeeds; clear the state only after
successful delivery. Add a regression test covering a rejected send followed by
a successful retry.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 8908d3c7-3628-42bd-b371-010f4aaa3c35
📒 Files selected for processing (3)
src/agent-engine.tstests/agent-engine.test.tstests/quality-tracking.test.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (1)
- GitHub Check: Macroscope - Correctness Check
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-03-15T10:42:35.917Z
Learnt from: EtanHey
Repo: EtanHey/cmuxlayer PR: 1
File: tests/quality-tracking.test.ts:171-200
Timestamp: 2026-03-15T10:42:35.917Z
Learning: In tests/quality-tracking.test.ts for the cmuxlayer project, ensure that at or above 80% context quality degradation, behavior depends on depth: depth-0 agents receive a /compact command; depth > 0 agents are killed and logged (kill + log). Respawn of non-root agents is out of scope for v1. Treat the design doc quality tracking section as the authoritative source for this behavior, and align test expectations accordingly.
Applied to files:
tests/quality-tracking.test.tstests/agent-engine.test.ts
🔇 Additional comments (2)
tests/agent-engine.test.ts (1)
3465-3465: LGTM!Also applies to: 3496-3507
tests/quality-tracking.test.ts (1)
3-3: LGTM!Also applies to: 194-194, 216-269, 309-320
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e15f2b185c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
| beforeMutation: async () => { | ||
| await this.resolveUnchangedAgentIoRoute( | ||
| agentId, | ||
| nudgeRoute, | ||
| "context-limit nudge", | ||
| ); |
There was a problem hiding this comment.
Execute the stale-route gate in the app-server adapter
When cmuxlayer-app-server runs this sweep and a surface ref is rebound after nudgeRoute is resolved, this callback does not protect the write: the adapter at src/app-server-runtime.ts:283-287 neither invokes beforeMutation nor locks by stableSurfaceIdentity, and instead forwards both engine-only fields to CmuxClient.send, which ignores them. It consequently locks and writes through the old mutable ref, potentially placing the nudge in an unrelated pane; the adapter must execute the gate and use the UUID lock as the main server connector does.
AGENTS.md reference: AGENTS.md:L20-L25
Useful? React with 👍 / 👎.
| await this.client.send( | ||
| nudgeRoute.surface_id, | ||
| `[cmuxlayer] context at ${contextPct}% — checkpoint at-risk work and /compact when safe`, | ||
| { | ||
| workspace: nudgeRoute.workspace_id ?? undefined, | ||
| ...this.stableSurfaceWriteOptions(nudgeRoute.surface_uuid), | ||
| beforeMutation: async () => { |
There was a problem hiding this comment.
Retry the nudge after delivery failures
When this send or its new stale-route gate throws—for example because the surface moves during the guarded mutation—the surrounding catch suppresses the error after the record has already been persisted as quality: "degraded". Every later sweep then fails the agent.quality !== "degraded" condition, so the nudge is never attempted on the corrected route; delivery state should be tracked separately or the quality transition rolled back when the nudge was not delivered.
Useful? React with 👍 / 👎.
Summary
quality: "degraded"transition at 80% context/compact+ Return with a warning log and an unsubmitted plain-text nudge for root agentsVerification
bun run test— 107 files passed; 2,499 tests passed; 1 skippedbun run typecheckbun run buildquality-trackingandagent-engineRefs:
orchestrator/collab/2026-08-10-cmuxlayer-auto-compact-removal.md— cmuxlayerCodex (worker) · codex/gpt-5.6-sol
Note
Medium Risk
Changes automated terminal I/O on high context for root agents; mis-routing could still send text to the wrong pane, though beforeMutation and stable UUID guards mitigate that.
Overview
When the quality sweep sees ≥80% context, it still sets
quality: "degraded", but it no longer submits/compactand Return on root agents.For depth-0 agents it now sends an unsubmitted plain-text nudge (
[cmuxlayer] context at …% — checkpoint at-risk work and /compact when safe) with workspace scope,beforeMutationroute re-validation, and stable surface identity—same pattern as other guarded terminal writes. Depth > 0 behavior is unchanged: warn only, leave the pane running for the orchestrator.Warning logs include the percent and are wrapped in try/catch so a logging failure cannot block the nudge. Tests were updated to match the new contract and add coverage for nudge when
logfails.Reviewed by Cursor Bugbot for commit e15f2b1. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit
Bug Fixes
Tests
Note
Replace auto-submitted
/compactcommand with a nudge message for depth-0 agents at high context usage/compactand areturnkeypress auto-submitted; these are replaced with an unsubmitted nudge message:[cmuxlayer] context at {pct}% — checkpoint at-risk work and /compact when safe.beforeMutationhook that validates the route binding viaresolveUnchangedAgentIoRoutebefore writing./compactauto-submitted on their behalf; compaction is now user-initiated.Macroscope summarized e15f2b1.