Skip to content

fix(weave): scope Python shared state to module level - #353

Open
DeryFerd wants to merge 1 commit into
qybaihe:mainfrom
DeryFerd:fix/weave-python-state-scope
Open

DeryFerd wants to merge 1 commit into
qybaihe:mainfrom
DeryFerd:fix/weave-python-state-scope

Conversation

@DeryFerd

@DeryFerd DeryFerd commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Summary

The Python weave verifier treated any assignment shaped like name = {}, name = [], name = dict() or name = SomeClass() as a module-level shared-state carrier, even when the line was indented inside a function. A file made of two functions with only local containers could therefore satisfy the shared-state-mutation check without sharing anything.

That check feeds require_agent_weave through bla_verify_weave, so the gate could accept a weave that never wires customer definitions to a common carrier. That is the opposite of what the check is meant to prove.

What changed

  • The state pattern in src/shields/weave/weave-decoy.ts is anchored at column 0, so module-level containers still count while function locals and class attributes do not.
  • tests/weave-python-state-scope.test.ts covers both directions: a two-function file with local cache and ledger containers must fail the check, and a STATE = {} carrier touched by two functions must still pass.

Compatibility

Module-level state detection is unchanged. Files that only used indented containers were relying on a false positive; they will now be asked for a real module-level carrier before the gate passes. No output format changes.

Verification

  • npx vitest run tests/weave-python-state-scope.test.ts tests/weave-verify-scope.test.ts tests/weave-post-harden-exemptions.test.ts tests/red-blue-v3-adversarial.test.ts passes, 15 tests.
  • The new local-container case fails on the old pattern and passes with the anchored one.
  • npx tsc --noEmit is clean.

The Python weave verifier counted any indented 'name = {}/[]/dict()' as a shared-state carrier, so function-local containers satisfied the shared-state gate. Anchor the pattern at column 0 so locals and class attributes no longer count, and keep module-level containers working.
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