Share via

SWA managed Functions serving stale code after successful deploys — Standard tier, UK South

Muhammad Rizwan 0 Reputation points
2026-05-24T15:14:02.1166667+00:00

Setup: Azure Static Web Apps Standard tier, UK South region (Microsoft.Web/staticSites). Affected endpoint: anonymous public signup POST on our SWA managed Functions deployment.

Summary

After multiple successful SWA Actions deploys (most recent: a commit containing fresh diagnostic logging), the running Functions worker continues to execute old code. Diagnostic log markers added in the new deploy do not appear in App Insights despite the deploy reporting success and Oryx confirming fresh artifact build.

Reproduction window: 2026-05-25 between approximately 12:00 and 15:32 UK time (UTC+1). Most recent reproduction:

  • Deploy via GitHub Actions: completed approximately 12:57 UTC on 2026-05-25
  • Cold-start retry: 2026-05-25 14:32:34 UTC
  • App Insights shows endpoint executed at 14:32:35.192 UTC
  • Old code path's warning log fired at 14:32:35.192 UTC (proving OLD code path executed)
  • New diagnostic log markers from new code: absent

Reproduction steps

Reproduced 4 times across 90 minutes plus a separate 60-minute cold-start retry:

  1. Code change committed and pushed to main
  2. SWA Actions workflow runs to completion (Status: Succeeded, ~1m30s duration)
  3. Oryx build log shows new commit SHA building fresh artifacts
  4. POST to the API endpoint via a frontend form
  5. App Insights shows endpoint executed, but old code path runs (warning log from old behaviour fires)
  6. New diagnostic log markers do not appear in any App Insights query

Hypotheses already ruled out

R1. Node.js require()-cache lifecycle stuck on warm worker.

Ruled out: 60+ minute idle window with zero endpoint traffic, then single cold-start retry, still serves old code. Cold-start by definition forces fresh require().

R2. SWA Actions deploy failure.

Ruled out: all 4 deploys reported success in GitHub Actions. Oryx build log explicitly confirms the new commit SHA is what was built.

R3. App settings causing module init to skip.

Ruled out: appsetting toggle (DIAG_FORCE_RESTART=<unix timestamp>) saved successfully and visible in az staticwebapp appsettings list output. Did not change running behaviour.

R4. Configurable restart via CLI.

Ruled out: az staticwebapp does not expose restart/stop/start/reload subcommands. No separate Microsoft.Web/sites Function App resource exists (confirmed via az resource list -g <our-resource-group>). All Function code encapsulated in the SWA resource.

Remaining hypotheses (cannot verify from customer side)

  • H1. WEBSITE_RUN_FROM_PACKAGE-style read-only mount serving stale package
  • H2. Build artifact / CDN caching layer not invalidating on deploy
  • H3. Deployment slot / environment split where deploys land in one slot but live URL serves another

These involve platform internals not visible from customer-side CLI or portal investigation.

Workaround status

  • Step 2 (trivial file-content change to invalidate hash-based caches): IN PROGRESS, will update this thread with results
  • Step 3 (SWA SKU toggle Free → Standard): NOT YET ATTEMPTED pending guidance on whether disruption is justified
  • No confirmed working workaround as of post submission

Looking for guidance on

A confirmed CLI or portal mechanism (or sequence of mechanisms) that forces SWA managed Functions to serve the most recent deployed code, applicable in scenarios where standard deploy mechanisms have apparently completed successfully but old code continues to run.

Specifically:

  • Which mechanism does SWA managed Functions use to serve Function code (RunFromPackage / direct filesystem / other)?
  • What does and does not force a code-refresh on the running worker?
  • If the supported mechanism is "scale tier to Free and back" or similar disruptive operation, is this the supported path?
  • If the mechanism does not exist and Functions configuration detachment/reattachment is required, what is the exact procedure?

Context

Working through pre-production verification discipline before broader rollout. Establishing deploy reliability with the platform is part of that.

Diagnostic data available on request

  • Full Oryx build logs from GitHub Actions
  • App Insights query results with timestamps showing the absent log markers
  • Complete log of all reproduction attempts with timestamps
  • Output of all az staticwebapp investigation commands run
  • Resource details available privately to Microsoft engineers if needed for backend correlation

Community engagement

If anyone else has encountered this pattern on SWA managed Functions, would value hearing your resolution path. Happy to help this thread become a community reference if we find a working mechanism.

Azure Static Web Apps
Azure Static Web Apps

An Azure service that provides streamlined full-stack web app development.


1 answer

Sort by: Most helpful
  1. AI answer

    2026-05-24T15:14:24.0366667+00:00

    For Static Web Apps with managed Functions, the supported way to force new code to run is to ensure that:

    1. The latest build artifacts are actually being used by the SWA environment.
    2. The Functions runtime has restarted and loaded the new artifacts.

    From the available information, the following mechanisms and checks are supported.

    1. Confirm the deployment actually produced the expected artifacts

    Static Web Apps uses the Oryx build process and then validates the configured folders:

    • app_location – root of the frontend source
    • output_location – build output folder under app_location
    • api_location – root of the Azure Functions app for managed functions

    If these are misconfigured, SWA can successfully run the workflow while still serving older artifacts.

    Actions:

    • In the GitHub Actions workflow, verify that app_location, output_location, and api_location match the repo layout and that the Functions app is under the configured api_location.
    • Check the workflow logs for any of the folder-configuration errors listed in the troubleshooting article (for example, “App Directory Location: '…' is invalid” or “Either no API directory was specified, or the specified directory wasn't found”).

    If api_location is wrong or missing, the build may succeed but the live /api route continues to use the previous managed Functions app.

    1. Verify that the managed Functions app is the one serving /api

    For SWA managed Functions:

    • The /api route is fixed.
    • The source folder for the managed Functions app is controlled by api_location in the workflow.

    If api_location is changed or misaligned, SWA can end up with an older managed Functions app still serving /api while new builds are going to a different folder that is not wired to the live route.

    Actions:

    • Confirm that the api_location in the workflow is stable and points to the same folder across all commits.
    • Ensure there is no second Functions app or alternative API configuration (such as API Management or App Service) mapped to /api that might be serving an older backend.
    1. Use Application Insights to confirm which code path is running

    Application Insights is the supported way to see runtime behavior for both Static Web Apps and managed Functions:

    • For SWA, enable Application Insights on the static web app.
    • Use the Failures and operation details views to inspect the exact timestamps and stack traces for the /api endpoint.

    Actions:

    • In the portal, open the resource group → Application Insights instance for the SWA.
    • Under Investigate → Failures, drill into failed or successful operations for the signup endpoint and confirm whether any new log markers appear after the deployment time.

    If no new markers appear at all, this reinforces that the live Functions host is still using older artifacts or a different API backend.

    1. What forces a code refresh for SWA managed Functions

    The platform behavior for managed Functions in Static Web Apps is:

    • The Functions code is deployed as part of the SWA build and deployment pipeline.
    • A successful SWA deployment that includes the api_location content is expected to update the managed Functions app and cause the Functions host to load the new package.

    There is no separate restart/stop/start command for managed Functions; the refresh is tied to the SWA deployment itself. The documented mechanisms to influence runtime behavior are:

    • Correcting the workflow configuration so the right folders are built and deployed.
    • Redeploying via the SWA workflow so that new artifacts are produced and swapped in.
    • Using Application Insights to verify that the new code is executing.
    1. Recommended end-to-end path for this scenario

    Given the symptoms (successful builds, old code executing), the most actionable steps supported by the documentation are:

    1. In the GitHub Actions workflow YAML:
      • Confirm app_location, output_location, and especially api_location are correct for the repo.
      • Ensure output_location is actually produced by the build (for example, the folder exists after npm run build).
    2. Re-run the SWA workflow after any configuration correction and verify in the logs that:
      • Oryx builds the expected commit.
      • No folder-configuration errors are reported.
    3. In Application Insights for the SWA:
      • Use Failures and operation details to confirm that requests after the deployment time show the new diagnostic log markers.

    If, after confirming folder configuration and redeploying, the Functions host still serves old code, this becomes a platform-side issue that requires Azure support to inspect the SWA’s internal deployment state. The public documentation does not expose an additional CLI/portal “force refresh” operation beyond correcting configuration and redeploying.

    There is no documented guidance that scaling between Free and Standard, or detaching/reattaching Functions, is required or supported as a normal mechanism to force managed Functions to pick up new code.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.