Hello @luis-patino, I took a look at both internal and external documentation and here is what I found.
Short version: your reading of the source holds up as far as I could verify it. The 403 comes from the credential the Feature Engineering client attaches to its Unity Catalog REST call. It isn't a problem with your stream or your tables. Spark-native reads and writes don't use that credential, which is why they keep working.
On DBR 16.4 (bundled MLflow 2.21.3), MLflow's credential helper checks environment variables first and then a dynamic provider. That provider tries the REPL context's apiToken before the path that refreshes. MLflow's own code comment says the command-context token "is not refreshed." Rebuilding the client doesn't help because the same stale token is resolved again. The Knowledge Base documents the same kind of failure: dbutils tokens in long-running streams expire, return "403 Invalid access token," and their lifetime can't be extended. That article cites 48 hours for dbutils. I couldn't find a public source for the roughly 30-day lifetime you're seeing.
Taking your questions in order:
1. Token lifetime and refreshable credentials. The lifetime of the command-context token isn't publicly documented. I also couldn't find a supported way to point the Feature Engineering REST calls at OAuth M2M or the SDK default chain. This looks like a product gap, so I'd open a support ticket. Your source analysis plus the failure timestamps make a strong case.
2. write_table inside foreachBatch. Functionally it works. foreachBatch hands write_table a batch DataFrame, so it runs a normal merge. The documented streaming pattern is to pass the streaming DataFrame directly with mode="merge", checkpoint_location, and trigger, and write_table then returns a StreamingQuery. I couldn't confirm that the direct path uses a different credential, though, so I wouldn't switch patterns expecting it to fix this.
3. Replacing write_table with a native Delta MERGE. This is supported, and it's the most practical fix for the streaming path. Any Unity Catalog Delta table with a primary key constraint is a feature table, and the docs say you can write to it like any other Delta table.
- Schema evolution: you can run ALTER TABLE ... ADD COLUMNS first and then MERGE. Or, on DBR 15.4 LTS and above, use MERGE WITH SCHEMA EVOLUTION in SQL or .withSchemaEvolution() in Python. Worth flagging: the mergeSchema write option is for append and overwrite writes, not MERGE.
- Layout tuning: for tables with a timeseries key, write_table keeps existing liquid clustering or Z-order and otherwise Z-orders the table after each write. With a native MERGE you'd run OPTIMIZE yourself or rely on liquid clustering.
- Producer metadata: the docs say feature table metadata tracks the notebooks and jobs that wrote to the table, but they don't say whether native Delta writes are captured. If that matters to you, keep write_table in any short batch jobs and use the native MERGE only in the continuous stream.
- Don't change the primary key, partition key, or the name or type of existing features. The docs warn that this breaks downstream training and serving.
4. Fixed versions. I went through the Feature Engineering release notes from 0.10 through 0.18.4. None of them mention authentication, tokens, or 403 errors, so I don't see a fix to upgrade to yet.
One more guardrail: run the stream as a continuous job with task retry mode set to On failure. Continuous jobs retry without limit and resume from the checkpoint, so an unexpected failure costs you a restart rather than an outage.
The links below are to the AWS docs, since the thread doesn't say which cloud you're on.
References
- Feature tables in Unity Catalog: https://docs.databricks.com/aws/en/machine-learning/feature-store/uc/feature-tables-uc
- Feature Store concepts (feature table metadata): https://docs.databricks.com/aws/en/machine-learning/feature-store/concepts
- FeatureEngineeringClient.write_table API reference: https://api-docs.databricks.com/python/feature-engineering/latest/feature_engineering.client.html
- KB, Job fails with invalid access token: https://kb.databricks.com/en_US/jobs/job-fails-invalid-access-token
- MLflow 2.21.3 credential resolution source: https://github.com/mlflow/mlflow/blob/v2.21.3/mlflow/utils/databricks_utils.py
- foreachBatch and MERGE in Structured Streaming: https://docs.databricks.com/aws/en/structured-streaming/foreach
- Delta schema evolution (ADD COLUMNS, MERGE WITH SCHEMA EVOLUTION): https://docs.databricks.com/aws/en/delta/update-schema
- Continuous jobs: https://docs.databricks.com/aws/en/jobs/continuous
- Feature Engineering release notes: https://docs.databricks.com/aws/en/release-notes/feature-store/databricks-feature-store
If you found this answer helpful please check off "Accept as Solutions" so that others can have confidence in the answer.
Cheers, Lou.