Skip to content

platform: inject ExtraEnv into spawned children on Delphi builds (Windows + POSIX) - #296

Merged
FMXExpress merged 1 commit into
mainfrom
claude/delphi-env-inject
Jun 16, 2026
Merged

FMXExpress merged 1 commit into
mainfrom
claude/delphi-env-inject

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

The bug

RunOneShotWithEnv(Cmd, WorkingDir, ExtraEnv, Output) runs a child process with extra environment variables. On Delphi builds (both Windows and POSIX) it was a stub — it ignored ExtraEnv and just called RunOneShot. Only the FPC build injected the vars. execute_code's tool-RPC callback passes env vars through here (so a sandboxed script can call back into the agent's tool registry), so on a Delphi-compiled PasClaw those vars silently vanished. The old comments admitted it ("ExtraEnv silently ignored on this build… the fix is a follow-up").

The fix

Inject env at the single place each backend launches a child — TStdioProcess.Spawn, now with an optional ExtraEnv: TStrings = nil (default keeps every existing caller byte-identical):

  • Delphi/Windows: new BuildUnicodeEnvBlock merges the parent environment with the overrides (override wins, case-insensitive, sorted) into a double-null CREATE_UNICODE_ENVIRONMENT block for CreateProcessW. (A non-nil block means the child sees exactly that, so parent env must be folded in or it'd lose PATH/SystemRoot.)
  • Delphi/POSIX: setenv() each override in the forked child before execvp (the child already inherited the parent env across fork).
  • FPC: Spawn now also honors ExtraEnv (merges into TProcess.Environment) for consistency — FPC was already correct via its own RunOneShotWithEnv.

The two Delphi RunOneShotWithEnv stubs now carry the real capture loop and pass ExtraEnv to Spawn; RunOneShot delegates with nil (no duplicated loop).

Tests

New env_inject_tests (in make test): the var reaches the child, parent env survives the merge, an override beats an inherited var, and nil injects nothing. make test-shell-backend still green; full binary builds clean.

Caveat

This sandbox only compiles the FPC backend, so the Delphi Windows/POSIX code is verified by inspection, not compilation — a Delphi build is the real test. The FPC path (build + tests) is fully green here.

https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6


Generated by Claude Code

RunOneShotWithEnv silently ignored ExtraEnv on Delphi/Windows and
Delphi/POSIX -- it just fell through to RunOneShot -- so execute_code's
tool-RPC env vars never reached the child on a Delphi-compiled PasClaw
(only FPC honored them).

Thread an optional ExtraEnv through TStdioProcess.Spawn (default nil =
existing callers unchanged) and implement it per backend:
- Delphi/Windows: BuildUnicodeEnvBlock merges parent env + overrides
  (override wins, case-insensitive, sorted) into a CREATE_UNICODE_
  ENVIRONMENT block for CreateProcessW. A non-nil block means the child
  sees exactly that, so parent env is folded in.
- Delphi/POSIX: setenv() each override in the forked child before execvp
  (child already inherited the parent env).
- FPC: Spawn now also honors ExtraEnv (merges into TProcess.Environment).
The two Delphi RunOneShotWithEnv stubs now carry the real capture loop and
pass ExtraEnv to Spawn; RunOneShot delegates with nil (no duplicated loop).

New env_inject_tests: var reaches the child, parent env survives the
merge, an override beats an inherited var, nil injects nothing. Verified
on FPC; the Delphi backends mirror the same contract (this sandbox only
compiles FPC).
@FMXExpress
FMXExpress merged commit 9601bc8 into main Jun 16, 2026
khongten001 pushed a commit to khongten001/PasClaw that referenced this pull request Jul 13, 2026
The README + docs/changelog.md last entry was 2026-06-13 (FMXExpress#244). Five
substantial PRs (FMXExpress#314 FMXExpress#315 FMXExpress#316 FMXExpress#317 FMXExpress#318) and ten more feature PRs
between them and that entry shipped without changelog entries. This
brings both files current through today.

Twenty new entries (newest first, matching the existing style):

  2026-06-21
    FMXExpress#318  Relay pull-worker provider (queue + provider + /v1/relay/* HTTP)

  2026-06-20
    FMXExpress#317  pasclaw plan + build PLAN.md pickup + build --goal + cog mode
    FMXExpress#316  Cloudflare AI Gateway provider catalog rows
    FMXExpress#315  MCP progressive disclosure + tool_search
    FMXExpress#314  Stock defaults adopt lean-edit shape; fs_grep split-gate

  2026-06-18
    FMXExpress#312  Web UI workspace.zip export + import
    FMXExpress#310  Model-callable cron tool
    FMXExpress#309  FTS5 snippet window widened 24 -> 60
    FMXExpress#307  Windows cmd.exe quoting fix

  2026-06-17
    FMXExpress#306  cog-build honours profile=security sandbox
    FMXExpress#304  cog-build default profile = max-build
    FMXExpress#303  cog-build list[Path] outputs + Secret inputs + -q

  2026-06-16
    FMXExpress#302  cog-build optional workspace_in
    FMXExpress#300  pasclaw build cmd + cog-build/ predictor (parent feature)
    FMXExpress#299  Checkpoints zpaq backend + /redo
    FMXExpress#298  AGENTS.md + pasclaw init + /init
    FMXExpress#297  tool_choice force-a-specific-tool form
    FMXExpress#296  Delphi ExtraEnv injection fix
    FMXExpress#295  KB native PDF ingest

  2026-06-15
    FMXExpress#292  pasclaw profile diff + bench

Skipped per the changelog's stated convention ("Bug fixes and review
follow-ups are in the full git log"):

  FMXExpress#293  cmd/profile dcc64 fix
  FMXExpress#294  skills_manage gemini empty-enum fix
  FMXExpress#301  cmd.build dcc64 fix
  FMXExpress#311  cron dcc64 fix

Files updated identically (the docs/changelog.md note at the top says
"This file mirrors the changelog section at the top of the root
README.md"):

  M README.md           20 entries + 20 link refs added
  M docs/changelog.md   same

The link-ref block at the bottom of each file gained 20 [#NNN] entries
keeping the existing one-per-line / sorted-numerically format.
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.

2 participants