Skip to content
TheChatArchiveThe Chat Archive
xiaomi/mimo-v2.5-pro· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION [BUG] API Gateway REST: path-based invocation…

  1. User

    ISSUE DESCRIPTION

    [BUG] API Gateway REST: path-based invocation (/restapis/{id}/{stage}/user_request/{path}) returns 404 After creating a REST API, adding a resource with a Lambda proxy integration, and deploying to a stage, invoking via the documented path format returns "Invalid API id specified" (404).

    Reproduction

    # Create Lambda function
    aws --endpoint-url=http://localhost:4566 lambda create-function \
      --function-name test-fn --runtime nodejs22.x --handler index.handler \
      --role arn:aws:iam::000000000000:role/r \
      --code S3Bucket=...,S3Key=...
    
    # Create REST API + resource + integration + deployment
    API_ID=$(aws --endpoint-url=http://localhost:4566 apigateway create-rest-api --name test | jq -r '.id')
    ROOT_ID=$(aws --endpoint-url=http://localhost:4566 apigateway get-resources --rest-api-id $API_ID | jq -r '.items[0].id')
    RES_ID=$(aws --endpoint-url=http://localhost:4566 apigateway create-resource --rest-api-id $API_ID --parent-id $ROOT_ID --path-part hello | jq -r '.id')
    aws --endpoint-url=http://localhost:4566 apigateway put-method --rest-api-id $API_ID --resource-id $RES_ID --http-method GET --authorization-type NONE
    aws --endpoint-url=http://localhost:4566 apigateway put-integration --rest-api-id $API_ID --resource-id $RES_ID --http-method GET --type AWS_PROXY --integration-http-method POST --uri "arn:aws:apigateway:eu-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:eu-west-2:000000000000:function:test-fn/invocations"
    aws --endpoint-url=http://localhost:4566 apigateway create-deployment --rest-api-id $API_ID --stage-name dev
    
    # Invoke via documented path
    curl http://localhost:4566/restapis/$API_ID/dev/_user_request_/hello
    

    Actual behavior

    HTTP 404: {"message":"Invalid API id specified"}

    Expected behavior

    Request routes through API Gateway to the Lambda function and returns the Lambda response.

    Notes

    • The API is created successfully (confirmed via get-rest-api and Floci logs)
    • The deployment succeeds
    • Management plane operations (create/get/update APIs) all work correctly
    • Only the data plane invocation path fails
    • Tested with Floci 1.5.16

    Environment

    • Floci 1.5.16 (docker.io/floci/floci:latest)
    • Podman 5.8.0 rootless (also likely reproducible with Docker)
    • AWS CLI v2
    • Region: eu-west-2

    Interface

    No new interfaces are introduced.

    ADDITIONAL ADVICE

    Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use git checkout <file> to restore the file to its original state. You can also reset all changes in the repository using git reset --hard command. Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands. However you don't need to use git add or git commit before submitting your changes. In fact, submit only submits currently unstaged changes because it uses git diff to get the changes that need to be submitted.

    CHECKLIST

    Before submitting your solution, please go over the following checklist and make sure you've done everything:

    • If an error was reported in the issue description, I have successfully reproduced it.
    • If an error was reported in the issue description, I have confirmed that my fix resolves the error.
    • I have thought about edge cases and made sure my fix handles them as well.
    • I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.

    Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!

    (Current directory: /floci, current file: none) bash-$

  2. Assistant

    I'll start by exploring the repository structure to understand the codebase and locate relevant files for the API Gateway REST path-based invocation issue. Let's first get an overview.

  3. Assistant

    Let me explore the repository structure more thoroughly to understand the project and find the API Gateway implementation.

  4. Assistant

    This is a Java project (Maven-based). Let me look for the API Gateway related code.

  5. Assistant

    Let me look at the key files related to the API Gateway routing, specifically the ApiGatewayUserRequestController.java and AwsServiceRouter.java files since these are likely responsible for handling the /restapis/{id}/{stage}/_user_request_/{path} route.

  6. Assistant

    Now let me look at the ApiGatewayExecuteController.java to understand the dispatch method.

  7. Assistant

    Let me look at the AwsServiceRouter.java and ApiGatewayService.java to understand how the routing works.

  8. Assistant

    Now let me look at the ApiGatewayService.java to understand how it handles API lookups:

  9. Assistant

    Let me look at the main API Gateway controller (management plane):

  10. Assistant

    Now let me look at the ApiGatewayAwsExecuteController.java file:

  11. Assistant

    Now I need to understand the routing conflict. The ApiGatewayController has @Path("/") and likely has a @GET @Path("/restapis/{apiId}") method that's matching the user request path before the ApiGatewayUserRequestController gets a chance. Let me look at the full ApiGatewayController to see all its paths:

  12. Assistant

    Let me see all paths in the ApiGatewayController:

  13. Assistant

    Let me look for any request filter or routing logic that handles incoming requests:

  14. Assistant

    Now let me understand the flow better. Let me look at the dispatch method in ApiGatewayExecuteController more closely, particularly the region resolution:

  15. Assistant

    Let me look at the dispatch method:

  16. Assistant

    Let me check if there are tests for this path-based invocation:

  17. Assistant

    Let me look at the test file:

  18. Assistant

    Now I understand the test setup. Let me look at the RegionResolver to understand how region resolution works:

  19. Assistant

    Let me look for any request filters that might be intercepting the /restapis/ path:

  20. Assistant

    Let me check for any filters that might affect API Gateway routing:

  21. Assistant

    Let me run the existing tests to see if they pass:

  22. Assistant

    Let me check if there's a Maven wrapper available or we need to use a different build command.

  23. Assistant

    The test passes! So the basic routing works fine. The issue must be more subtle. Let me look at the RegionResolver and understand how the region is resolved when using curl directly (without AWS SDK headers):

  24. Assistant

    Now I see the issue! The RegionResolver.resolveRegion() extracts the region from the Authorization header. When using curl directly (no Authorization header), it returns the defaultRegion. But the API was created with a different region (eu-west-2). Let me check the default region configuration:

  25. Assistant

    Wait, the test passes. Let me look more carefully at the issue. The issue says the user is using eu-west-2 region. Let me check if there's a region mismatch issue. The RegionResolver resolves from Authorization headers, but when using curl directly, there's no Authorization header. Let me look at the issue again and understand the flow better:

  26. Assistant

    Now I understand the issue! The RegionResolver resolves the region from the Authorization header. When using curl directly (without AWS SDK headers), there's no Authorization header, so it defaults to us-east-1. But if the API was created in a different region (e.g., eu-west-2), the lookup fails with "Invalid API id specified".

    The fix should be in the dispatch method to try finding the API across all regions when the default region lookup fails. Let me check how to get all regions:

  27. Assistant

    Let me look at the StorageBackend interface to understand how to scan for APIs by ID regardless of region:

  28. Assistant

    Let me understand the test. The test passes, which means the basic routing works. The issue must be specific to the user's scenario. Let me re-read the issue and look more carefully at the path routing:

  29. Assistant

    The test passes, so the routing itself works. Let me re-read the issue more carefully. The key detail is the region: eu-west-2. When using curl directly, there's no Authorization header, so the region resolves to us-east-1 (default). But the API was created with eu-west-2 via the AWS CLI. Let me verify this hypothesis:

  30. Assistant

    Let me look at the key generation:

  31. Assistant

    Let me see the key format:

  32. Assistant

    Let me now understand the issue better. I believe the problem is a region mismatch. When a user creates an API using AWS CLI with eu-west-2 region, but then invokes via curl without region headers, the default region us-east-1 is used and the API isn't found. Let me also look at how the getStage method works:

  33. Assistant

    Now I understand the issue completely. The problem is region mismatch: when a user creates an API with the AWS CLI (which sends Authorization headers with region info like eu-west-2), but then invokes via curl without any Authorization headers, the default region us-east-1 is used and the API lookup fails.

    The fix should make the dispatch method in ApiGatewayExecuteController find the API regardless of region when the initial lookup fails. In real AWS, the API ID is globally unique, so the /restapis/{apiId} path should work regardless of the region used.

    Let me add a method to ApiGatewayService that looks up an API by ID across all regions:

  34. Assistant

    Now let me add a method to ApiGatewayService that can find a REST API by ID regardless of region:

  35. Assistant

    Let me look at the RegionResolver more carefully:

  36. Assistant

    Now I understand the bug! The issue is region mismatch. When the user creates an API via AWS CLI with region eu-west-2, the API is stored under key eu-west-2::${apiId}. But when they invoke via curl (which has no Authorization header), the region resolves to us-east-1 (default), and the lookup for us-east-1::${apiId} fails with "Invalid API id specified".

    The fix should be: in the dispatch method, when the API is not found in the resolved region, fall back to searching all regions. Let me implement this:

  37. Assistant

    Now I need to add a method to ApiGatewayService that finds a REST API by ID regardless of region. Let me add it:

  38. Assistant

    Now I understand the issue. The API is stored with region-specific keys (eu-west-2::apiId), but when curl is used without auth headers, the region defaults to us-east-1. Let me add a fallback method to ApiGatewayService to find an API by ID across all regions:

  39. Assistant

    I see the edit created duplicate lines. Let me fix that:

  40. Assistant

    I see there's a duplicate line. Let me fix it:

  41. Assistant

    Wait, let me reconsider. Instead of adding a separate method with Object[], let me just modify the dispatch method directly. Let me first revert the findRestApiAcrossRegions method and instead modify the dispatch in ApiGatewayExecuteController:

  42. Assistant

    Let me clean up the empty line and think about a better approach. Let me first clean up the file:

  43. Assistant

    Good, the file looks clean now. Let me add the method back using a cleaner approach - a proper record:

  44. Assistant

    Now I need to add a blank line before deleteRestApi:

  45. Assistant

    Good, the ApiGatewayService now has the findRestApiAcrossRegions method. Now I need to modify the dispatch method in ApiGatewayExecuteController to use this fallback. Let me update the dispatch method:

  46. Assistant

    Now let me update the dispatch method to use the cross-region lookup as a fallback:

  47. Assistant

    Now let me modify the dispatch method to use the cross-region lookup:

  48. Assistant

    Good, the dispatch method is updated. Now let me run the test to make sure it still passes:

  49. Assistant

    The existing test passes. Now let me run all the API Gateway related tests to make sure nothing is broken:

  50. Assistant

    Let me check if these test failures are pre-existing by checking out the original code:

  51. Assistant

    Good, those failures are pre-existing. Let me restore my changes and run just the API Gateway tests that matter:

  52. Assistant

    Let me run the API Gateway tests excluding the pre-existing failures:

  53. Assistant

    I need to escape the ! character. Let me use a different approach.

  54. Assistant

    All 40 tests pass. Now let me also run the AWS integration test and custom domain test:

  55. Assistant

    All tests pass. Now let me verify the changes are correct by looking at both modified files:

  56. Assistant

    Good. The diff looks clean. Let me also fix a missing blank line in the ApiGatewayService.java:

  57. Assistant

    Let me fix the missing blank line:

  58. Assistant

    Good, the file looks clean now. Let me run the full test suite one more time to confirm everything passes:

  59. Assistant

    All 95 tests pass. Now let me also check the dispatchV2 path for the same issue. Let me look at the v2 dispatch to see if it also needs the cross-region fallback:

  60. Assistant

    Let me also look at the v2 dispatch to make sure it handles region correctly:

  61. Assistant

    Let me also consider if the V2 API check needs the same fallback. Looking at the dispatch method, the V2 check also uses the resolved region:

  62. Assistant

    Let me check if the V2 API also has the same region issue. Looking at the dispatchV2 method, the region is passed to it from the dispatch method. If the V2 API was created in a different region, the initial V2 check would fail and fall through to v1 handling. However, since the issue is specifically about REST APIs (v1), and the V2 check silently catches the exception, my fix should still work correctly for the reported issue.

    Now let me also think about whether the region variable can be reassigned in the catch block. In Java, local variables can be reassigned as long as they're not captured in a lambda or anonymous class. Let me verify:

  63. Assistant

    Wait, I just realized there's a problem with the region variable. In Java, you can't reassign a local variable in a catch block if it was already used before the try. Actually, you CAN reassign it - the issue would be if it were captured in a lambda. But let me check if the region variable needs to be a final or effectively final. Let me verify the code compiles and runs correctly:

  64. Assistant

    The code compiles and runs. Let me also check that the region variable reassignment doesn't cause any issues with Java's effectively-final requirement. Since region is only passed as a parameter (not captured in lambdas), this should be fine.

    Now let me also consider if the V2 API check needs the same fix. Let me look at the full dispatch flow:

  65. Assistant

    I notice there's a potential issue: the region variable is reassigned in the inner try-catch block, but Java might complain about it not being effectively final if it's used in a lambda or anonymous class downstream. Let me verify the code is correct. Actually, looking at the code, region is only used as a direct parameter in method calls, not in lambdas, so this should be fine.

    Let me verify the final diff:

  66. Assistant

    The diff looks clean. Let me run the full API Gateway test suite one more time to confirm everything is good:

  67. Assistant

    Wait, I notice that the Execute test and CustomDomain test aren't showing up in the output. Let me check if they were actually run:

  68. Assistant

    Let me check what the exact test class names are:

  69. Assistant

    Let me also run those tests to make sure they pass.

  70. Assistant

    All tests pass. Let me now verify the final state of the changes:

  71. Assistant

    Now let me review the final changes one more time to make sure they're correct:

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.