Skip to content

Comments

address code rabbit comments#58

Merged
riatzukiza merged 9 commits intodevfrom
review/v0.3.5
Nov 20, 2025
Merged

address code rabbit comments#58
riatzukiza merged 9 commits intodevfrom
review/v0.3.5

Conversation

@riatzukiza
Copy link
Collaborator

No description provided.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 20, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved cache handling to gracefully fall back to alternative sources when cached data is unavailable, with enhanced warning logging.
    • Prevented duplicate tool remap messages from being injected into conversations.
  • Tests

    • Added comprehensive tests for message compaction logic.

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

Walkthrough

Codex cache reads now return nullable results and callers treat null as cache misses with logged warnings and fallbacks; compaction helpers avoid mutating inputs when removing the last user message; tool-remap injection skips duplicates by checking a stable content hash; tests added for compaction behavior.

Changes

Cohort / File(s) Summary
Codex cache null-handling
lib/prompts/codex.ts
readCachedInstructions now returns `string
Input processing refactor
lib/request/compaction-helpers.ts
removeLastUserMessage now returns a new array without mutating the input; non-command path in maybeBuildCompactionPrompt uses the original input instead of cloning. JSDoc added.
Tool message deduplication
lib/request/input-filters.ts
Introduced internal TOOL_REMAP_MESSAGE_HASH and a pre-injection scan in addToolRemapMessage to skip injecting a duplicate remap message when the hash is present.
Tests
test/compaction-helpers.test.ts
Added tests verifying compaction: drops only the last user command while preserving trailing items, returns original items when no user message exists, and asserts request mutations and absence of tool-specific fields.
Manifest
package.json
No exported/declaration changes; manifest included in diff.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Caller
  participant Codex as lib/prompts/codex.ts
  participant Bundle as bundled-instructions

  Note over Codex: readCachedInstructions may return null
  Caller->>Codex: readCachedInstructions()
  alt cached content (string)
    Codex-->>Caller: "instructions string"
    Caller->>Caller: use cached instructions
  else cache miss (null)
    Codex-->>Caller: null + warning
    Caller->>Bundle: load bundled/fallback instructions
    Bundle-->>Caller: "bundled instructions"
    Caller->>Caller: continue with fallback
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Focus areas:
    • lib/prompts/codex.ts: ensure all callers handle null from readCachedInstructions (risk: missed null checks causing runtime errors).
    • lib/request/compaction-helpers.ts: verify no callers relied on previous in-place mutation or on array identity.
    • lib/request/input-filters.ts: confirm hash computation is deterministic and that the pre-check won't produce false negatives/positives.

Possibly related PRs

Poem

Cache whispers null, we ask it twice,
Trim the last command, keep the rest concise.
A hash guards duplicate tool-chat's claim,
Tests shine green — tidy code, same game. ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 2 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title 'address code rabbit comments' is too vague and generic; it does not convey what specific changes were made to the codebase. Use a more descriptive title that specifies the main change, such as 'Add compaction assertions to test suite' or 'Update cached instruction and input filter handling'.
Description check ❓ Inconclusive No pull request description was provided by the author, making it impossible to assess the intent and rationale for the changes. Add a clear description explaining what changes were made and why they address the review feedback, including any behavioral updates or testing additions.
✨ 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 review/v0.3.5

📜 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 7466b2b and 0c8ed15.

📒 Files selected for processing (1)
  • test/compaction-helpers.test.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
test/compaction-helpers.test.ts (2)
lib/types.ts (1)
  • RequestBody (147-169)
lib/request/compaction-helpers.ts (1)
  • applyCompactionIfNeeded (82-107)
🔇 Additional comments (3)
test/compaction-helpers.test.ts (3)

1-3: LGTM! Imports are clean.

The imports are correct and concise. The previously flagged duplicate import has been successfully resolved.


5-30: Well-structured test with comprehensive assertions.

This test correctly verifies both the returned decision and the RequestBody mutations. All previously requested assertions are present:

  • Decision mode and transcript content
  • Body.input mutation verification
  • Command string removal check
  • Tool-related field deletions

The test accurately validates the "command" compaction path.


32-58: Excellent resolution of previous feedback.

This test now correctly:

  • Has a test name that matches its assertions (compaction is applied, not skipped)
  • Verifies that body.input was mutated rather than checking equality with the original
  • Includes all requested assertions for tool-related field deletions

The test accurately validates compaction behavior when no user message exists in the input.


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

📜 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 4e16ae8 and bb15475.

⛔ Files ignored due to path filters (1)
  • spec/review-v0.3.5-fixes.md is excluded by none and included by none
📒 Files selected for processing (3)
  • lib/prompts/codex.ts (5 hunks)
  • lib/request/compaction-helpers.ts (2 hunks)
  • lib/request/input-filters.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
lib/request/input-filters.ts (3)
lib/cache/prompt-fingerprinting.ts (1)
  • generateContentHash (15-17)
lib/prompts/codex.ts (1)
  • TOOL_REMAP_MESSAGE (272-334)
lib/utils/input-item-utils.ts (1)
  • extractTextFromItem (16-27)
lib/prompts/codex.ts (2)
lib/utils/file-system-utils.ts (1)
  • safeReadFile (56-62)
lib/logger.ts (1)
  • logWarn (112-114)
🔇 Additional comments (2)
lib/prompts/codex.ts (1)

66-79: Robust cache miss handling and null‑safety look solid

The changes to readCachedInstructions and its call sites improve safety without introducing obvious regressions:

  • Missing/empty cache files now log a warning and return null instead of caching empty content.
  • 304 and fetch‑failure paths correctly treat null as a hard miss: they either throw (304 case) or fall back to bundled instructions with clear logging.
  • Fresh cache and “failed to get latest tag” paths now re‑read the cache defensively and log when it’s empty/unavailable before falling back.

The control flow is consistent and keeps session cache, filesystem cache, and bundled fallback in a sensible order of preference. No blockers spotted here.

Also applies to: 108-114, 163-174, 210-221, 230-239

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

16-17: Hash‑based tool remap deduplication is correct and non‑intrusive

Precomputing TOOL_REMAP_MESSAGE_HASH and checking developer messages by generateContentHash(extractTextFromItem(item)) cleanly avoids injecting duplicate tool‑remap instructions when the canonical text is already present.

This is strict (only an exact text match via extractTextFromItem will register as existing), but that’s reasonable given you control the injected template. The cost of hashing per developer message is acceptable for typical histories, and the early hasTools / Array.isArray guards keep this cheap in the common no‑tools case.

No blockers from this change.

Also applies to: 252-261

@riatzukiza riatzukiza enabled auto-merge November 20, 2025 22:31
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 bb15475 and e4bf799.

⛔ Files ignored due to path filters (4)
  • .github/workflows/dev-release-prep.yml is excluded by none and included by none
  • .github/workflows/review-response.yml is excluded by none and included by none
  • scripts/review-response-context.mjs is excluded by none and included by none
  • spec/review-response-token.md is excluded by none and included by none
📒 Files selected for processing (2)
  • lib/request/compaction-helpers.ts (2 hunks)
  • test/compaction-helpers.test.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
test/compaction-helpers.test.ts (2)
lib/types.ts (1)
  • RequestBody (147-169)
lib/request/compaction-helpers.ts (1)
  • applyCompactionIfNeeded (82-107)
🪛 Biome (2.1.2)
test/compaction-helpers.test.ts

[error] 2-2: Shouldn't redeclare 'applyCompactionIfNeeded'. Consider to delete it or rename it.

'applyCompactionIfNeeded' is defined here:

(lint/suspicious/noRedeclare)

🪛 GitHub Actions: CI
test/compaction-helpers.test.ts

[error] 2-2: ESLint: 'applyCompactionIfNeeded' is already defined. (no-redeclare)

🪛 GitHub Check: Lint & Typecheck
test/compaction-helpers.test.ts

[failure] 2-2:
'applyCompactionIfNeeded' is already defined

🔇 Additional comments (5)
lib/request/compaction-helpers.ts (3)

26-29: JSDoc accurately describes the preservation behavior.

The documentation clearly states that trailing items are preserved, which aligns with the implementation.


30-36: Past review concern has been addressed.

The implementation now correctly preserves trailing items by concatenating slice(0, index) and slice(index + 1), which excludes only the user message at position index. The previous concern about removing all subsequent items is resolved.


46-46: Conditional logic correctly avoids unnecessary operations.

Using removeLastUserMessage only when commandText is present optimizes the non-command path by avoiding unnecessary array operations.

test/compaction-helpers.test.ts (2)

6-24: Test correctly validates trailing item preservation.

This test confirms that removeLastUserMessage preserves the trailing assistant message (line 10, validated at line 22) while removing only the user command. Good coverage of the updated behavior.


26-44: Edge case properly tested.

This test validates that when no user message exists, the original items are preserved unchanged. Good coverage of the fallback behavior in removeLastUserMessage.

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 e4bf799 and 74c6155.

📒 Files selected for processing (1)
  • test/compaction-helpers.test.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
test/compaction-helpers.test.ts (2)
lib/types.ts (1)
  • RequestBody (147-169)
lib/request/compaction-helpers.ts (1)
  • applyCompactionIfNeeded (82-107)
🔇 Additional comments (1)
test/compaction-helpers.test.ts (1)

1-2: Imports look correct—duplicate import fixed.

The duplicate import issue flagged in the previous review has been resolved.

@riatzukiza
Copy link
Collaborator Author

/oc In test/compaction-helpers.test.ts around lines 25 to 43, the test that checks
behavior when no user message exists should also assert that body.input remains
defined and that any tool-related properties were removed; add assertions
immediately after the existing expectations (after line 42) verifying body.input
is defined and that body.tools and body.tool_choice are undefined (use (body as
any) for the latter two if needed).

@riatzukiza
Copy link
Collaborator Author

/oc In test/compaction-helpers.test.ts around lines 5 to 23, the test verifies the
returned decision but doesn't assert that applyCompactionIfNeeded mutated the
RequestBody; add assertions after the existing expects to confirm body.input was
changed (not equal to originalInput), that the user command string
"/codex-compact please" is no longer present in body.input, and that body.tools,
body.tool_choice, and body.parallel_tool_calls are undefined to validate the
side effects described in the code comment.

@opencode-agent
Copy link
Contributor

opencode-agent bot commented Nov 20, 2025

To https://github.com/open-hax/codex
! [rejected] review/v0.3.5 -> review/v0.3.5 (fetch first)
error: failed to push some refs to 'https://github.com/open-hax/codex'
hint: Updates were rejected because the remote contains work that you do not
hint: have locally. This is usually caused by another repository pushing to
hint: the same ref. If you want to integrate the remote changes, use
hint: 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

opencode session  |  github run

@opencode-agent
Copy link
Contributor

opencode-agent bot commented Nov 20, 2025

Perfect! I've successfully added the missing assertions to both test cases in test/compaction-helpers.test.ts:

First test (lines 24-29):

  • Verifies body.input was mutated (not equal to original)
  • Confirms the user command string "/codex-compact please" was removed
  • Validates that tools, tool_choice, and parallel_tool_calls are undefined

Second test (lines 51-54):

  • Verifies body.input remains defined
  • Confirms tools and tool_choice are undefined

The tests now properly validate the side effects described in the code comment, ensuring that applyCompactionIfNeeded correctly mutates the RequestBody by removing tool-related properties and appropriately handling the input array.

New%20session%20-%202025-11-20T22%3A41%3A39.262Z
opencode session  |  github run

Co-authored-by: riatzukiza <riatzukiza@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: 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 74c6155 and 4540ec3.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json and included by none
📒 Files selected for processing (1)
  • test/compaction-helpers.test.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
test/compaction-helpers.test.ts (2)
lib/types.ts (1)
  • RequestBody (147-169)
lib/request/compaction-helpers.ts (1)
  • applyCompactionIfNeeded (82-107)
🔇 Additional comments (1)
test/compaction-helpers.test.ts (1)

5-30: Test now fully validates compaction behavior and side effects

This test cleanly covers both the returned decision and the RequestBody side effects: body.input is mutated, the /codex-compact please command is removed, and tools/tool_choice/parallel_tool_calls are asserted undefined as requested. No blockers here.

@riatzukiza
Copy link
Collaborator Author

/oc In test/compaction-helpers.test.ts around lines 32 to 55, the test verifies that
body.input remains defined after applying compaction but does not assert it
still equals the original items; add a strict equality assertion to ensure the
RequestBody input was not mutated or altered by the compaction call by adding
expect(body.input).toEqual(originalInput) to the test (use deep equality, not
reference checks).

@opencode-agent
Copy link
Contributor

opencode-agent bot commented Nov 20, 2025

Added the strict equality assertion expect(body.input).toEqual(originalInput) to ensure the RequestBody input was not mutated when no user message exists.

New%20session%20-%202025-11-20T22%3A48%3A22.543Z
opencode session  |  github run

Co-authored-by: riatzukiza <riatzukiza@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: 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 4540ec3 and 07b5591.

📒 Files selected for processing (1)
  • test/compaction-helpers.test.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
test/compaction-helpers.test.ts (2)
lib/types.ts (1)
  • RequestBody (147-169)
lib/request/compaction-helpers.ts (1)
  • applyCompactionIfNeeded (82-107)
🪛 GitHub Actions: CI
test/compaction-helpers.test.ts

[error] 53-53: Test failed: returns original items when no user message exists. AssertionError: expected [ { type: 'message', …(2) }, …(1) ] to deeply equal [ { type: 'message', …(2) } ]

🪛 GitHub Check: Test (20.x)
test/compaction-helpers.test.ts

[failure] 53-53: test/compaction-helpers.test.ts > compaction helpers > returns original items when no user message exists
AssertionError: expected [ { type: 'message', …(2) }, …(1) ] to deeply equal [ { type: 'message', …(2) } ]

  • Expected
  • Received

    [
    {

  • "content": "system-only follow-up",
    
  • "role": "assistant",
    
  • "content": "You are performing a CONTEXT CHECKPOINT COMPACTION. Create a handoff summary for another LLM that will resume the task.
    
  • Include:
    • Current progress and key decisions made
    • Important context, constraints, or user preferences
    • What remains to be done (clear next steps)
    • Any critical data, examples, or references needed to continue
  • Be concise, structured, and focused on helping the next LLM seamlessly continue the work.",
  • "role": "developer",
    
  • "type": "message",
    
  • },
  • {
  • "content": "## Assistant
    
  • system-only follow-up
  • ",
  • "role": "user",
    "type": "message",
    
    },
    ]

❯ test/compaction-helpers.test.ts:53:22

🪛 GitHub Check: Test (22.x)
test/compaction-helpers.test.ts

[failure] 53-53: test/compaction-helpers.test.ts > compaction helpers > returns original items when no user message exists
AssertionError: expected [ { type: 'message', …(2) }, …(1) ] to deeply equal [ { type: 'message', …(2) } ]

  • Expected
  • Received

    [
    {

  • "content": "system-only follow-up",
    
  • "role": "assistant",
    
  • "content": "You are performing a CONTEXT CHECKPOINT COMPACTION. Create a handoff summary for another LLM that will resume the task.
    
  • Include:
    • Current progress and key decisions made
    • Important context, constraints, or user preferences
    • What remains to be done (clear next steps)
    • Any critical data, examples, or references needed to continue
  • Be concise, structured, and focused on helping the next LLM seamlessly continue the work.",
  • "role": "developer",
    
  • "type": "message",
    
  • },
  • {
  • "content": "## Assistant
    
  • system-only follow-up
  • ",
  • "role": "user",
    "type": "message",
    
    },
    ]

❯ test/compaction-helpers.test.ts:53:22

🔇 Additional comments (2)
test/compaction-helpers.test.ts (2)

1-2: Imports look good.

The necessary imports are present and there are no duplicates.


5-30: Test correctly verifies command-mode compaction and mutations.

The test properly asserts the decision mode, transcript content, and RequestBody mutations including the removal of tool-related fields.

@riatzukiza
Copy link
Collaborator Author

/oc In test/compaction-helpers.test.ts around line 53, the failing assertion
expect(body.input).toEqual(originalInput) is incorrect because
applyCompactionIfNeeded mutates body.input into the compacted prompt; remove
that equality assertion and replace it with assertions that validate compaction
occurred (for example assert body.input length > 0 and that body.input is not
equal to originalInput, or assert the specific compacted structure you expect).
Ensure the test no longer expects the original unmodified input and instead
checks for the compacted output properties.

@opencode-agent
Copy link
Contributor

opencode-agent bot commented Nov 20, 2025

ProviderInitError

opencode session  |  github run

@riatzukiza
Copy link
Collaborator Author

/oc In test/compaction-helpers.test.ts around line 53, the failing assertion
expect(body.input).toEqual(originalInput) is incorrect because
applyCompactionIfNeeded mutates body.input into the compacted prompt; remove
that equality assertion and replace it with assertions that validate compaction
occurred (for example assert body.input length > 0 and that body.input is not
equal to originalInput, or assert the specific compacted structure you expect).
Ensure the test no longer expects the original unmodified input and instead
checks for the compacted output properties.

@opencode-agent
Copy link
Contributor

opencode-agent bot commented Nov 20, 2025

Fixed the test by removing the incorrect equality assertion and replacing it with proper compaction validation that checks the input was mutated and contains content.

New%20session%20-%202025-11-20T22%3A57%3A37.365Z
opencode session  |  github run

Co-authored-by: riatzukiza <riatzukiza@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 07b5591 and 7466b2b.

📒 Files selected for processing (1)
  • test/compaction-helpers.test.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
test/compaction-helpers.test.ts (2)
lib/types.ts (1)
  • RequestBody (147-169)
lib/request/compaction-helpers.ts (1)
  • applyCompactionIfNeeded (82-107)
🔇 Additional comments (1)
test/compaction-helpers.test.ts (1)

5-30: Test correctly verifies command-based compaction.

The test properly validates the compaction decision and RequestBody mutations, including removal of the user command, preservation of trailing items, and deletion of tool-related fields.

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

/oc In test/compaction-helpers.test.ts around line 32, the test title "returns
original items when no user message exists" contradicts the assertions which
expect body.input to be mutated; update the test name to reflect the actual
behavior (e.g., "applies compaction when no user message exists") and/or adjust
the assertions so title and expectations match—ensure the test description and
assertions are consistent (rename the it(...) string to the new title and leave
assertions as-is unless you intend to change expected behavior).

@opencode-agent
Copy link
Contributor

opencode-agent bot commented Nov 20, 2025

ProviderInitError

opencode session  |  github run

@riatzukiza
Copy link
Collaborator Author

/oc In test/compaction-helpers.test.ts around line 32, the test title "returns
original items when no user message exists" contradicts the assertions which
expect body.input to be mutated; update the test name to reflect the actual
behavior (e.g., "applies compaction when no user message exists") and/or adjust
the assertions so title and expectations match—ensure the test description and
assertions are consistent (rename the it(...) string to the new title and leave
assertions as-is unless you intend to change expected behavior).

@opencode-agent
Copy link
Contributor

opencode-agent bot commented Nov 20, 2025

Perfect! I've updated the test title from "returns original items when no user message exists" to "applies compaction when no user message exists" to accurately reflect the actual behavior being tested. The test assertions correctly expect that body.input is mutated during compaction, so the new title is now consistent with the test expectations.

New%20session%20-%202025-11-20T23%3A05%3A18.370Z
opencode session  |  github run

Co-authored-by: riatzukiza <riatzukiza@users.noreply.github.com>
@riatzukiza riatzukiza merged commit 798a8be into dev Nov 20, 2025
15 of 16 checks passed
@riatzukiza riatzukiza deleted the review/v0.3.5 branch November 20, 2025 23:08
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