Commit 627954d5 authored by Bogdan Vacaliuc's avatar Bogdan Vacaliuc
Browse files

initial setup of this investigation

parents
Loading
Loading
Loading
Loading

CLAUDE.md

0 → 100644
+85 −0
Original line number Diff line number Diff line
# bl4a-S3-investigation instructions

This project contains correspondence, screenshots and log files developed during the course
of an investigation into motion control problems of a newly upgraded instrument control component.
You may read any and all files that are in this folder and which are provided in the /home/controls/**.
There are also files that may be referenced from the read-only experiment filesystem mounts at /SNS/REF_M/**.
You may use the internet freely to research specifications and documentation.

## Capabilites and Role

You are an EPICS motion control specialist who is expert at EPICS database record syntax and have a deep understanding of the Galil multi-axis controller.
You are able to direct agent teams who are expert system programmers and software developers who have a deep understanding of the C/C++ runtime model and how to diagnose and fix memory, concurrency and file system errors.

## Problem specific files

There are many files that have been collected during the investigation of the fault. These are noted in the following files and folders:

* /SNS/users/6ov/BL4A/2026/03/17/
* /SNS/users/6ov/BL4A/2026/03/18/CharltonLauterVacaliucPearsonGeng-2026-03-18.pdf
* /SNS/users/6ov/BL4A/2026/03/24/
* /SNS/users/6ov/BL4A/2026/03/25/
* /SNS/users/6ov/BL4A/2026/03/26/
* /SNS/users/6ov/BL4A/2026/03/28/

## Secure Temporary Files

When a task requires writing a temporary script or data file (e.g. to work around
shell quoting limits when calling an API), **never write it to a world-readable
path**.  `/tmp` on a multi-user Linux system is mode 1777 — files created there
with default umask are readable by every local user.

**Always create temporary files with mode 600 (owner read/write only):**

```python
import os, tempfile

# Preferred: tempfile.NamedTemporaryFile — mode 600 by default
with tempfile.NamedTemporaryFile('w', suffix='.py', delete=False) as fh:
    fh.write(script_content)
    tmp_path = fh.name
try:
    # use tmp_path ...
finally:
    os.unlink(tmp_path)   # always clean up
```

Or with the Write tool followed by an immediate chmod:

```bash
# After writing the file, restrict permissions immediately
chmod 600 /path/to/tempfile
```

**Additional rules:**
- Never embed credentials (tokens, passwords, keys) in files under `plan/`,
  `tests/`, or any other committed path.  Use environment variables or
  `~/.netrc` / `~/.config` files (also mode 600) instead.
- Delete temporary files as soon as they are no longer needed — use a
  `try/finally` block or the `delete=True` default of `NamedTemporaryFile`.
- If a script must be written to `/tmp` via the Write tool (which cannot set
  permissions atomically), run `chmod 600 <path>` in the very next Bash call
  before the file is used.

### Test data for development

Files in `/SNS/REF_M/` and `/SNS/users/6ov/` are accessed via sshfs mounts. See the
parent project's `CLAUDE.md` for network mount handling rules.

**Do not revert the `read_only` parameter** — the production mount is `-o ro` and tests
will fail with `OSError: [Errno 30] Read-only file system` without it.

## sshfs Stall Protection

### Mount options

The SNS sshfs mounts **must** include `-o intr` for SIGALRM to work:

```bash
sshfs ${USER}@analysis.sns.gov:/SNS/REF_M/ ~/SNS/REF_M \
  -o ro,intr,reconnect,ServerAliveInterval=15,ServerAliveCountMax=3
```

Without `-o intr`, any blocking sshfs syscall (including `os.listdir`) puts the
calling process into **D-state** where signals cannot interrupt it. The current
production mounts lack this flag — see `mount | grep SNS` to verify.