Skip to content

fix: remove machine-initiated context compaction - #384

Merged
EtanHey merged 1 commit into
mainfrom
fix/remove-auto-compact
Aug 10, 2026
Merged

fix: remove machine-initiated context compaction#384
EtanHey merged 1 commit into
mainfrom
fix/remove-auto-compact

Conversation

@EtanHey

@EtanHey EtanHey commented Aug 10, 2026

Copy link
Copy Markdown
Owner

Summary

  • preserve the quality sweep's quality: "degraded" transition at 80% context
  • replace machine-submitted /compact + Return with a warning log and an unsubmitted plain-text nudge for root agents
  • guard the nudge against stale surface routes and keep it independent from advisory log failures

Verification

  • bun run test — 107 files passed; 2,499 tests passed; 1 skipped
  • bun run typecheck
  • bun run build
  • targeted TDD regression: 296 tests passed across quality-tracking and agent-engine

Refs: 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 /compact and 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, beforeMutation route 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 log fails.

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

    • Improved high-context handling with clearer warnings and safer workspace-scoped nudges.
    • Root agents now receive validated checkpoint guidance instead of automatic compaction commands.
    • Nudges continue even when warning logs fail.
    • Prevented stale screen information from being used after an agent surface moves.
  • Tests

    • Expanded coverage for context warnings, degraded agent status, logging failures, and relocated agent surfaces.

Note

Replace auto-submitted /compact command with a nudge message for depth-0 agents at high context usage

  • When context usage reaches ≥80%, depth-0 agents previously had /compact and a return keypress auto-submitted; these are replaced with an unsubmitted nudge message: [cmuxlayer] context at {pct}% — checkpoint at-risk work and /compact when safe.
  • Non-root agents only receive a degraded quality mark and a warning log; no pane interaction occurs.
  • The nudge send includes workspace scoping, stable surface write options, and a beforeMutation hook that validates the route binding via resolveUnchangedAgentIoRoute before writing.
  • If the warning log throws, the nudge is still attempted for depth-0 agents.
  • Behavioral Change: depth-0 agents no longer have /compact auto-submitted on their behalf; compaction is now user-initiated.

Macroscope summarized e15f2b1.

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>
@cursor

cursor Bot commented Aug 10, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot 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)

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The agent engine now logs context-limit warnings for all degraded agents. Root agents receive a route-validated checkpoint nudge instead of automatic /compact and Return actions. Tests cover logging failures and recycled surfaces.

Changes

Context-limit handling

Layer / File(s) Summary
Warning and checkpoint nudge flow
src/agent-engine.ts
All degraded agents emit a warning. Root agents receive a stable-route-validated checkpoint nudge. Logging failures do not block the nudge.
Context-limit behavior validation
tests/agent-engine.test.ts, tests/quality-tracking.test.ts
Tests verify degradation, warning logging, nudging, recycled-surface handling, and the absence of automatic /compact and Return actions.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Poem

A rabbit saw the context grow,
And warned the agents before overflow.
No /compact, no Return to press,
Just a checkpoint nudge with route-checked finesse.
Hop, hop—safe work is stored!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: removing machine-initiated context compaction.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/remove-auto-compact

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Retry the root-agent nudge after a delivery failure.

Lines 3827-3831 set quality to "degraded" before the nudge is sent. If resolveAgentIoRoute, beforeMutation, or client.send fails, 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

📥 Commits

Reviewing files that changed from the base of the PR and between 78d32c3 and e15f2b1.

📒 Files selected for processing (3)
  • src/agent-engine.ts
  • tests/agent-engine.test.ts
  • tests/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.ts
  • tests/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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/agent-engine.ts
Comment on lines +3850 to +3855
beforeMutation: async () => {
await this.resolveUnchangedAgentIoRoute(
agentId,
nudgeRoute,
"context-limit nudge",
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment thread src/agent-engine.ts
Comment on lines +3844 to +3850
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 () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@EtanHey
EtanHey merged commit 4c8ff45 into main Aug 10, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant