Skip to content

Feat: Give ibac and sparc the session facts from the store - #1708

Merged
huang195 merged 8 commits into
rossoctl:mainfrom
huang195:refactor/session-facts-1499
Nov 7, 2026
Merged

huang195 merged 8 commits into
rossoctl:mainfrom
huang195:refactor/session-facts-1499

Conversation

@huang195

@huang195 huang195 commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Part of #1499. Phase 2 of the Praxis prep (#1437).

What this changes

  • The session store keeps two facts for each session, in its append path: the newest user intent (inbound A2A request) and the newest outbound inference request. An event of neither kind changes nothing. The cost is 16 bytes per session and no new allocation per request.
  • Store.ViewFacts(id) returns the view and the facts under one read lock, so the two describe the same instant. Store.View does not change.
  • pipeline.Context gets LastIntent() and LastInference(), read-only. Listeners set them with SetSessionFacts, from the same ViewFacts call that fills pctx.Session. A fact has 3 states:
    • FactNoSession: the request has no session (pctx.Session is nil).
    • FactNone: the session has no such event. It has no entry yet, the entry was dropped, no event of that kind was appended, or session.max_events trimmed it. This is the zero value.
    • FactPresent: Event points into pctx.Session.
  • ibac and sparc read the facts, not pctx.Session.Events. ibac keeps "no session" apart from "no intent": the no_session and no_intent decisions and every sub_reason stay the same.
  • One predicate. The intent pin, the facts and the SessionView accessors use model.IsIntent and model.IsInferenceRequest.
  • Docs: a "Session facts" section in docs/plugin-reference.md, and docs/ibac-plugin.md.

The facts serve a class of plugins: intent-aware guardrails (ibac), and plugins that judge an action against the agent's newest LLM context (sparc). pctx.Session stays filled as today. The inference router still reads pctx.Session. It moves to a fact in a follow-up PR.

Behaviour

No change. The existing ibac, sparc, session and pipeline tests pass with no edit. No golden changes, and nothing on the wire changes.

Checks run

  • New tests, red first:
    • a property test: 3,000 random appends for each max_events in {0, 1, 2, 3, 7}. After each append, each fact is the same pointer as the view's own accessor.
    • one test for each way an entry is dropped (max_sessions, Delete, Clear, ttl), for Rekey, and for "an event of neither kind";
    • the 3 context rules, including "facts set, Session nil → FactNoSession" and "zero facts with a session → FactNone";
    • ibac, sparc and forward-proxy hydration tests.
  • go vet, go test, gofmt -l and go mod tidy -diff with GOWORK=off in all 8 workspace modules, and vet in the 3 demos modules. -race on the listener, session, pipeline, model, ibac and sparc packages.
  • cmd/cortex builds with the local, full and lite profiles. cmd/cortex-envoy vet, build and test with envoy. core vet with the full and cpex tags.
  • go doc -all of core/pipeline and core/session: additions only.
  • pre-commit run on every changed file.

Deferred review nits

  • demos/ibac/agent/main.go lines 8 and 563 still say that IBAC reads pctx.Session.LastIntent(). It now reads pctx.LastIntent().
  • Context.LastInference rule 3 and session/facts_test.go each scan for the newest inference request. A SessionView.LastInferenceRequest() would give them one implementation.
  • No test fails when a listener does not call SetSessionFacts. Today the view gives the same answer, so a plugin cannot see the difference. The router-fact PR adds a fact that the view cannot give, and it adds those tests.

Assisted-By: Claude (Anthropic AI) [email protected]

… store

The store now records the Seq of the newest user intent and the newest
outbound inference request of each session when it appends an event.
An event of neither kind does not change them.

Store.ViewFacts returns the view and the two facts under one read lock,
so they agree. Each present fact points into the returned view.

A fact has 3 states: FactNoSession, FactNone and FactPresent. ViewFacts
gives FactNone when the store has no entry, when no event of the kind
was appended, and when a session.max_events trim removed the event.

The types are in core/model, with aliases in core/pipeline. The intent
pin of the trim and the LastIntent fact use one rule, model.IsIntent.

Part of rossoctl#1499.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
Context.LastIntent and Context.LastInference give a plugin the newest
user intent and the newest outbound inference request of its session.
A listener sets the store's facts with SetSessionFacts.

The rules, in order:
1. The listener set the facts: return them.
2. Session is nil: FactNoSession.
3. Else read Session.Events: FactPresent or FactNone.

Rule 3 keeps the answers for a listener outside this repo that sets
only Session, and for the plugin tests that build a view.

Part of rossoctl#1499.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
LastIntent and LastInference now give FactNoSession when Session is
nil, also when the listener set facts. Before, a nil view from
Store.ViewFacts came with FactNone facts, so ibac would read no_intent
in place of no_session.

SessionView.LastIntent, Intents and InferenceRequests now call
model.IsIntent and model.IsInferenceRequest. The conditions are the
same as before, so the view, the trim pin and the facts use one rule.

Part of rossoctl#1499.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
The forward proxy and the ext_proc server now read the view and the
session facts with Store.ViewFacts, under one lock, and set the facts on
the pipeline context with SetSessionFacts.

- forwardproxy: sessionViewFor returns the view and its facts. The empty
  view that it makes for a session with no entry comes with FactNone.
  hydrateSession and each WebSocket turn set the facts.
- extproc: both outbound entry points set the facts only with a view, so
  a request with no view stays FactNoSession.

The guard test for the hydration path also finds a two-value assignment
to pctx.Session.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
ibac reads pctx.LastIntent(). FactNoSession takes the no_session path.
FactNone, or an intent with no user text, takes the no_intent path. The
decisions and their sub_reason values do not change.

sparc reads pctx.LastInference(). With no present fact, it has no
context and skips, as before.

The new tests set FactNone with SetSessionFacts on a view that holds the
event. They show that the facts from the listener win over the view.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
FactNoSession comes only from a nil Context.Session (rule 1). No code
stores it. So a zero SessionFacts on a context with a session now reads
FactNone ("no intent"), not FactNoSession ("no session").

Nothing persists or prints the numeric value.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
- plugin-reference.md: a new "Session facts" section. It gives the 3
  states, the ordered rules of LastIntent and LastInference, and the
  listener rule: set Session and the facts from one ViewFacts call.
- ibac-plugin.md: ibac reads pctx.LastIntent(). FactNoSession gives
  no_session. FactNone, or an intent with no user text, gives no_intent.
- CLAUDE.md: the intent-pin gotcha names pctx.LastIntent() and a
  restart.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
The step said that no_intent_policy "deny" gives deny/no_intent for both
cases. A request with no session gets deny/no_session (403
ibac.no_session).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
@huang195
huang195 requested a review from a team as a code owner November 7, 2026 14:50
@coderabbitai

coderabbitai Bot commented Nov 7, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 8 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 34c9ca5a-4ac0-4f11-8267-41ef9c639f54
Commits

Reviewing files that changed from the base of the PR and between cc18885 and d4b189a.

Files selected for processing: 18

  • CLAUDE.md
  • core/listener/extproc/server.go
  • core/listener/forwardproxy/identity.go
  • core/listener/forwardproxy/session_identity_test.go
  • core/listener/forwardproxy/websocket.go
  • core/model/facts.go
  • core/model/session.go
  • core/pipeline/context.go
  • core/pipeline/facts_test.go
  • core/pipeline/model_alias.go
  • core/plugins/ibac/plugin.go
  • core/plugins/ibac/plugin_test.go
  • core/plugins/sparc/collect.go
  • core/plugins/sparc/plugin_test.go
  • core/session/facts_test.go
  • core/session/store.go
  • docs/ibac-plugin.md
  • docs/plugin-reference.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

This is a clean refactor with no behaviour change. The store tracks the newest intent and inference-request Seq in appendLocked, which every append path goes through (Append, AppendBucket, AppendTrailing, AppendPair*). ViewFacts resolves those Seqs against the copied view under one RLock. factAt uses sort.Search, and that holds because Seq rises within an entry, the pinned intent stays oldest after a trim, and a SeqSeeder seed keeps 0 free as the "none" value. I traced each hydration site: extproc (both phases), forward proxy hydrateSession (HTTPS, tunnel, transparent) and the WebSocket turn context. All of them now pair pctx.Session with SetSessionFacts. I found no other writer of pctx.Session outside tests. ibac's no_session / no_intent split and its sub_reasons are unchanged: a nil view still gives FactNoSession, and the forward proxy's synthesized empty view still gives FactNone → no_intent. sparc's correlateInferenceContext gives the same answer as InferenceRequests()[last].

I verified locally on d4b189a: go vet and go test (GOWORK=off) pass for session, pipeline, model, plugins/ibac, plugins/sparc, listener/extproc and listener/forwardproxy. The property test and the drop/rekey tests pass too. My -race run of forwardproxy was OOM-killed in this sandbox, which is an environment limit. The other packages passed under -race, and CI is green.

Non-blocking:

  • demos/ibac/agent/main.go lines 8 and 563 still say IBAC reads pctx.Session.LastIntent(). The PR updates every other such reference (CLAUDE.md, identity.go, both docs). This file is outside the diff, so I can't comment on it inline.
  • One inline nit on Context.LastInference.

No new JSON-decoded fields, so no decoder-strictness probe was needed. SessionFact and SessionFacts carry no JSON tags and are never serialized.

Author: huang195 (MEMBER — maintainer)
Areas reviewed: Go (session store, pipeline context, model, ibac, sparc, extproc and forward-proxy listeners), Docs
Agent/IDE config (.claude/.vscode): none. The root CLAUDE.md changes one line of docs text.
Commits: 8 commits, all signed-off: yes
CI status: passing

Comment thread core/pipeline/context.go
if c.factsSet {
return c.facts.LastInference
}
for i := len(c.Session.Events) - 1; i >= 0; i-- {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Rule 3 here hand-rolls the newest-inference-request scan, and core/session/facts_test.go has a second copy of it (lastInferenceIn). A SessionView.LastInferenceRequest() beside LastIntent() in core/model/session.go would give both one implementation. This branch would then read the same as LastIntent's: return factOf(c.Session.LastInferenceRequest()). The router-fact follow-up may want it too.

@huang195
huang195 merged commit 85846f8 into rossoctl:main Nov 7, 2026
42 checks passed
@huang195
huang195 deleted the refactor/session-facts-1499 branch November 7, 2026 15:25
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 7, 2026
huang195 added a commit that referenced this pull request Nov 7, 2026
#1708, the PR this branch was stacked on, is merged. Bring the branch up to date with main.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants