feat(session-mgmt): Redis-backed concurrency control for gateway turns#4
Merged
Conversation
Add the ConcurrencyGuard integration tests (task 4.4) and the docker-compose-based end-to-end script (task 4.5). Wire SESSION_LOCK_TTL and LOCK_ACQUIRE_TIMEOUT into the gateway service and add a hold_ms argument to the fake upstream so the e2e script can hold a turn long enough to observe the Redis lock and the SIGKILL restart path. Also tighten the spec: mark 4.4/4.5 complete, correct the restart scenario wording to match Req 2.4 (sessions are not preserved across restarts), and fix mermaid escaping in the design sequence diagram. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
Summary
pipeline.Run()so that different sessions never block each other, only one turn is active per session at a time, and within a turn read-class calls run in parallel while write-class calls are serialized and wait for in-flight reads to drain.SessionLocker(reference-counted session mutex),TurnRWLock(per-turn reader-writer lock),OperationClassifier(configurable map +read_/get_/list_heuristic), andConcurrencyGuard(server-level wrapper with deferred lock release) — all built ongo-redis/v9via inline Lua scripts.cmd/gateway/server.gohandleMCPPost, extendsConfigwithSessionLockTTL(default 60s) andLockAcquireTimeout(default 5s), addsCodeSessionBusy = -32002JSON-RPC error, extendsAgentPolicywithOperationClasses, and adds theredis:7-alpineservice to docker-compose.Spec
Implements
.kiro/specs/session-mgmt(Reqs 1.1, 2.1–2.6, 3.1–3.4, 4.1–4.2, 5.1). Validation report: GO. All 14 tasks complete.Test plan
go build ./...andgo vet ./...cleanTOOLGATE_TEST_REDIS_DSN=redis://127.0.0.1:16380/0 go test -race -timeout 180s ./...— all packages green, race-cleanbash scripts/demo_session_mgmt.sh— Redis lock observed during request, cleared after completion, post-restart fresh session acquires its lock immediately (Req 2.4)cmd/gateway/concurrency_guard.go(acquire SessionLocker → RWLock; defer-LIFO release RWLock → SessionLocker)session_locker.goandturn_rwlock.gofor atomicity and TTL refresh semantics🤖 Generated with Claude Code