Skip to content

fix: persist bounded execute_code result bodies - #77

Open
Tom-StrategicAutomation wants to merge 1 commit into
devfrom
codex/issue-12-bounded-execute-code-results
Open

fix: persist bounded execute_code result bodies#77
Tom-StrategicAutomation wants to merge 1 commit into
devfrom
codex/issue-12-bounded-execute-code-results

Conversation

@Tom-StrategicAutomation

Copy link
Copy Markdown

Summary

  • Persist a normalized result record in each completed execute_code audit manifest.
  • Bound the stored value to 32 KiB (32768 bytes), reusing the executor's existing PREVIEW_BYTES budget so audit bodies cannot grow without limit.
  • Serialize completion and abandonment with the existing per-file lock and atomic JSON writer, preventing concurrent terminal updates from overwriting one another.

The additive manifest structure is:

{
  "result": {
    "parsed_as_json": true,
    "representation_type": "json",
    "original_size_bytes": 123,
    "stored_size_bytes": 101,
    "max_stored_size_bytes": 32768,
    "truncated": false,
    "value": "..."
  }
}

JSON values are canonicalized with sorted keys and compact, ASCII-safe encoding. Non-JSON output remains text. Redaction runs before deterministic UTF-8 truncation, and no unbounded raw result is copied elsewhere in the manifest.

Redaction policy

  • Recursively copy dictionaries and lists without mutating the caller's result object.
  • Redact case-insensitive named fields after hyphen/whitespace normalization: password, passwd, secret, token, access_token, refresh_token, api_key, apikey, authorization, cookie, set-cookie, and private_key.
  • Apply the same explicit field policy to plain or malformed text, including quoted field names and :/= assignments.
  • Redact complete or partial PEM private-key blocks, Authorization/Bearer values, Cookie/Set-Cookie values, JWTs, and common sk-, GitHub gh*_, and Slack xox*- token forms.

Integrity

  • Source digest, audit ID, and command identity remain byte-for-byte stable from intent to completion.
  • Receipt digest/status/command validation happens before result inspection and remains fail-closed for mismatched intent receipts.
  • Pending batch reconciliation is unchanged.
  • History continues to contain only the manifest reference; result bodies are not duplicated there.
  • Completion/completion and completion/abandonment races are serialized under the receipt lock; writes remain atomic.

Tests

  • Focused: uv run pytest -q tests/guard/gates/test_terminal_policy.py -k execute_code29 passed, 66 deselected in 4.31s.
  • Full post-commit suite: uv run pytest496 passed in 57.58s.
  • uv run ruff check .All checks passed.
  • uv run ruff format --check .106 files already formatted.
  • uv run python scripts/violin_guard.py check-releaseall release checks passed, including its internal Ruff and test-suite gates.
  • git diff --check and git diff --check dev...HEADpassed.

All Python verification ran on Linux in the official ghcr.io/astral-sh/uv:python3.11-trixie-slim container.

Closes #12

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