Skip to content

fix: keep an agent name through a process-exit observation - #3574

Open
caner-akca wants to merge 1 commit into
herdrdev:masterfrom
caner-akca:issue/3225-agent-name-release
Open

fix: keep an agent name through a process-exit observation#3574
caner-akca wants to merge 1 commit into
herdrdev:masterfrom
caner-akca:issue/3225-agent-name-release

Conversation

@caner-akca

@caner-akca caner-akca commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • free a pane's agent name when the agent is confirmed gone rather than on a
    single process-exit observation
  • keep the name through a false exit that the next probe clears, matching how
    detection uncertainty is already handled
  • leave the pane.agent_detected { released: true } event unchanged

This fixes the failure reported in the #3225 comment thread: a named pane stops
resolving by its name while its process keeps running, with a rename as the only
recovery. It does not address the failure in the issue body, so #3225 should stay
open.

Validation

  • just check
  • API-boundary reproduction of the reported agent_not_found, plus state-layer
    tests pinning both directions — a false exit keeps the name, a confirmed exit
    frees it
  • two live_handoff tests fail identically on master and this branch on macOS
    26.2, before reaching changed code: their fake agent execs /bin/sleep, and
    KERN_PROCARGS2 there returns an empty environment section, so HERDR_AGENT
    is invisible to process_agent_hint. Those run in CI.

refs #3225

@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 0ae282b2-53a9-45fb-b0bd-02f7f30c4d4c

📥 Commits

Reviewing files that changed from the base of the PR and between 9a2a7af and 065026e.

📒 Files selected for processing (3)
  • src/app/api.rs
  • src/app/api/agents.rs
  • src/terminal/state.rs

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The change updates agent name handling after process-exit observations. Names remain associated with terminals when the agent is still detected or is detected again. A subsequent no-agent observation after a process exit still releases the name. Tests cover terminal state transitions, named live agents, idle agents, and hook-owned agent registrations.

Suggested reviewers: ogulcancelik

Merge Risk: ⚪ Minimal · up to 06502

This change preserves agent names through false process-exit observations while still releasing names after a later no-agent observation confirms exit. The covered state and API scenarios indicate no current merge-blocking risk.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 3 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: preserving an agent name through a single process-exit observation.
Description check ✅ Passed The description directly explains the agent-name release behavior, test coverage, validation, and scope of the fix.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@caner-akca
caner-akca marked this pull request as ready for review September 3, 2026 12:30
@kangal-bot

Copy link
Copy Markdown
Collaborator

@coderabbitai review
@greptileai

@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown

@kangal-bot I will review the changes in #3574.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@greptile-apps

greptile-apps Bot commented Sep 3, 2026

Copy link
Copy Markdown

Greptile Summary

This PR delays clearing an assigned agent name until process-exit evidence is followed by a no-agent observation, preserving name-based API targeting when an exit observation proves false.

  • Keeps the agent name through an initial process-exit observation while retaining the existing release event.
  • Clears the name after a subsequent observation confirms that no agent remains.
  • Adds state-level and API-level regression coverage for false and confirmed exits.

Confidence Score: 5/5

The PR appears safe to merge, with the revised cleanup transition preserving name reachability while retaining confirmed-exit cleanup.

The changed state transition is consistent with the production detection sequence: a renewed agent observation clears the exit marker, while a confirmed no-agent observation releases the name, and no concrete blocking failure remains.

Important Files Changed

Filename Overview
src/terminal/state.rs Changes agent-name cleanup to require both recorded exit evidence and a subsequent no-agent observation, with focused state-machine regression tests.
src/app/api/agents.rs Adds API-boundary coverage proving that a falsely reported exit does not make a re-detected live agent unreachable by its assigned name.
src/app/api.rs Updates release-event tests to reflect that registration release no longer immediately clears the assigned agent name.

Sequence Diagram

sequenceDiagram
    participant D as Agent detection
    participant T as TerminalState
    participant API as Agent API
    D->>T: Exit observation with agent present
    T->>T: Record recent process exit
    T->>T: Preserve assigned name
    alt Agent detected again
        D->>T: AgentProcessDetected
        T->>T: Clear exit marker, retain name
        API->>T: Resolve assigned name
        T-->>API: Named live agent
    else No agent confirmed
        D->>T: "StateChanged(agent=None)"
        T->>T: Clear assigned name
    end
Loading

Reviews (1): Last reviewed commit: "fix: keep an agent name through a proces..." | Re-trigger Greptile

A process-exit observation is not proof the agent is gone: the same
observation can be wrong while the agent keeps running, and the name is
the only handle its owner has on the pane. Detection uncertainty already
preserves the name, so releasing it on the observation alone contradicts
that contract and leaves a live agent unreachable by name with a rename
as the only recovery.

Free the name at the point the agent actually leaves the pane - a
recorded exit with no agent detected any more - so a wrong observation
costs nothing and a real exit still releases the name for reuse.

refs herdrdev#3225
@caner-akca
caner-akca force-pushed the issue/3225-agent-name-release branch from 065026e to 692e021 Compare September 3, 2026 18:00
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.

2 participants