Skip to content

Comments

Add prefix mismatch diagnostics#73

Merged
riatzukiza merged 27 commits intomainfrom
dev
Nov 23, 2025
Merged

Add prefix mismatch diagnostics#73
riatzukiza merged 27 commits intomainfrom
dev

Conversation

@riatzukiza
Copy link
Collaborator

Summary

  • classify session prefix mismatches to flag system prompt changes vs history pruning
  • log diagnostic evidence (roles, counts, fingerprints) when prefixes diverge
  • cover new diagnostics with session manager tests and a spec note

riatzukiza and others added 12 commits November 21, 2025 15:05
docs: clarify install and plugin settings
Co-authored-by: riatzukiza <riatzukiza@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: riatzukiza <riatzukiza@users.noreply.github.com>
Allow config overrides for logging and silence warn toasts
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 21, 2025

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • package.json is excluded by none and included by none

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Summary by CodeRabbit

Release Notes

  • New Features

    • Runtime logging control via configureLogger() function with customizable warning toasts, console output, and log rotation settings.
    • Environment context handling improvements with appendEnvContext configuration option.
  • Bug Fixes & Improvements

    • Enhanced session management diagnostics and prefix change analysis.
    • Improved logging decision-making with dynamic runtime checks via isLoggingEnabled().
  • Removals

    • Removed automatic conversation compaction feature and related configuration options.

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

Walkthrough

Replaces the Codex compaction pipeline with env-aware OpenCode prompt filtering, adds nested runtime-configurable logging (isLoggingEnabled/configureLogger), and augments SessionManager with prefix-change analysis used for cache-key decisions and structured warnings.

Changes

Cohort / File(s) Summary
Types
lib/types.ts
Remove Codex compaction fields from PluginConfig/SessionState; add appendEnvContext?: boolean and logging?: LoggingConfig and introduce LoggingConfig shape.
Config loader
lib/config.ts
Add exported getDefaultConfig(); merge user config with defaults and perform nested logging merge; use defaults on load error.
Logger core
lib/logger.ts
Replace exported LOGGING_ENABLED const with runtime isLoggingEnabled() and add runtime override APIs (apply/configure/refresh), accept pluginConfig?: PluginConfig in LoggerOptions.
Logger callers & tests
lib/request/response-handler.ts, test/*.test.ts, test/README.md, test/cache-warming.test.ts, test/logger.test.ts
Update imports/mocks and tests to use isLoggingEnabled() and new configure APIs; adapt tests to assert runtime logging behavior and toast/console gating.
Session manager
lib/session/session-manager.ts, test/session-manager.test.ts
Remove compaction-related APIs; add prefix-change analysis utilities (analyzePrefixChange and helpers), log prefix analysis and propagate fork identifiers/diagnostics during fork/regenerate.
Compaction removal
lib/compaction/*, lib/request/compaction-helpers.ts, lib/request/codex-fetcher.ts, lib/request/fetch-helpers.ts, lib/request/request-transformer.ts, lib/prompts/codex-compaction.ts
Delete compaction modules and prompts; remove compaction decision flows from transform/fetch paths; replace compaction options with appendEnvContext and simplify transform return values.
Input filters / env handling
lib/request/input-filters.ts
Add stripOpenCodeEnvBlocks, filterOpenCodeSystemPromptsInternal with optional env capture; expose filterOpenCodeSystemPromptsWithEnv; public filterOpenCodeSystemPrompts delegates to internal result.
Tests: removed/added/updated
test/codex-compaction.test.ts, test/compaction-helpers.test.ts, test/compaction-executor.test.ts, test/*
Remove compaction test suites; update many tests for new logging API and env-tail behavior; add e2e cache tests for prompt_cache_key stability and prefix-change warnings.
Manifest
package.json
Mentioned in manifest blocks (no content described in diff).

Sequence Diagram(s)

sequenceDiagram
    participant ConfigLoader as Config Loader
    participant Config as lib/config.ts
    participant Logger as lib/logger.ts
    participant Consumer as Request/Response Handler

    ConfigLoader->>Config: read plugin config file
    Config->>Config: getDefaultConfig()
    Config->>Config: merge user config (shallow) and merge logging: { ...defaults.logging, ...user.logging }
    Config->>Logger: pass merged PluginConfig
    Logger->>Logger: applyLoggingOverrides(pluginConfig.logging)
    Logger->>Logger: refreshLoggingState()
    Consumer->>Logger: isLoggingEnabled()
    Logger-->>Consumer: boolean
    Consumer->>Logger: logRequest / logWarn (conditional)
Loading
sequenceDiagram
    participant Session as SessionManager
    participant Analyzer as Prefix Analyzer
    participant Logger as lib/logger.ts
    participant Cache as Prompt Cache

    Session->>Analyzer: detect non-full-prefix match(oldPrefix, newPrefix)
    Analyzer->>Session: PrefixChangeAnalysis
    Session->>Logger: logWarn(prefixAnalysis)
    alt analysis.sharedPrefixLength == 0
        Session->>Cache: regenerate prompt_cache_key (fork)
    else
        Session->>Cache: fork with forkSessionId & forkPromptCacheKey metadata
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Areas to focus on:

  • lib/logger.ts: merging/validation of runtime overrides, gating logic for toasts vs console, and the new exported isLoggingEnabled()/configure APIs.
  • lib/config.ts: correctness of default construction via getDefaultConfig() and nested logging merges on error paths.
  • Removal completeness: verify no leftover references to compaction types/functions (compaction modules, prompts, executor, helpers).
  • lib/request/input-filters.ts: correctness of env-block stripping, capture semantics, and preservation of AGENTS.md content.
  • lib/session/session-manager.ts: correctness of analyzePrefixChange outcomes, fork vs regenerate decision, and structure of logged diagnostics.

Possibly related PRs

Poem

A flag turned to a function, tidy and keen,
Defaults folded in where the logs had been.
Compaction stepped back; env tails stayed near,
Sessions hum prefixes that now we hear.
Small changes, clearer paths — ship without fear.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.71% 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 'Add prefix mismatch diagnostics' directly and clearly describes the main change: implementing diagnostic logging for session prefix mismatches.
Description check ✅ Passed The description is related to the changeset. It outlines the three key objectives: classifying prefix mismatches, logging diagnostic evidence, and adding test coverage.

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

@riatzukiza riatzukiza enabled auto-merge November 21, 2025 21:54
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: 3

Caution

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

⚠️ Outside diff range comments (1)
lib/logger.ts (1)

172-211: Warn toast gating and forwarding logic matches tests and intent

The new warnToastEnabled / shouldForwardToAppLog / shouldLogToConsole logic:

  • Keeps disk logging tied to LOGGING_ENABLED || DEBUG_ENABLED.
  • For warnings:
    • Default: forward to app.log and console, no toast.
    • When toasts are enabled and TUI is present: send a toast, suppress app.log and console to avoid double surfacing.
  • For errors: always send a toast (if available) and log to console, regardless of the toast config.

This aligns with the new tests and yields predictable behavior without introducing regressions. The duplicated condition (level !== "warn" || !warnToastEnabled) for app‑log vs console decisions is acceptable; you could extract it to a small helper for readability, but it’s not necessary.

📜 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 2304f4b and ed41bff.

⛔ Files ignored due to path filters (9)
  • README.md is excluded by none and included by none
  • config/README.md is excluded by none and included by none
  • docs/README.md is excluded by none and included by none
  • index.ts is excluded by none and included by none
  • package-lock.json is excluded by !**/package-lock.json and included by none
  • package.json is excluded by none and included by none
  • spec/environment-variables.md is excluded by none and included by none
  • spec/prefix-diagnostics.md is excluded by none and included by none
  • spec/readme-cleanup.md is excluded by none and included by none
📒 Files selected for processing (10)
  • lib/config.ts (2 hunks)
  • lib/logger.ts (6 hunks)
  • lib/request/response-handler.ts (2 hunks)
  • lib/session/session-manager.ts (3 hunks)
  • lib/types.ts (1 hunks)
  • test/README.md (1 hunks)
  • test/cache-warming.test.ts (1 hunks)
  • test/logger.test.ts (5 hunks)
  • test/plugin-config.test.ts (5 hunks)
  • test/session-manager.test.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (7)
lib/config.ts (2)
lib/types.ts (1)
  • PluginConfig (6-40)
lib/logger.ts (1)
  • logWarn (157-159)
test/session-manager.test.ts (2)
lib/session/session-manager.ts (1)
  • SessionManager (286-640)
lib/types.ts (2)
  • RequestBody (167-189)
  • SessionContext (219-225)
lib/request/response-handler.ts (1)
lib/logger.ts (1)
  • isLoggingEnabled (22-24)
lib/session/session-manager.ts (2)
lib/types.ts (1)
  • InputItem (156-162)
lib/logger.ts (1)
  • logWarn (157-159)
test/logger.test.ts (1)
lib/logger.ts (5)
  • isLoggingEnabled (22-24)
  • configureLogger (106-128)
  • logRequest (130-147)
  • flushRollingLogsForTest (165-170)
  • logWarn (157-159)
test/plugin-config.test.ts (1)
lib/config.ts (1)
  • loadPluginConfig (30-70)
lib/logger.ts (2)
lib/utils/file-system-utils.ts (1)
  • getOpenCodePath (22-24)
lib/types.ts (2)
  • PluginConfig (6-40)
  • LoggingConfig (42-55)
🪛 GitHub Check: Lint & Typecheck
test/session-manager.test.ts

[warning] 173-173:
'context' is assigned a value but never used. Allowed unused vars must match /^_/u


[warning] 126-126:
'context' is assigned a value but never used. Allowed unused vars must match /^_/u

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Mutation Tests
🔇 Additional comments (18)
lib/types.ts (1)

35-55: LGTM!

The new LoggingConfig interface is well-structured with clear documentation. Optional fields are appropriate for configuration overrides.

test/README.md (1)

82-82: LGTM!

Documentation correctly updated to reflect the new isLoggingEnabled() function API.

test/cache-warming.test.ts (1)

23-23: LGTM!

Mock correctly updated to reflect the new isLoggingEnabled() function signature.

test/plugin-config.test.ts (2)

57-57: LGTM!

Test assertions correctly updated to validate the new default logging configuration.

Also applies to: 76-76, 91-92, 122-122, 142-142


95-108: LGTM!

Excellent test coverage for the nested logging configuration merge behavior, validating that user overrides are applied while defaults are preserved.

test/session-manager.test.ts (1)

2-2: LGTM!

Import additions support the new logging verification tests.

Also applies to: 5-5

lib/request/response-handler.ts (1)

2-2: LGTM!

Clean refactor to use the new isLoggingEnabled() function API.

Also applies to: 53-53

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

80-111: LGTM!

Helper functions are well-implemented with appropriate null checks and comprehensive pattern matching for tool messages.


113-190: LGTM!

The prefix change analysis logic is well-structured:

  • Correctly detects history pruning via suffix reuse
  • Identifies system prompt changes
  • Provides detailed diagnostic information for debugging

409-418: LGTM!

Prefix change analysis is properly integrated into the session management flow, providing diagnostic information for both cache key regeneration and session forking scenarios.

Also applies to: 464-472

lib/config.ts (3)

17-19: LGTM!

Default logging configuration added with showWarningToasts: false.


45-45: LGTM!

Nested logging configuration merge correctly implemented:

  • User settings override defaults
  • Unspecified user settings preserve defaults
  • Spread operator prevents DEFAULT_CONFIG mutation

Also applies to: 50-59


67-67: LGTM!

Error fallback correctly spreads DEFAULT_CONFIG to prevent mutation.

test/logger.test.ts (4)

68-76: isLoggingEnabled env + override coverage is solid

This test cleanly asserts the env-driven default and the pluginConfig override behavior for isLoggingEnabled(), matching the new runtime-configurable design.


114-131: Good regression test for config overriding env‑enabled request logging

This case correctly asserts that a pluginConfig.logging.enableRequestLogging = false override wins over ENABLE_PLUGIN_REQUEST_LOGGING=1, both via isLoggingEnabled() and disk‑write expectations.


155-175: Default warning behavior with TUI client is well‑specified

This test clearly documents the default semantics with a TUI‑capable client: no warning toast, one app.log call, and a console warn. That aligns with the new WARN_TOASTS_ENABLED gating and is a good guard against regressions.


176-201: Config‑driven warning toasts and wrapping behavior are well covered

These tests collectively:

  • Assert that enabling pluginConfig.logging.showWarningToasts flips behavior from app.log+console to TUI toast only.
  • Verify long warning messages are wrapped to ≤72 characters per line.

They tightly couple to the intended runtime behavior and should catch most regressions in toast handling.

Also applies to: 214-215

lib/logger.ts (1)

4-31: Env defaults + mutable logging state and isLoggingEnabled() look consistent

The introduction of envLoggingDefaults, mutable LOGGING_ENABLED/DEBUG_FLAG_ENABLED and isLoggingEnabled() cleanly preserves prior env semantics while enabling later overrides. Initial DEBUG_ENABLED and CONSOLE_LOGGING_ENABLED derivations are straightforward, and using getEnvNumber for rotation/queue limits with hard minimums avoids pathological values like 0 or negatives. No blockers here.

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

📜 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 ed41bff and 89fb08b.

⛔ Files ignored due to path filters (6)
  • README.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
  • spec/codex-compaction.md is excluded by none and included by none
  • spec/compaction-heuristics-22.md is excluded by none and included by none
  • spec/remove-plugin-compaction.md is excluded by none and included by none
📒 Files selected for processing (11)
  • lib/config.ts (2 hunks)
  • lib/request/codex-fetcher.ts (1 hunks)
  • lib/request/fetch-helpers.ts (1 hunks)
  • lib/request/request-transformer.ts (4 hunks)
  • lib/types.ts (1 hunks)
  • test/codex-compaction.test.ts (0 hunks)
  • test/codex-fetcher.test.ts (0 hunks)
  • test/compaction-executor.test.ts (0 hunks)
  • test/compaction-helpers.test.ts (0 hunks)
  • test/fetch-helpers.test.ts (0 hunks)
  • test/plugin-config.test.ts (5 hunks)
💤 Files with no reviewable changes (5)
  • test/fetch-helpers.test.ts
  • test/compaction-executor.test.ts
  • test/codex-compaction.test.ts
  • test/compaction-helpers.test.ts
  • test/codex-fetcher.test.ts
🧰 Additional context used
🧬 Code graph analysis (5)
test/plugin-config.test.ts (1)
lib/config.ts (1)
  • loadPluginConfig (28-68)
lib/config.ts (2)
lib/types.ts (1)
  • PluginConfig (6-24)
lib/logger.ts (1)
  • logWarn (157-159)
lib/request/codex-fetcher.ts (1)
lib/request/fetch-helpers.ts (1)
  • handleSuccessResponse (352-367)
lib/request/fetch-helpers.ts (1)
lib/types.ts (1)
  • PluginConfig (6-24)
lib/request/request-transformer.ts (1)
lib/request/tooling.ts (1)
  • normalizeToolsForCodexBody (5-31)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Mutation Tests
🔇 Additional comments (9)
lib/request/codex-fetcher.ts (1)

95-95: Clean removal of compaction handling.

The direct assignment from handleSuccessResponse simplifies the flow now that compaction is removed. The change is correct and aligns with the broader removal of codex compaction paths.

lib/config.ts (2)

48-57: Well-implemented nested configuration merge.

The nested merge logic correctly preserves both default and user-provided logging values. Extracting userLogging separately and then performing an explicit nested merge ensures that user settings override defaults at the field level rather than replacing the entire logging object.


43-43: Good practice: Cloning default config.

Using spread operator to clone DEFAULT_CONFIG prevents unintended mutations to the default configuration object. This is correctly applied in both the missing-file case (line 43) and error case (line 65).

lib/types.ts (1)

26-39: Clear and well-documented type definitions.

The LoggingConfig interface provides comprehensive logging customization options with clear JSDoc comments. All fields are appropriately optional, allowing granular control over logging behavior while maintaining backward compatibility.

test/plugin-config.test.ts (2)

89-102: Excellent test coverage for nested merge logic.

This test specifically validates that nested logging configuration is properly merged with defaults, preserving both user-provided values (enableRequestLogging: false, logMaxFiles: 2) and default values (showWarningToasts: false). This ensures the merge behavior works correctly at the nested level.


52-56: Comprehensive test updates reflect new structure.

All test expectations have been correctly updated to include the nested logging: { showWarningToasts: false } structure across default, success, and error scenarios. The consistency across all test cases ensures the configuration behavior is properly validated.

Also applies to: 69-73, 82-86, 111-115, 129-133

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

108-108: Hardcoded parameter value after compaction removal.

The second parameter to normalizeToolsForCodexBody is now hardcoded to false, meaning skipConversationTransforms will always be false. This is consistent with removing compaction logic, ensuring conversation transforms always occur.


23-31: Simplified public API surface.

The removal of compaction property from TransformRequestOptions and compactionDecision from TransformResult cleanly reflects the elimination of compaction features. The interfaces are now more focused and easier to understand.


128-128: Return type simplified correctly.

The return statement now only includes { body }, matching the updated TransformResult interface. This is consistent with the removal of compaction decision tracking.

@riatzukiza
Copy link
Collaborator Author

/oc address the code review comments

@opencode-agent
Copy link
Contributor

opencode-agent bot commented Nov 21, 2025

UnknownError:

opencode session  |  github run

@riatzukiza
Copy link
Collaborator Author

/oc address the coderabbit codereview comments

@opencode-agent
Copy link
Contributor

opencode-agent bot commented Nov 21, 2025

ProviderInitError

opencode session  |  github run

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@riatzukiza
Copy link
Collaborator Author

/oc In lib/request/fetch-helpers.ts around line 127, remove the unused optional
parameter _pluginConfig?: PluginConfig from the function signature (and from
any TS type annotations on that declaration). Update the function's exported
type/signature so callers and declarations match (no other code changes required
since production callers don't pass it); run TypeScript/linters to ensure no
remaining references and delete any related unused import of PluginConfig if it
becomes unused.

@opencode-agent
Copy link
Contributor

opencode-agent bot commented Nov 21, 2025

ProviderInitError

opencode session  |  github run

@opencode-agent
Copy link
Contributor

opencode-agent bot commented Nov 21, 2025

ProviderInitError

opencode session  |  github run

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: 5

Caution

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

⚠️ Outside diff range comments (2)
lib/request/request-transformer.ts (2)

42-63: Env-tail capture/reattachment path matches tests and keeps ID semantics clear

The refactored transformInputForCodex cleanly separates concerns:

  • Initial filterInput(..., { preserveIds, preserveMetadata: true }) keeps metadata around long enough for OpenCode/env detection.
  • CODEX_APPEND_ENV_CONTEXT toggles between simple filtering and capturing env segments, which are then reattached as a separate developer message while env-only/system messages are dropped.
  • A second filterInput pass when preserveIds === false ensures statelessness (IDs stripped, metadata removed) before adding the bridge/tool messages.

This aligns with the new tests and keeps the behavior explicit; the extra workingInput = workingInput || [] before the spread is a tiny redundancy but not worth changing unless you’re already touching this block.

Also applies to: 64-83


99-106: Remove unused _pluginConfig parameter from transformRequestForCodex in fetch-helpers.ts

The call site at line 156 correctly passes the new transformRequestBody signature without _pluginConfig. However, transformRequestForCodex (line 127) still declares this parameter as unused—it's not referenced anywhere in the function body.

Remove _pluginConfig?: PluginConfig, from the function signature to complete the refactoring.

♻️ Duplicate comments (1)
lib/logger.ts (1)

66-77: Reconfirm semantics of applyLoggingOverrides when logging is omitted

Current behavior keeps any prior in-memory overrides when options.pluginConfig?.logging is omitted, only recomputing derived flags via refreshLoggingState(). If configureLogger may be called with different plugin configs over time, you might instead want the “no logging config” path to reset all mutable logging state from envLoggingDefaults (including numeric limits via ensurePositiveNumber) before refreshing, so callers can reliably get back to env defaults.

Also applies to: 78-92, 94-94, 109-117

📜 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 89fb08b and fea41f3.

⛔ Files ignored due to path filters (29)
  • .eslintignore is excluded by none and included by none
  • .gitignore is excluded by none and included by none
  • 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
  • eslint.config.mjs is excluded by none and included by none
  • package.json is excluded by none and included by none
  • scripts/inspect-codex-logs.mjs 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/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 (16)
  • lib/compaction/codex-compaction.ts (0 hunks)
  • lib/compaction/compaction-executor.ts (0 hunks)
  • lib/config.ts (2 hunks)
  • lib/logger.ts (6 hunks)
  • lib/prompts/codex-compaction.ts (0 hunks)
  • lib/request/compaction-helpers.ts (0 hunks)
  • lib/request/input-filters.ts (3 hunks)
  • lib/request/request-transformer.ts (6 hunks)
  • lib/session/session-manager.ts (4 hunks)
  • lib/types.ts (1 hunks)
  • test/cache-e2e.test.ts (1 hunks)
  • test/logger.test.ts (6 hunks)
  • test/plugin-config.test.ts (5 hunks)
  • test/prompts-codex.test.ts (4 hunks)
  • test/request-transformer.test.ts (4 hunks)
  • test/session-manager.test.ts (6 hunks)
💤 Files with no reviewable changes (4)
  • lib/prompts/codex-compaction.ts
  • lib/request/compaction-helpers.ts
  • lib/compaction/compaction-executor.ts
  • lib/compaction/codex-compaction.ts
🧰 Additional context used
🧬 Code graph analysis (10)
test/logger.test.ts (1)
lib/logger.ts (5)
  • isLoggingEnabled (23-25)
  • configureLogger (109-131)
  • logRequest (133-150)
  • flushRollingLogsForTest (168-173)
  • logWarn (160-162)
test/plugin-config.test.ts (1)
lib/config.ts (1)
  • loadPluginConfig (29-69)
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)
lib/request/request-transformer.ts (2)
lib/request/input-filters.ts (2)
  • filterOpenCodeSystemPromptsWithEnv (158-162)
  • filterOpenCodeSystemPrompts (151-156)
lib/request/tooling.ts (1)
  • normalizeToolsForCodexBody (5-31)
lib/session/session-manager.ts (2)
lib/types.ts (1)
  • InputItem (142-148)
lib/logger.ts (1)
  • logWarn (160-162)
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/logger.ts (2)
lib/utils/file-system-utils.ts (1)
  • getOpenCodePath (22-24)
lib/types.ts (2)
  • PluginConfig (6-24)
  • LoggingConfig (26-41)
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)
lib/config.ts (2)
lib/types.ts (1)
  • PluginConfig (6-24)
lib/logger.ts (1)
  • logWarn (160-162)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Mutation Tests
🔇 Additional comments (10)
test/prompts-codex.test.ts (1)

113-153: Logger-based warning assertions for prompt fallbacks are correct

Switching these tests from console-based checks to spying on logger.logWarn aligns with the new logging API, and the dynamic import + explicit mockRestore() keep test isolation clean. No issues here.

Also applies to: 242-272

test/cache-e2e.test.ts (1)

12-45: Env-churn cache stability scenario is well covered

The envMessage helper plus the “env/files churn” test do a good job of validating that environment/file noise is stripped before session matching and that prompt_cache_key remains stable while user content is unchanged. The expectations on input length and role are tight but still robust. No changes needed.

Also applies to: 52-89

test/logger.test.ts (2)

68-76: isLoggingEnabled and request-logging override coverage is solid

The new tests around isLoggingEnabled and configureLogger({ pluginConfig: { logging: { enableRequestLogging: false } } }) validate both env‑driven enablement and config‑driven disablement, and they tie that directly to disk I/O expectations via logRequest. This gives good confidence that request logging will honour plugin config overrides at runtime.

Also applies to: 114-131


145-221: logWarn behaviour under LoggingConfig is thoroughly exercised

The added logWarn tests cover all key dimensions of the new logging config: default behaviour (rolling log only), toast suppression by default, toast enablement via showWarningToasts, and console mirroring via logWarningsToConsole. The use of an OpencodeClient mock and flushRollingLogsForTest keeps the assertions precise without depending on implementation details.

This suite provides strong regression protection for the new LoggingConfig surface.

Also applies to: 233-247

test/plugin-config.test.ts (1)

52-57: Logging defaults and merge behavior are exercised well

The expectations for logging across default, file-present, empty, malformed, and error cases align with the nested merge in loadPluginConfig, including the override behavior for enableRequestLogging and logMaxFiles. No blockers here.

Also applies to: 69-73, 82-87, 89-103, 112-117, 131-135

lib/types.ts (1)

21-24: LoggingConfig extension of PluginConfig is coherent and non-breaking

Adding logging?: LoggingConfig with all-optional fields keeps existing configs valid and documents the new overrides (request logging, debug, toasts, rotation) clearly; this looks consistent with how the tests use config.logging.

Also applies to: 26-40

lib/logger.ts (2)

12-33: Logging defaults and runtime flags are wired coherently (no blockers)

The env-derived defaults and initial module-level flags (including LOGGING_ENABLED, DEBUG_FLAG_ENABLED, rotation and queue limits) are consistent and correctly funneled through DEBUG_ENABLED / CONSOLE_LOGGING_ENABLED. isLoggingEnabled() cleanly exposes the intended boolean without leaking internal flags. No issues here.


175-215: Warn persistence and toast/console routing look correct

The updated emit logic consistently:

  • Persists all warn-level entries regardless of env flags.
  • Avoids double-reporting by skipping app-log forwarding when a warn toast is shown.
  • Gates console output for warns via WARN_CONSOLE_ENABLED and toast presence, while always logging errors.
    This matches the intended separation between persistence, app logs, toasts, and console output. No blockers.
lib/request/input-filters.ts (2)

72-103: Env-block stripping is targeted and preserves non-env content

The stripOpenCodeEnvBlocks helper cleanly:

  • Removes the known OpenCode env header phrase.
  • Strips <env>...</env> and <files>...</files> blocks while capturing their exact text into removedBlocks.
  • Returns trimmed residual text, so surrounding narrative isn’t lost.

This is a focused, low-risk transformation for the expected OpenCode shapes; behavior looks sound and doesn’t introduce blockers.


105-110: Internal filter + new env-capturing API look consistent with prior behavior

filterOpenCodeSystemPromptsInternal preserves users, drops OpenCode system prompts as before, and now additionally:

  • Strips env/file blocks from non-OpenCode non-user items, dropping items that become empty after stripping.
  • Optionally accumulates removed blocks into envSegments when captureEnv is set.
  • Returns { input: filteredInput, envSegments }, with wrappers providing either just input or the full FilterResult.

The non-array input path preserves prior external behavior (filterOpenCodeSystemPrompts still returns the original value), while the new filterOpenCodeSystemPromptsWithEnv gets a predictable { envSegments: [] } fallback. Overall, the control flow and result typing are coherent; no blockers identified.

Also applies to: 118-149, 151-162

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 (1)
lib/request/fetch-helpers.ts (1)

120-167: Blocker: Unit tests don't pass pluginConfig, leaving the new parameter untested

The call sites in test/fetch-helpers.test.ts at lines 299, 340, and 380 omit pluginConfig entirely. While the e2e test (test/cache-e2e.test.ts:39) does exercise it, the unit test suite should pass this parameter to ensure the behavior is tested consistently with production call sites (lib/request/codex-fetcher.ts:55 already passes it correctly).

The error and early-return tests (lines 259, 269) reasonably skip it since they won't reach the appendEnvContext logic, but the happy-path tests should include it for complete coverage.

📜 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 fea41f3 and 208d9d2.

⛔ Files ignored due to path filters (1)
  • spec/append-env-context-config.md is excluded by none and included by none
📒 Files selected for processing (7)
  • lib/config.ts (2 hunks)
  • lib/request/fetch-helpers.ts (1 hunks)
  • lib/request/request-transformer.ts (5 hunks)
  • lib/types.ts (1 hunks)
  • test/cache-e2e.test.ts (1 hunks)
  • test/plugin-config.test.ts (7 hunks)
  • test/request-transformer.test.ts (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (5)
test/request-transformer.test.ts (3)
lib/types.ts (2)
  • InputItem (148-154)
  • RequestBody (159-181)
lib/request/request-transformer.ts (2)
  • filterOpenCodeSystemPrompts (20-20)
  • transformRequestBody (101-159)
lib/request/input-filters.ts (1)
  • filterOpenCodeSystemPrompts (151-156)
test/cache-e2e.test.ts (3)
lib/types.ts (4)
  • UserConfig (52-59)
  • InputItem (148-154)
  • RequestBody (159-181)
  • PluginConfig (6-30)
lib/session/session-manager.ts (1)
  • SessionManager (267-591)
lib/request/fetch-helpers.ts (1)
  • transformRequestForCodex (120-200)
test/plugin-config.test.ts (1)
lib/config.ts (1)
  • loadPluginConfig (32-74)
lib/config.ts (3)
lib/types.ts (1)
  • PluginConfig (6-30)
lib/utils/file-system-utils.ts (1)
  • safeReadFile (56-62)
lib/logger.ts (1)
  • logWarn (160-162)
lib/request/request-transformer.ts (3)
lib/types.ts (2)
  • RequestBody (159-181)
  • SessionContext (209-215)
lib/request/input-filters.ts (2)
  • filterOpenCodeSystemPromptsWithEnv (158-162)
  • filterOpenCodeSystemPrompts (151-156)
lib/request/tooling.ts (1)
  • normalizeToolsForCodexBody (5-31)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Mutation Tests
🔇 Additional comments (5)
lib/config.ts (1)

12-22: Default config + nested logging merge behave correctly

getDefaultConfig now returns a fresh object per call (including a fresh logging object), and loadPluginConfig merges user settings over those defaults while deep‑merging logging. The missing/invalid‑file paths also clone defaults rather than sharing references.

This resolves the earlier shared‑logging concern and matches the expectations in the plugin‑config tests; no changes needed here.

Also applies to: 43-72

test/cache-e2e.test.ts (1)

12-125: Cache E2E and prefix-diagnostics coverage look solid

The runTransform helper plus the two scenarios (“env/files churn” and “user_message_changed”) exercise the new session-prefix diagnostics end‑to‑end, while cleanly stubbing Codex and logger behavior. Using a minimal PluginConfig focused on appendEnvContext keeps the tests aligned with the new configuration surface.

No issues or blockers from this file.

test/plugin-config.test.ts (1)

31-54: Plugin config tests correctly cover env + logging semantics

The updated tests now fully cover the intended behavior of loadPluginConfig—including env‑driven appendEnvContext, config overrides, and nested logging merges—while safely snapshotting and restoring both relevant env vars.

Everything here lines up with lib/config.ts; no changes needed.

Also applies to: 56-193

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

242-257: Transformer tests capture env-stripping and cache-key stability well

The added cases around env-only system messages, mixed env+AGENTS content, and the dedicated “caching stability” describe block closely mirror the new transformer behavior:

  • filterOpenCodeSystemPrompts specs ensure env noise is stripped while AGENTS.md survives.
  • The caching tests validate that prompt_cache_key remains stable when only env/files change and that env/files can be reattached as a tail when appendEnvContext is enabled.

These provide good coverage of the new env-context flow; no blockers here.

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

lib/types.ts (1)

20-47: PluginConfig and LoggingConfig shape matches downstream usage

Adding appendEnvContext?: boolean and a nested logging?: LoggingConfig aligns with how config loading and logging are now wired. The LoggingConfig fields are all optional and forward‑compatible, which works well with the default + merge strategy in lib/config.ts.

No issues with these type changes.

riatzukiza and others added 3 commits November 22, 2025 11:25
Refactor session manager item equality
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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

📜 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 208d9d2 and a0c5fee.

⛔ Files ignored due to path filters (1)
  • spec/session-manager-items-equality.md is excluded by none and included by none
📒 Files selected for processing (1)
  • lib/session/session-manager.ts (6 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
lib/session/session-manager.ts (2)
lib/types.ts (1)
  • InputItem (148-154)
lib/logger.ts (1)
  • logWarn (160-162)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Mutation Tests
🔇 Additional comments (2)
lib/session/session-manager.ts (2)

117-183: Prefix-change analysis covers key cases without leaking content

analyzePrefixChange cleanly separates history_pruned, system_prompt_changed, user_message_changed, and unknown, and the diagnostics payload sticks to roles, counts, and short fingerprints instead of raw message bodies. This aligns well with the PR objectives and avoids privacy/log‑bloat pitfalls. I don’t see functional issues here; any further refinement (e.g., extra sub‑causes) would be purely iterative.


383-386: applyRequest integration with prefix diagnostics and forking looks correct and non‑leaky

The new flow—cloning input, hashing once, computing sharedPrefixLength, and then using analyzePrefixChange only when needed—preserves existing session behavior while adding clear diagnostics. Both the “regenerate cache key” path (sharedPrefixLength === 0) and the “fork session” path (partial prefix) now log only counts, hashes, and the derived analysis fields, with no raw InputItem content. Fork state propagation of lastCachedTokens and bridgeInjected also looks correct. I don’t see any blockers in this integration.

Also applies to: 398-402, 406-414, 438-453, 455-468

@riatzukiza riatzukiza disabled auto-merge November 23, 2025 00:13
@riatzukiza riatzukiza merged commit c963bd5 into main Nov 23, 2025
21 of 26 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Dec 5, 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