Skip to content

feat(types): wire-shape alignment sweep (proper audit) — 36 → 26 drift entries#155

Merged
saurabhjain1592 merged 6 commits into
mainfrom
fix/wire-shape-alignment-sweep
Apr 25, 2026
Merged

feat(types): wire-shape alignment sweep (proper audit) — 36 → 26 drift entries#155
saurabhjain1592 merged 6 commits into
mainfrom
fix/wire-shape-alignment-sweep

Conversation

@saurabhjain1592
Copy link
Copy Markdown
Member

Summary

Correction to the overnight handoff: the earlier claim that "Python baseline is clean — 0 drift via pydantic aliases" was wrong. That was a key-name confusion — Python's baseline uses `per_model_drift` while TS/Go use `per_type_drift`. A proper per-entry audit found 36 drift entries, very similar in pattern to the TS+Go sweeps.

This PR ships the same Cat B + RENAME_SAFE + UNRECOVERABLE work that landed in axonflow-sdk-typescript#185 and axonflow-sdk-go#133. No version bump triggered — all changes are additive or marked `DEPRECATED` for source-compat.

Changes

Cat B (pure additions; SDK was missing wire fields)

  • `WebhookSubscription.secret` — HMAC-SHA256 signing key surfaced on `create_webhook` response. Security-critical: required to verify the `X-AxonFlow-Signature` header on inbound deliveries. Also adds `org_id` / `tenant_id`.
  • `StepGateRequest.{tokens_in, tokens_out, cost_usd}` — budget policies can now evaluate gate-time cost estimates.
  • `StepGateResponse.decision_id` — unique audit correlator.
  • `ListWorkflowsResponse.{limit, offset}` — pagination echo.
  • `StaticPolicy.{policy_id, priority}` — wire-canonical fields.
  • `CreateStaticPolicyRequest.{priority, tags}` + `UpdateStaticPolicyRequest.{priority, tags}` — match spec.
  • `UpdatePlanRequest.metadata` — accept arbitrary plan metadata.
  • `UsageBreakdownItem.group_by` — dimension name.
  • `BudgetAlert.acknowledged` — alert dismissal flag.
  • `Budget.{org_id, tenant_id}` — ownership scoping.
  • `WorkflowStatusResponse.metadata` — workflow metadata.
  • `ExecutionSnapshot.retry_count` — retry counter.
  • `Finding.article` — regulatory article reference.
  • `MCPCheckInputRequest.{client_id, tenant_id, user_id, user_role, user_token}` + `MCPCheckOutputRequest.{client_id, tenant_id, user_id, user_token}` — match the spec scoping fields.

RENAME_SAFE (orphan reads fixed; old fields kept as DEPRECATED for source-compat)

The audit found these fields were declared in the SDK but read None against actual server responses (the wire emits a different key). Wire-canonical names added; legacy fields marked DEPRECATED with removal scheduled for v7:

  • `DynamicPolicyMatch.message` (was `reason` reading None)
  • `ExfiltrationCheckInfo.{exceeded, limit_type}` (was `within_limits` reading None)
  • `PolicyOverride.{id, enabled_override}` (was `active` reading None)
  • `PolicyVersion.{id, policy_id, change_summary, snapshot}` (was `change_description` / `previous_values` / `new_values` reading None)
  • `CancelPlanResponse.success` (was `message` reading None)
  • `CreateWorkflowResponse.started_at` (was `created_at` and `source` reading None)
  • `UsageRecord.{created_at, success, error_message, latency_ms, team_id, tenant_id, user_id, workflow_id}` (was `timestamp` reading None)
  • `ResumePlanResponse.result` + 6 fields marked DEPRECATED that were declared but never populated (`workflow_id`, `message`, `step_result`, `next_step`, `next_step_name`, `total_steps`)
  • `PlanResponse` gains wire top-level fields (`success`, `version`, `result`, `error`, `workflow_execution_id`, `policy_info`)

Spec issues already filed

  • axonflow-enterprise#1708 — `AISystemRegistry.materiality` is wrong field name (server emits `materiality_classification`); spec needs update, no SDK change.
  • axonflow-enterprise#1709 — `DynamicPolicyInfo` schema completely wrong shape (server, all 4 SDKs agree; spec drift).

Verification

  • Tests: ✅ 924 pass, 29 skipped
  • Coverage: 80.96%
  • Wire-shape baseline regenerated: 36 → 26 drift entries
  • All Cat B types resolved (no SDK-only or spec-only entries)

Note on baseline regeneration

The refresh script (`scripts/refresh_wire_shape_baseline.py`) needs an explicit `PYTHONPATH=$PWD` when run from the worktree if you have an editable install of axonflow elsewhere on your system; otherwise `import axonflow` resolves to the editable install instead of the worktree's local copy and the baseline refreshes against stale types. The CI workflow runs from a fresh clone so this isn't an issue there.

Test plan

  • All tests pass
  • Coverage above threshold
  • Baseline regenerated correctly (verified by inspection)
  • CI on this PR is green

…VERABLE)

Audit-driven cleanup against the wire-shape contract gate. Mirrors
the equivalent sweeps on the TS (axonflow-sdk-typescript#185) and Go
(axonflow-sdk-go#133) SDKs.

The earlier overnight claim that "Python baseline is clean" was a
key-name confusion (Python's baseline uses `per_model_drift`, while
TS/Go use `per_type_drift`). A proper per-entry audit found 36 drift
entries similar in pattern to the TS+Go SDK sweeps. After this sweep,
26 drift entries remain (mostly DEPRECATED aliases retained for
source-compat + Cat C entries to file separately + Plugin Batch 1
SDK additions pending platform-side spec coverage).

All changes additive (new fields default to None) or DEPRECATED-
marked alias fields kept for source-compat. Removal scheduled for
v7. No version bump.

Per-type changes (full detail in CHANGELOG):

Pure additions (Cat B):
- WebhookSubscription.{secret, org_id, tenant_id} — security-critical;
  secret is the HMAC-SHA256 signing key required to verify inbound
  webhook payload signatures.
- StepGateRequest.{tokens_in, tokens_out, cost_usd}
- StepGateResponse.decision_id
- ListWorkflowsResponse.{limit, offset}
- StaticPolicy.{policy_id, priority}
- CreateStaticPolicyRequest.{priority, tags}
- UpdateStaticPolicyRequest.{priority, tags}
- UpdatePlanRequest.metadata
- UsageBreakdownItem.group_by
- BudgetAlert.acknowledged
- Budget.{org_id, tenant_id}
- WorkflowStatusResponse.metadata
- ExecutionSnapshot.retry_count
- Finding.article
- MCPCheckInputRequest.{client_id, tenant_id, user_id, user_role,
  user_token}
- MCPCheckOutputRequest.{client_id, tenant_id, user_id, user_token}

RENAME_SAFE (orphan reads → wire-aligned canonical, old DEPRECATED):
- DynamicPolicyMatch.message + reason DEPRECATED
- ExfiltrationCheckInfo.{exceeded, limit_type} + within_limits
  DEPRECATED
- PolicyOverride.{id, enabled_override} + active DEPRECATED
- PolicyVersion.{id, policy_id, change_summary, snapshot} +
  {change_description, previous_values, new_values} DEPRECATED
- CancelPlanResponse.success + message DEPRECATED
- CreateWorkflowResponse.started_at + {created_at, source} DEPRECATED
- UsageRecord.{created_at, success, error_message, latency_ms,
  team_id, tenant_id, user_id, workflow_id} + timestamp DEPRECATED
- ResumePlanResponse.result + 6 declared-but-never-populated fields
  DEPRECATED (workflow_id, message, step_result, next_step,
  next_step_name, total_steps)
- PlanResponse: wire top-level fields (success, version, result,
  error, workflow_execution_id, policy_info)

Wire-shape baseline regenerated: 36 → 26 drift entries.

Filed alongside (no SDK change needed; spec is wrong):
- axonflow-enterprise#1708 — AISystemRegistry.materiality_classification
- axonflow-enterprise#1709 — DynamicPolicyInfo schema wrong shape

Tests: 924 pass. Coverage: 80.96%.
Companion to the type-definition sweep in this PR. Same systematic
audit as TS PR #185: type updates added wire-canonical fields, but
several methods in client.py hand-roll request bodies or response
objects instead of routing through pydantic's auto-handling, so the
fields were unreachable at runtime. 10 gaps confirmed by audit; all
fixed in this commit.

Read-path fixes:

- generate_plan: PlanResponse now carries success/version/result/
  error/workflow_execution_id/policy_info, sourced from the
  ClientResponse top level + nested data dict for back-compat with
  older platform builds that nested everything under data.
- create_workflow: started_at populated from wire (canonical) with
  fallback to legacy created_at; the deprecated created_at slot is
  also populated for source-compat with callers that read it.
  source field surfaced when the legacy server still emits it.
- step_gate: StepGateResponse.decision_id now populated from the
  wire response.
- list_workflows: ListWorkflowsResponse.limit / offset now populated
  from the wire echo.
- _map_workflow_response: WorkflowStatusResponse.metadata propagated
  (used by both get_workflow and list_workflows).

Write-path fixes:

- step_gate: request body now includes tokens_in / tokens_out /
  cost_usd when set on StepGateRequest (budget-policy hint fields).
- update_plan: body now includes metadata when set on UpdatePlanRequest.
- mcp_check_input: signature gains 5 keyword-only params
  (client_id, tenant_id, user_id, user_role, user_token); when set,
  serialized into the request body. Previously the SDK had no way
  to send these spec-declared scoping fields; multi-tenant /
  per-user policy use cases depend on them.
- mcp_check_output: same pattern, gains 4 keyword-only params
  (client_id, tenant_id, user_id, user_token).

Verified clean (no fix needed): every type whose decoder uses
`Type.model_validate(...)` (e.g. UpdatePlanResponse, PlanVersionsResponse,
EffectivePoliciesResponse, etc.) and every request whose body uses
`request.model_dump(...)` propagate new fields automatically through
pydantic's serialization. Only methods that hand-roll dicts/objects
needed updating.

Tests: 924 pass. Coverage: 80.41%. Lint clean.
Three findings from the round-3 review on the Python sweep:

1. generate_plan falsey-clobber: `response.result or data_dict.get("result")`
   replaced legitimate empty results (0, False, "", [], {}) with the
   data_dict fallback. Switched to explicit `is not None` check.

2. mcp_check_input / mcp_check_output sync wrappers: the async
   counterparts gained client_id / tenant_id / user_id / user_role /
   user_token (and user_id / user_token for output) in round 2,
   but the sync class at the bottom of client.py still exposed the
   old signatures. Both sync wrappers now mirror their async
   counterparts and forward the new keyword-only params.

3. check_tool_input / check_tool_output aliases (both async and
   sync): same problem — they delegated through the legacy
   positional signature and didn't pass the new scoping fields.
   Both aliases now accept and forward the same keyword-only
   params as the canonical methods.

Bonus: while sweeping for the same class of bug, found one more
falsey-clobber in create_workflow's `started_at = response.get(
"started_at") or response.get("created_at")`. Switched to
`is not None` so an empty string from a buggy server doesn't
silently swap to the legacy slot.

The first systematic audit (round-2 transformer review) clearly
wasn't exhaustive — these were the same class as the 5 it caught.
This commit also expands the audit to enumerate every type touched
in the sweep with its read + write paths verified, and confirms
no further gaps.

Tests: 924 pass. Lint + format clean.
@saurabhjain1592 saurabhjain1592 merged commit 5ba604d into main Apr 25, 2026
13 checks passed
@saurabhjain1592 saurabhjain1592 deleted the fix/wire-shape-alignment-sweep branch April 25, 2026 12:04
saurabhjain1592 added a commit that referenced this pull request Apr 25, 2026
The wire-shape sweep merged in #155 added new fields to several
transformers, shifting line numbers in axonflow/client.py and
axonflow/masfeat.py. Baseline still listed the old positions, so
CI saw 23 "new" findings (same code, new line numbers) and 23
"burned down" entries (same code, old line numbers) — pure
churn, no real change.

Mechanical refresh; finding count unchanged at 61.

Follow-up: line-keyed baselines are fragile to upstream merges.
Consider keying by file + symbol/snippet in a future iteration so
sweeps don't trigger this churn.
saurabhjain1592 added a commit that referenced this pull request Apr 25, 2026
* docs(contrib): add baseline burndown policy

* fix: correct wire-shape baseline filename (underscores not hyphens)

* chore(falsey-clobber): refresh baseline after PR #155 line shifts

The wire-shape sweep merged in #155 added new fields to several
transformers, shifting line numbers in axonflow/client.py and
axonflow/masfeat.py. Baseline still listed the old positions, so
CI saw 23 "new" findings (same code, new line numbers) and 23
"burned down" entries (same code, old line numbers) — pure
churn, no real change.

Mechanical refresh; finding count unchanged at 61.

Follow-up: line-keyed baselines are fragile to upstream merges.
Consider keying by file + symbol/snippet in a future iteration so
sweeps don't trigger this churn.
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