← Back to Pull requests

sessionapi: guard Session messages against concurrent reads, drop GIT_CONFIG block from generate-proto #23

Merged
codebot-robot merged 19 files (3488 lines) on Oct 27, 2026 20:37 UTC
View on GitHub
codebot-robot codebot-robot commented on Oct 24, 2026 12:20 UTC
Author

This PR addresses the follow-up items from issue #20 on the Session API and tooling:

1. Guard Session.messages against concurrent reads:
- Added messagesMu sync.RWMutex to pkg/session.Session, protecting messages in AddMessages and Messages().
- Used session.Messages() in EnsureSystemPrompt and RunTurn.
- Added divergence tracking comment referencing issue #14, and updated issue #14 with item 8.
- Added TestConcurrentReadDuringTurn to pkg/sessionapi/server_test.go using blockingSandbox to verify concurrent ListMessages, ListSessions, and GetSession reads during an in-flight and completing turn without data races under go test -race.
- Note on .ap/go.yaml: Checked gke-labs-infra's ap test implementation and .ap/go.yaml schema; there is currently no configuration knob for enabling -race in ap test (it runs go test -json ./...). This can be filed on gke-labs-infra.

2. Drop GIT_CONFIG block from dev/tasks/generate-proto:
- Removed the unset GIT_CONFIG_GLOBAL / GIT_CONFIG_SYSTEM block so grep -rn GIT_CONFIG dev/ returns nothing.

3. CLI and Documentation follow-ups:
- Updated ao serve default listen env var from LISTEN to AO_LISTEN to align with AO_SERVER.
- Added --json flag to ao session get for machine-readable JSON output, and verified it in e2e tests.
- Documented AO_LISTEN, ao session get --json, and noted that the first SendMessage on a session streams the system prompt to the client in docs/sessions.md.

Fixes #20

Diff: 3488 lines (+3485 / -3) across 19 files Reviewer: justinsb Review duration: 4817m
All Vouch review confidence checks passed
Residual risk 0.38 = Change Risk (0.95) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.95 · 3488 lines diff across 19 files
0.95
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.15 · 2 substantive comment(s)
0.15
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
59%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.400
Shallow Review Depth shallow_review_depth
0.297
Sensitive Paths sensitive_paths
0.095
Mass File Touch mass_file_touch
0.080
Real PR Conversation Timeline
5 items
justinsb justinsb requested changes on Oct 24, 2026 13:43 UTC
Changes Requested Reviewer

This PR carries the four commits of #19 plus four fix commits, so I am treating it as the replacement for #19. CI is green on this head. Checked each fix against its diff:

  • dbdc264: the GIT_CONFIG_* block is gone from dev/tasks/generate-proto. Good.

  • 956922c: Session.messages is guarded by an RWMutex in Messages() and AddMessages, the two direct reads in LoadSession now go through Messages(), and the field carries the "diverges from upstream, see #14" marker. Good.

  • 7366927: TestConcurrentReadDuringTurn runs ListMessages, ListSessions, and GetSession in loops while a turn is blocked in the sandbox and while it finishes. Good. Note that ap test does not run with -race (.ap/go.yaml has only gofmt and govet), so this test proves the behaviour, not the absence of the race; if ap has no knob for -race, a one-line note on #14 or gke-labs-infra is enough.

  • 309744a: AO_LISTEN, --json on ao session get, docs for both and for the system prompt event, and an e2e check for --json. Good.
  • One requested change remains, from the maintainer's comment on #19: the three _ = closeErr sites in cmd/ao/client.go (lines 54, 102, 162 here) are unchanged. Assigning an error and discarding it with _ is ignoring it with extra lines. Please log it at a verbose level, ideally through one small helper:

    defer func() {
        if err := conn.Close(); err != nil {
            scoped.Log(cmd.Context()).V(4).Info("closing gRPC connection", "error", err)
        }
    }()
    

    (scoped.Log lands with #26; if this merges first, klog.FromContext and a follow-up swap are fine.)

    Also, the four fix commits say Issue #20. #20 was closed as superseded by the review on #19, so reference Part of #17 instead, and keep Fixes #17 on the final commit.

    I will approve once the close-error fix is pushed.

    justinsb justinsb commented on Oct 24, 2026 13:47 UTC
    Contributor

    #26 (pkg/scoped) and #27 (commit message rules) are on main now, and this branch still merges cleanly. When you push the close-error fix, use scoped.Log(ctx).V(4).Info(...) directly rather than klog.FromContext, and please rebase onto main so CI runs against the merged pkg/scoped. Per the updated AGENTS.md, either amend the touched commit or add a fixup! commit and leave it in place; do not squash.

    justinsb justinsb commented on Oct 24, 2026 13:47 UTC
    Contributor

    Please rebase for easier code review

    justinsb justinsb approved these changes on Oct 24, 2026 14:36 UTC
    Approved Reviewer

    Approving. Head 7251e28 is rebased onto current main (merge-base equals main), CI is green on it, and the e2e log shows TestSessionAPI passing on kind alongside TestSession and TestSmoke.

    Checked against the earlier review:

  • The three discarded close errors are gone; closeConnection logs at V(4) through scoped.Log, and ao serve uses scoped.Log too.

  • Session.messages is guarded by an RWMutex with the divergence marker, and TestConcurrentReadDuringTurn is present.

  • dev/tasks/generate-proto has no GIT_CONFIG_* block.

  • Commit references are Part of #17 with Fixes #17 on the last commit, and the last commit's body matches its diff.
  • This PR introduces the Session gRPC API, ao serve, and the ao session list|get|send CLI from #17; #19 was closed in its favour. Remaining notes are tracked elsewhere: -race in ap test and the lint knob for printf-style klog (gke-labs-infra), and the fork divergences (#14).

    Reviewers
    Assignees
    codebot-robot codebot-robot
    Labels
    risk: medium confidence: 59.6% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 94.7% (HIGH) · Higher = larger blast radius
    94.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 59.6% · Lower = rushed or shallow review
    59.6%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 38.3% · Moderate risk
    38.3%