Skip to content

chore: add the verify-native-lifecycle TLA+ skill - #24

Merged
ThomasK33 merged 3 commits into
mainfrom
skills/verify-native-lifecycle
Oct 29, 2026
Merged

ThomasK33 merged 3 commits into
mainfrom
skills/verify-native-lifecycle

Conversation

@ThomasK33

Copy link
Copy Markdown
Member

Adds .agents/skills/verify-native-lifecycle/, a project skill that model-checks with TLA+ (TLC) how the native addon keeps state across Node environments and across one terminal's life.

Rules it checks

Rule In plain words
CreateUsesOwnClass createTerminal in a thread uses the class reference that this thread made.
LoadDeletesOnlyOwnRef Loading the addon in a thread never deletes another thread's reference.
HandleFreedOnce libghostty frees each terminal handle at most once.
NoCallOnDeadHandle No libghostty call reaches a freed or null terminal handle.

The model found the worker-thread crash that the PR below this one fixes. It describes the fixed code. Each action in model/AddonEnvLifecycle.tla names the function it stands for, and SKILL.md has a coverage record and a sync commit.

Each rule can fail

run.sh checks the current code and three mutants, and compares each result with an expected list:

Config Expected breaks
current none
mutant-process-static (the code before the fix) CreateUsesOwnClass, LoadDeletesOnlyOwnRef
mutant-dispose-keeps-pointer (no terminal_ = nullptr in DisposeNative) HandleFreedOnce
mutant-no-use-guards (no #assertUsable, no RequireTerminal null check) NoCallOnDeadHandle

Run

.agents/skills/verify-native-lifecycle/run.sh

It takes about 20 seconds, needs Java 11 or later, and downloads tla2tools v1.7.4 to vendor/tla2tools/ with a sha256 check. Result here: OK: every result matches EXPECT.

Bounds and limits

  • Bounds: the main thread, 2 workers, and 2 terminals (2,121 distinct states).
  • Not covered: libghostty itself, snapshot and text content, argument validation, and packaging.

I proved the skill once on a scratch break: removing terminal_ = nullptr from DisposeNative made HandleFreedOnce break, and the real build then segfaulted on GC after dispose(). I dropped the scratch change afterwards.

The sync commit names this stack's fix commit. After the fix squash-merges, I will move it to the squash commit on main.


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high

Adds a project skill that model-checks, with TLA+ and TLC, how the native
addon keeps state across Node environments (the main thread and
worker_threads Workers) and across one terminal's life. It checks four
rules: createTerminal uses its own environment's class reference,
loading never deletes another environment's reference, each handle is
freed at most once, and no libghostty call reaches a freed or null
handle.

This check found the worker-thread crash that the previous commit fixes.
The model describes the fixed code. Three mutant configs (the old static
reference, DisposeNative without `terminal_ = nullptr`, and no use
guards) must each break their rule, so every run shows that each rule
can fail.

Run: .agents/skills/verify-native-lifecycle/run.sh (about 20 s, needs
Java 11+, downloads tla2tools v1.7.4 to vendor/ with a sha256 check).

_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_

Change-Id: Iff1cda4aaa5bc6e98624787e0e5ed21d1adfa587
Signed-off-by: Thomas Kosiewski <tk@coder.com>
@ThomasK33
ThomasK33 added this pull request to stack #26 October 29, 2026 13:09
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T13:29:33.451386Z 4c4a49b Manual request
🔒 Security Review ✅ Completed 2026-10-29T13:29:36.948406Z 4c4a49b Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: e7b67ed2e0

ℹ️ 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 .agents/skills/verify-native-lifecycle/run.sh
Comment thread .agents/skills/verify-native-lifecycle/SKILL.md Outdated
@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: e7b67ed2e0

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Change-Id: Ie78a8d38ccb368f4d3d5df8b7f3585ff8c5a018c
Signed-off-by: Thomas Kosiewski <tk@coder.com>
… fix

Explains how to read a TLC counterexample from the log when the agent
does not have the pstack /statechart skill. Updates the model comment
and the coverage record for the instance-data assertion in
TerminalWrap::Init, and moves the sync commit to that change.

_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_

Change-Id: I0cf397b7723446c7de3a06eefba399c3b7b431ed
Signed-off-by: Thomas Kosiewski <tk@coder.com>
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 4c4a49b263

ℹ️ 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".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 4c4a49b263

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ThomasK33
ThomasK33 removed this pull request from stack #26 October 29, 2026 17:56
@ThomasK33
ThomasK33 changed the base branch from fix/worker-thread-class-ref to main October 29, 2026 17:56
@ThomasK33
ThomasK33 merged commit 79ce9c1 into main Oct 29, 2026
4 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.

1 participant