Skip to content

cmd.build: fix dcc64 errors (Windows-unit shadowing + GetTempDir) - #301

Merged
FMXExpress merged 2 commits into
mainfrom
claude/build-dcc64-fixes
Jun 17, 2026
Merged

FMXExpress merged 2 commits into
mainfrom
claude/build-dcc64-fixes

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

Summary

Fixes the dcc64 compile errors reported on PR #300 after it merged. These slipped in because the fix commit was pushed after the merge — landing them on a fresh branch off main.

[dcc64 Error] PasClaw.Cmd.Build.pas(281): E2003 Undeclared identifier: 'GetTempDir'
[dcc64 Error] PasClaw.Cmd.Build.pas(282): E2035 Not enough actual parameters
[dcc64 Error] PasClaw.Cmd.Build.pas(297): E2010 Incompatible types: 'PWideChar' and 'string'
[dcc64 Error] PasClaw.Cmd.Build.pas(308): E2010 Incompatible types: 'PWideChar' and 'string'
[dcc64 Error] PasClaw.Cmd.Build.pas(311): E2010 Incompatible types: 'UInt64' and 'TSearchRec'
[dcc64 Error] PasClaw.Cmd.Build.pas(324): E2010 Incompatible types: 'UInt64' and 'TSearchRec'
[dcc64 Fatal Error] PasClaw.Cmd.Root.pas(63): F2063 Could not compile used unit 'PasClaw.Cmd.Build.pas'

Root causes

Error Cause Fix
GetTempDir undeclared (281, 282) FPC-only SysUtils.GetTempDir(Global: Boolean); Delphi has no such function New PlatformTempRoot helper — GetTempDir(False) under FPC, TPath.GetTempPath from System.IOUtils under Delphi
PWideChar/string on DeleteFile (297, 308) Windows unit (in scope for SetEnvironmentVariable) shadows SysUtils.DeleteFile with the PWideChar overload Explicit SysUtils.DeleteFile(...)
UInt64/TSearchRec on FindClose (311, 324) Windows.FindClose takes a THandle, not a TSearchRec Explicit SysUtils.FindClose(SR)

Defense-in-depth on the rest of the family the Windows unit shadows: FileExists, DirectoryExists, FindFirst, FindNext, RemoveDir, TSearchRec — all now SysUtils.-qualified. Documented the "don't strip the prefix" reasoning on RemoveTree's docstring so a future contributor doesn't "clean it up" and re-break dcc64.

Bonus

Dropped GetProcessID from the tempdir-naming scheme. It's SysUtils-FPC-only with no portable Delphi equivalent (would need Windows.GetCurrentProcessId on Windows + Posix.Unistd.getpid on Linux). Two Random(MaxInt) calls already give ~2^62 entropy — overkill for a per-invocation tempdir on a single host.

Files

src/cmd/PasClaw.Cmd.Build.pas    # 39 insertions, 15 deletions

Test plan


Generated by Claude Code

User reported on PR #300:

  [dcc64 Error] PasClaw.Cmd.Build.pas(281): E2003 Undeclared
    identifier: 'GetTempDir'
  [dcc64 Error] PasClaw.Cmd.Build.pas(282): E2035 Not enough
    actual parameters
  [dcc64 Error] PasClaw.Cmd.Build.pas(297): E2010 Incompatible
    types: 'PWideChar' and 'string'
  [dcc64 Error] PasClaw.Cmd.Build.pas(308): E2010 Incompatible
    types: 'PWideChar' and 'string'
  [dcc64 Error] PasClaw.Cmd.Build.pas(311): E2010 Incompatible
    types: 'UInt64' and 'TSearchRec'
  [dcc64 Error] PasClaw.Cmd.Build.pas(324): E2010 Incompatible
    types: 'UInt64' and 'TSearchRec'

Two root causes.

ROOT CAUSE 1: SysUtils.GetTempDir is FPC-only.

The signature `GetTempDir(Global: Boolean): string` exists in FPC's
SysUtils but Delphi's RTL has no such function. Delphi exposes
TPath.GetTempPath in System.IOUtils instead.

Fix: wrap once at the unit top:

  function PlatformTempRoot: string;
  begin
    {$IFDEF FPC} Result := GetTempDir(False);
    {$ELSE}      Result := TPath.GetTempPath;
    {$ENDIF}
  end;

ROOT CAUSE 2: the Windows unit (in scope for SetEnvironmentVariable
under {$IFDEF MSWINDOWS}) shadows several SysUtils file-system
helpers with PWideChar/THandle overloads, which then collide with
TSearchRec parameters.

Specifically:
  Windows.DeleteFile(lpFileName: PWideChar)      shadows
    SysUtils.DeleteFile(const FileName: string)
  Windows.FindClose(hFindFile: THandle)          shadows
    SysUtils.FindClose(var F: TSearchRec)
  Windows.FindFirst* / FindNext*                 shadow
    SysUtils.FindFirst / FindNext for TSearchRec

The dcc64 errors were:
  PWideChar mismatch -> we passed `string` to DeleteFile.
  UInt64 mismatch    -> we passed a TSearchRec to FindClose.

Fix: explicit SysUtils. qualification on every file-system call in
the Windows-uses scope -- DeleteFile, FileExists, DirectoryExists,
FindFirst, FindNext, FindClose, RemoveDir, TSearchRec. Comment block
on RemoveTree documents the why so a future contributor doesn't
"clean up the redundant prefix" and break dcc64.

Bonus: dropped GetProcessID from the tempdir name. It's
SysUtils-FPC-only with no portable Delphi equivalent (Delphi requires
Windows.GetCurrentProcessId on Windows or Posix.Unistd.getpid on
Linux). Two Random calls give 2^62 entropy which is ample for
per-invocation tempdir uniqueness on a single host.

FPC build (linux/x86_64) still clean. test-build-roundtrip still
passes 10/10 (5 zip round-trip + 5 zip-slip regression).

End-to-end smoke unchanged: `pasclaw build -d "smoke" --max-iters 1
--workspace-out /tmp/out.zip` produces the expected tempdir + zip
output.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a9c6071c55

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/cmd/PasClaw.Cmd.Build.pas Outdated
Comment on lines 297 to 299
Result := JoinPath(PlatformTempRoot,
'pasclaw_build_' + IntToStr(Random(MaxInt)) + '_' +
IntToStr(Random(MaxInt)));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve temp-home uniqueness across parallel builds

When pasclaw build runs without --home/PASCLAW_HOME in parallel, the temp home now depends only on the PRNG values produced immediately after Randomize. Separate processes that receive the same time-based seed can generate the same two values, and ForceDirectories(Home) accepts an existing directory, so both builds can share one $PASCLAW_HOME; the first one to exit may then RemoveTree(Home) while the other is still using it. The previous PID component avoided this cross-process collision, so use an OS-created unique temp directory or include a platform PID/creation retry.

Useful? React with 👍 / 👎.

Codex P2 on PR #301: parallel `pasclaw build` invocations could
share one $PASCLAW_HOME and stomp on each other.

The previous Randomize+Random scheme seeded the PRNG from the
system clock (SysUtils.Randomize behavior), so two processes
started inside the same second produced identical Random(MaxInt)
sequences -> identical tempdir paths.  ForceDirectories happily
accepted the pre-existing directory, so both processes ran against
the same $PASCLAW_HOME; whichever exited first wiped the other's
state via RemoveTree(Home).

Fix: new MakeUniqueTempDir(NamePrefix) helper.

  * Random component is a 128-bit GUID via SysUtils.CreateGUID,
    backed by OS entropy on both compilers (UuidCreate on Windows,
    /dev/urandom on Linux).  Cross-process collision is
    statistically impossible (2^-128).
  * Atomic creation via SysUtils.CreateDir, NOT ForceDirectories.
    CreateDir fails when the target already exists -- so even in
    the cosmic event that some other tool pre-created the name, we
    surface the collision rather than silently sharing.
  * 8-attempt retry loop covers the (also vanishingly unlikely)
    CreateGUID failure on systems with no entropy source, and the
    pre-existing-name case above.

ResolveHome's tempdir branch now calls MakeUniqueTempDir.  The
--home and PASCLAW_HOME-env branches are unchanged -- those are
explicit operator choices where shared-directory behavior is the
intended semantic.

MakeUniqueTempDir exposed in the interface for the regression
test.

Tests in src/tests/build_workspace_roundtrip_tests.pas:

  TestUniqueTempDirNoCollisions -- 64 sequential calls all produce
    distinct paths that actually exist on disk.  A duplicate would
    fail because Seen.Duplicates = dupError.

Real cross-process race verified by smoke harness: 8 parallel
`pasclaw build` invocations all picked distinct GUID-suffixed
paths.  The output:

    PASCLAW_HOME=/tmp/pasclaw_build_C9BE1D5FC9D54525AEDBA9BEFB958534
    PASCLAW_HOME=/tmp/pasclaw_build_FC7C6667C2784C29AAF04078429D403B
    PASCLAW_HOME=/tmp/pasclaw_build_7569F1DB22F54E0097188B1C58826C77
    PASCLAW_HOME=/tmp/pasclaw_build_23A94F02B7FE4ED58907E69FFE8A8F3F
    (8 more, all distinct)

FPC build clean; all 11 round-trip tests pass.
@FMXExpress
FMXExpress merged commit 3a395d6 into main Jun 17, 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