Add CORS middleware and Yellow Network stub endpoints#4
Draft
Add CORS middleware and Yellow Network stub endpoints#4
Conversation
Co-authored-by: Mharris40 <150187165+Mharris40@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Implement production-ready stub backend for Railway deployment
Add CORS middleware and Yellow Network stub endpoints
Mar 3, 2026
Comment on lines
+25
to
+31
| @router.post("/order/submit", response_model=OrderSubmitResponse) | ||
| def order_submit(request: OrderSubmitRequest): | ||
| global _order_counter | ||
| _order_counter += 1 | ||
| order_id = f"order_{_order_counter}" | ||
| _orders[order_id] = {"status": "SUBMITTED", "details": {}} | ||
| return OrderSubmitResponse(order_id=order_id, status="SUBMITTED") |
There was a problem hiding this comment.
🟠 High routes/yellow.py:25
Concurrent requests read _order_counter before either has incremented it, so both threads compute the same order_id and the second order silently overwrites the first in _orders. This loses the first order's data without any error being raised. Consider using threading.Lock to serialize access to the counter and dictionary, or switch to an atomic counter (e.g., itertools.count with a lock, or UUIDs).
+import threading
+
+_order_lock = threading.Lock()
+
@router.post("/order/submit", response_model=OrderSubmitResponse)
def order_submit(request: OrderSubmitRequest):
global _order_counter
- _order_counter += 1
- order_id = f"order_{_order_counter}"
- _orders[order_id] = {"status": "SUBMITTED", "details": {}}
+ with _order_lock:
+ _order_counter += 1
+ order_id = f"order_{_order_counter}"
+ _orders[order_id] = {"status": "SUBMITTED", "details": {}}
return OrderSubmitResponse(order_id=order_id, status="SUBMITTED")🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file apps/api/app/routes/yellow.py around lines 25-31:
Concurrent requests read `_order_counter` before either has incremented it, so both threads compute the same `order_id` and the second order silently overwrites the first in `_orders`. This loses the first order's data without any error being raised. Consider using `threading.Lock` to serialize access to the counter and dictionary, or switch to an atomic counter (e.g., `itertools.count` with a lock, or UUIDs).
Evidence trail:
apps/api/app/routes/yellow.py lines 12-13 (global `_orders` dict and `_order_counter`), lines 25-30 (`order_submit` function with non-atomic `_order_counter += 1` and dict assignment). Python's `+=` operator is not atomic - it involves separate LOAD, ADD, STORE bytecode operations that can interleave between threads.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements a production-ready stub backend for Railway deployment, adding CORS support, a proper receipt verification endpoint, and Yellow Network session/order management routes.
CORS (
main.py)CORSMiddlewarewithallow_origins=["*"],allow_credentials=False— wildcard + credentials is a browser security violation per CORS specReceipt verification (
routes/receipt.py,models/receipt.py)dictinput withReceiptVerifyRequestPydantic model (payload: dict,signature: str){"valid": true}(was{"verified": true})Yellow Network (
routes/yellow.py,models/yellow.py)Three new endpoints registered under
/v1/yellow:Orders stored in an in-memory dict; no DB required for this stub. All inputs/outputs are validated via Pydantic models.
Original prompt
This pull request was created from Copilot chat.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
Note
Adjust whitespace in stub backend files for Railway deployment to prepare WIP production-ready backend
Change only blank lines across affected files to modify whitespace formatting.
📍Where to Start
Start with the main backend entrypoint to view whitespace changes in server/main.go.
📊 Macroscope summarized e4dec87. 4 files reviewed, 1 issue evaluated, 0 issues filtered, 1 comment posted
🗂️ Filtered Issues