Skip to content

fix: honor ambient hot-reload and platform-aware badge tests - #1276

Merged
1jehuang merged 1826 commits into
masterfrom
fix/issue-triage-20260915
Sep 19, 2026
Merged

1jehuang merged 1826 commits into
masterfrom
fix/issue-triage-20260915

Conversation

@1jehuang

@1jehuang 1jehuang commented Sep 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

Fixes #1269. Fixes #1275.

Two independently reviewable, narrow fixes from issue triage:

Commits: 2200140 (#1269), 180e95d (#1275).

Verification

Performed on Linux x86_64 through the coordinated self-dev test/build queue:

  • Reproduced the original badge assertion with an isolated JCODE_HOME and [display] copy_badge_alt_label = "⌥": 18 != 16 before the fixture fix.
  • scripts/dev_cargo.sh test --offline --locked -p jcode-tui --lib copy_badge -- --test-threads=1: 16 passed with default Alt, and 16 passed with configured ⌥, including platform-default and trimmed-override tests.
  • Ran each of the two changed badge fixtures separately with --exact --test-threads=1 under each label: 4 exact invocations passed on the final formatted tree.
  • scripts/dev_cargo.sh test --offline --locked -p jcode-app-core --lib ambient::runner:: -- --test-threads=1: 6 passed, including the new toggle regression and real running-loop hot-reload regression and existing disabled-ambient scheduled-task coverage.
  • scripts/dev_cargo.sh build --profile selfdev -p jcode --bin jcode: passed via selfdev build.
  • git diff --check and rustfmt --check --edition 2024 on all three changed files: passed.

Measured behavior follow-up

Additional regression coverage in c515991 exercises the actual run_loop, not just the extracted gate. It starts disabled, edits config.toml to enable ambient without invalidating the cache, and observes the loop enter Paused for an active user session after nudging it. This exercises file fingerprint reload and the production gate without model inference.

Restoring the old startup-snapshot gate made this exact test fail after its 3-second observation deadline. Restoring the fix made it pass, along with all six ambient runner tests. This establishes a behavioral improvement at the real loop boundary, while not claiming a full CLI/daemon or native macOS acceptance run.

Limits and non-goals

Hosted CI follow-up

This PR is draft pending hosted checks and native macOS validation. The CI run, Windows smoke, and iOS workflow all failed before creating any jobs. gh run view reports a likely workflow-file issue, and these unchanged base workflows each contain duplicate top-level env maps. The existing repair is tracked by #1191 / PR #1193 and is not duplicated here. Require Linked Issue passed. Local test/build results above remain valid, but this is not green hosted CI.


Jcode agent (automated triage), on behalf of @1jehuang

1jehuang and others added 30 commits August 25, 2026 22:39
@1jehuang
1jehuang marked this pull request as ready for review September 19, 2026 01:54
@1jehuang

Copy link
Copy Markdown
Owner Author

All three scoped commits were already present byte-for-byte on current master. Integrating ancestry-only 7d25a5646 records the contribution without replacing newer code.

Fresh exact executable acceptance with a private daemon/local provider fixture observed disabled startup with zero requests, config=true on next wake producing one cycle, config=false stopping further requests/cycles, and explicit ambient stop still winning after config=true. The real-loop, config-gate, and schedule-service regressions pass.

Both full copy-badge cohorts passed: sixteen rendering tests with default config and sixteen with Unicode Alt label ⌥, including right-margin reservation and full-width-line truncation. No native macOS run is claimed.

@1jehuang
1jehuang merged commit 7d25a56 into master Sep 19, 2026
3 checks passed
@greptile-apps

greptile-apps Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 2/5

Not safe to merge until the workflow configuration is parseable and downloaded embedding assets are pinned and integrity-checked. The ambient comment issue is non-blocking but should be corrected for accurate maintenance guidance.

Findings

  1. P1 Merge environment maps ▶
  2. P1 Security Pin model downloads ▶
  3. P2 Correct reload timing ▶
Fix with agent prompt
### Issue 1
.github/workflows/ci.yml:3-4
This workflow declares `env` twice at the top level, so GitHub Actions cannot parse it and none of its jobs can start. Merge `JCODE_CI` into the existing environment map. The same parse-breaking duplicate exists in `ios-testflight.yml` and `windows-smoke.yml`, so their environment maps also need to be consolidated before merging.

### Issue 2
.github/workflows/ci.yml:259-265
The embedding job downloads `model.onnx` and `tokenizer.json` from mutable `resolve/main` URLs, checks only that they are nonempty, and then loads them into the tokenizer and ONNX inference stack. An upstream replacement or compromise can therefore make CI process arbitrary replacement bytes. Pin reviewed immutable revisions and verify checked-in cryptographic checksums before loading either artifact.

**How this was verified:** A nonempty malformed model passed the workflow's existence check and reached the ONNX parser, while the configured URLs use mutable branch references without integrity verification.

### Issue 3
crates/jcode-app-core/src/ambient/runner.rs:31-32
This comment promises that configuration edits take effect on the next wake, but production configuration reads may return the cached value for up to 500 ms. A wake immediately after an edit can therefore still use the old `ambient.enabled` setting. This is a non-blocking documentation concern, but leaving it inaccurate can cause future lifecycle code and tests to rely on a timing guarantee the implementation does not provide.

```suggestion
/// Re-read enabled on each loop iteration, without overriding an explicit stop.
/// Config edits take effect after the config cache refreshes on a subsequent wake.
```

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

This change introduces two merge-blocking CI problems: three workflow files redeclare their top-level environment map, preventing the workflows from parsing, and the embedding check loads mutable, unverified external model files. The ambient configuration documentation also promises an immediate refresh that production caching does not provide.

Reviews (1) · Last reviewed commit: "test: verify running ambient loop observ..."

Comment thread .github/workflows/ci.yml
Comment on lines +3 to +4
env:
JCODE_CI: "1"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Merge environment maps

This workflow declares env twice at the top level, so GitHub Actions cannot parse it and none of its jobs can start. Merge JCODE_CI into the existing environment map. The same parse-breaking duplicate exists in ios-testflight.yml and windows-smoke.yml, so their environment maps also need to be consolidated before merging.

Artifacts

Evidence from the check

  • Ruby/Psych AST source checks the three requested workflow roots without Hash-loading duplicate keys, providing a reproducible detector.

Command output from the check

  • Captured execution of the detector from `/home/user/repo` reports all three duplicate `env` keys and exit code 1, confirming the finding.

View artifacts

T-Rex Ran code and verified through T-Rex

Prompt To Fix With AI
This is a comment left during a code review.
Path: .github/workflows/ci.yml
Line: 3-4

Comment:
**Merge environment maps**

This workflow declares `env` twice at the top level, so GitHub Actions cannot parse it and none of its jobs can start. Merge `JCODE_CI` into the existing environment map. The same parse-breaking duplicate exists in `ios-testflight.yml` and `windows-smoke.yml`, so their environment maps also need to be consolidated before merging.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Comment thread .github/workflows/ci.yml
Comment on lines +259 to +265
base="https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2/resolve/main"
curl -sSfL --retry 3 -o "$model_dir/model.onnx" "$base/onnx/model.onnx"
curl -sSfL --retry 3 -o "$model_dir/tokenizer.json" "$base/tokenizer.json"
# Fail loudly if the fetch produced something unusable, so this cannot
# degrade back into a silent skip.
test -s "$model_dir/model.onnx"
test -s "$model_dir/tokenizer.json"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 security Pin model downloads

The embedding job downloads model.onnx and tokenizer.json from mutable resolve/main URLs, checks only that they are nonempty, and then loads them into the tokenizer and ONNX inference stack. An upstream replacement or compromise can therefore make CI process arbitrary replacement bytes. Pin reviewed immutable revisions and verify checked-in cryptographic checksums before loading either artifact.

How this was verified: A nonempty malformed model passed the workflow's existence check and reached the ONNX parser, while the configured URLs use mutable branch references without integrity verification.

Artifacts

Evidence from the check

  • The executed shell verifier inspects the CI fetch and consumer path, injects a malformed nonempty model, and runs the actual numeric-stability test; it demonstrates that existence checks do not provide integrity.

Command output from the check

  • Complete captured output from the verifier run shows the mutable URLs, absent cryptographic check, parser failure for a malformed nonempty ONNX file, and passing execution with currently downloaded artifacts; it confirms unverified bytes reach the parser.

View artifacts

T-Rex Ran code and verified through T-Rex

Prompt To Fix With AI
This is a comment left during a code review.
Path: .github/workflows/ci.yml
Line: 259-265

Comment:
**Pin model downloads**

The embedding job downloads `model.onnx` and `tokenizer.json` from mutable `resolve/main` URLs, checks only that they are nonempty, and then loads them into the tokenizer and ONNX inference stack. An upstream replacement or compromise can therefore make CI process arbitrary replacement bytes. Pin reviewed immutable revisions and verify checked-in cryptographic checksums before loading either artifact.

**How this was verified:** A nonempty malformed model passed the workflow's existence check and reached the ONNX parser, while the configured URLs use mutable branch references without integrity verification.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Comment on lines +31 to +32
/// Re-read enabled on each loop iteration, without overriding an explicit stop.
/// Config edits take effect on the next wake, not on the config cache's cadence.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Correct reload timing

This comment promises that configuration edits take effect on the next wake, but production configuration reads may return the cached value for up to 500 ms. A wake immediately after an edit can therefore still use the old ambient.enabled setting. This is a non-blocking documentation concern, but leaving it inaccurate can cause future lifecycle code and tests to rely on a timing guarantee the implementation does not provide.

Suggested change
/// Re-read enabled on each loop iteration, without overriding an explicit stop.
/// Config edits take effect on the next wake, not on the config cache's cadence.
/// Re-read enabled on each loop iteration, without overriding an explicit stop.
/// Config edits take effect after the config cache refreshes on a subsequent wake.
Artifacts

Evidence from the check

  • Authored shell script builds and runs a non-test cache probe before and after the 500 ms interval, then runs the focused ambient runner reload test; it demonstrates the timing comparison.

Command output from the check

  • Executed non-test probe warmed the disabled config cache, edited the file to enabled, and immediately re-read it; it shows the old false value remains visible.

Command output from the check

  • Executed the same non-test probe after a 550 ms delay; it shows the edited true value is reloaded after the production cache cadence.

Command output from the check

  • Executed the focused ambient runner unit test without explicit cache invalidation; it passes, but the test build uses the zero-duration cache interval and therefore does not prove production next-wake timing.

View artifacts

T-Rex Ran code and verified through T-Rex

Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-app-core/src/ambient/runner.rs
Line: 31-32

Comment:
**Correct reload timing**

This comment promises that configuration edits take effect on the next wake, but production configuration reads may return the cached value for up to 500 ms. A wake immediately after an edit can therefore still use the old `ambient.enabled` setting. This is a non-blocking documentation concern, but leaving it inaccurate can cause future lifecycle code and tests to rely on a timing guarantee the implementation does not provide.

```suggestion
/// Re-read enabled on each loop iteration, without overriding an explicit stop.
/// Config edits take effect after the config cache refreshes on a subsequent wake.
```

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@greptile-apps

greptile-apps Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Comments Outside Diff

These findings sit on lines the diff does not cover, so they could not be posted inline. Each one leaves this list once its file changes.

  • P1 Three GitHub Actions workflows redeclare the top-level env key ▶

    • Bug
      • The focused YAML AST detector found duplicate top-level env mapping keys in .github/workflows/ci.yml (lines 3, 16), .github/workflows/ios-testflight.yml (lines 3, 18), and .github/workflows/windows-smoke.yml (lines 3, 23).
    • Cause
      • Each workflow defines a new top-level env: block instead of merging all required environment variables into the existing top-level env mapping.
    • Fix
      • Merge JCODE_CI and the later workflow-specific variables into one top-level env mapping in each affected workflow.
  • P1 CI parses mutable, unverified Hugging Face model artifacts ▶

    • Bug
      • The embedding cohort downloads model.onnx and tokenizer.json from https://huggingface.co/.../resolve/main, checks only that the files are nonempty, then invokes test code that parses the tokenizer JSON and ONNX model. resolve/main is not a commit-pinned immutable reference, and the fetch block has no hash, signature, or digest verification. Consequently, an upstream artifact change or compromise can cause arbitrary replacement model/tokenizer bytes to be processed by the CI parser/inference stack.
    • Cause
      • Workflow lines 259-265 use a mutable branch URL and test -s checks instead of a pinned revision plus cryptographic verification.
    • Fix
      • Pin both downloads to a reviewed immutable Hugging Face commit revision and verify each file against checked-in SHA-256 digests before running the embedding tests. Fail before invoking Rust test code on any mismatch.
  • P2 Ambient runner comment incorrectly promises edits take effect on the next wake ▶

    • Bug
      • ambient_allowed() calls the reloadable global config(), whose production fast path returns the prior snapshot when less than 500 ms has elapsed since the last fingerprint check. Consequently, a wake/nudge immediately after editing config.toml can observe the old ambient.enabled value. The included runner test does not disprove this because the cache interval is explicitly zero under cfg(test).
    • Cause
      • crates/jcode-base/src/config.rs sets CONFIG_CACHE_CHECK_INTERVAL to 500 ms outside tests; crates/jcode-app-core/src/ambient/runner.rs does not invalidate or bypass that cache before calling ambient_allowed().
    • Fix
      • Revise the comment to state that edits are observed on a wake after the config cache's next check (up to 500 ms), or explicitly invalidate/check config on the config-edit notification path if next-wake semantics are required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants