Skip to content

feat(cli): resolve ping-peer by durable agentSessionId (#1203) - #137

Open
heavygee wants to merge 1 commit into
mainfrom
feat/ping-peer-agent-session-id
Open

feat(cli): resolve ping-peer by durable agentSessionId (#1203)#137
heavygee wants to merge 1 commit into
mainfrom
feat/ping-peer-agent-session-id

Conversation

@heavygee

Copy link
Copy Markdown
Owner

Summary

  • hapi ping-peer, hapi inspect-peer, and MCP ping_peer / inspect_peer now resolve peers by durable metadata.agentSessionId (exact, prefix, and overseer substring parity) in addition to hub session id prefix.
  • Resolution prefers the active + most-recently-updated hub row when multiple rows share an agentSessionId, then POSTs/resumes using the current hub id (ids still rotate; agentSessionId is the find-key).
  • Ambiguous / not-found errors include actionable hints (name, hub id sample, agentSessionId when present).
  • MCP tool descriptions updated in shared/src/sessionCitation.ts.

Part of reply-addressable peer handoffs (tiann/hapi#1203). Does not add fortress/capability HMAC (tiann#1473) or automatic reply loops.

Upstream prep (tiann/hapi)

Ready to open as upstream PR against tiann/hapi:main when lane allows. Diff is product-only (cli/, shared/).

Test plan

  • bunx vitest run cli/src/modules/pingPeer/ (30 tests)
  • bun run typecheck in cli/
  • Dogfood: hapi ping-peer 05d9f0f2 "…" delivered to orchestrator session

Made with Cursor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3c224cb459

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +252 to +254
const exactHub = sessions.filter((session) => session.id === trimmed)
if (exactHub.length === 1) {
return exactHub[0]!

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Redirect stale hub IDs to the current durable peer

When a stale and a current hub row share the same metadata.agentSessionId, supplying the stale row's exact /sessions/<id> value returns it immediately and bypasses the active/newest durable-ID selection below. pingPeer consequently resumes and posts to the stale hub ID rather than the current row, defeating the row-churn behavior this change advertises and potentially reviving a duplicate session. Resolve an exact hub match through its durable-ID group before returning it.

Useful? React with 👍 / 👎.

Comment thread cli/src/agent/agentAvailability.ts Outdated
Comment on lines +40 to +45
function hasValidDshConfiguration(env: LaunchEnvironment): boolean {
const config = env.HAPI_DSH_ACP_CONFIG?.trim()
if (!config) return true
if (!isAbsolute(config)) return false
try {
return existsSync(config) && statSync(config).isFile()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Validate the effective DSH launch configuration

Valid DSH setups can now be blocked before spawning because this validator diverges from resolveDshAcpCommand: a relative HAPI_DSH_ACP_CONFIG is launchable relative to the runner cwd but is rejected here, and a stale config is still checked even when HAPI_DSH_ACP_ARGS_JSON overrides and ignores it. In either case availability reports invalid_configuration, so all new-session clients disable DSH even though the actual launch specification is usable.

Useful? React with 👍 / 👎.

Hub session ids rotate on resume; metadata.agentSessionId is the durable find-key.
ping-peer / inspect_peer / MCP ping_peer now match agentSessionId (exact, prefix,
and overseer substring parity), prefer active+newest rows, and still POST to the
resolved hub id. Ambiguous/not-found errors include name and hub id hints.

Co-authored-by: Cursor <cursoragent@cursor.com>
@heavygee
heavygee force-pushed the feat/ping-peer-agent-session-id branch from 3c224cb to 74c784f Compare August 29, 2026 15:22

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 74c784f1b2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if (tied.length > 1) {
throwPeerResolveAmbiguous(trimmed, tied, kind)
}
return top

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Reject prefixes spanning multiple durable peers

When an agentSessionId prefix or substring matches different durable peers with unequal activity or timestamps, pickBestPeerMatch silently selects the active/newest row instead of reporting ambiguity, so ping-peer can send a message to an unintended session. Activity/recency should select among churned hub rows only after grouping by the same normalized agentSessionId and flavor; distinct groups must remain ambiguous (the flavor distinction is already required by web/src/components/SessionList.tsx:189-195).

Useful? React with 👍 / 👎.

@heavygee

Copy link
Copy Markdown
Owner Author

CI fix (2026-08-29)

All checks green after force-push to 74c784f1b.

What failed (not ping-peer logic):

  • Branch was originally cut from upstream/main, while PR feat(cli): resolve ping-peer by durable agentSessionId (#1203) #137 targets heavygee/hapi:main. GitHub’s merge commit pulled in a mismatched bun.lockbun install --frozen-lockfile failed (drift-gate, test).
  • Integration failures on that merge base were spawn/session HTTP errors from the divergent tree — same jobs pass on clean fork main and on this rebased tip.

Fix: reset to origin/main, cherry-picked only the 4-file feature commit. Diff vs main is unchanged product scope.

Still not in soup — needs merge + driver remat for :3006 dogfood.

heavygee added a commit that referenced this pull request Aug 29, 2026
Durable find-key for hapi ping-peer so dogfood works on :3006 while the
fork PR stays open for upstream prep. Thin tip 93cae0a on live soup.

Co-authored-by: Cursor <cursoragent@cursor.com>
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