Skip to content

feat(policy): activate prompt policy sets per session - #468

Draft
tumberger wants to merge 1 commit into
jens/eng-624-c2-signed-policy-bundlefrom
jens/eng-624-c3-session-policy-manager
Draft

tumberger wants to merge 1 commit into
jens/eng-624-c2-signed-policy-bundlefrom
jens/eng-624-c3-session-policy-manager

Conversation

@tumberger

@tumberger tumberger commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

ENG-624 CLI stack 3/6; stacked on #467.

Adds the small session policy manager. For each prompt it synchronously derives, validates, parses, and atomically activates one complete PolicySet. Prompt sequence is ordering only; a failed newer prompt makes the older set ineligible rather than falling back to broader authority.

Policy generation happens once per prompt, never once per tool call.

tumberger commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor Author

@greptile-apps

greptile-apps Bot commented Aug 15, 2026

Copy link
Copy Markdown

Greptile Summary

Adds a per-session prompt-policy manager that synchronously derives, verifies, parses, and atomically exposes a complete Cedar PolicySet while invalidating prior authority when a newer prompt fails.

  • Introduces provider-qualified authorization session keys and per-session prompt sequencing.
  • Adds fail-closed snapshots for missing parents and derivation, verification, or parsing failures.
  • Allows verifier callers to omit organization matching and adds activation and failure-invalidation tests.

Confidence Score: 4/5

The PR appears safe to merge, with non-blocking lifecycle and parent-refresh races worth resolving before the manager is integrated into policy evaluation.

The manager correctly fails closed on derivation failures, but EndSession can split one key across two session objects and activation does not revalidate a parent that may change during derivation.

Files Needing Attention: internal/sessionpolicy/manager.go

Important Files Changed

Filename Overview
internal/sessionpolicy/manager.go Introduces synchronous per-session policy activation; lifecycle deletion and parent refresh can race with an in-flight derivation.
internal/promptpolicy/verifier.go Makes organization audience matching optional when callers intentionally provide no expected organization.
internal/sessionpolicy/manager_test.go Covers successful activation and fail-closed invalidation, but not session teardown or parent-refresh overlap.

Reviews (1): Last reviewed commit: "feat(policy): activate prompt policy set..." | Re-trigger Greptile

Comment on lines +148 to +152
func (m *Manager) EndSession(key SessionKey) {
m.mu.Lock()
delete(m.sessions, key)
m.mu.Unlock()
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Session deletion splits prompt ordering

If EndSession overlaps an in-flight BeginPrompt and the key is reused, the old operation continues on a detached session while sessionFor creates a replacement whose sequence restarts at zero, producing duplicate prompt sequences and a returned policy that SnapshotFor no longer represents.

Comment thread internal/sessionpolicy/manager.go Outdated
Comment on lines +120 to +132
if err := m.verifier.Verify(bundle, promptpolicy.ExpectedAudience{
InstallationID: m.installationID, AuthorizationSessionID: authorizationSessionID,
PromptSequence: sequence, ParentDeploymentIdentity: parent.DeploymentIdentity,
}); err != nil {
state.snapshot.Failure = err
return state.snapshot, err
}
if _, err := cedareval.New(bundle.PolicySet.Source); err != nil {
state.snapshot.Failure = fmt.Errorf("parse effective prompt policy set: %w", err)
return state.snapshot, state.snapshot.Failure
}
deployment := deploymentFromBundle(bundle)
state.snapshot = Snapshot{Required: true, Ready: true, PromptSequence: sequence, Deployment: &deployment}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Parent refresh leaves stale derivation

If the parent deployment refreshes or expires while Deriver.Put is running, BeginPrompt verifies and activates the response against the previously captured identity without confirming it remains current, leaving the session ready with a policy derived from obsolete parent authority.

Knowledge Base Used: Guard runtime decision engine

@tumberger
tumberger force-pushed the jens/eng-624-c3-session-policy-manager branch from f12befe to 8867b94 Compare August 15, 2026 13:31
@tumberger
tumberger force-pushed the jens/eng-624-c2-signed-policy-bundle branch from a5516fa to 7390811 Compare August 15, 2026 13:31
@tumberger
tumberger marked this pull request as draft August 15, 2026 13:34
@tumberger
tumberger force-pushed the jens/eng-624-c3-session-policy-manager branch from 8867b94 to 03a75ff Compare August 26, 2026 09:00
@tumberger
tumberger force-pushed the jens/eng-624-c2-signed-policy-bundle branch from 7390811 to a3cfb57 Compare August 26, 2026 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant