Skip to content

fix(cc-task): recover consult destination and show consult hold state…#1

Open
Shreyas281299 wants to merge 1 commit into
akulakum:TASK_REFACTOR_IMPLEMENTATIONfrom
Shreyas281299:fix-hydrate-transfer
Open

fix(cc-task): recover consult destination and show consult hold state…#1
Shreyas281299 wants to merge 1 commit into
akulakum:TASK_REFACTOR_IMPLEMENTATIONfrom
Shreyas281299:fix-hydrate-transfer

Conversation

@Shreyas281299
Copy link
Copy Markdown
Collaborator

@Shreyas281299 Shreyas281299 commented May 5, 2026

COMPLETES #N/A (No linked issue)

This pull request addresses

Consult transfer destination recovery failing after refresh/hydration for consult calls, especially EP-DN consult payloads where the transfer target should resolve to an entry point (epId).

by making the following changes

  • Added robust consult media resolution in consultTransfer using:
    1. consultMediaResourceId hint from task data,
    2. latest consult media fallback,
    3. legacy consult media lookup fallback.
  • Added EP-DN target recovery:
    • Detects consult participant as EP-DN/EpDn
    • Uses participant epId
    • Builds transfer destination as {to: epId, destinationType: 'entryPoint'}
  • Added fallback chain for non-EP-DN payloads:
    • Other consult-leg Agent participant
    • interaction.callProcessingDetails.consultedAgentId

Change Type

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Tooling change
  • Internal code refactor

The following scenarios were tested

  • The testing is done with the amplify link
  • Manual validation with hydrated consult payload shape (task-object.json) to verify destination resolves to entry point for EP-DN case
  • Local package build: yarn workspace @webex/cc-task build

The GAI Coding Policy And Copyright Annotation Best Practices

  • GAI was not used (or, no additional notation is required)
  • Code was generated entirely by GAI
  • GAI was used to create a draft that was subsequently customized or modified
  • Coder created a draft manually that was non-substantively modified by GAI (e.g., refactoring was performed by GAI on manually written code)
  • Tool used for AI assistance (GitHub Copilot / Other - specify)
    • Github Copilot
    • Other - Cursor Agent
  • This PR is related to
    • Feature
    • Defect fix
    • Tech Debt
    • Automation

Checklist before merging

  • I have not skipped any automated checks
  • All existing and new tests passed
  • I have updated the testing document
  • I have tested the functionality with amplify link

Make sure to have followed the contributing guidelines before submitting.

@Shreyas281299
Copy link
Copy Markdown
Collaborator Author

Changeset Review Summary

Changeset 1: Robust consult media resolution after refresh

  • What changed: Replaced direct findMediaResourceId(..., 'consult') lookup with a prioritized consult-media resolver: consultMediaResourceId hint -> latest consult media -> legacy fallback.
  • Why: After hydration/refresh, consult metadata can be stale or reordered; relying on one source caused missed destination recovery.

Changeset 2: EP-DN consult destination recovery

  • What changed: Added detection of consult participants with pType === 'EP-DN' / type === 'EpDn' and maps their epId to transfer destination as { destinationType: 'entryPoint' }.
  • Why: For EP-DN consult payloads, the expected transfer target is the entry point (epId), not an agent id.

Changeset 3: Agent fallback chain for non-EP-DN consults

  • What changed: Added fallback order when no EP-DN target is found:
    1. Other consult-leg participant with pType === 'Agent'
    2. interaction.callProcessingDetails.consultedAgentId
  • Why: Covers multiple backend payload shapes and prevents consult destination not found after state rehydration.

Overall this change set improves transfer resiliency for hydrated consult tasks while preserving existing agent-transfer behavior.

});
const media = interaction?.media;
const hinted = (currentTask.data as {consultMediaResourceId?: string | null}).consultMediaResourceId;
const consultId =
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Change 1 (media resolution fallback chain): this replaces single-source consult lookup with a resilient order (consultMediaResourceId hint -> latest consult media -> legacy finder). This is needed because hydrated task payloads can reorder media or keep stale consult entries.

if (!p || p.id === myAgentId) continue;
const epId = (p as {epId?: string}).epId?.trim();
if (epId && (p.pType === 'EP-DN' || (p as {type?: string}).type === 'EpDn')) {
destination = {to: epId, destinationType: 'entryPoint' as DestinationType};
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Change 2 (EP-DN mapping): this block intentionally builds an entryPoint transfer destination from participant epId when consult participant is EP-DN/EpDn. This is the core fix for payloads where transfer must target entry point instead of an agent.

if (!destination?.to) {
for (const pid of pids) {
const p = parts[pid];
if (p?.id !== myAgentId && p.pType === 'Agent') {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Change 3 (agent fallback): if EP-DN target is not present, this loop preserves existing behavior by recovering transfer destination from the other consult-leg agent participant.

}
if (!destination?.to) {
const cid = (
interaction as {callProcessingDetails?: {consultedAgentId?: string}}
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Change 4 (payload-shape fallback): this uses callProcessingDetails.consultedAgentId as a final recovery path for hydrated payloads where consult media participants do not include the answered agent.

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