Skip to content

Refactor SandboxThread init/reset state setup helpers#196

Merged
seanwevans merged 1 commit intomainfrom
codex/refactor-state-setup-in-thread.py
Apr 21, 2026
Merged

Refactor SandboxThread init/reset state setup helpers#196
seanwevans merged 1 commit intomainfrom
codex/refactor-state-setup-in-thread.py

Conversation

@seanwevans
Copy link
Copy Markdown
Owner

Motivation

  • Reduce duplicated initialization logic by centralizing immutable/config wiring and transient runtime state so __init__ and reset share identical setup behavior.
  • Make capabilities deserialization, quota/policy wiring, NUMA/cgroup pointers and transient counters initialization explicit and easier to maintain.
  • Make lifecycle expectations for attach-message deduplication explicit so message-id behavior is intentional and auditable.

Description

  • Add a private _init_config_wiring(...) helper to centralize configuration/immutable wiring including quotas, merged imports, NUMA/cgroup pointers, and capabilities deserialization.
  • Add a private _reset_runtime_state() helper to centralize resetting transient counters and runtime fields such as _cpu_time, _mem_peak, _ops, _errors, _latency, _latency_sum, _trace_enabled, _syscall_log, _start_time, _open_files, _network_ops, _output_bytes, and _child_work plus quarantine/termination fields.
  • Update __init__ and reset to call the two helpers so both construction and reuse flows share the same initialization behavior while keeping existing public method signatures and behavior unchanged.
  • Add an inline comment near _next_attach_msg_id / _seen_attach_msg_ids clarifying that the dedup set spans sandbox lifetimes and that attach message IDs are monotonic and intentionally preserved across reset() to avoid stale replay collisions.

Testing

  • Ran python -m compileall -q pyisolate/runtime/thread.py which completed successfully.
  • Ran full test suite with python -m pytest -q; the run produced repository-wide failures (106 failed, 101 passed, 1 error) caused by a mismatch in the test stub (_StubBPFManager.load() receiving an unexpected mode keyword) and are unrelated to this refactor.

Codex Task

@seanwevans seanwevans merged commit b90177a into main Apr 21, 2026
9 of 19 checks passed
@seanwevans seanwevans deleted the codex/refactor-state-setup-in-thread.py branch April 21, 2026 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant