Skip to content

feat(server): target-bearing runtime resolution (3/7)#181

Draft
abhinav-galileo wants to merge 1 commit intoabhi/rfc-1-1-pr2-target-apisfrom
abhi/rfc-1-1-pr3-runtime-resolution
Draft

feat(server): target-bearing runtime resolution (3/7)#181
abhinav-galileo wants to merge 1 commit intoabhi/rfc-1-1-pr2-target-apisfrom
abhi/rfc-1-1-pr3-runtime-resolution

Conversation

@abhinav-galileo
Copy link
Copy Markdown
Collaborator

@abhinav-galileo abhinav-galileo commented Apr 20, 2026

Stacked on top of #180. Kept in draft until the full stack has been validated end-to-end.

Summary

  • Extends EvaluationRequest with optional target_type and target_id (both or neither; validated by a model validator).
  • Resolves the internal target row from (tenant_id, target_type, external_id) when supplied.
  • Merges target_controls into the effective runtime control set when a target is present.
  • Requests that omit target fields use the classic agent + policy path unchanged.

Resolution semantics

  • Effective control set is union(direct_agent, policy_derived, enabled_target_controls).
  • UNION deduplicates by control_id; agent/policy rows effectively mask target rows when the same control appears from multiple sources (agent-level attachment takes precedence over target-level state).
  • target_controls.enabled=false hides the control from the effective set only when target is the sole source; an agent/policy attachment for the same control still activates it.
  • Unknown target in a target-bearing request returns 404 TARGET_NOT_FOUND. Lazy upsert is explicitly deferred to a later PR.

Scope boundaries

  • Hot-path change: this PR is intentionally kept small and isolated so the diff that touches evaluation is easy to review and bisect.
  • No schema migrations (done in the PR at the bottom of the stack).
  • No management API changes (done in the previous PR).
  • No SDK behavior changes. The SDK's mock expectation was updated because the shared EvaluationRequest model now serializes target_type / target_id as null when unset; this is a test-fixture adjustment, not a behavior change.

Performance notes

  • No-target path: identical SQL as before (two-way UNION of agent+policy).
  • Target path: three-way UNION with a single indexed lookup on (target_id, enabled).
  • Target resolution is a single indexed hit on the new (tenant_id, target_type, external_id) unique constraint.

Test plan

  • make check clean locally (1490 tests across packages; 553 server including 9 new target-resolution tests)
  • New test coverage: target control enabled contributes, target control disabled hidden, no-target regression, agent mask beats target disable, dedup when same control in agent + target, unknown target returns 404, cross-tenant target resolution 404, only target_type fails 422, only target_id fails 422
  • Validated on the integration branch with PR1 + PR2 + PR3 merged (all checks pass)

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@abhinav-galileo abhinav-galileo force-pushed the abhi/rfc-1-1-pr2-target-apis branch from 23b990f to 46ed17b Compare April 20, 2026 19:42
@abhinav-galileo abhinav-galileo force-pushed the abhi/rfc-1-1-pr3-runtime-resolution branch from 24b421b to 55a647d Compare April 20, 2026 19:44
@abhinav-galileo abhinav-galileo changed the title (3/N) feat(server): target-bearing runtime resolution (RFC 1.1 section 8.2) feat(server): target-bearing runtime resolution (3/4) Apr 20, 2026
@abhinav-galileo abhinav-galileo force-pushed the abhi/rfc-1-1-pr2-target-apis branch from 46ed17b to fe437c4 Compare April 20, 2026 20:23
@abhinav-galileo abhinav-galileo force-pushed the abhi/rfc-1-1-pr3-runtime-resolution branch from 55a647d to 5222252 Compare April 20, 2026 20:24
@abhinav-galileo abhinav-galileo force-pushed the abhi/rfc-1-1-pr2-target-apis branch from fe437c4 to 7067673 Compare April 20, 2026 20:28
@abhinav-galileo abhinav-galileo force-pushed the abhi/rfc-1-1-pr3-runtime-resolution branch 2 times, most recently from 1f581f1 to 41e3d21 Compare April 20, 2026 20:47
EvaluationRequest now accepts optional target_type + target_id. When both
are set, the server resolves the target row via (tenant_id, target_type,
external_id) and merges target_controls into the effective set. Direct
agent controls and policy-derived controls mask any target-level setting;
target_controls with enabled=true contribute otherwise. Missing target
returns 404. No-target requests remain unchanged.
@abhinav-galileo abhinav-galileo force-pushed the abhi/rfc-1-1-pr3-runtime-resolution branch from 41e3d21 to af42b84 Compare April 20, 2026 20:48
@abhinav-galileo abhinav-galileo changed the title feat(server): target-bearing runtime resolution (3/4) feat(server): target-bearing runtime resolution (3/5) Apr 20, 2026
@abhinav-galileo abhinav-galileo changed the title feat(server): target-bearing runtime resolution (3/5) feat(server): target-bearing runtime resolution (3/6) Apr 20, 2026
@abhinav-galileo abhinav-galileo changed the title feat(server): target-bearing runtime resolution (3/6) feat(server): target-bearing runtime resolution (3/7) Apr 21, 2026
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