Skip to content

integrate: merge five reviewed and repaired PRs - #192

Merged
Zongwei9888 merged 29 commits into
mainfrom
codex/integrate-repaired-prs
Aug 23, 2026
Merged

integrate: merge five reviewed and repaired PRs#192
Zongwei9888 merged 29 commits into
mainfrom
codex/integrate-repaired-prs

Conversation

@Zongwei9888

Copy link
Copy Markdown
Collaborator

Summary

Integrates five individually reviewed contributor PRs in dependency order, including maintainer-side fixes:

  1. fix(security): bump sidecar pip 26.1.2 → 26.2 (PYSEC-2026-3721) #191 — keep the sidecar pip source pin and generated lock in sync at pip 26.2, clearing PYSEC-2026-3721.
  2. feat(core): Claude Code lessons — instruction file exclusion + explicit dangerous preset #186 — add predictable repository-relative instruction-file exclusions; remove the incomplete dangerous access preset.
  3. feat(mcp): lazy server activation (deferLoading + activate_server) #184 — make deferred MCP servers reachable through a model-visible activation tool; propagate cancellation and reject required+deferred configs.
  4. feat(hooks): SessionEnd lifecycle + PreCompact context injection #172 — fire SessionEnd exactly once on real teardown with a compatible reason and bounded timeout; preserve PreCompact checkpoints without defeating compaction.
  5. fix(security): restrict Windows private files with fail-safe ACL ordering #164 — atomically detect Windows file creation, use trusted Windows identity/tool resolution, inherit private directory ACLs, remove broad explicit SIDs, and reject junction traversal.

Why

These changes unblock the repository-wide dependency audit, reduce prompt/instruction contamination, lower MCP startup cost without making deferred servers unreachable, make hook teardown semantics reliable, and harden private Windows runtime state.

Verification

  • Combined focused suite: 217 passed, 5 skipped
  • Combined full suite: 1554 passed, 8 skipped
  • Ruff 0.15.21 check and format: passed
  • sidecar lock regenerated from source with uv: no diff
  • Windows ACL behavior must pass the Windows lifecycle job before merge

Closes #191
Closes #186
Closes #184
Closes #172
Closes #164

DeepCodeClone and others added 29 commits August 16, 2026 08:58
- SessionEnd: notification-only hook fired on every terminal path (complete / interrupted / error), so summaries can be persisted even when compaction never ran
…ompact context

- SessionEnd fires exactly once at real session termination
  (AgentSession.submit(Shutdown)), never per turn; per-turn
  notifications belong to the Stop event.
- SessionEnd honours its matcher: the session-exit reason
  (shutdown/interrupted/error) is the matcher input.
- hooks_config.json (deepcode-hooks MCP list format) is accepted
  only from the user-mcp source, with explicit validation, priority
  ordering, timeout parsing, event aliases and optional matchers.
- PreCompact checkpoint re-injection is bounded and provider-safe:
  per-context and total limits, only after a successful compaction.
- Add e2e regression tests (tests/test_session_end_lifecycle.py).
…paths

- execution._default_shell(): prefer a POSIX shell (Git Bash sh) on
  Windows so POSIX-syntax hook commands run; fall back to cmd.exe.
- sandbox.build_exec_command(): resolve POSIX-style shell paths to a
  real executable on Windows (CreateProcessW cannot launch /bin/bash);
  job backend injects PYTHONPATH so the windows_sandbox wrapper can
  import core.
- tools/shell.BashTool: pass wrapped.extra_env into the subprocess env
  so the injected PYTHONPATH reaches the sandbox wrapper.
- tests/test_hooks.py: use capture.as_posix() in shell commands so
  WindowsPath backslashes are not escaped by sh.

Local result: tests/test_hooks.py 53 passed; tests/test_agent_session.py 25 passed.
…th bare

The Windows shell-path resolution in build_exec_command() was applied to
all paths, including the sandbox-disabled one. That broke the
upstream-locked contract (test_disabled_via_env_returns_bare expects the
bare '/bin/bash -c' argv when sandboxing is disabled).

Move the resolution after the disabled early return so only the Job
Object sandbox path (CreateProcessW) gets a real executable path, while
the disabled path keeps the bare argv untouched.
Resolve core/agent_runtime/runner.py conflicts: keep PreCompact
checkpoint injection (PR) + upstream refused-compaction guard.
The merged upstream main renamed the prompt-size estimator
(estimate_prompt_tokens_chain -> _estimate_prompt instance method) and
added the dsh convergence rule that rejects summaries which do not
shrink the history. Update the three _maybe_compact tests:

- patch runner._estimate_prompt (returns a plain int) instead of the
  removed module-level function
- enlarge the sample turns so the compacted history + summary prefix
  is genuinely smaller than the source, satisfying the shrink gate
Security CI's 'Audit locked App Server environment' step fails on every
branch because the sidecar lock pins pip==26.1.2, which PYSEC-2026-3721
(healchecks pip < 26.2) now flags. pip publishes no wheels-only constraint
here, so bump the universal lock entry to the fixed 26.2 release.
…it dangerous preset

借鉴 Claude Code 两处机制 (2026-08-19):

1. core/harness/memory.py — 指令文件排除模式
   - DEEPCODE_INSTRUCTION_EXCLUDES env: 逗号分隔 glob (如 **/code/CLAUDE.md,**/vendor/**)
   - 命中的 AGENTS.md/DEEPCODE.md/CLAUDE.md 跳过注入, 避免 monorepo 子目录/
     第三方代码指令污染主提示词
   - 自实现 glob→regex: ** 匹配任意层级(可选前缀 (?:.*/)?), * / ? 不跨路径
     分隔符; vendorized ≠ vendor/ 前缀同名不误匹配
   - 非法模式忽略不阻断加载

2. core/domain/execution_security.py — 显式危险预设
   - ExecutionAccessPreset.DANGEROUS_SKIP="dangerous_skip", 对齐 Claude Code
     --allow-dangerously-skip-permissions; 与 FULL_ACCESS 同强度但名字自带
     危险警示, 供日志/UI 明确区分

3. tests/test_memory.py — 4 个新用例 (glob 正反例/集成/非法模式)
Addresses maintainer feedback on the earlier ACL PR (#148): re-running icacls
on every open costs two subprocesses per call for no change.

- open_private_file now restricts a file's ACL only when it was just created
  (target did not exist before os.open); opening an existing private file
  never re-runs _restrict_windows_acl.
- harden_private_tree keeps forcing the restriction (it repairs legacy trees
  whose ACLs may be absent), so its semantics are unchanged.
- new cross-platform tests (mock _restrict_windows_acl) assert: new file
  restricted exactly once, existing file never re-restricted, read-only open
  of an existing file never restricts.
Cross-platform call-count tests exposed two structural bugs:
- elif created: hid the file restriction behind the POSIX fchmod branch,
  so the mocked ACL call never fired on non-Windows runners (0 calls).
- _chmod restricted unconditionally on Windows, so ensure_private_directory
  re-ran icacls on the already-existing parent dir on every open (2-4
  calls instead of 1).

Now: directories restrict only when actually created (was_missing),
files restrict only when created (independent if created), and _chmod
honors force= (harden_private_tree/ensure_private_file still re-apply,
regular callers do not churn existing paths).
Add McpServerDefinition.defer_loading (deferLoading). Servers marked deferred
are skipped by ensure_started (status stays 'deferred', no connection, no
tools) and are brought up on demand via McpSessionRuntime.activate_server,
which starts the connection, registers the server's tools into the
ToolRegistry, and publishes status/capabilities. Idempotent; startup
failures mark the server 'failed' without raising.

Derived from the MCP lifecycle study of Hmbown/CodeWhale.
core/mcp/test_runtime_lazy.py sat outside pytest testpaths (tests/ +
quant_trading/tests), so CI never collected the 5 new cases. Move it to
tests/test_mcp_runtime_lazy.py; now collected and run by CI.
@Zongwei9888
Zongwei9888 merged commit e0767d0 into main Aug 23, 2026
14 checks passed
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.

3 participants