Skip to content

fix: accept cwd alias in SessionStart hook + fix doctor false-positive warnings#72

Merged
fajarhide merged 12 commits intofajarhide:mainfrom
tomraider4720:fix/session-start-cwd-alias-and-doctor-all-ok
May 3, 2026
Merged

fix: accept cwd alias in SessionStart hook + fix doctor false-positive warnings#72
fajarhide merged 12 commits intofajarhide:mainfrom
tomraider4720:fix/session-start-cwd-alias-and-doctor-all-ok

Conversation

@tomraider4720
Copy link
Copy Markdown

@tomraider4720 tomraider4720 commented May 2, 2026

Summary

Two bugs fixed that together caused omni doctor to always show ⚠ ATTENTION NEEDED and prevented session tracking from working with Claude Code.

Bug 1: SessionStart hook silently fails with Claude Code payloads

Claude Code sends "cwd" as the working directory field in SessionStart hook payloads. The HookInput struct in session_start.rs only accepted "workingDirectory" and "working_directory", so serde_json::from_str failed on every real Claude Code invocation, printing [omni] parse error and returning early — before the store.upsert_session() call on line 151.

Result: The sessions table stayed permanently empty. omni doctor reported 0 records and Last session: none. Session context injection (hot files, previous errors at SessionStart) never worked.

Fix: Add #[serde(alias = "cwd")] to the working_directory field.

Verified by inspecting actual Claude Code hook transcripts in ~/.omni/transcripts/ which confirmed the "cwd" field name, and by a new regression test test_claude_code_cwd_alias_accepted using the real payload format.

Bug 2: Optional agents return false when not configured → spurious ATTENTION NEEDED

All 11 optional agent integrations (Cursor, Zed, Cline, Roo Code, Copilot, Gemini, OpenCode, Codex, OpenClaw, Antigravity, VS Code) returned false from doctor_check() when simply not configured. In doctor.rs, all_ok is AND-ed with every agent's result:

all_ok &= agent.doctor_check(fix_mode, &mut warnings);

This means any system that only uses Claude Code (the most common case) would always have all_ok = false and see ⚠ ATTENTION NEEDED — even with a perfectly healthy installation.

Fix: Return true when an optional agent is not configured. Only a broken or partial configuration (e.g. config file exists but "omni" is missing) would be a real problem.

Test plan

  • omni doctor shows ✓ ALL OK on a system with only Claude Code configured
  • SessionStart hook creates a session record in the DB when Claude Code sends its standard payload
  • cargo test passes (all 46 tests, including new test_claude_code_cwd_alias_accepted)
  • Existing test_continue_session_inject_summary still passes (session continuation unaffected)

🤖 Generated with Claude Code

PR Auto Describe

Summary

Added support for the cwd alias in SessionStart payloads to accommodate Claude Code’s output format. Updated tests to verify correct parsing, persistence, and that no parse errors arise when cwd is supplied.


Key Changes

  • HookInput now accepts cwd as an alias for working_directory.
  • New test test_claude_code_cwd_alias_accepted ensures:
    • Payloads with cwd parse successfully.
    • Session records are written to the database.
    • No output (None) is produced for a fresh session without a toolchain.

Detailed Breakdown

  • Struct Update
    • Added #[serde(alias = "cwd")] to working_directory field.
    • Keeps existing rename and alias for workingDirectory and working_directory intact.
  • Test Addition
    • Creates a store and a sample payload using cwd.
    • Calls process_payload and expects None (no watch paths).
    • Confirms the session exists in the DB via store.find_latest_session().
    • Asserts that using cwd does not trigger a parse error or prevent persistence.

Notes

  • Test covers both camelCase (cwd) and snake_case usage, mirroring real Claude Code transcripts.
  • No breaking API changes; backward compatibility preserved.

Last updated: 2026-05-03 10:53:12

**Bug 1: SessionStart hook ignores Claude Code payloads (sessions table stays empty)**

Claude Code sends `"cwd"` as the working directory field in SessionStart hook
payloads. The HookInput struct only accepted `"workingDirectory"` and
`"working_directory"`, causing serde deserialization to fail silently with
`[omni] parse error`. As a result, no sessions were ever written to the DB,
`omni doctor` always reported 0 records, and session context injection
(hot files, previous errors) never worked.

Fix: add `#[serde(alias = "cwd")]` to the `working_directory` field.
Adds regression test `test_claude_code_cwd_alias_accepted` with the actual
Claude Code hook payload format (snake_case fields + cwd).

**Bug 2: omni doctor always shows ATTENTION NEEDED (false positive)**

All 11 optional agent integrations (Cursor, Zed, Cline, Roo Code, Copilot,
Gemini, OpenCode, Codex, OpenClaw, Antigravity, VS Code) returned false
from doctor_check() when not configured. Since all_ok is AND-ed with every
agent result, any non-Claude-Code agent not installed caused the doctor to
report ATTENTION NEEDED even when everything was working correctly.

Fix: return true (not an error) when an optional agent is simply not
configured. Only a broken/partial configuration should indicate failure.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@fajarhide fajarhide self-requested a review May 2, 2026 14:57
Copy link
Copy Markdown
Owner

@fajarhide fajarhide left a comment

Choose a reason for hiding this comment

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

Hi @tomraider4720, thank you so much for this PR and for catching these two critical issues!

Bug 1 (cwd alias): Spot on! This is a great catch and the fix with #[serde(alias = "cwd")] is perfect.

Bug 2 (Doctor False Positive): You are absolutely right about the root cause (the all_ok &= ... logic causing false positives if optional agents aren't configured). However, changing all 11 agents to return true when they are not configured isn't the ideal architectural fix, as the return value of doctor_check() is supposed to accurately represent whether the agent is successfully configured or not.

Instead of changing all the agents, the better fix is to update the logic in src/cli/doctor.rs to not require every agent to be true. We just need at least one agent to be configured:

let mut any_agent_ok = false;
    for agent in integrations {
        if agent.doctor_check(fix_mode, &mut warnings) {
            any_agent_ok = true;
        }
    }
    if !any_agent_ok {
        all_ok = false;
        // maybe push a warning
    }

Would you be open to updating this PR to revert the agent files and apply the fix to doctor.rs instead? Let me know, or I can also merge the cwd fix first and handle the doctor logic in a separate commit. Thanks again!

@fajarhide fajarhide added bug Something isn't working ai-describe and removed bug Something isn't working labels May 3, 2026
@tomraider4720
Copy link
Copy Markdown
Author

Thanks for the detailed review! Totally agree on the architectural feedback for Bug 2.

Would you be happy to merge the cwd alias fix first (since that's the critical bug causing sessions to never be stored), and I'll open a separate PR for the doctor.rs logic fix?

@fajarhide
Copy link
Copy Markdown
Owner

Thanks for the detailed review! Totally agree on the architectural feedback for Bug 2.

Would you be happy to merge the cwd alias fix first (since that's the critical bug causing sessions to never be stored), and I'll open a separate PR for the doctor.rs logic fix?

Well noted. i'll to merge the bug 1. Thanks to contribute!

Copy link
Copy Markdown
Owner

@fajarhide fajarhide left a comment

Choose a reason for hiding this comment

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

rollback true to false and merged fixed bug 1 accept cwd.

Comment thread src/agents/zed.rs Outdated
Comment thread src/agents/vscode.rs Outdated
Comment thread src/agents/roo_code.rs Outdated
Comment thread src/agents/opencode.rs Outdated
Comment thread src/agents/openclaw.rs Outdated
Comment thread src/agents/cursor.rs Outdated
Comment thread src/agents/copilot.rs Outdated
Comment thread src/agents/codex.rs Outdated
Comment thread src/agents/cline.rs Outdated
Comment thread src/agents/antigravity.rs Outdated
fajarhide added 11 commits May 3, 2026 17:51
Signed-off-by: Fajar Hidayat <fajarhide@gmail.com>
Signed-off-by: Fajar Hidayat <fajarhide@gmail.com>
Signed-off-by: Fajar Hidayat <fajarhide@gmail.com>
Signed-off-by: Fajar Hidayat <fajarhide@gmail.com>
Signed-off-by: Fajar Hidayat <fajarhide@gmail.com>
Signed-off-by: Fajar Hidayat <fajarhide@gmail.com>
Signed-off-by: Fajar Hidayat <fajarhide@gmail.com>
Signed-off-by: Fajar Hidayat <fajarhide@gmail.com>
Signed-off-by: Fajar Hidayat <fajarhide@gmail.com>
Signed-off-by: Fajar Hidayat <fajarhide@gmail.com>
Signed-off-by: Fajar Hidayat <fajarhide@gmail.com>
Copy link
Copy Markdown
Owner

@fajarhide fajarhide left a comment

Choose a reason for hiding this comment

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

Thanks for contribute!

@fajarhide fajarhide merged commit fa5e5bd into fajarhide:main May 3, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants