Why Editing One Day Breaks Most Trip Planners (And How I Built TripGraph)
Most trip planners do a fine job generating a first draft. Where they usually fall apart is the moment a user edits something. Imagine 3-day Japan trip: Sunday in Tokyo, Monday in Tokyo (with a locked visit to Meiji Shr
Most trip planners do a fine job generating a first draft. Where they usually fall apart is the moment a user edits something.
Imagine 3-day Japan trip: Sunday in Tokyo, Monday in Tokyo (with a locked visit to Meiji Shrine), a Shinkansen ride, and Tuesday in Kyoto split across two hotels. Now suppose the user makes one small change on Monday, like trying to fit in the Mori Art Museum.
If you just re-run a global planner or ask an LLM to update the itinerary, you usually get one of two annoying outcomes:
- It schedules a venue that is closed on Mondays.
- It re-optimizes the whole trip and shuffles around Sunday, the train, or Kyoto, even though the user already signed off on those parts.

I built TripGraph (v7) to treat itinerary replanning as a deterministic systems problem rather than a prompt-engineering one. Below is a quick walkthrough of the live API, followed by the architecture choices and tradeoffs behind it.
DEMO HERE
Walking Through a Real Edit Cycle
To make the failure modes easy to test without burning external API quotas, the public demo runs against seeded fixtures. Here is the exact 5-step sequence from scripts/live_demo.py:
-
Create the baseline trip (
HTTP 201): Commitsversion=1with Sunday Tokyo, Monday Tokyo (Meiji Shrine locked asa_mon_shrine), the Shinkansen transfer, and Tuesday Kyoto. - Verify the user's Monday edit: The user tries to add Mori Art Museum on Monday. Before touching the solver, an independent verifier checks opening rules and rejects it:
VIOLATED_FALSE | CLOSED_BY_AUTHORITATIVE_SOURCE
-
Localized repair (
version=2): CP-SAT repairs only Monday. The response returns:
{
"version": 2,
"solver_status": "PROVEN_OPTIMAL_IN_SCOPE",
"verification": "VERIFIED_TRUE",
"blast_radius": {
"semantic": 0.0,
"temporal": 0.0
}
}
Sunday Tokyo, the Shinkansen leg, and Kyoto come back with the exact same SHA-256 hashes they had in version=1. Not "mostly unchanged"βbyte-for-byte frozen.
-
Attempt a 2-day global shift (
HTTP 409): If a request tries to shift the entire itinerary by two days, TripGraph refuses it upfront because Meiji Shrine is locked:
HTTP 409 | status=LOCKED_NODE_CONFLICT | locked_activities=['a_mon_shrine']
-
Explicit opt-in async shift (
HTTP 202): Pass the explicit opt-in flag to override the lock, and TripGraph accepts the work asynchronously, polls until"stage": "completed", runs LockGuard and the verifier again before writing, and commitsversion=3.
The Solver Was the easy Part
Getting OR-Tools CP-SAT to schedule 20 activities isn't hard. The hard part is what happens when a constraint solver meets partial data, concurrent requests, and users who don't want their approved plans silently rewritten.
I ended up putting four hard boundaries around the solver.
1. Localized Dirty Closure + SHA-256 Blast Radius Checks
Instead of feeding the entire trip into the solver on every edit, TripGraph computes the minimal dirty subgraphβthe specific day or coupled dependency chain touched by the edit. Everything outside that dirty scope is treated as read-only context.
Before a commit goes through, TripGraph hashes the untouched days and transit legs and verifies they match the pre-edit SHA-256 hashes. If an edit to Monday somehow leaks a side effect into Tuesday's hotel check-in or the Shinkansen leg, the commit fails rather than silently corrupting the trip.
2. Three-Valued Logic (Kleene K3) Instead of Booleans
Standard boolean validation (True / False) is a trap in travel data because venue metadata is constantly incomplete. If a restaurant's Monday hours aren't in the database, what should is_open(venue, monday) return?
- If you default to
True, you send users to closed places. - If you default to
False, you throw away perfectly valid options just because your data source had a gap.
TripGraph's independent verifier uses Kleene three-valued logic (K3): TRUE, FALSE, and UNKNOWN.
| A \ B | AND B | OR B |
|---|---|---|
| TRUE | UNKNOWN |
TRUE |
| FALSE | FALSE |
UNKNOWN |
| UNKNOWN | UNKNOWN |
UNKNOWN |
When an authoritative source says Mori Art Museum is closed on Mondays, the verifier returns VIOLATED_FALSE and blocks the plan. When data is missing, it propagates UNKNOWN all the way to the API response instead of faking certainty. Separating verification from the solver also means a bug in the CP-SAT model can't rubber-stamp its own broken output.
3. Keeping OR-Tools Out of FastAPI
CP-SAT is native C++ code wrapped in Python. If you call it directly inside a FastAPI request handlerβeven in a thread poolβa pathological constraint graph can pin CPU cores, ignore Python-level timeouts, and starve your entire API server.
In TripGraph, OR-Tools never imports or executes inside the FastAPI process. Solver jobs are dispatched to a pool of isolated Linux worker subprocesses. Every solve has a hard wall-clock budget; if a worker stalls or runs long, the supervisor sends a SIGKILL to the OS process, tears it down cleanly, and returns a controlled failure without touching the API event loop.
(Full subprocess pool diagram is in docs/architecture.md.)
4. LockGuard and SQLite Version Fencing
Two problems show up the moment you add async replanning (HTTP 202):
-
Accidental lock overrides: Global operations shouldn't silently move an activity the user explicitly pinned. LockGuard forces a
409 Conflictlisting the exact conflicting node IDs unless the caller passes explicit opt-in. - Stale writes: Imagine a slow async global shift finishes after the user already committed a quick local edit. Without concurrency control, the slower job overwrites newer state.
Every itinerary carries a monotonically increasing integer version, and commits are fenced atomically in SQLite (WHERE id = ? AND version = expected_version). If the version moved while the solver was running, the stale write is rejected instead of clobbering the latest plan.
Numbers (And How They Were Measured)
I ran a local benchmark suite across 116 fixture scenarios spanning 12 to 40 activities, comparing a greedy baseline against CP-SAT + ontology constraints:
- Feasibility: 100% for CP-SAT + ontology vs. 93.1% for greedy
- Median latency (p50): 13β14 ms across 12 to 40 activities
-
Test suite: 78 passing CI tests covering localized closure, K3 edge cases, LockGuard
409/202paths, worker isolation, and version fencing
What This Is Not
To be upfront about scope: TripGraph is an embeddable replanning component, not a consumer booking app.
- Seeded fixtures, not live GDS: Opening hours, transit legs, and venue data come from deterministic fixtures rather than live Amadeus/Sabre feeds.
-
In-memory async jobs: The async
202job runner is in-memory for simplicity; in production you'd swap the queue/store behind the interface for Redis/Postgres or Temporal. - SQLite storage: Great for single-node durability and deterministic tests, though a multi-region deployment would move the version-fenced commits to Postgres.
Code & Demo
- GitHub Repo: sainathmanda7/tripgraph-engine
- Live Swagger Docs: tripgraph-engine.onrender.com/docs
The whole thing is open source. If you find bugs in the K3 propagation, the subprocess isolation model, or the version fencing, drop a comment or open an issue - I'd genuinely like the critique.
(Side note: I'm currently looking for backend and systems engineering rolesβif your team works on scheduling, distributed state, or reliability-heavy Python/Go/C++ systems, feel free to reach out.)
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.
