Skip to content

Comments

Remove compaction paths and opt-in warning logging#75

Merged
riatzukiza merged 3 commits intodevfrom
compaction-logging-cleanup
Nov 22, 2025
Merged

Remove compaction paths and opt-in warning logging#75
riatzukiza merged 3 commits intodevfrom
compaction-logging-cleanup

Conversation

@riatzukiza
Copy link
Collaborator

Summary

  • remove the compaction pipeline (code and specs) and simplify prompt filtering/session cache handling
  • make warning-to-console logging opt-in via config/env, document logging controls, and keep warnings in file/app logs by default
  • update tests/docs/specs to cover new logging defaults and the compaction removal work

Testing

  • npm test

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 21, 2025

Summary by CodeRabbit

  • Removed Features

    • Removed conversation compaction feature, including automatic conversation summarization and context trimming capabilities.
  • New Features

    • Added logWarningsToConsole option to control whether warning messages are displayed in the console.
  • Improvements

    • Enhanced prompt cache key stability to remain consistent when environment files change across conversation turns.
    • Improved environment block stripping in OpenCode system prompts for cleaner context management.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

This PR removes the codex-based conversation compaction subsystem (modules, prompts, helpers, and session APIs), adds an optional config/env flag to mirror warnings to the console, and updates OpenCode prompt filtering to strip environment blocks with optional env-segment reattachment.

Changes

Cohort / File(s) Summary
Compaction modules removed
lib/compaction/codex-compaction.ts, lib/compaction/compaction-executor.ts, lib/request/compaction-helpers.ts
Deleted entire modules and all exported types/functions for codex compaction, prompt construction, decisioning, and finalization.
Prompts removed
lib/prompts/codex-compaction.ts
Removed exported constants CODEX_COMPACTION_PROMPT and CODEX_SUMMARY_PREFIX.
Session state / API changes
lib/session/session-manager.ts, lib/types.ts
Removed applyCompactionSummary / applyCompactedHistory and removed compactionBaseSystem / compactionSummaryItem from SessionState.
Input-filter behavior
lib/request/input-filters.ts
Reworked OpenCode system-prompt filtering: added stripOpenCodeEnvBlocks, captureable envSegments, and new filterOpenCodeSystemPromptsWithEnv; removed compaction-related sanitization/metadata path.
Request transformer updates
lib/request/request-transformer.ts
When CODEX_APPEND_ENV_CONTEXT=1, uses filterOpenCodeSystemPromptsWithEnv and may append envSegments as a developer message; re-exports the helper.
Config & logging config/type
lib/config.ts, lib/types.ts
Added logWarningsToConsole default in DEFAULT_CONFIG and LoggingConfig; added environment flag mapping.
Logger behavior
lib/logger.ts, test/logger.test.ts
New env flag CODEX_LOG_WARNINGS_TO_CONSOLEWARN_CONSOLE_ENABLED; warn-level routing adjusted (still writes rolling log; console mirroring controlled by new flag); tests updated.
Tests added/updated
test/*.test.ts, test/cache-e2e.test.ts
Tests updated to reflect compaction removals and logging changes; added e2e cache test covering env-tail behavior and user-only change warnings.

Sequence Diagram(s)

sequenceDiagram
    participant Config
    participant RequestTransformer
    participant InputFilters
    participant SessionManager
    participant Logger
    participant Console

    Note over RequestTransformer,InputFilters: Codex transform with optional env-tail
    Config->>RequestTransformer: CODEX_APPEND_ENV_CONTEXT flag
    RequestTransformer->>InputFilters: filterOpenCodeSystemPromptsWithEnv(input)
    InputFilters-->>RequestTransformer: { input, envSegments? }
    alt envSegments present && flag enabled
        RequestTransformer->>RequestTransformer: append envSegments as developer message
    end
    RequestTransformer->>SessionManager: produce transformed RequestBody (prompt_cache_key preserved)
    alt warning emitted (prefix mismatch / user change)
        RequestTransformer->>Logger: logWarn(warningPayload)
        alt WARN_CONSOLE_ENABLED && level == "warn"
            Logger->>Console: console.warn(...)
        end
        Logger->>Logger: appendFile to rolling log
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Areas needing extra attention:

  • Search for any remaining imports/usages of removed compaction exports (lib/compaction/*, compaction-helpers) and update callers.
  • Verify session fork and consumer code that previously relied on compactionBaseSystem / compactionSummaryItem are updated or removed.
  • Validate filterOpenCodeSystemPromptsWithEnv correctness (envSegments capture, removed-blocks semantics) and prompt_cache_key stability tests.
  • Confirm WARN_CONSOLE_ENABLED initialization and merge with config/env and associated test coverage.

Possibly related PRs

Poem

Compaction wings are clipped and flown,
Env blocks stripped, their secrets known.
Warnings may now knock on console doors,
Rolling logs keep all the scores.
A cleaner branch, a steadier course. ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.56% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the two main changes: removing the compaction pipeline and making warning logging opt-in.
Description check ✅ Passed The description is directly related to the changeset, covering the removal of compaction code and the opt-in warning logging feature.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch compaction-logging-cleanup

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4225303 and 138b520.

📒 Files selected for processing (1)
  • test/session-manager.test.ts (8 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
test/session-manager.test.ts (2)
lib/types.ts (2)
  • SessionContext (203-209)
  • RequestBody (153-175)
lib/session/session-manager.ts (1)
  • SessionManager (267-591)
🔇 Additional comments (7)
test/session-manager.test.ts (7)

5-5: LGTM: Type imports align with simplified test flow.

The import now explicitly includes RequestBody and SessionContext types, which are used throughout the updated test assertions.


52-53: LGTM: Correctly adopts two-step context flow.

The test now separates context retrieval and request application, matching the updated SessionManager API pattern.


76-106: LGTM: Past CI blocker has been resolved.

The test now correctly expects previousRole: "user" and incomingRole: "system", matching the actual roles when a system message is introduced to a user-only history. This aligns with the fix recommended in the previous review.


147-189: LGTM: History pruning detection is correct.

The test properly verifies that the SessionManager detects and logs history pruning, including the removed count and roles.


191-213: LGTM: Token usage and metrics tests are straightforward.

Both tests correctly exercise the SessionManager APIs and follow the updated context flow pattern.


215-288: LGTM: Session lifecycle tests cover key scenarios.

The tests properly verify fallback behavior, session reuse, and fork ID derivation, all using the updated context flow.


290-318: LGTM: Eviction and capacity tests verify session management limits.

The tests correctly exercise pruning of idle sessions and enforcement of maximum capacity limits.


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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
test/request-transformer.test.ts (1)

243-252: Host metadata test update matches new semantics; consider stronger assertion

Switching the sample item to content: "Custom host metadata message" with metadata: { source: "host-metadata" } is consistent with the new host-metadata flow and keeps the behavior (preserve metadata, drop IDs) intact.

If you want tighter regression coverage, you could assert the metadata value itself, e.g. expect(result![0].metadata).toEqual({ source: "host-metadata" }), instead of only checking that metadata exists.

test/logger.test.ts (1)

38-45: Clear new logging env flags in tests to avoid env‑dependent flakiness

The setup resets several logging env vars, but not CODEX_LOG_WARNINGS_TO_CONSOLE (and CODEX_SHOW_WARNING_TOASTS), while later tests assume warnings stay off the console by default and toasts are disabled unless explicitly enabled.

If those vars are set in the outer environment, tests like the new logWarn cases can start failing spuriously. It’s safer to normalize them in beforeEach.

Apply this change to the test setup:

 beforeEach(() => {
   vi.resetModules();
   Object.assign(process.env, originalEnv);
   delete process.env.ENABLE_PLUGIN_REQUEST_LOGGING;
   delete process.env.DEBUG_CODEX_PLUGIN;
   delete process.env.CODEX_LOG_MAX_BYTES;
   delete process.env.CODEX_LOG_MAX_FILES;
   delete process.env.CODEX_LOG_QUEUE_MAX;
+  delete process.env.CODEX_SHOW_WARNING_TOASTS;
+  delete process.env.CODEX_LOG_WARNINGS_TO_CONSOLE;
lib/logger.ts (1)

12-20: Warn logging defaults and overrides are wired correctly; consider error persistence symmetry

The new pieces all fit together cleanly:

  • envLoggingDefaults.logWarningsToConsole seeds WARN_CONSOLE_ENABLED, and applyLoggingOverrides lets LoggingConfig.logWarningsToConsole override the env default.
  • emit now:
    • Always appends warn entries to the rolling log (LOGGING_ENABLED || DEBUG_ENABLED || level === "warn"), matching the goal of keeping warnings in file logs even when request logging is “off”.
    • Sends warn‑level console output only when WARN_CONSOLE_ENABLED is true and warning toasts aren’t being used, which is exactly what the tests assert.
    • Leaves debug/info console behavior controlled by CONSOLE_LOGGING_ENABLED, and errors always hit the console.

One thing to sanity‑check: with shouldPersist = LOGGING_ENABLED || DEBUG_ENABLED || level === "warn", error logs are not persisted unless logging or debug is enabled, while warnings are. If you intended “errors should never be less durable than warnings”, you might want to extend the condition to include level === "error" as well. Otherwise, the implementation looks coherent.

Also applies to: 27-32, 78-92, 187-188, 211-215

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a455bd1 and 0552640.

⛔ Files ignored due to path filters (25)
  • CHANGELOG.md is excluded by none and included by none
  • README.md is excluded by none and included by none
  • docs/code-cleanup-summary.md is excluded by none and included by none
  • docs/code-quality-analysis-report.md is excluded by none and included by none
  • docs/configuration.md is excluded by none and included by none
  • docs/getting-started.md is excluded by none and included by none
  • docs/notes/2025.11.19.18.38.24.md is excluded by none and included by none
  • spec/auto-compaction-summary.md is excluded by none and included by none
  • spec/cache-analysis.md is excluded by none and included by none
  • spec/complexity-reduction.md is excluded by none and included by none
  • spec/issue-triage-2025-11-20.md is excluded by none and included by none
  • spec/log-warnings-default-file-only.md is excluded by none and included by none
  • spec/merge-conflict-resolution.md is excluded by none and included by none
  • spec/open-issues-triage.md is excluded by none and included by none
  • spec/plugin-log-settings-doc.md is excluded by none and included by none
  • spec/pr-2-conflict-analysis.md is excluded by none and included by none
  • spec/pr-20-review.md is excluded by none and included by none
  • spec/pr-29-review-analysis.md is excluded by none and included by none
  • spec/pr-commit-2025-11-21.md is excluded by none and included by none
  • spec/readme-cleanup.md is excluded by none and included by none
  • spec/remove-plugin-compaction.md is excluded by none and included by none
  • spec/request-transformer-refactor.md is excluded by none and included by none
  • spec/review-pr-20-plan.md is excluded by none and included by none
  • spec/review-v0.3.5-fixes.md is excluded by none and included by none
  • spec/session-prefix-mismatch.md is excluded by none and included by none
📒 Files selected for processing (14)
  • lib/compaction/codex-compaction.ts (0 hunks)
  • lib/compaction/compaction-executor.ts (0 hunks)
  • lib/config.ts (1 hunks)
  • lib/logger.ts (5 hunks)
  • lib/prompts/codex-compaction.ts (0 hunks)
  • lib/request/compaction-helpers.ts (0 hunks)
  • lib/request/input-filters.ts (0 hunks)
  • lib/session/session-manager.ts (2 hunks)
  • lib/types.ts (1 hunks)
  • test/logger.test.ts (3 hunks)
  • test/plugin-config.test.ts (6 hunks)
  • test/prompts-codex.test.ts (4 hunks)
  • test/request-transformer.test.ts (1 hunks)
  • test/session-manager.test.ts (0 hunks)
💤 Files with no reviewable changes (6)
  • lib/prompts/codex-compaction.ts
  • lib/compaction/compaction-executor.ts
  • lib/request/compaction-helpers.ts
  • lib/request/input-filters.ts
  • test/session-manager.test.ts
  • lib/compaction/codex-compaction.ts
🧰 Additional context used
🧬 Code graph analysis (1)
test/logger.test.ts (1)
lib/logger.ts (3)
  • logWarn (160-162)
  • flushRollingLogsForTest (168-173)
  • configureLogger (109-131)
🔇 Additional comments (5)
test/plugin-config.test.ts (1)

52-56: Config tests correctly cover new logWarningsToConsole default across paths

The added logging: { showWarningToasts: false, logWarningsToConsole: false } expectations on default, file-load, merge, and error/fallback paths match the new default config and nested logging merge behavior. Looks consistent and thorough.

Also applies to: 69-73, 82-86, 97-102, 112-116, 131-135

lib/types.ts (1)

33-35: LoggingConfig extension for logWarningsToConsole is consistent

The new logWarningsToConsole?: boolean field and its documentation align with the logger’s override logic and the DEFAULT_CONFIG shape; no typing or behavioral concerns here.

lib/config.ts (1)

15-18: Default plugin config now correctly includes logWarningsToConsole

Adding logWarningsToConsole: false to DEFAULT_CONFIG.logging keeps the runtime config shape in sync with LoggingConfig and the tests, and it participates in the nested logging merge as expected.

test/logger.test.ts (1)

145-158: logWarn tests correctly exercise new console‑mirroring behavior

The new tests verify that:

  • By default, logWarn appends to the rolling log but doesn’t touch console.warn.
  • With a TUI client and default config, warnings go to the app log (file), not toasts or console.
  • When logging.logWarningsToConsole is enabled via configureLogger, logWarn both appends and emits a prefixed console warning.

This matches the updated emit logic (shouldPersist including warn and shouldLogToConsole gating warn on WARN_CONSOLE_ENABLED) and gives good coverage of the new flag.

Also applies to: 160-180, 209-220

test/prompts-codex.test.ts (1)

113-117: Prompts tests now correctly assert via logger.logWarn instead of console.warn

Swapping the expectations to spy on logger.logWarn in the “fetch fails” and “no cache available” cases lines the tests up with the new logging pathway, while still using console.error for the actual fetch error details. This keeps behavior the same from a user perspective but decouples tests from console‑warning defaults.

Also applies to: 144-145, 151-153, 242-246, 263-264, 270-272

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
test/session-manager.test.ts (1)

108-145: Test name vs behavior for user-only changes.

The "does not warn on user-only content changes" test does expect a "prefix mismatch" warning and asserts prefixCause: "user_message_changed". Behavior-wise this is correct and useful, but the name is now misleading. Consider renaming to better match the semantics (e.g., "labels user-only prefix mismatches as user_message_changed").

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0552640 and 4225303.

⛔ Files ignored due to path filters (5)
  • .eslintignore is excluded by none and included by none
  • .gitignore is excluded by none and included by none
  • README.md is excluded by none and included by none
  • eslint.config.mjs is excluded by none and included by none
  • scripts/inspect-codex-logs.mjs is excluded by none and included by none
📒 Files selected for processing (6)
  • lib/request/input-filters.ts (3 hunks)
  • lib/request/request-transformer.ts (2 hunks)
  • lib/session/session-manager.ts (5 hunks)
  • test/cache-e2e.test.ts (1 hunks)
  • test/request-transformer.test.ts (4 hunks)
  • test/session-manager.test.ts (8 hunks)
🧰 Additional context used
🧬 Code graph analysis (6)
lib/request/request-transformer.ts (1)
lib/request/input-filters.ts (2)
  • filterOpenCodeSystemPromptsWithEnv (158-162)
  • filterOpenCodeSystemPrompts (151-156)
test/request-transformer.test.ts (3)
lib/types.ts (2)
  • InputItem (142-148)
  • RequestBody (153-175)
lib/request/input-filters.ts (1)
  • filterOpenCodeSystemPrompts (151-156)
lib/request/request-transformer.ts (2)
  • filterOpenCodeSystemPrompts (20-20)
  • transformRequestBody (99-149)
test/session-manager.test.ts (2)
lib/types.ts (2)
  • SessionContext (203-209)
  • RequestBody (153-175)
lib/session/session-manager.ts (1)
  • SessionManager (267-591)
test/cache-e2e.test.ts (3)
lib/types.ts (2)
  • UserConfig (46-53)
  • RequestBody (153-175)
lib/session/session-manager.ts (1)
  • SessionManager (267-591)
lib/request/fetch-helpers.ts (1)
  • transformRequestForCodex (120-198)
lib/request/input-filters.ts (2)
lib/types.ts (1)
  • InputItem (142-148)
lib/utils/input-item-utils.ts (1)
  • extractTextFromItem (16-27)
lib/session/session-manager.ts (1)
lib/logger.ts (1)
  • logWarn (160-162)
🪛 GitHub Actions: CI
test/session-manager.test.ts

[error] 99-101: SessionManager regenerates cache key when prefix differs. AssertionError: expected { sessionId: 'conv-789', …(12) } to match object { …(3) }

🪛 GitHub Check: Test (20.x)
test/session-manager.test.ts

[failure] 99-99: test/session-manager.test.ts > SessionManager > regenerates cache key when prefix differs
AssertionError: expected { sessionId: 'conv-789', …(12) } to match object { …(3) }
(10 matching properties omitted from actual)

  • Expected
  • Received

    {
    "incomingRole": "system",
    "prefixCause": "system_prompt_changed",

  • "previousRole": "system",
  • "previousRole": "user",
    }

❯ test/session-manager.test.ts:99:25

🪛 GitHub Check: Test (22.x)
test/session-manager.test.ts

[failure] 99-99: test/session-manager.test.ts > SessionManager > regenerates cache key when prefix differs
AssertionError: expected { sessionId: 'conv-789', …(12) } to match object { …(3) }
(10 matching properties omitted from actual)

  • Expected
  • Received

    {
    "incomingRole": "system",
    "prefixCause": "system_prompt_changed",

  • "previousRole": "system",
  • "previousRole": "user",
    }

❯ test/session-manager.test.ts:99:25

🔇 Additional comments (8)
test/session-manager.test.ts (2)

147-189: History-pruning warning expectations align with implementation.

This test nicely targets the history_pruned path: pruning earlier tool/tool_result messages yields removedCount: 4 and removedRoles including "tool", matching the findSuffixReuseStart and isToolMessage logic in analyzePrefixChange. No changes needed here.


191-318: Session usage, metrics, and capacity tests track the updated flow correctly.

Using getContext(...); applyRequest(...); in these tests mirrors the real SessionManager lifecycle and validates:

  • recordResponse correctly updates lastCachedTokens.
  • getMetrics surfaces session summaries.
  • Host-provided prompt_cache_key reuse, fork-specific keys, TTL eviction, and MAX_ENTRIES capping all behave as intended.

These tests look consistent with the current SessionManager API and state fields.

lib/session/session-manager.ts (3)

6-7: Using cloneInputItems before hashing is the right call.

Cloning body.input via cloneInputItems before computing inputHash and storing lastInput prevents external mutation from invalidating session prefix comparisons or cache-key decisions. This keeps SessionManager’s view of the conversation stable across callers.

Also applies to: 371-377


105-171: Prefix-change analysis covers system, history-prune, and user-only changes cleanly.

The updated PrefixChangeCause and analyzePrefixChange logic now distinguish:

  • history_pruned via findSuffixReuseStart and removedSegment analysis,
  • system_prompt_changed when either side of the mismatch is system-like,
  • user_message_changed when both mismatching roles are "user",

with an explicit "unknown" fallback. This matches how tests introspect prefixCause, previousRole, incomingRole, and pruning details, and gives good diagnostic data without changing the underlying fork vs reset behavior.


392-404: Expanded warn payloads are consistent and useful for debugging.

Including promptCacheKey, previousHash, and incomingHash in both the reset and fork warning logs, alongside prefixCause and detailed analysis fields, makes it much easier to trace cache-key churn and mismatches in production without changing control flow. The structure matches what the new tests assert against.

Also applies to: 432-456

lib/request/input-filters.ts (1)

72-103: Env-block stripping and optional env capture behave as intended.

The combination of stripOpenCodeEnvBlocks and filterOpenCodeSystemPromptsInternal:

  • Drops OpenCode system prompts entirely via isOpenCodeSystemPrompt.
  • Removes the standard OpenCode env header plus <env>/<files> blocks, capturing them into envSegments when requested.
  • Discards env-only system/developer messages while preserving user messages and non-OpenCode prompts.
  • Produces sanitized content (e.g., keeps AGENTS.md text) and a clean FilterResult API for callers that want to reattach env/files later.

The implementation aligns with the new tests around env-only drops and AGENTS.md preservation.

Also applies to: 105-149, 158-162

lib/request/request-transformer.ts (1)

8-10: Env-tail behavior is well-isolated behind CODEX_APPEND_ENV_CONTEXT.

In codexMode:

  • When CODEX_APPEND_ENV_CONTEXT === "1", you correctly:
    • Run filterOpenCodeSystemPromptsWithEnv to both sanitize input and collect env/files blocks.
    • Append a final developer message containing envSegments.join("\n") only when segments exist.
  • When the flag is unset, you retain the previous filterOpenCodeSystemPrompts behavior.

Subsequent ID-stripping and bridge injection logic are unchanged and still gated on preserveIds and hasNormalizedTools, so the new feature is opt-in and backward-compatible.

Also applies to: 64-83

test/request-transformer.test.ts (1)

242-257: Env-block tests and caching stability coverage match the transformer logic.

The added/updated tests:

  • Ensure host metadata is preserved when requested, decoupled from legacy compaction tags.
  • Verify that env-only system messages are dropped, while AGENTS.md content survives env/files stripping.
  • Confirm that transformRequestBody keeps prompt_cache_key stable when only env/files churn and, when CODEX_APPEND_ENV_CONTEXT is enabled, reattaches env/files as a trailing developer message containing <env> and <files>.

These assertions align with stripOpenCodeEnvBlocks, filterOpenCodeSystemPrompts*, and the new env-tail branch in transformInputForCodex.

Also applies to: 590-615, 638-675, 682-774

@riatzukiza riatzukiza merged commit fea41f3 into dev Nov 22, 2025
15 of 16 checks passed
@riatzukiza riatzukiza deleted the compaction-logging-cleanup branch November 22, 2025 02:17
@coderabbitai coderabbitai bot mentioned this pull request Dec 13, 2025
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