Skip to content

Fix Devin sample agent: observability v2 migration, runtime crashes, and deployment issues#264

Open
Yogeshp-MSFT wants to merge 1 commit intomicrosoft:mainfrom
Yogeshp-MSFT:Devin-sample
Open

Fix Devin sample agent: observability v2 migration, runtime crashes, and deployment issues#264
Yogeshp-MSFT wants to merge 1 commit intomicrosoft:mainfrom
Yogeshp-MSFT:Devin-sample

Conversation

@Yogeshp-MSFT
Copy link
Copy Markdown

Summary

Updates the nodejs/devin/sample-agent to compile and run correctly against @microsoft/agents-a365-observability v2 breaking API changes, fixes multiple runtime crashes discovered during App Service deployment, and addresses code quality issues.

Changes

src/agent.ts

  • L4–L15: Updated imports — added InvokeAgentScopeDetails (L11), Request (L13)
    Reason: v2 SDK renamed/removed these types; InvokeAgentScope.start() now requires InvokeAgentScopeDetails and Request instead of the old positional args.
  • L98–L103: Removed .correlationId(uuidv4()) from BaggageBuilder chain
    Reason: .correlationId() method was removed in the v2 SDK.
  • L103–L107: Added Request object with conversationId, sessionId, content
    Reason: v2 SDK requires a Request object as the first argument to scope .start() methods; conversationId moved here from AgentDetails.
  • L108: Added InvokeAgentScopeDetails typed variable
    Reason: v2 SDK requires this as the second argument to InvokeAgentScope.start().
  • L110–L112: Updated InvokeAgentScope.start() to new 3-arg signature with tenantId merged into agentDetails
    Reason: v2 SDK changed the signature from (agentDetails, tenantDetails) to (request, scopeDetails, agentDetails) and moved tenantId onto AgentDetails.
  • L208: Hoisted inferenceScope declaration with definite assignment assertion (let inferenceScope!:) before try
    Reason: Allows finally block to call inferenceScope?.dispose() even when an exception is thrown inside try.
  • L215–L222: Removed responseId field from InferenceDetails
    Reason: responseId was moved to InferenceResponse in v2 and is no longer accepted on InferenceDetails.
  • L219: Updated InferenceScope.start() to new 3-arg signature
    Reason: v2 SDK changed the signature from (inferenceDetails, agentDetails, tenantDetails) to (conversationId, inferenceDetails, agentDetails).
  • L231–L250: Made stream data/error/close handlers synchronous; chunks collected into an array
    Reason: Stream.emit() is synchronous — async handlers' returned promises are silently discarded. Calling turnContext.sendActivity() inside an async handler raced against turn-context proxy revocation, causing "Cannot perform 'set' on a proxy that has been revoked" crashes.
  • L248–L255: Send collected response via sendActivity after invokeAgent resolves
    Reason: The turn context is still valid at this point; sending here avoids the revoked-proxy crash.
  • L257: catch block calls stopTypingLoop() before sending error message
    Reason: Ensures the typing indicator stops even on error paths.
  • L263: finally block calls inferenceScope?.dispose()
    Reason: Previously dispose() was only called on the happy path; an exception would leak the scope.

src/utils.ts

  • L5: Replaced InvokeAgentDetails and ExecutionType import with AgentDetails
    Reason: InvokeAgentDetails type was removed in v2; AgentDetails is the replacement.
  • L11: getAgentDetails() return type changed to AgentDetails
    Reason: Matches the new v2 type.
  • L31: Removed conversationId and request fields from return value
    Reason: These fields moved to the Request interface in v2 and are no longer part of AgentDetails.

src/index.ts

  • L36: Added Error type annotation to err parameter
    Reason: TypeScript strict mode requires an explicit type; without it the implicit any caused a compilation error.

src/devin-client.ts

  • L150: Added break after emitting a devin_message event
    Reason: DevinSessionStatus only includes new/claimed/running; Devin stays in running after replying, so without the break the poll loop ran until the 5-minute timeout, and the agent never returned a response.

package.json

  • L7: Changed start script from node --env-file=.env dist/index.js to node dist/index.js
    Reason: App Service doesn't have a .env file — env vars come from Application Settings. --env-file=.env crashed on startup with "file not found".
  • L28: Added @types/express to devDependencies
    Reason: Missing type definitions caused TypeScript compilation errors for Express types.

tsconfig.json

  • L20: Added "exclude": ["publish", "dist", "node_modules"]
    Reason: Without this, tsc tried to compile .ts files (or .json with resolveJsonModule) inside publish/ and dist/, causing duplicate identifier and type errors.

Testing

  • npm run build passes with zero errors
  • Verified stream handler behavior: chunks are collected synchronously, then sent as a single sendActivity call after invokeAgent resolves
  • Confirmed polling exits after first Devin reply

@Yogeshp-MSFT Yogeshp-MSFT requested a review from a team as a code owner April 3, 2026 06:44
Copilot AI review requested due to automatic review settings April 3, 2026 06:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the nodejs/devin/sample-agent to work with @microsoft/agents-a365-observability v2 API changes, while addressing deployment/runtime issues discovered during App Service deployment.

Changes:

  • Migrates observability scope initialization in src/agent.ts to the v2 Request/InvokeAgentScopeDetails-based signatures and adjusts inference tracking.
  • Fixes Devin polling to return after the first emitted reply and avoids turn-context proxy revocation by deferring sendActivity until after invokeAgent completes.
  • Updates build/runtime configuration (TypeScript excludes, start script) and adds missing type dependencies.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
nodejs/devin/sample-agent/src/agent.ts Updates observability v2 scope APIs and changes streaming handling to avoid revoked-proxy crashes.
nodejs/devin/sample-agent/src/utils.ts Updates helper return types to match v2 AgentDetails shape.
nodejs/devin/sample-agent/src/index.ts Tightens error handler typing for strict TS.
nodejs/devin/sample-agent/src/devin-client.ts Breaks polling loop after first Devin reply; fixes debug output.
nodejs/devin/sample-agent/package.json Removes --env-file from start; adds @types/express.
nodejs/devin/sample-agent/tsconfig.json Excludes publish/, dist/, node_modules/ from compilation.

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