Skip to content

fix(session): skip LFS stubs in detect loop, re-summarize stub artifacts#428

Merged
rsnodgrass merged 3 commits intomainfrom
ryan/lfs-stub-detect-loop
Apr 4, 2026
Merged

fix(session): skip LFS stubs in detect loop, re-summarize stub artifacts#428
rsnodgrass merged 3 commits intomainfrom
ryan/lfs-stub-detect-loop

Conversation

@rsnodgrass
Copy link
Copy Markdown
Contributor

@rsnodgrass rsnodgrass commented Apr 4, 2026

Summary

Fixes three issues in the anti-entropy session finalization pipeline:

  • LFS stub detect loop: Sessions with LFS pointer stubs as raw.jsonl were detected every 5 minutes, enqueued, and immediately failed in BuildPrompt — repeating forever. Now detectInDir calls lfs.IsPointerFile() early and skips them.
  • Stub summary.json never replaced: ox session stop writes stub artifacts (stats-only summary.json, summary.md, session.md) before the daemon can run LLM summarization. The daemon's missingArtifacts() check saw all files present and skipped the session. Now detectInDir also checks for the .needs-summary marker and re-enqueues for LLM regeneration. ProcessResult clears the marker after successful artifact generation.
  • Code search guidance too subtle in prime: Agents defaulted to Grep/Glob because their system prompts recommend those tools. Added a dedicated <code-search status="indexed"> XML block in prime output that clearly instructs agents to prefer ox code search when a code index exists.
flowchart TD
    A[detectInDir scans session] --> B{raw.jsonl exists?}
    B -->|No| Z[skip]
    B -->|Yes| C{LFS pointer stub?}
    C -->|Yes| Z
    C -->|No| D{Has substantive entries?}
    D -->|No| Z
    D -->|Yes| E{All artifacts exist?}
    E -->|No| F[Enqueue for LLM finalization]
    E -->|Yes| G{.needs-summary marker?}
    G -->|Yes| H[Enqueue for LLM re-summarization]
    G -->|No| I{In cache, not pushed?}
    I -->|Yes| J[Enqueue upload-only]
    I -->|No| Z
Loading

Test plan

  • TestDetect_SkipsLFSStubSessions — LFS pointer sessions skipped at detection
  • TestDetect_NeedsSummaryMarkerTriggersRefinalization — stub artifacts with marker enqueued for LLM
  • make lint — 0 issues
  • make test — all pass

Co-authored-by: SageOx ox@sageox.ai

Summary by CodeRabbit

  • New Features

    • Added code search index detection to improve agent capabilities and behavior when code search is available.
  • Bug Fixes

    • Fixed handling of Git LFS pointer files in sessions.
    • Sessions now correctly regenerate summaries when required.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4b2a2839-ed14-4fc9-852c-fb0127c90d78

📥 Commits

Reviewing files that changed from the base of the PR and between c1eba09 and 7dcf958.

📒 Files selected for processing (1)
  • cmd/ox/agent_prime_xml.go
✅ Files skipped from review due to trivial changes (1)
  • cmd/ox/agent_prime_xml.go

📝 Walkthrough

Walkthrough

The changes add code search availability detection and conditional guidance emission while enhancing session finalization to detect LFS pointer stubs and respect a needs-summary marker for artifact regeneration. A new struct field and utility functions support marker-based session re-finalization workflows.

Changes

Cohort / File(s) Summary
Code search availability detection
cmd/ox/agent_prime.go, cmd/ox/agent_prime_xml.go, internal/prime/types.go
Detect when code database exists, set CodeDBAvailable flag in output, and conditionally emit enhanced code-search instruction block in XML renderer when flag is true.
Session finalization with LFS and marker handling
internal/daemon/agentwork/session_finalize.go
Detect and skip LFS pointer-file stubs in raw.jsonl, check for needs-summary marker to trigger artifact regeneration despite their presence, and clear marker after artifact writing.
Session finalization test coverage
internal/daemon/agentwork/session_finalize_detect_test.go, internal/daemon/agentwork/session_finalize_lfs_test.go
Test needs-summary marker triggering re-finalization and LFS stub session skipping during detection.
Marker utility function
internal/session/summary_marker.go
Add HasNeedsSummaryMarker exported helper to check for needs-summary marker existence.

Sequence Diagram

sequenceDiagram
    participant Daemon
    participant Detect as Session Finalize<br/>(Detect)
    participant LFS
    participant Marker
    participant ProcessResult
    
    Daemon->>Detect: Detect(ledgerPath)
    Detect->>Detect: Scan session directories
    
    rect rgba(200, 150, 100, 0.5)
        Note over Detect,LFS: LFS Stub Check
        Detect->>LFS: IsPointerFile(rawPath)
        alt LFS Pointer Detected
            LFS-->>Detect: true
            Detect->>Detect: Log skip, continue
        else Real JSONL
            LFS-->>Detect: false
            Detect->>Detect: Check artifacts
        end
    end
    
    rect rgba(100, 150, 200, 0.5)
        Note over Detect,Marker: Needs-Summary Marker Check
        Detect->>Detect: All required artifacts present?
        alt Yes
            Detect->>Marker: HasNeedsSummaryMarker(sessionDir)
            alt Marker Found
                Marker-->>Detect: true
                Detect->>Detect: Queue session-finalize<br/>with Missing: requiredArtifacts
            else No Marker
                Marker-->>Detect: false
                Detect->>Detect: Treat as finalized
            end
        end
    end
    
    Detect-->>Daemon: WorkItems
    
    Daemon->>ProcessResult: Process finalization result
    ProcessResult->>ProcessResult: WriteSessionArtifacts
    ProcessResult->>Marker: ClearNeedsSummaryMarker
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • sageox/ox#350: Modifies the same runAgentPrime function in cmd/ox/agent_prime.go with overlapping changes.
  • sageox/ox#426: Also modifies internal/daemon/agentwork/session_finalize.go with complementary session finalization logic around artifact processing.
  • sageox/ox#176: Adds CodeDB-related features and modifies agent code-search guidance, directly connected to the new CodeDBAvailable flag and conditional instruction emission.

Suggested labels

sageox

Poem

🐰 The Code DB hops online with pride,
Markers guide sessions far and wide,
LFS stubs are skipped with care,
Artifacts sprout fresh in the air!
thump-thump goes the finalization flow ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main fixes: skipping LFS stubs in the detect loop and re-summarizing stub artifacts with the needs-summary marker workflow.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ryan/lfs-stub-detect-loop

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

@rsnodgrass rsnodgrass marked this pull request as ready for review April 4, 2026 15:14
Copy link
Copy Markdown
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

🧹 Nitpick comments (1)
internal/daemon/agentwork/session_finalize.go (1)

673-674: Consider logging marker clear failures for debuggability.

The error from ClearNeedsSummaryMarker is discarded. While ClearNeedsSummaryMarker handles os.IsNotExist gracefully, other failures (permission denied, I/O errors) would be silently ignored. If clearing fails, the session would be re-enqueued on the next detect cycle—benign but worth logging to surface file system issues.

🔧 Optional: Log warning on failure
 // clear .needs-summary marker now that LLM artifacts have replaced stubs
-_ = session.ClearNeedsSummaryMarker(payload.SessionDir)
+if err := session.ClearNeedsSummaryMarker(payload.SessionDir); err != nil {
+	h.logger.Warn("failed to clear .needs-summary marker", "session", sessionName, "err", err)
+}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/daemon/agentwork/session_finalize.go` around lines 673 - 674, The
call to session.ClearNeedsSummaryMarker(payload.SessionDir) currently discards
errors; capture its returned error and, if err != nil and not
os.IsNotExist(err), emit a warning log that includes the session directory and
the error (e.g., "failed to clear .needs-summary marker for %s: %v"). Use the
same logger used elsewhere in session_finalize.go (e.g., the file's
logger/processLogger) and keep the existing behavior of ignoring os.IsNotExist
errors.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.claude/settings.json:
- Around line 27-35: Remove the duplicate unguarded "bd prime" hook entry that
runs without the existing guard; either delete this second hook block (the one
with "hooks": [{"command": "bd prime", "type": "command"}], "matcher": "") or
modify it to match the guarded pattern used earlier by wrapping the command with
the same guard (e.g., use the shell presence check used in the prior hook block)
so machines without the bd binary don't error and the command isn't executed
twice.

In `@cmd/ox/agent_prime_xml.go`:
- Around line 79-86: The XML payload contains a literal "<query>" which will be
parsed as a tag; update the string construction in agent_prime_xml.go where the
StringBuilder variable sb is used to write the code-search block (the lines that
call sb.WriteString with the guidance text) so that the literal is escaped
(replace "<query>" with "&lt;query&gt;" or run the whole text through an
XML-escape helper like escapeXML) before writing; ensure both the opening and
closing angle brackets are escaped ("&lt;query&gt;" and "&lt;/query&gt;" if
needed) so the produced XML remains valid.

---

Nitpick comments:
In `@internal/daemon/agentwork/session_finalize.go`:
- Around line 673-674: The call to
session.ClearNeedsSummaryMarker(payload.SessionDir) currently discards errors;
capture its returned error and, if err != nil and not os.IsNotExist(err), emit a
warning log that includes the session directory and the error (e.g., "failed to
clear .needs-summary marker for %s: %v"). Use the same logger used elsewhere in
session_finalize.go (e.g., the file's logger/processLogger) and keep the
existing behavior of ignoring os.IsNotExist errors.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 016faf0f-a6e3-4eae-a657-8280f30dabdc

📥 Commits

Reviewing files that changed from the base of the PR and between 3092ca6 and c1eba09.

📒 Files selected for processing (8)
  • .claude/settings.json
  • cmd/ox/agent_prime.go
  • cmd/ox/agent_prime_xml.go
  • internal/daemon/agentwork/session_finalize.go
  • internal/daemon/agentwork/session_finalize_detect_test.go
  • internal/daemon/agentwork/session_finalize_lfs_test.go
  • internal/prime/types.go
  • internal/session/summary_marker.go

Comment thread .claude/settings.json Outdated
Comment thread cmd/ox/agent_prime_xml.go
…kets in code-search block

Co-Authored-By: SageOx <ox@sageox.ai>
@rsnodgrass rsnodgrass merged commit cdad9a1 into main Apr 4, 2026
3 checks passed
@rsnodgrass rsnodgrass deleted the ryan/lfs-stub-detect-loop branch April 4, 2026 15:28
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